From f181f83aa55491272bc5940b84b1adc75b10d77d Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 17 Mar 2024 18:30:42 -0400 Subject: [PATCH] Misc admin theme tweaks --- src/MyWebLog/Handlers/Admin.fs | 5 ++++- src/MyWebLog/Handlers/Upload.fs | 11 +++-------- src/MyWebLog/Views/WebLog.fs | 29 ++++++++++++++++------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/MyWebLog/Handlers/Admin.fs b/src/MyWebLog/Handlers/Admin.fs index 8d99828..a482305 100644 --- a/src/MyWebLog/Handlers/Admin.fs +++ b/src/MyWebLog/Handlers/Admin.fs @@ -3,6 +3,7 @@ module MyWebLog.Handlers.Admin open System.Threading.Tasks open Giraffe +open Giraffe.Htmx open MyWebLog open MyWebLog.ViewModels open NodaTime @@ -96,7 +97,9 @@ module Category = // GET /admin/categories let all : HttpHandler = fun next ctx -> - adminPage "Categories" true next ctx (Views.WebLog.categoryList (ctx.Request.Query.ContainsKey "new")) + let response = fun next ctx -> + adminPage "Categories" true next ctx (Views.WebLog.categoryList (ctx.Request.Query.ContainsKey "new")) + (withHxPushUrl (ctx.WebLog.RelativeUrl (Permalink "admin/categories")) >=> response) next ctx // GET /admin/category/{id}/edit let edit catId : HttpHandler = fun next ctx -> task { diff --git a/src/MyWebLog/Handlers/Upload.fs b/src/MyWebLog/Handlers/Upload.fs index a52b037..c992eda 100644 --- a/src/MyWebLog/Handlers/Upload.fs +++ b/src/MyWebLog/Handlers/Upload.fs @@ -127,11 +127,6 @@ let list : HttpHandler = requireAccess Author >=> fun next ctx -> task { let showNew : HttpHandler = requireAccess Author >=> fun next ctx -> adminPage "Upload a File" true next ctx Views.WebLog.uploadNew - -/// Redirect to the upload list -let showUploads : HttpHandler = - redirectToGet "admin/uploads" - // POST /admin/upload/save let save : HttpHandler = requireAccess Author >=> fun next ctx -> task { if ctx.Request.HasFormContentType && ctx.Request.Form.Files.Count > 0 then @@ -162,7 +157,7 @@ let save : HttpHandler = requireAccess Author >=> fun next ctx -> task { do! upload.CopyToAsync stream do! addMessage ctx { UserMessage.Success with Message = $"File uploaded to {form.Destination} successfully" } - return! showUploads next ctx + return! redirectToGet "admin/uploads" next ctx else return! RequestErrors.BAD_REQUEST "Bad request; no file present" next ctx } @@ -172,7 +167,7 @@ let deleteFromDb upId : HttpHandler = fun next ctx -> task { match! ctx.Data.Upload.Delete (UploadId upId) ctx.WebLog.Id with | Ok fileName -> do! addMessage ctx { UserMessage.Success with Message = $"{fileName} deleted successfully" } - return! showUploads next ctx + return! list next ctx | Error _ -> return! Error.notFound next ctx } @@ -195,6 +190,6 @@ let deleteFromDisk urlParts : HttpHandler = fun next ctx -> task { File.Delete path removeEmptyDirectories ctx.WebLog filePath do! addMessage ctx { UserMessage.Success with Message = $"{filePath} deleted successfully" } - return! showUploads next ctx + return! list next ctx else return! Error.notFound next ctx } diff --git a/src/MyWebLog/Views/WebLog.fs b/src/MyWebLog/Views/WebLog.fs index 26bcc9a..793826f 100644 --- a/src/MyWebLog/Views/WebLog.fs +++ b/src/MyWebLog/Views/WebLog.fs @@ -29,7 +29,7 @@ let categoryEdit (model: EditCategoryModel) app = |> Seq.map (fun c -> let parents = c.ParentNames - |> Array.map (fun it -> $"{it}   » ") + |> Array.map (fun it -> $"{it} ⟩ ") |> String.concat "" { Name = c.Id; Value = $"{parents}{c.Name}" }) |> Seq.append [ { Name = ""; Value = "– None –" } ] @@ -74,7 +74,7 @@ let categoryList includeNew app = [ _hxSwap $"{HxSwap.InnerHtml} show:#cat_{cat.Id}:top" ] [ raw "Edit" ]; actionSpacer - a [ _href catUrl; _hxDelete catUrl; _class "text-danger" + a [ _href catUrl; _hxDelete catUrl; _hxTarget "body"; _class "text-danger" _hxConfirm $"Are you sure you want to delete the category “{cat.Name}”? This action cannot be undone." ] [ raw "Delete" ] @@ -109,8 +109,6 @@ let categoryList includeNew app = [ ] ] form [ _method "post"; _class "container" ] [ - // don't think we need this... - // _hxTarget "#catList"; _hxSwap $"{HxSwap.OuterHtml} show:window:top" antiCsrf app div [ _class "row mwl-table-detail"; _id "cat_new" ] [ if includeNew then loadNew ] yield! app.Categories |> Seq.ofArray |> Seq.map categoryDetail |> List.ofSeq @@ -632,7 +630,10 @@ let uploadList (model: DisplayUpload seq) app = [ ] div [ _class "col-3" ] [ raw upload.Path ] div [ _class "col-3" ] [ - raw (match upload.UpdatedOn with Some updated -> updated.ToString "yyyy-MM-dd/HH:mm" | None -> "--") + match upload.UpdatedOn with + | Some updated -> updated.ToString("yyyy-MM-dd/h:mmtt").ToLowerInvariant() + | None -> "--" + |> raw ] ] @@ -680,14 +681,16 @@ let uploadNew app = [ ] ] div [ _class "col-12 col-md-6 pb-3 d-flex align-self-center justify-content-around" ] [ - raw "Destination"; br [] - div [ _class "btn-group"; _roleGroup; _ariaLabel "Upload destination button group" ] [ - input [ _type "radio"; _name "Destination"; _id "destination_db"; _class "btn-check" - _value (string Database); if app.WebLog.Uploads = Database then _checked ] - label [ _class "btn btn-outline-primary"; _for "destination_db" ] [ raw (string Database) ] - input [ _type "radio"; _name "Destination"; _id "destination_disk"; _class "btn-check" - _value (string Disk); if app.WebLog.Uploads= Disk then _checked ] - label [ _class "btn btn-outline-secondary"; _for "destination_disk" ] [ raw "Disk" ] + div [ _class "text-center" ] [ + raw "Destination"; br [] + div [ _class "btn-group"; _roleGroup; _ariaLabel "Upload destination button group" ] [ + input [ _type "radio"; _name "Destination"; _id "destination_db"; _class "btn-check" + _value (string Database); if app.WebLog.Uploads = Database then _checked ] + label [ _class "btn btn-outline-primary"; _for "destination_db" ] [ raw (string Database) ] + input [ _type "radio"; _name "Destination"; _id "destination_disk"; _class "btn-check" + _value (string Disk); if app.WebLog.Uploads= Disk then _checked ] + label [ _class "btn btn-outline-secondary"; _for "destination_disk" ] [ raw "Disk" ] + ] ] ] ]