From 64599316d5885223af12c67c9261a8d490729786 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 16 Mar 2024 10:56:55 -0400 Subject: [PATCH] Eliminate final admin theme Liquid resources - Update admin.js with new field IDs --- src/MyWebLog/Handlers/Admin.fs | 2 +- src/MyWebLog/Handlers/Helpers.fs | 9 +- src/MyWebLog/Handlers/Page.fs | 15 +- src/MyWebLog/Handlers/Post.fs | 15 +- src/MyWebLog/Views/Helpers.fs | 8 + src/admin-theme/_edit-common.liquid | 38 --- src/admin-theme/_layout.liquid | 80 ------ src/admin-theme/layout-bare.liquid | 5 - src/admin-theme/layout-partial.liquid | 5 - src/admin-theme/layout.liquid | 17 -- src/admin-theme/page-edit.liquid | 82 ------- src/admin-theme/post-edit.liquid | 341 -------------------------- src/admin-theme/wwwroot/admin.js | 18 +- 13 files changed, 25 insertions(+), 610 deletions(-) delete mode 100644 src/admin-theme/_edit-common.liquid delete mode 100644 src/admin-theme/_layout.liquid delete mode 100644 src/admin-theme/layout-bare.liquid delete mode 100644 src/admin-theme/layout-partial.liquid delete mode 100644 src/admin-theme/layout.liquid delete mode 100644 src/admin-theme/page-edit.liquid delete mode 100644 src/admin-theme/post-edit.liquid diff --git a/src/MyWebLog/Handlers/Admin.fs b/src/MyWebLog/Handlers/Admin.fs index 2446197..fefd983 100644 --- a/src/MyWebLog/Handlers/Admin.fs +++ b/src/MyWebLog/Handlers/Admin.fs @@ -384,7 +384,7 @@ module Theme = if ctx.Request.HasFormContentType && ctx.Request.Form.Files.Count > 0 then let themeFile = Seq.head ctx.Request.Form.Files match deriveIdFromFileName themeFile.FileName with - | Ok themeId when themeId <> adminTheme -> + | Ok themeId when themeId <> ThemeId "admin" -> let data = ctx.Data let! exists = data.Theme.Exists themeId let isNew = not exists diff --git a/src/MyWebLog/Handlers/Helpers.fs b/src/MyWebLog/Handlers/Helpers.fs index 74cd160..13a0501 100644 --- a/src/MyWebLog/Handlers/Helpers.fs +++ b/src/MyWebLog/Handlers/Helpers.fs @@ -355,13 +355,6 @@ let themedView template next ctx hash = task { return! viewForTheme (hash[ViewContext.WebLog] :?> WebLog).ThemeId template next ctx hash } -/// The ID for the admin theme -let adminTheme = ThemeId "admin" - -/// Display a bare view for the admin theme -let adminBareView template = - bareForTheme adminTheme template - /// Display a page for an admin endpoint let adminPage pageTitle includeCsrf next ctx (content: AppViewContext -> XmlNode list) = task { let! messages = getCurrentMessages ctx @@ -416,7 +409,7 @@ let someTask<'T> (it: 'T) = Task.FromResult(Some it) /// Create an absolute URL from a string that may already be an absolute URL let absoluteUrl (url: string) (ctx: HttpContext) = - if url.StartsWith "http" then url else ctx.WebLog.AbsoluteUrl (Permalink url) + if url.StartsWith "http" then url else ctx.WebLog.AbsoluteUrl(Permalink url) open MyWebLog.Data diff --git a/src/MyWebLog/Handlers/Page.fs b/src/MyWebLog/Handlers/Page.fs index 070976c..2d23bc1 100644 --- a/src/MyWebLog/Handlers/Page.fs +++ b/src/MyWebLog/Handlers/Page.fs @@ -115,18 +115,9 @@ let private findPageRevision pgId revDate (ctx: HttpContext) = task { let previewRevision (pgId, revDate) : HttpHandler = requireAccess Author >=> fun next ctx -> task { match! findPageRevision pgId revDate ctx with | Some pg, Some rev when canEdit pg.AuthorId ctx -> - return! {| - content = - [ """
""" - rev.Text.AsHtml() |> addBaseToRelativeUrls ctx.WebLog.ExtraPath - "
" - ] - |> String.concat "" - |} - |> makeHash |> adminBareView "" next ctx + return! adminBarePage "" false next ctx (Views.Helpers.commonPreview rev) | Some _, Some _ -> return! Error.notAuthorized next ctx - | None, _ - | _, None -> return! Error.notFound next ctx + | None, _ | _, None -> return! Error.notFound next ctx } // POST /admin/page/{id}/revision/{revision-date}/restore @@ -150,7 +141,7 @@ let deleteRevision (pgId, revDate) : HttpHandler = requireAccess Author >=> fun | Some pg, Some rev when canEdit pg.AuthorId ctx -> do! ctx.Data.Page.Update { pg with Revisions = pg.Revisions |> List.filter (fun r -> r.AsOf <> rev.AsOf) } do! addMessage ctx { UserMessage.Success with Message = "Revision deleted successfully" } - return! adminBareView "" next ctx (makeHash {| content = "" |}) + return! adminBarePage "" false next ctx (fun _ -> []) | Some _, Some _ -> return! Error.notAuthorized next ctx | None, _ | _, None -> return! Error.notFound next ctx diff --git a/src/MyWebLog/Handlers/Post.fs b/src/MyWebLog/Handlers/Post.fs index 6b8fec5..216cb8d 100644 --- a/src/MyWebLog/Handlers/Post.fs +++ b/src/MyWebLog/Handlers/Post.fs @@ -358,18 +358,9 @@ let private findPostRevision postId revDate (ctx: HttpContext) = task { let previewRevision (postId, revDate) : HttpHandler = requireAccess Author >=> fun next ctx -> task { match! findPostRevision postId revDate ctx with | Some post, Some rev when canEdit post.AuthorId ctx -> - return! {| - content = - [ """
""" - rev.Text.AsHtml() |> addBaseToRelativeUrls ctx.WebLog.ExtraPath - "
" - ] - |> String.concat "" - |} - |> makeHash |> adminBareView "" next ctx + return! adminBarePage "" false next ctx (Views.Helpers.commonPreview rev) | Some _, Some _ -> return! Error.notAuthorized next ctx - | None, _ - | _, None -> return! Error.notFound next ctx + | None, _ | _, None -> return! Error.notFound next ctx } // POST /admin/post/{id}/revision/{revision-date}/restore @@ -393,7 +384,7 @@ let deleteRevision (postId, revDate) : HttpHandler = requireAccess Author >=> fu | Some post, Some rev when canEdit post.AuthorId ctx -> do! ctx.Data.Post.Update { post with Revisions = post.Revisions |> List.filter (fun r -> r.AsOf <> rev.AsOf) } do! addMessage ctx { UserMessage.Success with Message = "Revision deleted successfully" } - return! adminBareView "" next ctx (makeHash {| content = "" |}) + return! adminBarePage "" false next ctx (fun _ -> []) | Some _, Some _ -> return! Error.notAuthorized next ctx | None, _ | _, None -> return! Error.notFound next ctx diff --git a/src/MyWebLog/Views/Helpers.fs b/src/MyWebLog/Views/Helpers.fs index 6ddfdc0..cf4d716 100644 --- a/src/MyWebLog/Views/Helpers.fs +++ b/src/MyWebLog/Views/Helpers.fs @@ -393,6 +393,14 @@ let commonMetaItems (model: EditCommonModel) = ] +/// Revision preview template +let commonPreview (rev: Revision) app = + div [ _class "mwl-revision-preview mb-3" ] [ + rev.Text.AsHtml() |> addBaseToRelativeUrls app.WebLog.ExtraPath |> raw + ] + |> List.singleton + + /// Form to manage permalinks for pages or posts let managePermalinks (model: ManagePermalinksModel) app = [ let baseUrl = relUrl app $"admin/{model.Entity}/" diff --git a/src/admin-theme/_edit-common.liquid b/src/admin-theme/_edit-common.liquid deleted file mode 100644 index e72622b..0000000 --- a/src/admin-theme/_edit-common.liquid +++ /dev/null @@ -1,38 +0,0 @@ -
- - -
-
- - - {%- unless model.is_new %} - {%- assign entity_url_base = "admin/" | append: entity | append: "/" | append: entity_id -%} - - Manage Permalinks - - Manage Revisions - {% if model.chapter_source == "internal" %} - - - Manage Chapters - - {% endif %} - - {%- endunless -%} -
-
-     -
- - - - -
-
-
- -
diff --git a/src/admin-theme/_layout.liquid b/src/admin-theme/_layout.liquid deleted file mode 100644 index 440acea..0000000 --- a/src/admin-theme/_layout.liquid +++ /dev/null @@ -1,80 +0,0 @@ -
- -
-
-
- {% for msg in messages %} - - {% endfor %} -
-
-
-

Loading…

- {{ content }} -
- diff --git a/src/admin-theme/layout-bare.liquid b/src/admin-theme/layout-bare.liquid deleted file mode 100644 index 4335d8d..0000000 --- a/src/admin-theme/layout-bare.liquid +++ /dev/null @@ -1,5 +0,0 @@ - - - -{{ content }} - diff --git a/src/admin-theme/layout-partial.liquid b/src/admin-theme/layout-partial.liquid deleted file mode 100644 index fe06a41..0000000 --- a/src/admin-theme/layout-partial.liquid +++ /dev/null @@ -1,5 +0,0 @@ - - - {{ page_title | strip_html }} « Admin « {{ web_log.name | strip_html }} - {% include_template "_layout" %} - diff --git a/src/admin-theme/layout.liquid b/src/admin-theme/layout.liquid deleted file mode 100644 index 264428c..0000000 --- a/src/admin-theme/layout.liquid +++ /dev/null @@ -1,17 +0,0 @@ - - - - - {{ page_title | strip_html }} « Admin « {{ web_log.name | strip_html }} - - - - {% include_template "_layout" %} - - {{ htmx_script }} - - - diff --git a/src/admin-theme/page-edit.liquid b/src/admin-theme/page-edit.liquid deleted file mode 100644 index 715ec05..0000000 --- a/src/admin-theme/page-edit.liquid +++ /dev/null @@ -1,82 +0,0 @@ -

{{ page_title }}

-
-
- - -
-
-
- {%- assign entity = "page" -%} - {%- assign entity_id = model.page_id -%} - {% include_template "_edit-common" %} -
-
-
- - -
-
- - -
-
-
-
-
- -
-
-
-
-
- - Metadata - - -
-
- {%- for meta in metadata %} -
-
- -
-
-
- - -
-
-
-
- - -
-
-
- {% endfor -%} -
- - -
-
-
-
-
-
-
diff --git a/src/admin-theme/post-edit.liquid b/src/admin-theme/post-edit.liquid deleted file mode 100644 index 03dcdd7..0000000 --- a/src/admin-theme/post-edit.liquid +++ /dev/null @@ -1,341 +0,0 @@ -

{{ page_title }}

-
-
- - -
-
-
- {%- assign entity = "post" -%} - {%- assign entity_id = model.post_id -%} - {% include_template "_edit-common" %} -
- - -
comma-delimited
-
- {% if model.status == "Draft" %} -
- - -
- {% endif %} - -
-
- - - - - - - - -
-
-
-
- - -
- Relative URL will be appended to base media path (if set) or served from this web log -
-
-
-
-
- - -
Optional; overrides podcast default
-
-
-
-
-
-
- - -
TODO: derive from above file name
-
-
-
-
- - -
Recommended; enter in HH:MM:SS format
-
-
-
-
-
-
- - -
Optional; a subtitle for this episode
-
-
-
-
-
-
- - -
- Optional; overrides podcast default; relative URL served from this web log -
-
-
-
-
- - -
Optional; overrides podcast default
-
-
-
-
-
-
Chapters
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
-
-
-
-
- - -
Relative URL served from this web log
-
-
-
-
- - -
- Optional; application/json+chapters assumed if chapter file ends with - .json -
-
-
-
-
-
-
- - -
Optional; relative URL served from this web log
-
-
-
-
- - -
Required if transcript URL provided
-
-
-
-
-
-
- - -
Optional; overrides podcast default
-
-
-
-
- - -
-
-
-
-
-
- - -
Optional
-
-
-
-
- - -
Optional
-
-
-
-
-
-
- - -
Optional; up to 2 decimal points
-
-
-
-
- - -
Optional
-
-
-
-
- -
-
- - Metadata - - -
-
- {%- for meta in metadata %} -
-
- -
-
-
- - -
-
-
-
- - -
-
-
- {% endfor -%} -
- - -
-
- {% if model.status == "Published" %} -
- Maintenance -
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
-
-
- {% endif %} -
-
-
- - -
-
- Categories - {% for cat in categories %} -
- - -
- {% endfor %} -
-
-
-
-
-
- diff --git a/src/admin-theme/wwwroot/admin.js b/src/admin-theme/wwwroot/admin.js index 7edc1e5..989065c 100644 --- a/src/admin-theme/wwwroot/admin.js +++ b/src/admin-theme/wwwroot/admin.js @@ -217,13 +217,13 @@ this.Admin = { * @param {"none"|"internal"|"external"} src The source for chapters for this episode */ setChapterSource(src) { - document.getElementById("containsWaypoints").disabled = src === "none" + document.getElementById("ContainsWaypoints").disabled = src === "none" const isDisabled = src === "none" || src === "internal" - const chapterFile = document.getElementById("chapterFile") + const chapterFile = document.getElementById("ChapterFile") chapterFile.disabled = isDisabled chapterFile.required = !isDisabled - document.getElementById("chapterType").disabled = isDisabled - const link = document.getElementById("chapterEditLink") + document.getElementById("ChapterType").disabled = isDisabled + const link = document.getElementById("ChapterEditLink") if (link) link.style.display = src === "none" || src === "external" ? "none" : "" }, @@ -231,13 +231,13 @@ this.Admin = { * Enable or disable podcast fields */ toggleEpisodeFields() { - const disabled = !document.getElementById("isEpisode").checked + const disabled = !document.getElementById("IsEpisode").checked let fields = [ - "media", "mediaType", "length", "duration", "subtitle", "imageUrl", "explicit", "transcriptUrl", "transcriptType", - "transcriptLang", "transcriptCaptions", "seasonNumber", "seasonDescription", "episodeNumber", "episodeDescription" + "Media", "MediaType", "Length", "Duration", "Subtitle", "ImageUrl", "Explicit", "TranscriptUrl", "TranscriptType", + "TranscriptLang", "TranscriptCaptions", "SeasonNumber", "SeasonDescription", "EpisodeNumber", "EpisodeDescription" ] if (disabled) { - fields.push("chapterFile", "chapterType", "containsWaypoints") + fields.push("ChapterFile", "ChapterType", "ContainsWaypoints") } else { const src = [...document.getElementsByName("ChapterSource")].filter(it => it.checked)[0].value this.setChapterSource(src) @@ -302,7 +302,7 @@ this.Admin = { * Require transcript type if transcript URL is present */ requireTranscriptType() { - document.getElementById("transcriptType").required = document.getElementById("transcriptUrl").value.trim() !== "" + document.getElementById("TranscriptType").required = document.getElementById("TranscriptUrl").value.trim() !== "" }, /**