Admin tweaks plus
- Version now reports the correct version - Post edit properly renders existing selected categories as checked, and uses the description in the title attribute if it is present - Created light/dark transparent logos Ready to test the functionality of the admin area next...
This commit is contained in:
@@ -130,7 +130,7 @@ type MyWebLogBootstrapper() =
|
||||
|
||||
|
||||
let version =
|
||||
let v = typeof<AppConfig>.GetType().GetTypeInfo().Assembly.GetName().Version
|
||||
let v = typeof<AppConfig>.GetTypeInfo().Assembly.GetName().Version
|
||||
match v.Build with
|
||||
| 0 -> match v.Minor with 0 -> string v.Major | _ -> sprintf "%d.%d" v.Major v.Minor
|
||||
| _ -> sprintf "%d.%d.%d" v.Major v.Minor v.Build
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace myWebLog.Web.AssemblyInfo
|
||||
namespace MyWebLog.AssemblyInfo
|
||||
|
||||
open System.Reflection
|
||||
open System.Runtime.CompilerServices
|
||||
@@ -14,7 +14,7 @@ open System.Runtime.InteropServices
|
||||
[<assembly: AssemblyCulture("")>]
|
||||
[<assembly: ComVisible(false)>]
|
||||
[<assembly: Guid("e6ee110a-27a6-4a19-b0cb-d24f48f71b53")>]
|
||||
[<assembly: AssemblyVersion("0.9.1.0")>]
|
||||
[<assembly: AssemblyVersion("0.9.2.0")>]
|
||||
[<assembly: AssemblyFileVersion("1.0.0.0")>]
|
||||
|
||||
do
|
||||
|
||||
@@ -103,18 +103,18 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this =
|
||||
upcast this.Response.FromStream(stream, sprintf "application/%s+xml" format) *)
|
||||
|
||||
do
|
||||
this.Get ("/", fun _ -> this.HomePage ())
|
||||
this.Get ("/{permalink*}", fun parms -> this.CatchAll (downcast parms))
|
||||
this.Get ("/posts/page/{page:int}", fun parms -> this.PublishedPostsPage (getPage <| downcast parms))
|
||||
this.Get ("/category/{slug}", fun parms -> this.CategorizedPosts (downcast parms))
|
||||
this.Get ("/category/{slug}/page/{page:int}", fun parms -> this.CategorizedPosts (downcast parms))
|
||||
this.Get ("/tag/{tag}", fun parms -> this.TaggedPosts (downcast parms))
|
||||
this.Get ("/tag/{tag}/page/{page:int}", fun parms -> this.TaggedPosts (downcast parms))
|
||||
this.Get ("/feed", fun _ -> this.Feed ())
|
||||
this.Get ("/posts/list", fun _ -> this.PostList 1)
|
||||
this.Get ("/posts/list/page/{page:int}", fun parms -> this.PostList (getPage <| downcast parms))
|
||||
this.Get ("/post/{postId}/edit", fun parms -> this.EditPost (downcast parms))
|
||||
this.Post ("/post/{postId}/edit", fun parms -> this.SavePost (downcast parms))
|
||||
this.Get ("/", fun _ -> this.HomePage ())
|
||||
this.Get ("/{permalink*}", fun p -> this.CatchAll (downcast p))
|
||||
this.Get ("/posts/page/{page:int}", fun p -> this.PublishedPostsPage (getPage <| downcast p))
|
||||
this.Get ("/category/{slug}", fun p -> this.CategorizedPosts (downcast p))
|
||||
this.Get ("/category/{slug}/page/{page:int}", fun p -> this.CategorizedPosts (downcast p))
|
||||
this.Get ("/tag/{tag}", fun p -> this.TaggedPosts (downcast p))
|
||||
this.Get ("/tag/{tag}/page/{page:int}", fun p -> this.TaggedPosts (downcast p))
|
||||
this.Get ("/feed", fun _ -> this.Feed ())
|
||||
this.Get ("/posts/list", fun _ -> this.PostList 1)
|
||||
this.Get ("/posts/list/page/{page:int}", fun p -> this.PostList (getPage <| downcast p))
|
||||
this.Get ("/post/{postId}/edit", fun p -> this.EditPost (downcast p))
|
||||
this.Post ("/post/{postId}/edit", fun p -> this.SavePost (downcast p))
|
||||
|
||||
// ---- Display posts to users ----
|
||||
|
||||
@@ -253,11 +253,10 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this =
|
||||
| None -> Revision.Empty
|
||||
let model = EditPostModel (this.Context, this.WebLog, post, rev)
|
||||
model.Categories <- findAllCategories data this.WebLog.Id
|
||||
|> List.map (fun cat -> string (fst cat).Id,
|
||||
sprintf "%s%s" (String.replicate (snd cat) " ")
|
||||
(fst cat).Name)
|
||||
|> List.map (fun cat ->
|
||||
DisplayCategory.Create cat (post.CategoryIds |> List.contains (fst cat).Id))
|
||||
model.PageTitle <- Strings.get <| match post.Id with "new" -> "AddNewPost" | _ -> "EditPost"
|
||||
upcast this.View.["admin/post/edit"]
|
||||
upcast this.View.["admin/post/edit", model]
|
||||
| _ -> this.NotFound ()
|
||||
|
||||
/// Save a post
|
||||
|
||||
@@ -9,7 +9,7 @@ open Newtonsoft.Json
|
||||
open NodaTime
|
||||
open NodaTime.Text
|
||||
open System
|
||||
|
||||
open System.Net
|
||||
|
||||
/// Levels for a user message
|
||||
[<RequireQualifiedAccess>]
|
||||
@@ -90,7 +90,7 @@ module FormatDateTime =
|
||||
|
||||
|
||||
/// Parent view model for all myWebLog views
|
||||
type MyWebLogModel (ctx : NancyContext, webLog : WebLog) =
|
||||
type MyWebLogModel (ctx : NancyContext, webLog : WebLog) as this =
|
||||
|
||||
/// Get the messages from the session
|
||||
let getMessages () =
|
||||
@@ -100,6 +100,20 @@ type MyWebLogModel (ctx : NancyContext, webLog : WebLog) =
|
||||
| _ -> ctx.Request.Session.Delete Keys.Messages
|
||||
msg
|
||||
|
||||
/// Generate a footer logo with the given scheme
|
||||
let footerLogo scheme =
|
||||
seq {
|
||||
yield sprintf "<img src=\"/content/logo-%s.png\" alt=\"myWebLog\" title=\"" scheme
|
||||
yield sprintf "%s %s • " (Strings.get "PoweredBy") this.Generator
|
||||
yield Strings.get "LoadedIn"
|
||||
yield " "
|
||||
yield TimeSpan(System.DateTime.Now.Ticks - this.RequestStart).TotalSeconds.ToString "f3"
|
||||
yield " "
|
||||
yield (Strings.get "Seconds").ToLower ()
|
||||
yield "\" height=\"30\" />"
|
||||
}
|
||||
|> Seq.reduce (+)
|
||||
|
||||
/// The web log for this request
|
||||
member this.WebLog = webLog
|
||||
/// The subtitle for the webLog (SSVE can't do IsSome that deep)
|
||||
@@ -134,19 +148,11 @@ type MyWebLogModel (ctx : NancyContext, webLog : WebLog) =
|
||||
| None -> this.WebLog.Name
|
||||
| pt -> sprintf "%s | %s" pt this.WebLog.Name
|
||||
|
||||
/// An image with the version and load time in the tool tip
|
||||
member this.FooterLogo =
|
||||
seq {
|
||||
yield "<img src=\"/default/footer-logo.png\" alt=\"myWebLog\" title=\""
|
||||
yield sprintf "%s %s • " (Strings.get "PoweredBy") this.Generator
|
||||
yield Strings.get "LoadedIn"
|
||||
yield " "
|
||||
yield TimeSpan(System.DateTime.Now.Ticks - this.RequestStart).TotalSeconds.ToString "f3"
|
||||
yield " "
|
||||
yield (Strings.get "Seconds").ToLower ()
|
||||
yield "\" />"
|
||||
}
|
||||
|> Seq.reduce (+)
|
||||
/// An image with the version and load time in the tool tip (using light text)
|
||||
member this.FooterLogoLight = footerLogo "light"
|
||||
|
||||
/// An image with the version and load time in the tool tip (using dark text)
|
||||
member this.FooterLogoDark = footerLogo "dark"
|
||||
|
||||
|
||||
// ---- Admin models ----
|
||||
@@ -399,6 +405,27 @@ type EditPostForm () =
|
||||
this.Text <- rev.Text
|
||||
this
|
||||
|
||||
/// Category information for display
|
||||
type DisplayCategory = {
|
||||
Id : string
|
||||
Indent : string
|
||||
Name : string
|
||||
Description : string
|
||||
IsChecked : bool
|
||||
}
|
||||
with
|
||||
/// Create a display category
|
||||
static member Create (cat : Category, indent) isChecked =
|
||||
{ Id = cat.Id
|
||||
Indent = String.replicate indent " "
|
||||
Name = WebUtility.HtmlEncode cat.Name
|
||||
IsChecked = isChecked
|
||||
Description = WebUtility.HtmlEncode (match cat.Description with Some d -> d | _ -> cat.Name)
|
||||
}
|
||||
/// The "checked" attribute for this category
|
||||
member this.CheckedAttr
|
||||
with get() = match this.IsChecked with true -> "checked=\"checked\"" | _ -> ""
|
||||
|
||||
/// View model for the edit post page
|
||||
type EditPostModel (ctx, webLog, post, revision) =
|
||||
inherit MyWebLogModel (ctx, webLog)
|
||||
@@ -408,7 +435,7 @@ type EditPostModel (ctx, webLog, post, revision) =
|
||||
/// The post being edited
|
||||
member val Post = post with get, set
|
||||
/// The categories to which the post may be assigned
|
||||
member val Categories : (string * string) list = [] with get, set
|
||||
member val Categories : DisplayCategory list = [] with get, set
|
||||
/// Whether the post is currently published
|
||||
member this.IsPublished = PostStatus.Published = this.Post.Status
|
||||
/// The published date
|
||||
|
||||
Reference in New Issue
Block a user