From d667d09372a3d3c9e757db2ee065dee8cf41a6d2 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Thu, 14 Jul 2022 23:25:29 -0400 Subject: [PATCH] WIP on revision mgt template (#13) --- src/MyWebLog.Domain/ViewModels.fs | 55 +++++++++++++++++++++++++++++ src/MyWebLog/DotLiquidBespoke.fs | 10 +++--- src/MyWebLog/Handlers/Admin.fs | 15 ++++++++ src/admin-theme/revisions.liquid | 58 +++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 src/admin-theme/revisions.liquid diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs index d12973c..8ed5232 100644 --- a/src/MyWebLog.Domain/ViewModels.fs +++ b/src/MyWebLog.Domain/ViewModels.fs @@ -147,6 +147,28 @@ type DisplayPage = } +/// Information about a revision used for display +[] +type DisplayRevision = + { /// The as-of date/time for the revision + asOf : DateTime + + /// The as-of date/time for the revision in the web log's local time zone + asOfLocal : DateTime + + /// The format of the text of the revision + format : string + } +with + + /// Create a display revision from an actual revision + static member fromRevision webLog (rev : Revision) = + { asOf = rev.asOf + asOfLocal = WebLog.localTime webLog rev.asOf + format = MarkupText.sourceType rev.text + } + + open System.IO /// Information about an uploaded file used for display @@ -766,6 +788,39 @@ type ManagePermalinksModel = } +/// View model to manage revisions +[] +type ManageRevisionsModel = + { /// The ID for the entity being edited + id : string + + /// The type of entity being edited ("page" or "post") + entity : string + + /// The current title of the page or post + currentTitle : string + + /// The revisions for the page or post + revisions : DisplayRevision[] + } + + /// Create a revision model from a page + static member fromPage webLog (pg : Page) = + { id = PageId.toString pg.id + entity = "page" + currentTitle = pg.title + revisions = pg.revisions |> List.map (DisplayRevision.fromRevision webLog) |> Array.ofList + } + + /// Create a revision model from a post + static member fromPost webLog (post : Post) = + { id = PostId.toString post.id + entity = "post" + currentTitle = post.title + revisions = post.revisions |> List.map (DisplayRevision.fromRevision webLog) |> Array.ofList + } + + /// View model for posts in a list [] type PostListItem = diff --git a/src/MyWebLog/DotLiquidBespoke.fs b/src/MyWebLog/DotLiquidBespoke.fs index 78786b3..9c25f17 100644 --- a/src/MyWebLog/DotLiquidBespoke.fs +++ b/src/MyWebLog/DotLiquidBespoke.fs @@ -226,11 +226,11 @@ let register () = typeof; typeof; typeof; typeof; typeof typeof; typeof; typeof; typeof // View models - typeof; typeof; typeof; typeof - typeof; typeof; typeof; typeof - typeof; typeof; typeof; typeof - typeof; typeof; typeof; typeof - typeof; typeof + typeof; typeof; typeof; typeof + typeof; typeof; typeof; typeof + typeof; typeof; typeof; typeof + typeof; typeof; typeof; typeof + typeof; typeof; typeof; typeof // Framework types typeof; typeof; typeof; typeof typeof; typeof; typeof; typeof diff --git a/src/MyWebLog/Handlers/Admin.fs b/src/MyWebLog/Handlers/Admin.fs index 1a20c68..4c181d2 100644 --- a/src/MyWebLog/Handlers/Admin.fs +++ b/src/MyWebLog/Handlers/Admin.fs @@ -190,6 +190,21 @@ let savePagePermalinks : HttpHandler = fun next ctx -> task { | false -> return! Error.notFound next ctx } +// GET /admin/page/{id}/revisions +let editPageRevisions pgId : HttpHandler = fun next ctx -> task { + let webLog = ctx.WebLog + match! ctx.Data.Page.findFullById (PageId pgId) webLog.id with + | Some pg -> + return! + Hash.FromAnonymousObject {| + csrf = csrfToken ctx + model = ManageRevisionsModel.fromPage webLog pg + page_title = $"Manage Page Permalinks" + |} + |> viewForTheme "admin" "revisions" next ctx + | None -> return! Error.notFound next ctx +} + // POST /admin/page/{id}/delete let deletePage pgId : HttpHandler = fun next ctx -> task { let webLog = ctx.WebLog diff --git a/src/admin-theme/revisions.liquid b/src/admin-theme/revisions.liquid new file mode 100644 index 0000000..4fe5bcf --- /dev/null +++ b/src/admin-theme/revisions.liquid @@ -0,0 +1,58 @@ +

{{ page_title }}

+
+
+ + +
+
+
+

+ {{ model.current_title }}
+ + {%- capture back_link %}admin/{{ model.entity }}/{{ model.id }}/edit{% endcapture -%} + « Back to Edit {{ model.entity | capitalize }} + +

+
+
+ {%- assign revision_count = model.revisions | size -%} + {%- capture rev_url_base %}admin/{{ model.entity }}/{{ model.id }}/revision{% endcapture -%} + {%- if revision_count > 1 %} + {% capture delete_all %}{{ rev_url_base }}s/purge{% endcapture %} +
+
+ +
+
+ {%- endif %} + {% for rev in model.revisions %} +
+
+ {{ rev.as_of_local | date: "MMMM d, yyyy" }} at {{ rev.as_of_local | date: "h:mmaa" | downcase }} + {{ ref.format }} + {%- if forloop.first %} + Current Revision + {%- endif %}
+ {% unless forloop.first %} + {%- capture rev_url_prefix %}{{ rev_url_base }}/{{ rev.as_of | date: "o" }}{% endcapture -%} + + Preview + + {%- capture rev_restore %}{{ rev_url_prefix }}/restore{% endcapture -%} + {%- capture rev_restore_link %}{{ rev_restore | relative_link }}{% endcapture -%} + Restore as Current + + {%- capture rev_del %}{{ rev_url_prefix }}/delete{% endcapture -%} + {%- capture rev_del_link %}{{ rev_del | relative_link }}{% endcapture -%} + Delete + + {% endunless %} +
+
+ {% endfor %} +
+
+