Version 2.1 #41

Merged
danieljsummers merged 123 commits from version-2.1 into main 2024-03-27 00:13:28 +00:00
3 changed files with 23 additions and 22 deletions
Showing only changes of commit f181f83aa5 - Show all commits

View File

@ -3,6 +3,7 @@ module MyWebLog.Handlers.Admin
open System.Threading.Tasks open System.Threading.Tasks
open Giraffe open Giraffe
open Giraffe.Htmx
open MyWebLog open MyWebLog
open MyWebLog.ViewModels open MyWebLog.ViewModels
open NodaTime open NodaTime
@ -96,7 +97,9 @@ module Category =
// GET /admin/categories // GET /admin/categories
let all : HttpHandler = fun next ctx -> 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 // GET /admin/category/{id}/edit
let edit catId : HttpHandler = fun next ctx -> task { let edit catId : HttpHandler = fun next ctx -> task {

View File

@ -127,11 +127,6 @@ let list : HttpHandler = requireAccess Author >=> fun next ctx -> task {
let showNew : HttpHandler = requireAccess Author >=> fun next ctx -> let showNew : HttpHandler = requireAccess Author >=> fun next ctx ->
adminPage "Upload a File" true next ctx Views.WebLog.uploadNew 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 // POST /admin/upload/save
let save : HttpHandler = requireAccess Author >=> fun next ctx -> task { let save : HttpHandler = requireAccess Author >=> fun next ctx -> task {
if ctx.Request.HasFormContentType && ctx.Request.Form.Files.Count > 0 then 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! upload.CopyToAsync stream
do! addMessage ctx { UserMessage.Success with Message = $"File uploaded to {form.Destination} successfully" } do! addMessage ctx { UserMessage.Success with Message = $"File uploaded to {form.Destination} successfully" }
return! showUploads next ctx return! redirectToGet "admin/uploads" next ctx
else else
return! RequestErrors.BAD_REQUEST "Bad request; no file present" next ctx 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 match! ctx.Data.Upload.Delete (UploadId upId) ctx.WebLog.Id with
| Ok fileName -> | Ok fileName ->
do! addMessage ctx { UserMessage.Success with Message = $"{fileName} deleted successfully" } do! addMessage ctx { UserMessage.Success with Message = $"{fileName} deleted successfully" }
return! showUploads next ctx return! list next ctx
| Error _ -> return! Error.notFound next ctx | Error _ -> return! Error.notFound next ctx
} }
@ -195,6 +190,6 @@ let deleteFromDisk urlParts : HttpHandler = fun next ctx -> task {
File.Delete path File.Delete path
removeEmptyDirectories ctx.WebLog filePath removeEmptyDirectories ctx.WebLog filePath
do! addMessage ctx { UserMessage.Success with Message = $"{filePath} deleted successfully" } do! addMessage ctx { UserMessage.Success with Message = $"{filePath} deleted successfully" }
return! showUploads next ctx return! list next ctx
else return! Error.notFound next ctx else return! Error.notFound next ctx
} }

View File

@ -29,7 +29,7 @@ let categoryEdit (model: EditCategoryModel) app =
|> Seq.map (fun c -> |> Seq.map (fun c ->
let parents = let parents =
c.ParentNames c.ParentNames
|> Array.map (fun it -> $"{it}   » ") |> Array.map (fun it -> $"{it} ⟩ ")
|> String.concat "" |> String.concat ""
{ Name = c.Id; Value = $"{parents}{c.Name}" }) { Name = c.Id; Value = $"{parents}{c.Name}" })
|> Seq.append [ { Name = ""; Value = "– None –" } ] |> Seq.append [ { Name = ""; Value = "– None –" } ]
@ -74,7 +74,7 @@ let categoryList includeNew app = [
_hxSwap $"{HxSwap.InnerHtml} show:#cat_{cat.Id}:top" ] [ _hxSwap $"{HxSwap.InnerHtml} show:#cat_{cat.Id}:top" ] [
raw "Edit" raw "Edit"
]; actionSpacer ]; 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." ] [ _hxConfirm $"Are you sure you want to delete the category “{cat.Name}”? This action cannot be undone." ] [
raw "Delete" raw "Delete"
] ]
@ -109,8 +109,6 @@ let categoryList includeNew app = [
] ]
] ]
form [ _method "post"; _class "container" ] [ form [ _method "post"; _class "container" ] [
// don't think we need this...
// _hxTarget "#catList"; _hxSwap $"{HxSwap.OuterHtml} show:window:top"
antiCsrf app antiCsrf app
div [ _class "row mwl-table-detail"; _id "cat_new" ] [ if includeNew then loadNew ] div [ _class "row mwl-table-detail"; _id "cat_new" ] [ if includeNew then loadNew ]
yield! app.Categories |> Seq.ofArray |> Seq.map categoryDetail |> List.ofSeq 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 upload.Path ]
div [ _class "col-3" ] [ 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" ] [ div [ _class "col-12 col-md-6 pb-3 d-flex align-self-center justify-content-around" ] [
raw "Destination"; br [] div [ _class "text-center" ] [
div [ _class "btn-group"; _roleGroup; _ariaLabel "Upload destination button group" ] [ raw "Destination"; br []
input [ _type "radio"; _name "Destination"; _id "destination_db"; _class "btn-check" div [ _class "btn-group"; _roleGroup; _ariaLabel "Upload destination button group" ] [
_value (string Database); if app.WebLog.Uploads = Database then _checked ] input [ _type "radio"; _name "Destination"; _id "destination_db"; _class "btn-check"
label [ _class "btn btn-outline-primary"; _for "destination_db" ] [ raw (string Database) ] _value (string Database); if app.WebLog.Uploads = Database then _checked ]
input [ _type "radio"; _name "Destination"; _id "destination_disk"; _class "btn-check" label [ _class "btn btn-outline-primary"; _for "destination_db" ] [ raw (string Database) ]
_value (string Disk); if app.WebLog.Uploads= Disk then _checked ] input [ _type "radio"; _name "Destination"; _id "destination_disk"; _class "btn-check"
label [ _class "btn btn-outline-secondary"; _for "destination_disk" ] [ raw "Disk" ] _value (string Disk); if app.WebLog.Uploads= Disk then _checked ]
label [ _class "btn btn-outline-secondary"; _for "destination_disk" ] [ raw "Disk" ]
]
] ]
] ]
] ]