From 355ade8c874a3e29825a56f3ef9a13e961485061 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Thu, 7 Jul 2022 12:42:37 -0400 Subject: [PATCH] Add slug and upload dest to settings (#2) --- src/MyWebLog.Data/RethinkDbData.fs | 2 + src/MyWebLog.Domain/ViewModels.fs | 10 +++++ src/MyWebLog/Handlers/Admin.fs | 23 ++++++++--- src/admin-theme/settings.liquid | 66 +++++++++++++++++++++--------- 4 files changed, 75 insertions(+), 26 deletions(-) diff --git a/src/MyWebLog.Data/RethinkDbData.fs b/src/MyWebLog.Data/RethinkDbData.fs index 4b653a7..58dc53e 100644 --- a/src/MyWebLog.Data/RethinkDbData.fs +++ b/src/MyWebLog.Data/RethinkDbData.fs @@ -888,12 +888,14 @@ type RethinkDbData (conn : Net.IConnection, config : DataConfig, log : ILogger obj + "slug", webLog.slug "subtitle", webLog.subtitle "defaultPage", webLog.defaultPage "postsPerPage", webLog.postsPerPage "timeZone", webLog.timeZone "themePath", webLog.themePath "autoHtmx", webLog.autoHtmx + "uploads", webLog.uploads ] write; withRetryDefault; ignoreResult conn } diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs index 27a6df9..d12973c 100644 --- a/src/MyWebLog.Domain/ViewModels.fs +++ b/src/MyWebLog.Domain/ViewModels.fs @@ -856,6 +856,9 @@ type SettingsModel = { /// The name of the web log name : string + /// The slug of the web log + slug : string + /// The subtitle of the web log subtitle : string @@ -873,29 +876,36 @@ type SettingsModel = /// Whether to automatically load htmx autoHtmx : bool + + /// The default location for uploads + uploads : string } /// Create a settings model from a web log static member fromWebLog (webLog : WebLog) = { name = webLog.name + slug = webLog.slug subtitle = defaultArg webLog.subtitle "" defaultPage = webLog.defaultPage postsPerPage = webLog.postsPerPage timeZone = webLog.timeZone themePath = webLog.themePath autoHtmx = webLog.autoHtmx + uploads = UploadDestination.toString webLog.uploads } /// Update a web log with settings from the form member this.update (webLog : WebLog) = { webLog with name = this.name + slug = this.slug subtitle = if this.subtitle = "" then None else Some this.subtitle defaultPage = this.defaultPage postsPerPage = this.postsPerPage timeZone = this.timeZone themePath = this.themePath autoHtmx = this.autoHtmx + uploads = UploadDestination.parse this.uploads } diff --git a/src/MyWebLog/Handlers/Admin.fs b/src/MyWebLog/Handlers/Admin.fs index 6342bbd..1a20c68 100644 --- a/src/MyWebLog/Handlers/Admin.fs +++ b/src/MyWebLog/Handlers/Admin.fs @@ -475,11 +475,15 @@ let settings : HttpHandler = fun next ctx -> task { |> List.map (fun p -> KeyValuePair.Create (PageId.toString p.id, p.title)) } |> Array.ofSeq - themes = themes - |> Seq.ofList - |> Seq.map (fun it -> - KeyValuePair.Create (ThemeId.toString it.id, $"{it.name} (v{it.version})")) - |> Array.ofSeq + themes = + themes + |> Seq.ofList + |> Seq.map (fun it -> KeyValuePair.Create (ThemeId.toString it.id, $"{it.name} (v{it.version})")) + |> Array.ofSeq + upload_values = + [| KeyValuePair.Create (UploadDestination.toString Database, "Database") + KeyValuePair.Create (UploadDestination.toString Disk, "Disk") + |] web_log = webLog page_title = "Web Log Settings" |} @@ -493,11 +497,18 @@ let saveSettings : HttpHandler = fun next ctx -> task { let! model = ctx.BindFormAsync () match! data.WebLog.findById webLog.id with | Some webLog -> - let webLog = model.update webLog + let oldSlug = webLog.slug + let webLog = model.update webLog do! data.WebLog.updateSettings webLog // Update cache WebLogCache.set webLog + + if oldSlug <> webLog.slug then + // Rename disk directory if it exists + let uploadRoot = Path.Combine ("wwwroot", "upload") + let oldDir = Path.Combine (uploadRoot, oldSlug) + if Directory.Exists oldDir then Directory.Move (oldDir, Path.Combine (uploadRoot, webLog.slug)) do! addMessage ctx { UserMessage.success with message = "Web log settings saved successfully" } return! redirectToGet (WebLog.relativeUrl webLog (Permalink "admin/settings")) next ctx diff --git a/src/admin-theme/settings.liquid b/src/admin-theme/settings.liquid index 3c49924..444b083 100644 --- a/src/admin-theme/settings.liquid +++ b/src/admin-theme/settings.liquid @@ -8,26 +8,33 @@
-
+
- +
- + + + + WARNING changing this value may break links + (more) + +
+
+
+
+
-
-
- - -
-
-
+
- -
-
-
+
+ +
+
+
+
+
+
+ + +
+
What is this?
+
+
+ + +
+