So close...
- Added comment display and counts - Fixed problem with set-up-from-scratch bombing on index creation - RSS feed is returning errors; need to determine why Nginx is intercepting theme content requests
This commit is contained in:
parent
458b8308ae
commit
739fe3ff9c
@ -112,7 +112,7 @@ type MyWebLogBootstrapper() =
|
||||
CryptographyConfiguration (
|
||||
AesEncryptionProvider (PassphraseKeyGenerator (cfg.AuthEncryptionPassphrase, cfg.AuthSalt)),
|
||||
DefaultHmacProvider (PassphraseKeyGenerator (cfg.AuthHmacPassphrase, cfg.AuthSalt))),
|
||||
RedirectUrl = "~/user/logon",
|
||||
RedirectUrl = "~/user/log-on",
|
||||
UserMapper = container.Resolve<IUserMapper> ())
|
||||
FormsAuthentication.Enable (pipelines, auth)
|
||||
// CSRF
|
||||
@ -163,6 +163,7 @@ let Run () =
|
||||
use host =
|
||||
WebHostBuilder()
|
||||
.UseContentRoot(System.IO.Directory.GetCurrentDirectory ())
|
||||
.UseUrls("http://localhost:5001")
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>()
|
||||
.Build ()
|
||||
|
@ -15,9 +15,9 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
|
||||
do
|
||||
this.Get ("/categories", fun _ -> this.CategoryList ())
|
||||
this.Get ("/category/{id}/edit", fun parms -> this.EditCategory (downcast parms))
|
||||
this.Post ("/category/{id}/edit", fun parms -> this.SaveCategory (downcast parms))
|
||||
this.Delete ("/category/{id}/delete", fun parms -> this.DeleteCategory (downcast parms))
|
||||
this.Get ("/category/{id}/edit", fun p -> this.EditCategory (downcast p))
|
||||
this.Post ("/category/{id}/edit", fun p -> this.SaveCategory (downcast p))
|
||||
this.Post ("/category/{id}/delete", fun p -> this.DeleteCategory (downcast p))
|
||||
|
||||
/// Display a list of categories
|
||||
member this.CategoryList () : obj =
|
||||
@ -26,6 +26,7 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
CategoryListModel (
|
||||
this.Context, this.WebLog, findAllCategories data this.WebLog.Id
|
||||
|> List.map (fun cat -> IndentedCategory.Create cat (fun _ -> false)))
|
||||
model.PageTitle <- Strings.get "Categories"
|
||||
upcast this.View.["admin/category/list", model]
|
||||
|
||||
/// Edit a category
|
||||
@ -35,10 +36,11 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
match catId with "new" -> Some Category.Empty | _ -> tryFindCategory data this.WebLog.Id catId
|
||||
|> function
|
||||
| Some cat ->
|
||||
let model = CategoryEditModel(this.Context, this.WebLog, cat)
|
||||
let model = CategoryEditModel (this.Context, this.WebLog, cat)
|
||||
model.Categories <- findAllCategories data this.WebLog.Id
|
||||
|> List.map (fun cat -> IndentedCategory.Create cat
|
||||
(fun c -> c = defaultArg (fst cat).ParentId ""))
|
||||
|> List.map (fun c ->
|
||||
IndentedCategory.Create c (fun catId -> catId = defaultArg cat.ParentId ""))
|
||||
model.PageTitle <- Strings.get <| match catId with "new" -> "AddNewCategory" | _ -> "EditCategory"
|
||||
upcast this.View.["admin/category/edit", model]
|
||||
| _ -> this.NotFound ()
|
||||
|
||||
@ -53,10 +55,13 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
| _ -> tryFindCategory data this.WebLog.Id catId
|
||||
|> function
|
||||
| Some old ->
|
||||
let cat = { old with Name = form.Name
|
||||
let cat =
|
||||
{ old with
|
||||
Name = form.Name
|
||||
Slug = form.Slug
|
||||
Description = match form.Description with "" -> None | d -> Some d
|
||||
ParentId = match form.ParentId with "" -> None | p -> Some p }
|
||||
ParentId = match form.ParentId with "" -> None | p -> Some p
|
||||
}
|
||||
let newCatId = saveCategory data cat
|
||||
match old.ParentId = cat.ParentId with
|
||||
| true -> ()
|
||||
@ -68,12 +73,12 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
| Some parentId -> addCategoryToParent data this.WebLog.Id parentId newCatId
|
||||
| _ -> ()
|
||||
let model = MyWebLogModel (this.Context, this.WebLog)
|
||||
model.AddMessage
|
||||
{ UserMessage.Empty with
|
||||
Level = Level.Info
|
||||
Message = System.String.Format
|
||||
(Strings.get "MsgCategoryEditSuccess",
|
||||
Strings.get (match catId with "new" -> "Added" | _ -> "Updated")) }
|
||||
|> model.AddMessage
|
||||
Strings.get (match catId with "new" -> "Added" | _ -> "Updated"))
|
||||
}
|
||||
this.Redirect (sprintf "/category/%s/edit" newCatId) model
|
||||
| _ -> this.NotFound ()
|
||||
|
||||
@ -85,10 +90,8 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
match tryFindCategory data this.WebLog.Id catId with
|
||||
| Some cat ->
|
||||
deleteCategory data cat
|
||||
let model = MyWebLogModel(this.Context, this.WebLog)
|
||||
{ UserMessage.Empty with
|
||||
Level = Level.Info
|
||||
Message = System.String.Format(Strings.get "MsgCategoryDeleted", cat.Name) }
|
||||
|> model.AddMessage
|
||||
let model = MyWebLogModel (this.Context, this.WebLog)
|
||||
model.AddMessage
|
||||
{ UserMessage.Empty with Message = System.String.Format(Strings.get "MsgCategoryDeleted", cat.Name) }
|
||||
this.Redirect "/categories" model
|
||||
| _ -> this.NotFound ()
|
||||
|
@ -23,16 +23,17 @@ type UserModule (data : IMyWebLogData, cfg : AppConfig) as this =
|
||||
|> Seq.fold (fun acc byt -> sprintf "%s%s" acc (byt.ToString "x2")) ""
|
||||
|
||||
do
|
||||
this.Get ("/logon", fun _ -> this.ShowLogOn ())
|
||||
this.Post ("/logon", fun p -> this.DoLogOn (downcast p))
|
||||
this.Get ("/logoff", fun _ -> this.LogOff ())
|
||||
this.Get ("/log-on", fun _ -> this.ShowLogOn ())
|
||||
this.Post ("/log-on", fun p -> this.DoLogOn (downcast p))
|
||||
this.Get ("/log-off", fun _ -> this.LogOff ())
|
||||
|
||||
/// Show the log on page
|
||||
member this.ShowLogOn () : obj =
|
||||
let model = LogOnModel (this.Context, this.WebLog)
|
||||
let query = this.Request.Query :?> DynamicDictionary
|
||||
model.Form.ReturnUrl <- match query.ContainsKey "returnUrl" with true -> query.["returnUrl"].ToString () | _ -> ""
|
||||
upcast this.View.["admin/user/logon", model]
|
||||
model.PageTitle <- Strings.get "LogOn"
|
||||
upcast this.View.["admin/user/log-on", model]
|
||||
|
||||
/// Process a user log on
|
||||
member this.DoLogOn (parameters : DynamicDictionary) : obj =
|
||||
@ -52,12 +53,10 @@ type UserModule (data : IMyWebLogData, cfg : AppConfig) as this =
|
||||
Level = Level.Error
|
||||
Message = Strings.get "ErrBadLogOnAttempt" }
|
||||
|> model.AddMessage
|
||||
this.Redirect (sprintf "/user/logon?returnUrl=%s" form.ReturnUrl) model
|
||||
this.Redirect (sprintf "/user/log-on?returnUrl=%s" form.ReturnUrl) model
|
||||
|
||||
/// Log a user off
|
||||
member this.LogOff () : obj =
|
||||
// FIXME: why are we getting the user here if we don't do anything with it?
|
||||
let user = this.Request.PersistableSession.GetOrDefault<User> (Keys.User, User.Empty)
|
||||
this.Session.DeleteAll ()
|
||||
let model = MyWebLogModel (this.Context, this.WebLog)
|
||||
model.AddMessage { UserMessage.Empty with Message = Strings.get "MsgLogOffSuccess" }
|
||||
|
@ -176,7 +176,7 @@ type IndentedCategory =
|
||||
Selected : bool }
|
||||
with
|
||||
/// Create an indented category
|
||||
static member Create (cat : Category * int) (isSelected : string -> bool) =
|
||||
static member Create cat isSelected =
|
||||
{ Category = fst cat
|
||||
Indent = snd cat
|
||||
Selected = isSelected (fst cat).Id }
|
||||
@ -304,6 +304,17 @@ type EditPageModel (ctx, webLog, page, revision) =
|
||||
|
||||
// ---- Post models ----
|
||||
|
||||
/// Formatter for comment information
|
||||
type CommentForDisplay (comment : Comment, tz) =
|
||||
/// The comment on which this model is based
|
||||
member this.Comment = comment
|
||||
/// The commentor (linked with a URL if there is one)
|
||||
member this.Commentor =
|
||||
match comment.Url with Some url -> sprintf "<a href=\"%s\">%s</a>" url comment.Name | _ -> comment.Name
|
||||
/// The date/time this comment was posted
|
||||
member this.CommentedOn =
|
||||
sprintf "%s / %s" (FormatDateTime.longDate tz comment.PostedOn) (FormatDateTime.time tz comment.PostedOn)
|
||||
|
||||
/// Model for single post display
|
||||
type PostModel (ctx, webLog, post) =
|
||||
inherit MyWebLogModel (ctx, webLog)
|
||||
@ -317,8 +328,19 @@ type PostModel (ctx, webLog, post) =
|
||||
member this.PublishedDate = this.DisplayLongDate this.Post.PublishedOn
|
||||
/// The time the post was published
|
||||
member this.PublishedTime = this.DisplayTime this.Post.PublishedOn
|
||||
/// The number of comments
|
||||
member this.CommentCount =
|
||||
match post.Comments |> List.length with
|
||||
| 0 -> Strings.get "NoComments"
|
||||
| 1 -> Strings.get "OneComment"
|
||||
| x -> String.Format (Strings.get "XComments", x)
|
||||
/// The comments for display
|
||||
member this.Comments = post.Comments
|
||||
|> List.filter (fun c -> c.Status = CommentStatus.Approved)
|
||||
|> List.map (fun c -> CommentForDisplay (c, webLog.TimeZone))
|
||||
|
||||
/// Does the post have tags?
|
||||
member this.HasTags = not (List.isEmpty post.Tags)
|
||||
member this.HasTags = not <| List.isEmpty post.Tags
|
||||
/// Get the tags sorted
|
||||
member this.Tags = post.Tags
|
||||
|> List.sort
|
||||
@ -347,6 +369,12 @@ type PostForDisplay (webLog : WebLog, post : Post) =
|
||||
match this.Post.Status with
|
||||
| PostStatus.Published -> FormatDateTime.time this.TimeZone this.Post.PublishedOn
|
||||
| _ -> FormatDateTime.time this.TimeZone this.Post.UpdatedOn
|
||||
/// The number of comments
|
||||
member this.CommentCount =
|
||||
match post.Comments |> List.length with
|
||||
| 0 -> Strings.get "NoComments"
|
||||
| 1 -> Strings.get "OneComment"
|
||||
| x -> String.Format (Strings.get "XComments", x)
|
||||
/// Tags
|
||||
member this.Tags =
|
||||
match List.length this.Post.Tags with
|
||||
|
@ -6,9 +6,18 @@ open RethinkDb.Driver.Ast
|
||||
let private r = RethinkDb.Driver.RethinkDB.R
|
||||
|
||||
/// Shorthand to select all published posts for a web log
|
||||
let private publishedPosts (webLogId : string)=
|
||||
let private publishedPosts (webLogId : string) =
|
||||
r.Table(Table.Post)
|
||||
.GetAll(r.Array (webLogId, PostStatus.Published)).OptArg("index", "WebLogAndStatus")
|
||||
.Without("Revisions")
|
||||
// This allows us to count comments without retrieving them all
|
||||
.Merge(ReqlFunction1 (fun p ->
|
||||
upcast r.HashMap(
|
||||
"Comments", r.Table(Table.Comment)
|
||||
.GetAll(p.["id"]).OptArg("index", "PostId")
|
||||
.Pluck("id")
|
||||
.CoerceTo("array"))))
|
||||
|
||||
|
||||
/// Shorthand to sort posts by published date, slice for the given page, and return a list
|
||||
let private toPostList conn pageNbr nbrPerPage (filter : ReqlExpr) =
|
||||
|
@ -45,7 +45,6 @@ let private createIndex cfg table (index : string * (ReqlExpr -> obj) option) =
|
||||
| Some f -> (tbl cfg table).IndexCreate(idxName, f)
|
||||
| None -> (tbl cfg table).IndexCreate(idxName))
|
||||
.RunResultAsync cfg.Conn
|
||||
do! (tbl cfg table).IndexWait(idxName).RunResultAsync cfg.Conn
|
||||
logStepDone ()
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
"Action": "Action",
|
||||
"Added": "Added",
|
||||
"AddNew": "Add New",
|
||||
"AddNewCategory": "Add New Category",
|
||||
"AddNewPage": "Add New Page",
|
||||
"AddNewPost": "Add New Post",
|
||||
"Admin": "Admin",
|
||||
@ -15,11 +16,13 @@
|
||||
"Category": "Category",
|
||||
"CategoryDeleteWarning": "Are you sure you wish to delete the category",
|
||||
"Close": "Close",
|
||||
"Comments": "Comments",
|
||||
"Dashboard": "Dashboard",
|
||||
"Date": "Date",
|
||||
"Delete": "Delete",
|
||||
"Description": "Description",
|
||||
"Edit": "Edit",
|
||||
"EditCategory": "Edit Category",
|
||||
"EditPage": "Edit Page",
|
||||
"EditPost": "Edit Post",
|
||||
"EmailAddress": "E-mail Address",
|
||||
@ -44,8 +47,10 @@
|
||||
"Name": "Name",
|
||||
"NewerPosts": "Newer Posts",
|
||||
"NextPost": "Next Post",
|
||||
"NoComments": "No Comments",
|
||||
"NoParent": "No Parent",
|
||||
"OlderPosts": "Older Posts",
|
||||
"OneComment": "1 Comment",
|
||||
"PageDeleteWarning": "Are you sure you wish to delete the page",
|
||||
"PageDetails": "Page Details",
|
||||
"PageHash": "Page #",
|
||||
@ -73,5 +78,6 @@
|
||||
"Title": "Title",
|
||||
"Updated": "Updated",
|
||||
"View": "View",
|
||||
"Warning": "Warning"
|
||||
"Warning": "Warning",
|
||||
"XComments": "{0} Comments"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
@Master['admin/admin-layout']
|
||||
|
||||
@Section['Content']
|
||||
<form action="/user/logon" method="post">
|
||||
<form action="/user/log-on" method="post">
|
||||
@AntiForgeryToken
|
||||
<input type="hidden" name="ReturnUrl" value="@Model.Form.ReturnUrl" />
|
||||
<div class="row">
|
4
src/MyWebLog/views/themes/default/comment.html
Normal file
4
src/MyWebLog/views/themes/default/comment.html
Normal file
@ -0,0 +1,4 @@
|
||||
<h4>
|
||||
@Model.Commentor <small>@Model.CommentedOn</small>
|
||||
</h4>
|
||||
@Model.Comment.Text
|
@ -22,10 +22,10 @@
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
@If.IsAuthenticated
|
||||
<li><a href="/admin">@Translate.Dashboard</a></li>
|
||||
<li><a href="/user/logoff">@Translate.LogOff</a></li>
|
||||
<li><a href="/user/log-off">@Translate.LogOff</a></li>
|
||||
@EndIf
|
||||
@IfNot.IsAuthenticated
|
||||
<li><a href="/user/logon">@Translate.LogOn</a></li>
|
||||
<li><a href="/user/log-on">@Translate.LogOn</a></li>
|
||||
@EndIf
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -32,7 +32,7 @@
|
||||
@EndEach
|
||||
</table>
|
||||
</div>
|
||||
<form method="delete" id="deleteForm">
|
||||
<form method="post" id="deleteForm">
|
||||
@AntiForgeryToken
|
||||
</form>
|
||||
@EndSection
|
||||
|
@ -16,7 +16,8 @@
|
||||
</h1>
|
||||
<p>
|
||||
<i class="fa fa-calendar" title="@Translate.Date"></i> @Current.PublishedDate
|
||||
<i class="fa fa-clock-o" title="@Translate.Time"></i> @Current.PublishedTime
|
||||
<i class="fa fa-clock-o" title="@Translate.Time"></i> @Current.PublishedTime
|
||||
<i class="fa fa-comments-o" title="@Translate.Comments"></i> @Current.CommentCount
|
||||
</p>
|
||||
@Current.Post.Text
|
||||
</article>
|
||||
|
@ -28,10 +28,10 @@
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
@If.IsAuthenticated
|
||||
<li><a href="/admin">@Translate.Dashboard</a></li>
|
||||
<li><a href="/user/logoff">@Translate.LogOff</a></li>
|
||||
<li><a href="/user/log-off">@Translate.LogOff</a></li>
|
||||
@EndIf
|
||||
@IfNot.IsAuthenticated
|
||||
<li><a href="/user/logon">@Translate.LogOn</a></li>
|
||||
<li><a href="/user/log-on">@Translate.LogOn</a></li>
|
||||
@EndIf
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -6,7 +6,8 @@
|
||||
<div class="col-xs-12">
|
||||
<h4>
|
||||
<i class="fa fa-calendar" title="@Translate.Date"></i> @Model.PublishedDate
|
||||
<i class="fa fa-clock-o" title="@Translate.Time"></i> @Model.PublishedTime
|
||||
<i class="fa fa-clock-o" title="@Translate.Time"></i> @Model.PublishedTime
|
||||
<i class="fa fa-comments-o" title="@Translate.Comments"></i> @Model.CommentCount
|
||||
@Each.Post.Categories
|
||||
<span style="white-space:nowrap;">
|
||||
<i class="fa fa-folder-open-o" title="@Translate.Category"></i>
|
||||
@ -37,20 +38,13 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-12"><hr /></div>
|
||||
</div>
|
||||
<!-- // TODO: format comments -->
|
||||
<!-- .row
|
||||
.col-xs-12
|
||||
each comment in post.comments
|
||||
if 'Approved' == comment.status
|
||||
h4
|
||||
if comment.url
|
||||
a(href=comment.url)= comment.name
|
||||
else
|
||||
= comment.name
|
||||
|
|
||||
small
|
||||
=moment(comment.postedDate).format('MMMM Do, YYYY / h:mma')
|
||||
!= comment.text -->
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
@Each.Comments
|
||||
@Partial['themes/default/comment', @Current]
|
||||
@EndEach
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12"><hr /></div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user