A little housekeeping

- Simplified user message generation (Info is default level)
- Removed paket and FAKE files, as we're using the default .NET Core
build system
This commit is contained in:
Daniel J. Summers 2016-11-12 08:52:53 -06:00
parent 739fe3ff9c
commit 47266817f6
8 changed files with 59 additions and 188 deletions

Binary file not shown.

View File

@ -15,17 +15,17 @@ type PageModule (data : IMyWebLogData, clock : IClock) as this =
inherit NancyModule () inherit NancyModule ()
do do
this.Get ("/pages", fun _ -> this.PageList ()) this.Get ("/pages", fun _ -> this.PageList ())
this.Get ("/page/{id}/edit", fun parms -> this.EditPage (downcast parms)) this.Get ("/page/{id}/edit", fun p -> this.EditPage (downcast p))
this.Post ("/page/{id}/edit", fun parms -> this.SavePage (downcast parms)) this.Post ("/page/{id}/edit", fun p -> this.SavePage (downcast p))
this.Delete ("/page/{id}/delete", fun parms -> this.DeletePage (downcast parms)) this.Delete ("/page/{id}/delete", fun p -> this.DeletePage (downcast p))
/// List all pages /// List all pages
member this.PageList () : obj = member this.PageList () : obj =
this.RequiresAccessLevel AuthorizationLevel.Administrator this.RequiresAccessLevel AuthorizationLevel.Administrator
let model = let model =
PagesModel(this.Context, this.WebLog, findAllPages data this.WebLog.Id PagesModel (this.Context, this.WebLog, findAllPages data this.WebLog.Id
|> List.map (fun p -> PageForDisplay (this.WebLog, p))) |> List.map (fun p -> PageForDisplay (this.WebLog, p)))
model.PageTitle <- Strings.get "Pages" model.PageTitle <- Strings.get "Pages"
upcast this.View.["admin/page/list", model] upcast this.View.["admin/page/list", model]
@ -74,12 +74,12 @@ type PageModule (data : IMyWebLogData, clock : IClock) as this =
} }
|> savePage data |> savePage data
let model = MyWebLogModel (this.Context, this.WebLog) let model = MyWebLogModel (this.Context, this.WebLog)
{ UserMessage.Empty with model.AddMessage
Level = Level.Info { UserMessage.Empty with
Message = System.String.Format Message = System.String.Format
(Strings.get "MsgPageEditSuccess", (Strings.get "MsgPageEditSuccess",
Strings.get (match pageId with "new" -> "Added" | _ -> "Updated")) } Strings.get (match pageId with "new" -> "Added" | _ -> "Updated"))
|> model.AddMessage }
this.Redirect (sprintf "/page/%s/edit" pId) model this.Redirect (sprintf "/page/%s/edit" pId) model
| _ -> this.NotFound () | _ -> this.NotFound ()
@ -92,9 +92,6 @@ type PageModule (data : IMyWebLogData, clock : IClock) as this =
| Some page -> | Some page ->
deletePage data page.WebLogId page.Id deletePage data page.WebLogId page.Id
let model = MyWebLogModel (this.Context, this.WebLog) let model = MyWebLogModel (this.Context, this.WebLog)
{ UserMessage.Empty with model.AddMessage { UserMessage.Empty with Message = Strings.get "MsgPageDeleted" }
Level = Level.Info
Message = Strings.get "MsgPageDeleted" }
|> model.AddMessage
this.Redirect "/pages" model this.Redirect "/pages" model
| _ -> this.NotFound () | _ -> this.NotFound ()

View File

