diff --git a/src/MyWebLog.Data/Data.fs b/src/MyWebLog.Data/Data.fs index 0dbcbf3..a3015c7 100644 --- a/src/MyWebLog.Data/Data.fs +++ b/src/MyWebLog.Data/Data.fs @@ -376,7 +376,7 @@ module Post = let findByPermalink (permalink : Permalink) (webLogId : WebLogId) = rethink { withTable Table.Post - getAll [ r.Array(permalink, webLogId) ] (nameof permalink) + getAll [ r.Array(webLogId, permalink) ] (nameof permalink) without [ "priorPermalinks"; "revisions" ] limit 1 result; withRetryDefault @@ -468,18 +468,12 @@ module WebLog = resultOption; withRetryOptionDefault } - /// Update web log settings + /// Update web log settings (updates all values) let updateSettings (webLog : WebLog) = rethink { withTable Table.WebLog get webLog.id - update [ - "name", webLog.name :> obj - "subtitle", webLog.subtitle - "defaultPage", webLog.defaultPage - "postsPerPage", webLog.postsPerPage - "timeZone", webLog.timeZone - ] + replace webLog write; withRetryDefault; ignoreResult } diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs index c0261de..95ee8d1 100644 --- a/src/MyWebLog.Domain/ViewModels.fs +++ b/src/MyWebLog.Domain/ViewModels.fs @@ -218,6 +218,15 @@ type EditPostModel = /// Values of metadata items metaValues : string[] + + /// Whether to override the published date/time + setPublished : bool + + /// The published date/time to override + pubOverride : Nullable + + /// Whether all revisions should be purged and the override date set as the updated date as well + setUpdated : bool } /// Create an edit model from an existing past static member fromPost (post : Post) = @@ -226,17 +235,20 @@ type EditPostModel = | Some rev -> rev | None -> Revision.empty let post = if post.metadata |> List.isEmpty then { post with metadata = [ MetaItem.empty ] } else post - { postId = PostId.toString post.id - title = post.title - permalink = Permalink.toString post.permalink - source = MarkupText.sourceType latest.text - text = MarkupText.text latest.text - tags = String.Join (", ", post.tags) - categoryIds = post.categoryIds |> List.map CategoryId.toString |> Array.ofList - status = PostStatus.toString post.status - doPublish = false - metaNames = post.metadata |> List.map (fun m -> m.name) |> Array.ofList - metaValues = post.metadata |> List.map (fun m -> m.value) |> Array.ofList + { postId = PostId.toString post.id + title = post.title + permalink = Permalink.toString post.permalink + source = MarkupText.sourceType latest.text + text = MarkupText.text latest.text + tags = String.Join (", ", post.tags) + categoryIds = post.categoryIds |> List.map CategoryId.toString |> Array.ofList + status = PostStatus.toString post.status + doPublish = false + metaNames = post.metadata |> List.map (fun m -> m.name) |> Array.ofList + metaValues = post.metadata |> List.map (fun m -> m.value) |> Array.ofList + setPublished = false + pubOverride = Nullable () + setUpdated = false } @@ -350,7 +362,19 @@ type SettingsModel = /// The time zone in which dates/times should be displayed timeZone : string + + /// The theme to use to display the web log + themePath : string } + /// Create a settings model from a web log + static member fromWebLog (webLog : WebLog) = + { name = webLog.name + subtitle = defaultArg webLog.subtitle "" + defaultPage = webLog.defaultPage + postsPerPage = webLog.postsPerPage + timeZone = webLog.timeZone + themePath = webLog.themePath + } [] diff --git a/src/MyWebLog/Handlers.fs b/src/MyWebLog/Handlers.fs index 79072b9..e34b3ac 100644 --- a/src/MyWebLog/Handlers.fs +++ b/src/MyWebLog/Handlers.fs @@ -197,6 +197,16 @@ module private Helpers = /// Handlers to manipulate admin functions module Admin = + open System.IO + + /// The currently available themes + let private themes () = + Directory.EnumerateDirectories "themes" + |> Seq.map (fun it -> it.Split Path.DirectorySeparatorChar |> Array.last) + |> Seq.filter (fun it -> it <> "admin") + |> Seq.map (fun it -> KeyValuePair.Create (it, it)) + |> Array.ofSeq + // GET /admin let dashboard : HttpHandler = requireUser >=> fun next ctx -> task { let webLogId = webLogId ctx @@ -230,20 +240,16 @@ module Admin = return! Hash.FromAnonymousObject {| csrf = csrfToken ctx - model = - { name = webLog.name - subtitle = defaultArg webLog.subtitle "" - defaultPage = webLog.defaultPage - postsPerPage = webLog.postsPerPage - timeZone = webLog.timeZone - } + model = SettingsModel.fromWebLog webLog pages = seq { KeyValuePair.Create ("posts", "- First Page of Posts -") yield! allPages + |> List.sortBy (fun p -> p.title.ToLower ()) |> List.map (fun p -> KeyValuePair.Create (PageId.toString p.id, p.title)) } |> Array.ofSeq + themes = themes () web_log = webLog page_title = "Web Log Settings" |} @@ -263,6 +269,7 @@ module Admin = defaultPage = model.defaultPage postsPerPage = model.postsPerPage timeZone = model.timeZone + themePath = model.themePath } do! Data.WebLog.updateSettings updated conn @@ -510,8 +517,10 @@ module Post = let permalink = (string >> Permalink) ctx.Request.RouteValues["link"] // Current post match! Data.Post.findByPermalink permalink webLog.id conn with - | Some _ -> return! Error.notFound next ctx - // TODO: return via single-post action + | Some post -> + let! model = preparePostList webLog [ post ] 1 1 conn + model.Add ("page_title", post.title) + return! themedView "single-post" next ctx model | None -> // Current page match! Data.Page.findByPermalink permalink webLog.id conn with @@ -610,10 +619,29 @@ module Post = |> List.ofSeq categoryIds = model.categoryIds |> Array.map CategoryId |> List.ofArray status = if model.doPublish then Published else post.status + metadata = Seq.zip model.metaNames model.metaValues + |> Seq.filter (fun it -> fst it > "") + |> Seq.map (fun it -> { name = fst it; value = snd it }) + |> Seq.sortBy (fun it -> $"{it.name.ToLower ()} {it.value.ToLower ()}") + |> List.ofSeq revisions = match post.revisions |> List.tryHead with | Some r when r.text = revision.text -> post.revisions | _ -> revision :: post.revisions } + let post = + match model.setPublished with + | true -> + let dt = DateTime (model.pubOverride.Value.ToUniversalTime().Ticks, DateTimeKind.Utc) + printf $"**** DateKind = {dt.Kind}" + match model.setUpdated with + | true -> + { post with + publishedOn = Some dt + updatedOn = dt + revisions = [ { (List.head post.revisions) with asOf = dt } ] + } + | false -> { post with publishedOn = Some dt } + | false -> post do! (match model.postId with "new" -> Data.Post.add | _ -> Data.Post.update) post conn do! addMessage ctx { UserMessage.success with message = "Post saved successfully" } return! redirectToGet $"/post/{PostId.toString post.id}/edit" next ctx diff --git a/src/MyWebLog/appsettings.json b/src/MyWebLog/appsettings.json index 5099ff2..3ba3a03 100644 --- a/src/MyWebLog/appsettings.json +++ b/src/MyWebLog/appsettings.json @@ -3,5 +3,5 @@ "hostname": "data02.bitbadger.solutions", "database": "myWebLog-dev" }, - "Generator": "myWebLog 2.0-alpha01" + "Generator": "myWebLog 2.0-alpha02" } diff --git a/src/MyWebLog/themes/admin/category-edit.liquid b/src/MyWebLog/themes/admin/category-edit.liquid index 0e5cc26..5927344 100644 --- a/src/MyWebLog/themes/admin/category-edit.liquid +++ b/src/MyWebLog/themes/admin/category-edit.liquid @@ -8,14 +8,14 @@
+ value="{{ model.name | escape }}">
+ value="{{ model.slug | escape }}">
@@ -41,7 +41,7 @@
+ placeholder="A short description of this category" value="{{ model.description | escape }}">
diff --git a/src/MyWebLog/themes/admin/post-edit.liquid b/src/MyWebLog/themes/admin/post-edit.liquid index 9e9aca0..fcebc1f 100644 --- a/src/MyWebLog/themes/admin/post-edit.liquid +++ b/src/MyWebLog/themes/admin/post-edit.liquid @@ -62,6 +62,85 @@ +
+
+
+ + Metadata + + +
+
+ {%- for meta in model.metadata %} +
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ {% endfor -%} +
+ + +
+
+
+
+ {% if model.status == "Published" %} +
+
+
+ Maintenance +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+
+ {% endif %} diff --git a/src/MyWebLog/themes/admin/post-list.liquid b/src/MyWebLog/themes/admin/post-list.liquid index b22ae1d..6a33ec3 100644 --- a/src/MyWebLog/themes/admin/post-list.liquid +++ b/src/MyWebLog/themes/admin/post-list.liquid @@ -5,7 +5,7 @@ Date - Title + Title Author Status Tags @@ -14,7 +14,7 @@ {% for post in model.posts -%} - + {% if post.published_on.has_value -%} {{ post.published_on | date: "MMMM d, yyyy" }} {%- else -%} @@ -31,9 +31,9 @@ Delete - {{ model.authors | value: post.author_id }} + {{ model.authors | value: post.author_id }} {{ post.status }} - {{ post.tags | join: ", " }} + {{ post.tags | join: ", " }} {%- endfor %} diff --git a/src/MyWebLog/themes/admin/settings.liquid b/src/MyWebLog/themes/admin/settings.liquid index 23ecde2..116536d 100644 --- a/src/MyWebLog/themes/admin/settings.liquid +++ b/src/MyWebLog/themes/admin/settings.liquid @@ -4,7 +4,7 @@
-
+
@@ -16,15 +16,25 @@
-
-
-
+
+
+
+ + +
+
Time Zone
-
+