From cac7b1d9b536572b7c937032c067a3847e502b3e Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Wed, 13 Mar 2024 21:31:15 -0400 Subject: [PATCH] Migrate page list template to GVE - Update chapter field names in admin.js --- src/MyWebLog/Handlers/Page.fs | 22 ++++----- src/MyWebLog/Handlers/Routes.fs | 2 +- src/MyWebLog/MyWebLog.fsproj | 1 + src/MyWebLog/Views/Page.fs | 84 ++++++++++++++++++++++++++++++++ src/admin-theme/page-list.liquid | 75 ---------------------------- src/admin-theme/wwwroot/admin.js | 2 +- 6 files changed, 96 insertions(+), 90 deletions(-) create mode 100644 src/MyWebLog/Views/Page.fs delete mode 100644 src/admin-theme/page-list.liquid diff --git a/src/MyWebLog/Handlers/Page.fs b/src/MyWebLog/Handlers/Page.fs index 5cf619b..9563b94 100644 --- a/src/MyWebLog/Handlers/Page.fs +++ b/src/MyWebLog/Handlers/Page.fs @@ -9,19 +9,15 @@ open MyWebLog.ViewModels // GET /admin/pages/page/{pageNbr} let all pageNbr : HttpHandler = requireAccess Author >=> fun next ctx -> task { let! pages = ctx.Data.Page.FindPageOfPages ctx.WebLog.Id pageNbr + let displayPages = + pages + |> Seq.ofList + |> Seq.truncate 25 + |> Seq.map (DisplayPage.FromPageMinimal ctx.WebLog) + |> List.ofSeq return! - hashForPage "Pages" - |> withAntiCsrf ctx - |> addToHash "pages" (pages - |> Seq.ofList - |> Seq.truncate 25 - |> Seq.map (DisplayPage.FromPageMinimal ctx.WebLog) - |> List.ofSeq) - |> addToHash "page_nbr" pageNbr - |> addToHash "prev_page" (if pageNbr = 2 then "" else $"/page/{pageNbr - 1}") - |> addToHash "has_next" (List.length pages > 25) - |> addToHash "next_page" $"/page/{pageNbr + 1}" - |> adminView "page-list" next ctx + Views.Page.pageList displayPages pageNbr (pages.Length > 25) + |> adminPage "Pages" true next ctx } // GET /admin/page/{id}/edit @@ -51,7 +47,7 @@ let edit pgId : HttpHandler = requireAccess Author >=> fun next ctx -> task { | None -> return! Error.notFound next ctx } -// POST /admin/page/{id}/delete +// DELETE /admin/page/{id} let delete pgId : HttpHandler = requireAccess WebLogAdmin >=> fun next ctx -> task { match! ctx.Data.Page.Delete (PageId pgId) ctx.WebLog.Id with | true -> diff --git a/src/MyWebLog/Handlers/Routes.fs b/src/MyWebLog/Handlers/Routes.fs index f0db9ca..87fe4e5 100644 --- a/src/MyWebLog/Handlers/Routes.fs +++ b/src/MyWebLog/Handlers/Routes.fs @@ -175,7 +175,6 @@ let router : HttpHandler = choose [ subRoute "/page" (choose [ route "/save" >=> Page.save route "/permalinks" >=> Page.savePermalinks - routef "/%s/delete" Page.delete routef "/%s/revision/%s/restore" Page.restoreRevision ]) subRoute "/post" (choose [ @@ -211,6 +210,7 @@ let router : HttpHandler = choose [ ] DELETE >=> validateCsrf >=> choose [ subRoute "/page" (choose [ + routef "/%s" Page.delete routef "/%s/revision/%s" Page.deleteRevision routef "/%s/revisions" Page.purgeRevisions ]) diff --git a/src/MyWebLog/MyWebLog.fsproj b/src/MyWebLog/MyWebLog.fsproj index c795441..40b0eb6 100644 --- a/src/MyWebLog/MyWebLog.fsproj +++ b/src/MyWebLog/MyWebLog.fsproj @@ -11,6 +11,7 @@ + diff --git a/src/MyWebLog/Views/Page.fs b/src/MyWebLog/Views/Page.fs new file mode 100644 index 0000000..360858d --- /dev/null +++ b/src/MyWebLog/Views/Page.fs @@ -0,0 +1,84 @@ +module MyWebLog.Views.Page + +open Giraffe.ViewEngine +open Giraffe.ViewEngine.Htmx +open MyWebLog +open MyWebLog.ViewModels + +/// Display a list of pages for this web log +let pageList (pages: DisplayPage list) pageNbr hasNext app = [ + h2 [ _class "my-3" ] [ raw app.PageTitle ] + article [] [ + a [ _href (relUrl app "admin/page/new/edit"); _class "btn btn-primary btn-sm mb-3" ] [ raw "Create a New Page" ] + if pages.Length = 0 then + p [ _class "text-muted fst-italic text-center" ] [ raw "This web log has no pages" ] + else + let titleCol = "col-12 col-md-5" + let linkCol = "col-12 col-md-5" + let upd8Col = "col-12 col-md-2" + form [ _method "post"; _class "container mb-3"; _hxTarget "body" ] [ + antiCsrf app + div [ _class "row mwl-table-heading" ] [ + div [ _class titleCol ] [ + span [ _class "d-none d-md-inline" ] [ raw "Title" ]; span [ _class "d-md-none" ] [ raw "Page" ] + ] + div [ _class $"{linkCol} d-none d-md-inline-block" ] [ raw "Permalink" ] + div [ _class $"{upd8Col} d-none d-md-inline-block" ] [ raw "Updated" ] + ] + for pg in pages do + let pageLink = if pg.IsDefault then "" else pg.Permalink + div [ _class "row mwl-table-detail" ] [ + div [ _class titleCol ] [ + txt pg.Title + if pg.IsDefault then + raw "   "; span [ _class "badge bg-success" ] [ raw "HOME PAGE" ] + if pg.IsInPageList then + raw "   "; span [ _class "badge bg-primary" ] [ raw "IN PAGE LIST" ] + br [] ; small [] [ + let adminUrl = relUrl app $"admin/page/{pg.Id}" + a [ _href (relUrl app pageLink); _target "_blank" ] [ raw "View Page" ] + if app.IsEditor || (app.IsAuthor && app.UserId.Value = WebLogUserId pg.AuthorId) then + span [ _class "text-muted" ] [ raw " • " ] + a [ _href $"{adminUrl}/edit" ] [ raw "Edit" ] + if app.IsWebLogAdmin then + span [ _class "text-muted" ] [ raw " • " ] + a [ _href adminUrl; _hxDelete adminUrl; _class "text-danger" + _hxConfirm $"Are you sure you want to delete the page “{pg.Title}”? This action cannot be undone." ] [ + raw "Delete" + ] + ] + ] + div [ _class linkCol ] [ + small [ _class "d-md-none" ] [ txt pageLink ] + span [ _class "d-none d-md-inline" ] [ txt pageLink ] + ] + div [ _class upd8Col ] [ + small [ _class "d-md-none text-muted" ] [ + raw "Updated "; txt (pg.UpdatedOn.ToString "MMMM d, yyyy") + ] + span [ _class "d-none d-md-inline" ] [ txt (pg.UpdatedOn.ToString "MMMM d, yyyy") ] + ] + ] + ] + if pageNbr > 1 || hasNext then + div [ _class "d-flex justify-content-evenly mb-3" ] [ + div [] [ + if pageNbr > 1 then + let prevPage = if pageNbr = 2 then "" else $"/page/{pageNbr - 1}" + p [] [ + a [ _class "btn btn-secondary"; _href (relUrl app $"admin/pages{prevPage}") ] [ + raw "« Previous" + ] + ] + ] + div [ _class "text-right" ] [ + if hasNext then + p [] [ + a [ _class "btn btn-secondary"; _href (relUrl app $"admin/pages/page/{pageNbr + 1}") ] [ + raw "Next »" + ] + ] + ] + ] + ] +] diff --git a/src/admin-theme/page-list.liquid b/src/admin-theme/page-list.liquid deleted file mode 100644 index 7682f02..0000000 --- a/src/admin-theme/page-list.liquid +++ /dev/null @@ -1,75 +0,0 @@ -

