WIP on saving chapters (#6)
This commit is contained in:
parent
d3c89dae5f
commit
6a5285ca54
@ -362,6 +362,7 @@ type EditCategoryModel = {
|
|||||||
|
|
||||||
|
|
||||||
/// View model to add/edit an episode chapter
|
/// View model to add/edit an episode chapter
|
||||||
|
[<CLIMutable; NoComparison; NoEquality>]
|
||||||
type EditChapterModel = {
|
type EditChapterModel = {
|
||||||
/// The ID of the post to which the chapter belongs
|
/// The ID of the post to which the chapter belongs
|
||||||
PostId: string
|
PostId: string
|
||||||
|
@ -409,6 +409,37 @@ let editChapter (postId, index) : HttpHandler = requireAccess Author >=> fun nex
|
|||||||
| Some _ | None -> return! Error.notFound next ctx
|
| Some _ | None -> return! Error.notFound next ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POST /admin/post/{id}/chapter/{idx}
|
||||||
|
let saveChapter (postId, index) : HttpHandler = requireAccess Author >=> fun next ctx -> task {
|
||||||
|
let data = ctx.Data
|
||||||
|
match! data.Post.FindById (PostId postId) ctx.WebLog.Id with
|
||||||
|
| Some post
|
||||||
|
when Option.isSome post.Episode
|
||||||
|
&& Option.isSome post.Episode.Value.Chapters
|
||||||
|
&& canEdit post.AuthorId ctx ->
|
||||||
|
let! form = ctx.BindFormAsync<EditChapterModel>()
|
||||||
|
let chapters = post.Episode.Value.Chapters.Value
|
||||||
|
if index = -1 || (index >= 0 && index < List.length chapters) then
|
||||||
|
let updatedPost =
|
||||||
|
{ post with
|
||||||
|
Episode = Some {
|
||||||
|
post.Episode.Value with
|
||||||
|
Chapters =
|
||||||
|
form.ToChapter() :: (if index = -1 then chapters else chapters |> List.removeAt index)
|
||||||
|
|> List.sortBy _.StartTime
|
||||||
|
|> Some } }
|
||||||
|
do! data.Post.Update updatedPost
|
||||||
|
do! addMessage ctx { UserMessage.Success with Message = "Chapter saved successfully" }
|
||||||
|
// TODO: handle "add another", only return chapter list vs. entire page with title
|
||||||
|
return!
|
||||||
|
hashForPage "Manage Chapters"
|
||||||
|
|> withAntiCsrf ctx
|
||||||
|
|> addToHash ViewContext.Model (ManageChaptersModel.Create updatedPost)
|
||||||
|
|> adminView "chapters" next ctx
|
||||||
|
else return! Error.notFound next ctx
|
||||||
|
| Some _ | None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
// POST /admin/post/save
|
// POST /admin/post/save
|
||||||
let save : HttpHandler = requireAccess Author >=> fun next ctx -> task {
|
let save : HttpHandler = requireAccess Author >=> fun next ctx -> task {
|
||||||
let! model = ctx.BindFormAsync<EditPostModel>()
|
let! model = ctx.BindFormAsync<EditPostModel>()
|
||||||
|
@ -178,6 +178,7 @@ let router : HttpHandler = choose [
|
|||||||
subRoute "/post" (choose [
|
subRoute "/post" (choose [
|
||||||
route "/save" >=> Post.save
|
route "/save" >=> Post.save
|
||||||
route "/permalinks" >=> Post.savePermalinks
|
route "/permalinks" >=> Post.savePermalinks
|
||||||
|
routef "/%s/chapter/%i" Post.saveChapter
|
||||||
routef "/%s/delete" Post.delete
|
routef "/%s/delete" Post.delete
|
||||||
routef "/%s/revision/%s/delete" Post.deleteRevision
|
routef "/%s/revision/%s/delete" Post.deleteRevision
|
||||||
routef "/%s/revision/%s/restore" Post.restoreRevision
|
routef "/%s/revision/%s/restore" Post.restoreRevision
|
||||||
|
Loading…
Reference in New Issue
Block a user