@ -23,12 +23,14 @@ type NewsItem =
} }
/// Routes dealing with posts (including the home page, /tag, /category, RSS, and catch-all routes) /// Routes dealing with posts (including the home page, /tag, /category, RSS, and catch-all routes)
type PostModule(data : IMyWebLogData, clock : IClock) as this = type PostModule (data : IMyWebLogData, clock : IClock) as this =
inherit NancyModule () inherit NancyModule ()
/// Get the page number from the dictionary /// Get the page number from the dictionary
let getPage (parameters : DynamicDictionary) = let getPage (parameters : DynamicDictionary) =
match parameters.ContainsKey "page" with true -> System.Int32.Parse (parameters.["page"].ToString ()) | _ -> 1 match parameters.ContainsKey "page" with
| true -> match System.Int32.TryParse (parameters.["page"].ToString ()) with true, pg -> pg | _ -> 1
| _ -> 1
/// Convert a list of posts to a list of posts for display /// Convert a list of posts to a list of posts for display
let forDisplay posts = posts |> List.map (fun post -> PostForDisplay (this.WebLog, post)) let forDisplay posts = posts |> List.map (fun post -> PostForDisplay (this.WebLog, post))
@ -37,23 +39,23 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this =
let generateFeed format : obj = let generateFeed format : obj =
let myChannelFeed channelTitle channelLink channelDescription (items : NewsItem list) = let myChannelFeed channelTitle channelLink channelDescription (items : NewsItem list) =
let xn = XName.Get let xn = XName.Get
let elem name (valu:string) = XElement (xn name, valu) let elem name (valu : string) = XElement (xn name, valu)
let elems = let elems =
items items
|> List.sortBy (fun i -> i.ReleaseDate) |> List.sortBy (fun i -> i.ReleaseDate)
|> List.map (fun i -> |> List.map (fun i ->
XElement XElement (
(xn "item", xn "item",
elem "title" (System.Net.WebUtility.HtmlEncode i.Title), elem "title" (System.Net.WebUtility.HtmlEncode i.Title),
elem "link" i.Link, elem "link" i.Link,
elem "guid" i.Link, elem "guid" i.Link,
elem "pubDate" (i.ReleaseDate.ToString "r"), elem "pubDate" (i.ReleaseDate.ToString "r"),
elem "description" (System.Net.WebUtility.HtmlEncode i.Description) elem "description" (System.Net.WebUtility.HtmlEncode i.Description)
)) ))
XDocument( XDocument (
XDeclaration("1.0", "utf-8", "yes"), XDeclaration ("1.0", "utf-8", "yes"),
XElement XElement (
(xn "rss", xn "rss",
XAttribute (xn "version", "2.0"), XAttribute (xn "version", "2.0"),
elem "title" channelTitle, elem "title" channelTitle,
elem "link" channelLink, elem "link" channelLink,
@ -61,16 +63,21 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this =
elem "language" "en-us", elem "language" "en-us",
XElement (xn "channel", elems)) XElement (xn "channel", elems))
|> box) |> box)
|> box
let schemeAndUrl = sprintf "%s://%s" this.Request.Url.Scheme this.WebLog.UrlBase let schemeAndUrl = sprintf "%s://%s" this.Request.Url.Scheme this.WebLog.UrlBase
findFeedPosts data this.WebLog.Id 10 let feed =
|> List.map (fun (post, _) -> findFeedPosts data this.WebLog.Id 10
{ Title = post.Title |> List.map (fun (post, _) ->
Link = sprintf "%s/%s" schemeAndUrl post.Permalink { Title = post.Title
ReleaseDate = Instant.FromUnixTimeTicks(post.PublishedOn).ToDateTimeOffset().DateTime Link = sprintf "%s/%s" schemeAndUrl post.Permalink
Description = post.Text ReleaseDate = Instant.FromUnixTimeTicks(post.PublishedOn).ToDateTimeOffset().DateTime
}) Description = post.Text
|> myChannelFeed this.WebLog.Name schemeAndUrl this.WebLog.Subtitle })
|> myChannelFeed this.WebLog.Name schemeAndUrl this.WebLog.Subtitle
let stream = new IO.MemoryStream ()
Xml.XmlWriter.Create stream |> feed.Save
//|> match format with "atom" -> feed.SaveAsAtom10 | _ -> feed.SaveAsRss20
stream.Position <- 0L
upcast this.Response.FromStream (stream, sprintf "application/%s+xml" format)
// TODO: how to return this? // TODO: how to return this?
(* (*
@ -246,11 +253,12 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this =
match postId with "new" -> Some Post.Empty | _ -> tryFindPost data this.WebLog.Id postId match postId with "new" -> Some Post.Empty | _ -> tryFindPost data this.WebLog.Id postId
|> function |> function
| Some post -> | Some post ->
let rev = match post.Revisions let rev =
|> List.sortByDescending (fun r -> r.AsOf) match post.Revisions
|> List.tryHead with |> List.sortByDescending (fun r -> r.AsOf)
| Some r -> r |> List.tryHead with
| None -> Revision.Empty | Some r -> r
| None -> Revision.Empty
let model = EditPostModel (this.Context, this.WebLog, post, rev) let model = EditPostModel (this.Context, this.WebLog, post, rev)
model.Categories <- findAllCategories data this.WebLog.Id model.Categories <- findAllCategories data this.WebLog.Id
|> List.map (fun cat -> |> List.map (fun cat ->
@ -270,12 +278,14 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this =
|> function |> function
| Some p -> | Some p ->
let justPublished = p.PublishedOn = 0L && form.PublishNow let justPublished = p.PublishedOn = 0L && form.PublishNow
let post = match postId with let post =
| "new" -> { p with match postId with
WebLogId = this.WebLog.Id | "new" ->
AuthorId = (this.Request.PersistableSession.GetOrDefault<User> { p with
(Keys.User, User.Empty)).Id } WebLogId = this.WebLog.Id
| _ -> p AuthorId = this.Request.PersistableSession.GetOrDefault<User>(Keys.User, User.Empty).Id
}
| _ -> p
let pId = let pId =
{ post with { post with
Status = match form.PublishNow with true -> PostStatus.Published | _ -> PostStatus.Draft Status = match form.PublishNow with true -> PostStatus.Published | _ -> PostStatus.Draft
@ -296,12 +306,12 @@ type PostModule(data : IMyWebLogData, clock : IClock) as this =
Text = form.Text } :: post.Revisions } Text = form.Text } :: post.Revisions }
|> savePost data |> savePost data
let model = MyWebLogModel(this.Context, this.WebLog) let model = MyWebLogModel(this.Context, this.WebLog)
{ UserMessage.Empty with model.AddMessage
Level = Level.Info { UserMessage.Empty with
Message = System.String.Format Message = System.String.Format
(Strings.get "MsgPostEditSuccess", (Strings.get "MsgPostEditSuccess",
Strings.get (match postId with "new" -> "Added" | _ -> "Updated"), Strings.get (match postId with "new" -> "Added" | _ -> "Updated"),
(match justPublished with true -> Strings.get "AndPublished" | _ -> "")) } (match justPublished with true -> Strings.get "AndPublished" | _ -> ""))
|> model.AddMessage }
this.Redirect (sprintf "/post/%s/edit" pId) model this.Redirect (sprintf "/post/%s/edit" pId) model
| _ -> this.NotFound () | _ -> this.NotFound ()

View File

@ -1,14 +0,0 @@
@echo off
cls
.paket\paket.bootstrapper.exe
if errorlevel 1 (
exit /b %errorlevel%
)
.paket\paket.exe restore
if errorlevel 1 (
exit /b %errorlevel%
)
packages\FAKE\tools\FAKE.exe build.fsx %*

View File

@ -1,42 +0,0 @@
// include Fake libs
#r "./packages/FAKE/tools/FakeLib.dll"
open Fake
// Directories
let buildDir = "./build/"
let deployDir = "./deploy/"
// Filesets
let appReferences =
!! "/**/*.csproj"
++ "/**/*.fsproj"
// version info
let version = "0.1" // or retrieve from CI server
// Targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; deployDir]
)
Target "Build" (fun _ ->
// compile all projects below src/app/
MSBuildDebug buildDir "Build" appReferences
|> Log "AppBuild-Output: "
)
Target "Deploy" (fun _ ->
!! (buildDir + "/**/*.*")
-- "*.zip"
|> Zip buildDir (deployDir + "ApplicationName." + version + ".zip")
)
// Build order
"Clean"
==> "Build"
==> "Deploy"
// start build
RunTargetOrDefault "Build"

View File

@ -1,33 +0,0 @@
#!/bin/bash
if test "$OS" = "Windows_NT"
then
# use .Net
.paket/paket.bootstrapper.exe
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
.paket/paket.exe restore
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
packages/FAKE/tools/FAKE.exe $@ --fsiargs build.fsx
else
# use mono
mono .paket/paket.bootstrapper.exe
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
mono .paket/paket.exe restore
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi
mono packages/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx
fi

View File

@ -1,13 +0,0 @@
framework: net40, net45, net452
source https://www.nuget.org/api/v2
nuget Common.Logging 3.3.0
nuget FAKE
nuget FSharp.Interop.Dynamic
nuget FSharp.Formatting
nuget Nancy
nuget Nancy.Authentication.Forms
nuget Nancy.Session.RethinkDb
nuget Newtonsoft.Json
nuget NodaTime
nuget RethinkDb.Driver
nuget Suave

View File

@ -1,34 +0,0 @@
FRAMEWORK: NET40, NET45, NET452
NUGET
remote: https://www.nuget.org/api/v2
Common.Logging (3.3)
Common.Logging.Core (>= 3.3)
Common.Logging.Core (3.3.1)
Dynamitey (1.0.2)
FAKE (4.36)
FSharp.Compiler.Service (2.0.0.6)
FSharp.Core (4.0.0.1)
FSharp.Formatting (2.14.4)
FSharp.Compiler.Service (2.0.0.6)
FSharpVSPowerTools.Core (>= 2.3 < 2.4)
FSharp.Interop.Dynamic (3.0)
Dynamitey (>= 1.0.2)
FSharp.Core (>= 3.1.2.1)
FSharpVSPowerTools.Core (2.3)
FSharp.Compiler.Service (>= 2.0.0.3)
Nancy (1.4.3)
Nancy.Authentication.Forms (1.4.1)
Nancy (>= 1.4.1)
Nancy.Session.Persistable (0.9)
Nancy (>= 1.4.3)
Newtonsoft.Json (>= 9.0.1)
Nancy.Session.RethinkDB (0.9)
Nancy.Session.Persistable (>= 0.9)
RethinkDb.Driver (>= 2.3.9)
Newtonsoft.Json (9.0.1)
NodaTime (1.3.2)
RethinkDb.Driver (2.3.10)
Common.Logging (>= 3.3) - framework: net45, net452
Newtonsoft.Json (>= 9.0.1) - framework: net45, net452
Suave (1.1.3)
FSharp.Core (>= 3.1.2.5)