{{ page_title }}

-
- Create a New Page - {%- assign page_count = pages | size -%} - {% if page_count > 0 %} - {%- assign title_col = "col-12 col-md-5" -%} - {%- assign link_col = "col-12 col-md-5" -%} - {%- assign upd8_col = "col-12 col-md-2" -%} -
- -
-
- TitlePage -
- -
Updated
-
- {% for pg in pages -%} -
-
- {{ pg.title }} - {%- if pg.is_default %}   HOME PAGE{% endif -%} - {%- if pg.is_in_page_list %}   IN PAGE LIST {% endif -%}
- - {%- capture pg_link %}{% unless pg.is_default %}{{ pg.permalink }}{% endunless %}{% endcapture -%} - View Page - {% if is_editor or is_author and user_id == pg.author_id %} - - Edit - {% endif %} - {% if is_web_log_admin %} - - {%- assign pg_del_link = "admin/page/" | append: pg.id | append: "/delete" | relative_link -%} - - Delete - - {% endif %} - -
- -
- Updated {{ pg.updated_on | date: "MMMM d, yyyy" }} - {{ pg.updated_on | date: "MMMM d, yyyy" }} -
-
- {%- endfor %} -
- {% if page_nbr > 1 or has_next %} -
-
- {% if page_nbr > 1 %} -

- - « Previous - - {% endif %} -

-
- {% if has_next %} -

- - Next » - - {% endif %} -

-
- {% endif %} - {% else %} -

This web log has no pages

- {% endif %} -
diff --git a/src/admin-theme/wwwroot/admin.js b/src/admin-theme/wwwroot/admin.js index 4867539..4727ca9 100644 --- a/src/admin-theme/wwwroot/admin.js +++ b/src/admin-theme/wwwroot/admin.js @@ -310,7 +310,7 @@ this.Admin = { */ checkChapterLocation() { const isDisabled = !document.getElementById("has_location").checked - ;["location_name", "location_geo", "location_osm"].forEach(it => { + ;["LocationName", "LocationGeo", "LocationOsm"].forEach(it => { const elt = document.getElementById(it) elt.disabled = isDisabled if (isDisabled) elt.value = ""