From c9dca517b07ec28f31d5ef730ab17e17a018921c Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Mon, 11 Mar 2019 06:08:12 -0500 Subject: [PATCH 01/14] WIP on search --- src/PrayerTracker.UI/PrayerRequest.fs | 10 +++++++--- src/PrayerTracker/PrayerRequest.fs | 8 +++++++- src/PrayerTracker/wwwroot/css/app.css | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/PrayerTracker.UI/PrayerRequest.fs b/src/PrayerTracker.UI/PrayerRequest.fs index e3a7601..ddb3c35 100644 --- a/src/PrayerTracker.UI/PrayerRequest.fs +++ b/src/PrayerTracker.UI/PrayerRequest.fs @@ -206,7 +206,7 @@ let maintain (reqs : PrayerRequest seq) (grp : SmallGroup) onlyActive (ctx : Htt yield match 60 > reqText.Length with | true -> rawText reqText - | false -> rawText (sprintf "%s…" (reqText.Substring (0, 60))) + | false -> rawText (sprintf "%s…" reqText.[0..59]) ] ]) |> List.ofSeq @@ -217,9 +217,13 @@ let maintain (reqs : PrayerRequest seq) (grp : SmallGroup) onlyActive (ctx : Htt rawText "       " a [ _href "/prayer-requests/view"; _title s.["View Prayer Request List"].Value ] [ icon "list"; rawText "  "; encLocText s.["View Prayer Request List"] ] - br [] - br [] ] + form [ _action "/prayer-requests"; _method "get"; _class "pt-center-text pt-search-form" ] [ + input [ _type "text"; _name "search"; _placeholder s.["Search requests..."].Value ] + space + submit [] "search" s.["Search"] + ] + br [] tableSummary requests.Length s table [ _class "pt-table pt-action-table" ] [ thead [] [ diff --git a/src/PrayerTracker/PrayerRequest.fs b/src/PrayerTracker/PrayerRequest.fs index fc17e56..fea0722 100644 --- a/src/PrayerTracker/PrayerRequest.fs +++ b/src/PrayerTracker/PrayerRequest.fs @@ -190,6 +190,8 @@ let lists : HttpHandler = /// GET /prayer-requests[/inactive?] +/// - OR - +/// GET /prayer-requests?search=[search-query] let maintain onlyActive : HttpHandler = requireAccess [ User ] >=> fun next ctx -> @@ -197,7 +199,11 @@ let maintain onlyActive : HttpHandler = let db = ctx.dbContext () let grp = currentGroup ctx task { - let reqs = db.AllRequestsForSmallGroup grp (ctx.GetService ()) None onlyActive + let reqs = + match ctx.GetQueryStringValue "search" with + | Ok srch -> + Seq.empty + | Error _ -> db.AllRequestsForSmallGroup grp (ctx.GetService ()) None onlyActive return! { viewInfo ctx startTicks with helpLink = Some Help.maintainRequests } |> Views.PrayerRequest.maintain reqs grp onlyActive ctx diff --git a/src/PrayerTracker/wwwroot/css/app.css b/src/PrayerTracker/wwwroot/css/app.css index 0134b44..dfed2dd 100644 --- a/src/PrayerTracker/wwwroot/css/app.css +++ b/src/PrayerTracker/wwwroot/css/app.css @@ -369,6 +369,12 @@ article.pt-overview section div p { border-radius: 5px; margin: auto; } +.pt-search-form input, +.pt-search-form button, +.pt-search-form i.material-icons { + font-size: .8rem; +} + .pt-request-update { font-style: italic; } -- 2.45.1 From ec7c12290b1e22caf67a2262bba4ae388243804f Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Wed, 13 Mar 2019 05:57:12 -0500 Subject: [PATCH 02/14] Add SQL to support search --- src/search-sql.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/search-sql.txt diff --git a/src/search-sql.txt b/src/search-sql.txt new file mode 100644 index 0000000..c5c2ce2 --- /dev/null +++ b/src/search-sql.txt @@ -0,0 +1,3 @@ +create extension pg_trgm; +create index "IX_PrayerRequest_Text_TRGM" on "PrayerRequest" using GIN ("Text" gin_trgm_ops); +alter table "ListPreference" add column "PageSize" int not null default 100; \ No newline at end of file -- 2.45.1 From c784c9e91e08408a99f6de4f73b73736b669843f Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 15 Mar 2019 20:05:51 -0500 Subject: [PATCH 03/14] WIP on search Added page size to model, first cut at search method --- src/PrayerTracker.Data/DataAccess.fs | 23 ++++++++++- src/PrayerTracker.Data/Entities.fs | 38 +++++++++++-------- .../20161217153124_InitialDatabase.fs | 32 ++++++++-------- .../Migrations/AppDbContextModelSnapshot.fs | 1 + 4 files changed, 63 insertions(+), 31 deletions(-) diff --git a/src/PrayerTracker.Data/DataAccess.fs b/src/PrayerTracker.Data/DataAccess.fs index 3a86252..d67d039 100644 --- a/src/PrayerTracker.Data/DataAccess.fs +++ b/src/PrayerTracker.Data/DataAccess.fs @@ -64,7 +64,7 @@ type AppDbContext with member this.CountMembersForSmallGroup gId = this.Members.CountAsync (fun m -> m.smallGroupId = gId) - (*-- PRAYER REQUEST EXTENSIONS *) + (*-- PRAYER REQUEST EXTENSIONS --*) /// Get a prayer request by its Id member this.TryRequestById reqId = @@ -108,6 +108,27 @@ type AppDbContext with member this.CountRequestsByChurch cId = this.PrayerRequests.CountAsync (fun pr -> pr.smallGroup.churchId = cId) + /// Get all (or active) requests for a small group as of now or the specified date + member this.SearchRequestsForSmallGroup (grp : SmallGroup) (searchTerm : string) pageNbr : PrayerRequest seq = + let skip = (pageNbr - 1) * 100 + upcast ( + this.PrayerRequests + .AsNoTracking() + .Where(fun pr -> pr.smallGroupId = grp.smallGroupId && pr.text.Contains(searchTerm.ToLowerInvariant())) + |> function + // Sort + | query when grp.preferences.requestSort = "D" -> + query.OrderByDescending(fun pr -> pr.updatedDate) + .ThenByDescending(fun pr -> pr.enteredDate) + .ThenBy(fun pr -> pr.requestor) + | query -> + query.OrderBy(fun pr -> pr.requestor) + .ThenByDescending(fun pr -> pr.updatedDate) + .ThenByDescending(fun pr -> pr.enteredDate) + |> function + // Pagination + | query -> query.Skip(skip).Take(100)) + (*-- SMALL GROUP EXTENSIONS --*) /// Find a small group by its Id diff --git a/src/PrayerTracker.Data/Entities.fs b/src/PrayerTracker.Data/Entities.fs index 681d994..50043d0 100644 --- a/src/PrayerTracker.Data/Entities.fs +++ b/src/PrayerTracker.Data/Entities.fs @@ -156,6 +156,8 @@ and [] ListPreferences = timeZoneId : TimeZoneId /// The time zone information timeZone : TimeZone + /// The number of requests displayed per page + pageSize : int } with /// A set of preferences with their default values @@ -177,6 +179,7 @@ and [] ListPreferences = isPublic = false timeZoneId = "America/Denver" timeZone = TimeZone.empty + pageSize = 100 } /// Configure EF for this entity static member internal configureEF (mb : ModelBuilder) = @@ -188,78 +191,83 @@ and [] ListPreferences = m.Property(fun e -> e.daysToKeepNew) .HasColumnName("DaysToKeepNew") .IsRequired() - .HasDefaultValue(7) + .HasDefaultValue 7 |> ignore m.Property(fun e -> e.daysToExpire) .HasColumnName("DaysToExpire") .IsRequired() - .HasDefaultValue(14) + .HasDefaultValue 14 |> ignore m.Property(fun e -> e.longTermUpdateWeeks) .HasColumnName("LongTermUpdateWeeks") .IsRequired() - .HasDefaultValue(4) + .HasDefaultValue 4 |> ignore m.Property(fun e -> e.emailFromName) .HasColumnName("EmailFromName") .IsRequired() - .HasDefaultValue("PrayerTracker") + .HasDefaultValue "PrayerTracker" |> ignore m.Property(fun e -> e.emailFromAddress) .HasColumnName("EmailFromAddress") .IsRequired() - .HasDefaultValue("prayer@djs-consulting.com") + .HasDefaultValue "prayer@djs-consulting.com" |> ignore m.Property(fun e -> e.listFonts) .HasColumnName("ListFonts") .IsRequired() - .HasDefaultValue("Century Gothic,Tahoma,Luxi Sans,sans-serif") + .HasDefaultValue "Century Gothic,Tahoma,Luxi Sans,sans-serif" |> ignore m.Property(fun e -> e.headingColor) .HasColumnName("HeadingColor") .IsRequired() - .HasDefaultValue("maroon") + .HasDefaultValue "maroon" |> ignore m.Property(fun e -> e.lineColor) .HasColumnName("LineColor") .IsRequired() - .HasDefaultValue("navy") + .HasDefaultValue "navy" |> ignore m.Property(fun e -> e.headingFontSize) .HasColumnName("HeadingFontSize") .IsRequired() - .HasDefaultValue(16) + .HasDefaultValue 16 |> ignore m.Property(fun e -> e.textFontSize) .HasColumnName("TextFontSize") .IsRequired() - .HasDefaultValue(12) + .HasDefaultValue 12 |> ignore m.Property(fun e -> e.requestSort) .HasColumnName("RequestSort") .IsRequired() .HasMaxLength(1) - .HasDefaultValue("D") + .HasDefaultValue "D" |> ignore m.Property(fun e -> e.groupPassword) .HasColumnName("GroupPassword") .IsRequired() - .HasDefaultValue("") + .HasDefaultValue "" |> ignore m.Property(fun e -> e.defaultEmailType) .HasColumnName("DefaultEmailType") .IsRequired() - .HasDefaultValue(EmailType.Html) + .HasDefaultValue EmailType.Html |> ignore m.Property(fun e -> e.isPublic) .HasColumnName("IsPublic") .IsRequired() - .HasDefaultValue(false) + .HasDefaultValue false |> ignore m.Property(fun e -> e.timeZoneId) .HasColumnName("TimeZoneId") .IsRequired() - .HasDefaultValue("America/Denver") + .HasDefaultValue "America/Denver" + |> ignore + m.Property(fun e -> e.pageSize) + .HasColumnName("PageSize") + .IsRequired() + .HasDefaultValue 100 |> ignore) |> ignore diff --git a/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs b/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs index aea51af..14f6ddb 100644 --- a/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs +++ b/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs @@ -37,6 +37,7 @@ type ListPreferencesTable = requestSort : OperationBuilder textFontSize : OperationBuilder timeZoneId : OperationBuilder + pageSize : OperationBuilder } type MemberTable = @@ -174,22 +175,23 @@ type InitialDatabase () = schema = "pt", columns = (fun table -> - { smallGroupId = table.Column (name = "SmallGroupId", nullable = false) - daysToExpire = table.Column (name = "DaysToExpire", nullable = false, defaultValue = 14) - daysToKeepNew = table.Column (name = "DaysToKeepNew", nullable = false, defaultValue = 7) - defaultEmailType = table.Column (name = "DefaultEmailType", nullable = false, defaultValue = "Html") - emailFromAddress = table.Column (name = "EmailFromAddress", nullable = false, defaultValue = "prayer@djs-consulting.com") - emailFromName = table.Column (name = "EmailFromName", nullable = false, defaultValue = "PrayerTracker") - groupPassword = table.Column (name = "GroupPassword", nullable = false, defaultValue = "") - headingColor = table.Column (name = "HeadingColor", nullable = false, defaultValue = "maroon") - headingFontSize = table.Column (name = "HeadingFontSize", nullable = false, defaultValue = 16) - isPublic = table.Column (name = "IsPublic", nullable = false, defaultValue = false) - lineColor = table.Column (name = "LineColor", nullable = false, defaultValue = "navy") - listFonts = table.Column (name = "ListFonts", nullable = false, defaultValue = "Century Gothic,Tahoma,Luxi Sans,sans-serif") + { smallGroupId = table.Column (name = "SmallGroupId", nullable = false) + daysToExpire = table.Column (name = "DaysToExpire", nullable = false, defaultValue = 14) + daysToKeepNew = table.Column (name = "DaysToKeepNew", nullable = false, defaultValue = 7) + defaultEmailType = table.Column (name = "DefaultEmailType", nullable = false, defaultValue = "Html") + emailFromAddress = table.Column (name = "EmailFromAddress", nullable = false, defaultValue = "prayer@djs-consulting.com") + emailFromName = table.Column (name = "EmailFromName", nullable = false, defaultValue = "PrayerTracker") + groupPassword = table.Column (name = "GroupPassword", nullable = false, defaultValue = "") + headingColor = table.Column (name = "HeadingColor", nullable = false, defaultValue = "maroon") + headingFontSize = table.Column (name = "HeadingFontSize", nullable = false, defaultValue = 16) + isPublic = table.Column (name = "IsPublic", nullable = false, defaultValue = false) + lineColor = table.Column (name = "LineColor", nullable = false, defaultValue = "navy") + listFonts = table.Column (name = "ListFonts", nullable = false, defaultValue = "Century Gothic,Tahoma,Luxi Sans,sans-serif") longTermUpdateWeeks = table.Column (name = "LongTermUpdateWeeks", nullable = false, defaultValue = 4) - requestSort = table.Column (name = "RequestSort", maxLength = Nullable 1, nullable = false, defaultValue = "D") - textFontSize = table.Column (name = "TextFontSize", nullable = false, defaultValue = 12) - timeZoneId = table.Column (name = "TimeZoneId", nullable = false, defaultValue = "America/Denver") + requestSort = table.Column (name = "RequestSort", nullable = false, defaultValue = "D", maxLength = Nullable 1) + textFontSize = table.Column (name = "TextFontSize", nullable = false, defaultValue = 12) + timeZoneId = table.Column (name = "TimeZoneId", nullable = false, defaultValue = "America/Denver") + pageSize = table.Column (name = "PageSize", nullable = false, defaultValue = 100) }), constraints = fun table -> diff --git a/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs b/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs index 3bd392b..1c707ce 100644 --- a/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs +++ b/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs @@ -49,6 +49,7 @@ type AppDbContextModelSnapshot () = b.Property("requestSort").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("D").HasMaxLength(1) |> ignore b.Property("textFontSize").ValueGeneratedOnAdd().HasDefaultValue(12) |> ignore b.Property("timeZoneId").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("America/Denver") |> ignore + b.Property("pageSize").IsRequired().ValueGeneratedOnAdd().HasDefaultValue(100) |> ignore b.HasKey("smallGroupId") |> ignore b.HasIndex("timeZoneId") |> ignore b.ToTable("ListPreference") |> ignore) -- 2.45.1 From 7ba7fede69dd5bfa88fc30be64d9c6686d4dadb4 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 15 Mar 2019 20:16:40 -0500 Subject: [PATCH 04/14] Fixed merge error missed one... --- src/PrayerTracker.UI/PrayerRequest.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PrayerTracker.UI/PrayerRequest.fs b/src/PrayerTracker.UI/PrayerRequest.fs index 9c503e0..c0d1850 100644 --- a/src/PrayerTracker.UI/PrayerRequest.fs +++ b/src/PrayerTracker.UI/PrayerRequest.fs @@ -215,7 +215,7 @@ let maintain (reqs : PrayerRequest seq) (grp : SmallGroup) onlyActive (ctx : Htt [ icon "add_circle"; rawText "  "; locStr s.["Add a New Request"] ] rawText "       " a [ _href "/prayer-requests/view"; _title s.["View Prayer Request List"].Value ] - [ icon "list"; rawText "  "; encLocText s.["View Prayer Request List"] ] + [ icon "list"; rawText "  "; locStr s.["View Prayer Request List"] ] ] yield form [ _action "/prayer-requests"; _method "get"; _class "pt-center-text pt-search-form" ] [ input [ _type "text"; _name "search"; _placeholder s.["Search requests..."].Value ] -- 2.45.1 From 8b46a670fa6ae60e4b39de3e15859c7e84397265 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 15 Mar 2019 22:22:32 -0500 Subject: [PATCH 05/14] Search works on request text --- src/PrayerTracker.Data/DataAccess.fs | 52 +++++++++---------- src/PrayerTracker.UI/Resources/Common.es.resx | 6 +++ src/PrayerTracker/PrayerRequest.fs | 3 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/PrayerTracker.Data/DataAccess.fs b/src/PrayerTracker.Data/DataAccess.fs index d67d039..e9516c2 100644 --- a/src/PrayerTracker.Data/DataAccess.fs +++ b/src/PrayerTracker.Data/DataAccess.fs @@ -8,6 +8,22 @@ open PrayerTracker.Entities open System.Collections.Generic open System.Linq +[] +module private Helpers = + + /// Central place to append sort criteria for prayer request queries + let reqSort sort (query : IQueryable) = + match sort with + | "D" -> + query.OrderByDescending(fun pr -> pr.updatedDate) + .ThenByDescending(fun pr -> pr.enteredDate) + .ThenBy(fun pr -> pr.requestor) + | _ -> + query.OrderBy(fun pr -> pr.requestor) + .ThenByDescending(fun pr -> pr.updatedDate) + .ThenByDescending(fun pr -> pr.enteredDate) + + type AppDbContext with (*-- DISCONNECTED DATA EXTENSIONS --*) @@ -79,7 +95,6 @@ type AppDbContext with upcast ( this.PrayerRequests.AsNoTracking().Where(fun pr -> pr.smallGroupId = grp.smallGroupId) |> function - // Filter | query when activeOnly -> let asOf = theDate.AddDays(-(float grp.preferences.daysToExpire)).Date query.Where(fun pr -> @@ -89,16 +104,7 @@ type AppDbContext with || RequestType.Expecting = pr.requestType) && not pr.isManuallyExpired) | query -> query - |> function - // Sort - | query when grp.preferences.requestSort = "D" -> - query.OrderByDescending(fun pr -> pr.updatedDate) - .ThenByDescending(fun pr -> pr.enteredDate) - .ThenBy(fun pr -> pr.requestor) - | query -> - query.OrderBy(fun pr -> pr.requestor) - .ThenByDescending(fun pr -> pr.updatedDate) - .ThenByDescending(fun pr -> pr.enteredDate)) + |> reqSort grp.preferences.requestSort) /// Count prayer requests for the given small group Id member this.CountRequestsBySmallGroup gId = @@ -110,24 +116,14 @@ type AppDbContext with /// Get all (or active) requests for a small group as of now or the specified date member this.SearchRequestsForSmallGroup (grp : SmallGroup) (searchTerm : string) pageNbr : PrayerRequest seq = - let skip = (pageNbr - 1) * 100 + let pgSz = grp.preferences.pageSize + let skip = (pageNbr - 1) * pgSz + let sql = RawSqlString """SELECT * FROM pt."PrayerRequest" WHERE "SmallGroupId" = {0} AND "Text" ILIKE {1}""" + let like = sprintf "%%%s%%" upcast ( - this.PrayerRequests - .AsNoTracking() - .Where(fun pr -> pr.smallGroupId = grp.smallGroupId && pr.text.Contains(searchTerm.ToLowerInvariant())) - |> function - // Sort - | query when grp.preferences.requestSort = "D" -> - query.OrderByDescending(fun pr -> pr.updatedDate) - .ThenByDescending(fun pr -> pr.enteredDate) - .ThenBy(fun pr -> pr.requestor) - | query -> - query.OrderBy(fun pr -> pr.requestor) - .ThenByDescending(fun pr -> pr.updatedDate) - .ThenByDescending(fun pr -> pr.enteredDate) - |> function - // Pagination - | query -> query.Skip(skip).Take(100)) + this.PrayerRequests.FromSql(sql, grp.smallGroupId, like searchTerm).AsNoTracking () + |> reqSort grp.preferences.requestSort + |> function query -> (query.Skip skip).Take pgSz) (*-- SMALL GROUP EXTENSIONS --*) diff --git a/src/PrayerTracker.UI/Resources/Common.es.resx b/src/PrayerTracker.UI/Resources/Common.es.resx index 80f9af9..978b6cf 100644 --- a/src/PrayerTracker.UI/Resources/Common.es.resx +++ b/src/PrayerTracker.UI/Resources/Common.es.resx @@ -819,4 +819,10 @@ Haga Clic para Obtener Ayuda en Esta Página + + Buscar + + + Busca las peticiones... + \ No newline at end of file diff --git a/src/PrayerTracker/PrayerRequest.fs b/src/PrayerTracker/PrayerRequest.fs index fea0722..19d49aa 100644 --- a/src/PrayerTracker/PrayerRequest.fs +++ b/src/PrayerTracker/PrayerRequest.fs @@ -201,8 +201,7 @@ let maintain onlyActive : HttpHandler = task { let reqs = match ctx.GetQueryStringValue "search" with - | Ok srch -> - Seq.empty + | Ok srch -> db.SearchRequestsForSmallGroup grp srch 1 | Error _ -> db.AllRequestsForSmallGroup grp (ctx.GetService ()) None onlyActive return! { viewInfo ctx startTicks with helpLink = Some Help.maintainRequests } -- 2.45.1 From 215325f6fbe165f1efebc691a6ad8d5eb96e053d Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 16 Mar 2019 09:15:50 -0500 Subject: [PATCH 06/14] Added requestor field to search --- src/PrayerTracker.Data/DataAccess.fs | 6 +++++- src/search-sql.txt | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PrayerTracker.Data/DataAccess.fs b/src/PrayerTracker.Data/DataAccess.fs index e9516c2..79bfe1d 100644 --- a/src/PrayerTracker.Data/DataAccess.fs +++ b/src/PrayerTracker.Data/DataAccess.fs @@ -118,7 +118,11 @@ type AppDbContext with member this.SearchRequestsForSmallGroup (grp : SmallGroup) (searchTerm : string) pageNbr : PrayerRequest seq = let pgSz = grp.preferences.pageSize let skip = (pageNbr - 1) * pgSz - let sql = RawSqlString """SELECT * FROM pt."PrayerRequest" WHERE "SmallGroupId" = {0} AND "Text" ILIKE {1}""" + let sql = + """ SELECT * FROM pt."PrayerRequest" WHERE "SmallGroupId" = {0} AND "Text" ILIKE {1} + UNION + SELECT * FROM pt."PrayerRequest" WHERE "SmallGroupId" = {0} AND COALESCE("Requestor", '') ILIKE {1}""" + |> RawSqlString let like = sprintf "%%%s%%" upcast ( this.PrayerRequests.FromSql(sql, grp.smallGroupId, like searchTerm).AsNoTracking () diff --git a/src/search-sql.txt b/src/search-sql.txt index c5c2ce2..801748d 100644 --- a/src/search-sql.txt +++ b/src/search-sql.txt @@ -1,3 +1,5 @@ create extension pg_trgm; +set search_path=pt,public; +create index "IX_PrayerRequest_Requestor_TRGM" on "PrayerRequest" using GIN (COALESCE("Requestor", '') gin_trgm_ops); create index "IX_PrayerRequest_Text_TRGM" on "PrayerRequest" using GIN ("Text" gin_trgm_ops); -alter table "ListPreference" add column "PageSize" int not null default 100; \ No newline at end of file +alter table "ListPreference" add column "PageSize" int not null default 100; -- 2.45.1 From ef4f82cf9d54e65cabe16cbad6522090fa622d33 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 16 Mar 2019 18:58:17 -0500 Subject: [PATCH 07/14] Search / inactive request list paginate Also: - Fixed a verbiage error with the confirmation prompts - Split the I18N for the maintain requests page into its own localized view --- src/PrayerTracker.Data/DataAccess.fs | 11 +- src/PrayerTracker.Tests/Data/EntitiesTests.fs | 4 +- src/PrayerTracker.Tests/UI/UtilsTests.fs | 15 ++ src/PrayerTracker.Tests/UI/ViewModelsTests.fs | 13 ++ src/PrayerTracker.UI/Church.fs | 2 +- src/PrayerTracker.UI/PrayerRequest.fs | 92 +++++++--- src/PrayerTracker.UI/PrayerTracker.UI.fsproj | 3 + src/PrayerTracker.UI/Resources/Common.es.resx | 35 +--- .../Resources/Views/Requests/Maintain.es.resx | 159 ++++++++++++++++++ src/PrayerTracker.UI/SmallGroup.fs | 8 +- src/PrayerTracker.UI/User.fs | 2 +- src/PrayerTracker.UI/Utils.fs | 14 ++ src/PrayerTracker.UI/ViewModels.fs | 25 +++ src/PrayerTracker/PrayerRequest.fs | 26 ++- src/PrayerTracker/SmallGroup.fs | 2 +- 15 files changed, 341 insertions(+), 70 deletions(-) create mode 100644 src/PrayerTracker.UI/Resources/Views/Requests/Maintain.es.resx diff --git a/src/PrayerTracker.Data/DataAccess.fs b/src/PrayerTracker.Data/DataAccess.fs index 79bfe1d..1567533 100644 --- a/src/PrayerTracker.Data/DataAccess.fs +++ b/src/PrayerTracker.Data/DataAccess.fs @@ -90,7 +90,7 @@ type AppDbContext with } /// Get all (or active) requests for a small group as of now or the specified date - member this.AllRequestsForSmallGroup (grp : SmallGroup) clock listDate activeOnly : PrayerRequest seq = + member this.AllRequestsForSmallGroup (grp : SmallGroup) clock listDate activeOnly pageNbr : PrayerRequest seq = let theDate = match listDate with Some dt -> dt | _ -> grp.localDateNow clock upcast ( this.PrayerRequests.AsNoTracking().Where(fun pr -> pr.smallGroupId = grp.smallGroupId) @@ -104,8 +104,13 @@ type AppDbContext with || RequestType.Expecting = pr.requestType) && not pr.isManuallyExpired) | query -> query - |> reqSort grp.preferences.requestSort) - + |> reqSort grp.preferences.requestSort + |> function + | query -> + match activeOnly with + | true -> query.Skip 0 + | false -> query.Skip((pageNbr - 1) * grp.preferences.pageSize).Take grp.preferences.pageSize) + /// Count prayer requests for the given small group Id member this.CountRequestsBySmallGroup gId = this.PrayerRequests.CountAsync (fun pr -> pr.smallGroupId = gId) diff --git a/src/PrayerTracker.Tests/Data/EntitiesTests.fs b/src/PrayerTracker.Tests/Data/EntitiesTests.fs index 17ed70a..64bec37 100644 --- a/src/PrayerTracker.Tests/Data/EntitiesTests.fs +++ b/src/PrayerTracker.Tests/Data/EntitiesTests.fs @@ -1,10 +1,9 @@ module PrayerTracker.Entities.EntitiesTests open Expecto -open System -open System.Linq open NodaTime.Testing open NodaTime +open System [] let churchTests = @@ -45,6 +44,7 @@ let listPreferencesTests = Expect.isFalse mt.isPublic "The isPublic flag should not have been set" Expect.equal mt.timeZoneId "America/Denver" "The default time zone should have been America/Denver" Expect.equal mt.timeZone.timeZoneId "" "The default preferences should have included an empty time zone" + Expect.equal mt.pageSize 100 "The default page size should have been 100" } ] diff --git a/src/PrayerTracker.Tests/UI/UtilsTests.fs b/src/PrayerTracker.Tests/UI/UtilsTests.fs index dbf2384..7fc94c4 100644 --- a/src/PrayerTracker.Tests/UI/UtilsTests.fs +++ b/src/PrayerTracker.Tests/UI/UtilsTests.fs @@ -68,6 +68,21 @@ let htmlToPlainTextTests = } ] +[] +let makeUrlTests = + testList "makeUrl" [ + test "returns the URL when there are no parameters" { + Expect.equal (makeUrl "/test" []) "/test" "The URL should not have had any query string parameters added" + } + test "returns the URL with one query string parameter" { + Expect.equal (makeUrl "/test" [ "unit", "true" ]) "/test?unit=true" "The URL was not constructed properly" + } + test "returns the URL with multiple encoded query string parameters" { + let url = makeUrl "/test" [ "space", "a space"; "turkey", "=" ] + Expect.equal url "/test?space=a+space&turkey=%3D" "The URL was not constructed properly" + } + ] + [] let sndAsStringTests = testList "sndAsString" [ diff --git a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs index 8255041..ba58dbe 100644 --- a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs +++ b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs @@ -438,6 +438,19 @@ let groupLogOnTests = } ] +[] +let maintainRequestsTests = + testList "MaintainRequests" [ + test "empty is as expected" { + let mt = MaintainRequests.empty + Expect.isEmpty mt.requests "The requests for the model should have been empty" + Expect.equal mt.smallGroup.smallGroupId Guid.Empty "The small group should have been an empty one" + Expect.isNone mt.onlyActive "The only active flag should have been None" + Expect.isNone mt.searchTerm "The search term should have been None" + Expect.isNone mt.pageNbr "The page number should have been None" + } + ] + [] let requestListTests = testList "RequestList" [ diff --git a/src/PrayerTracker.UI/Church.fs b/src/PrayerTracker.UI/Church.fs index 9deb102..341d473 100644 --- a/src/PrayerTracker.UI/Church.fs +++ b/src/PrayerTracker.UI/Church.fs @@ -75,7 +75,7 @@ let maintain (churches : Church list) (stats : Map) ctx vi |> List.map (fun ch -> let chId = flatGuid ch.churchId let delAction = sprintf "/church/%s/delete" chId - let delPrompt = s.["Are you want to delete this {0}? This action cannot be undone.", + let delPrompt = s.["Are you sure you want to delete this {0}? This action cannot be undone.", sprintf "%s (%s)" (s.["Church"].Value.ToLower ()) ch.name] tr [] [ td [] [ diff --git a/src/PrayerTracker.UI/PrayerRequest.fs b/src/PrayerTracker.UI/PrayerRequest.fs index c0d1850..adc9956 100644 --- a/src/PrayerTracker.UI/PrayerRequest.fs +++ b/src/PrayerTracker.UI/PrayerRequest.fs @@ -160,39 +160,50 @@ let lists (grps : SmallGroup list) vi = /// View for the prayer request maintenance page -let maintain (reqs : PrayerRequest seq) (grp : SmallGroup) onlyActive (ctx : HttpContext) vi = +let maintain m (ctx : HttpContext) vi = let s = I18N.localizer.Force () - let now = grp.localDateNow (ctx.GetService ()) + let l = I18N.forView "Requests/Maintain" + use sw = new StringWriter () + let raw = rawLocText sw + let now = m.smallGroup.localDateNow (ctx.GetService ()) let typs = ReferenceList.requestTypeList s |> Map.ofList let updReq (req : PrayerRequest) = - match req.updateRequired now grp.preferences.daysToExpire grp.preferences.longTermUpdateWeeks with + match req.updateRequired now m.smallGroup.preferences.daysToExpire m.smallGroup.preferences.longTermUpdateWeeks with | true -> "pt-request-update" | false -> "" |> _class let reqExp (req : PrayerRequest) = - _class (match req.isExpired now grp.preferences.daysToExpire with true -> "pt-request-expired" | false -> "") + _class (match req.isExpired now m.smallGroup.preferences.daysToExpire with true -> "pt-request-expired" | false -> "") /// Iterate the sequence once, before we render, so we can get the count of it at the top of the table let requests = - reqs + m.requests |> Seq.map (fun req -> let reqId = flatGuid req.prayerRequestId let reqText = Utils.htmlToPlainText req.text let delAction = sprintf "/prayer-request/%s/delete" reqId - let delPrompt = s.["Are you want to delete this prayer request? This action cannot be undone.\\n(If the prayer request has been answered, or an event has passed, consider inactivating it instead.)"].Value + let delPrompt = + [ s.["Are you sure you want to delete this {0}? This action cannot be undone.", + s.["Prayer Request"].Value.ToLower() ] + .Value + "\\n" + l.["(If the prayer request has been answered, or an event has passed, consider inactivating it instead.)"] + .Value + ] + |> String.concat "" tr [] [ td [] [ - yield a [ _href (sprintf "/prayer-request/%s/edit" reqId); _title s.["Edit This Prayer Request"].Value ] + yield a [ _href (sprintf "/prayer-request/%s/edit" reqId); _title l.["Edit This Prayer Request"].Value ] [ icon "edit" ] - match req.isExpired now grp.preferences.daysToExpire with + match req.isExpired now m.smallGroup.preferences.daysToExpire with | true -> yield a [ _href (sprintf "/prayer-request/%s/restore" reqId) - _title s.["Restore This Inactive Request"].Value ] + _title l.["Restore This Inactive Request"].Value ] [ icon "visibility" ] | false -> yield a [ _href (sprintf "/prayer-request/%s/expire" reqId) - _title s.["Expire This Request Immediately"].Value ] + _title l.["Expire This Request Immediately"].Value ] [ icon "visibility_off" ] - yield a [ _href delAction; _title s.["Delete This Request"].Value; + yield a [ _href delAction; _title l.["Delete This Request"].Value; _onclick (sprintf "return PT.confirmDelete('%s','%s')" delAction delPrompt) ] [ icon "delete_forever" ] ] @@ -210,15 +221,25 @@ let maintain (reqs : PrayerRequest seq) (grp : SmallGroup) onlyActive (ctx : Htt ]) |> List.ofSeq [ yield div [ _class "pt-center-text" ] [ - br [] - a [ _href (sprintf "/prayer-request/%s/edit" emptyGuid); _title s.["Add a New Request"].Value ] + yield br [] + yield a [ _href (sprintf "/prayer-request/%s/edit" emptyGuid); _title s.["Add a New Request"].Value ] [ icon "add_circle"; rawText "  "; locStr s.["Add a New Request"] ] - rawText "       " - a [ _href "/prayer-requests/view"; _title s.["View Prayer Request List"].Value ] + yield rawText "       " + yield a [ _href "/prayer-requests/view"; _title s.["View Prayer Request List"].Value ] [ icon "list"; rawText "  "; locStr s.["View Prayer Request List"] ] + match m.searchTerm with + | Some _ -> + yield rawText "       " + yield a [ _href "/prayer-requests"; _title l.["Clear Search Criteria"].Value ] + [ icon "highlight_off"; rawText "  "; raw l.["Clear Search Criteria"] ] + | None -> () ] yield form [ _action "/prayer-requests"; _method "get"; _class "pt-center-text pt-search-form" ] [ - input [ _type "text"; _name "search"; _placeholder s.["Search requests..."].Value ] + input [ _type "text" + _name "search" + _placeholder l.["Search requests..."].Value + _value (defaultArg m.searchTerm "") + ] space submit [] "search" s.["Search"] ] @@ -241,20 +262,41 @@ let maintain (reqs : PrayerRequest seq) (grp : SmallGroup) onlyActive (ctx : Htt ] yield div [ _class "pt-center-text" ] [ yield br [] - match onlyActive with - | true -> - yield locStr s.["Inactive requests are currently not shown"] + match m.onlyActive with + | Some true -> + yield raw l.["Inactive requests are currently not shown"] yield br [] - yield a [ _href "/prayer-requests/inactive" ] [ locStr s.["Show Inactive Requests"] ] - | false -> - yield locStr s.["Inactive requests are currently shown"] - yield br [] - yield a [ _href "/prayer-requests" ] [ locStr s.["Do Not Show Inactive Requests"] ] + yield a [ _href "/prayer-requests/inactive" ] [ raw l.["Show Inactive Requests"] ] + | _ -> + match Option.isSome m.onlyActive with + | true -> + yield raw l.["Inactive requests are currently shown"] + yield br [] + yield a [ _href "/prayer-requests" ] [ raw l.["Do Not Show Inactive Requests"] ] + yield br [] + yield br [] + | false -> () + let srch = [ match m.searchTerm with Some s -> yield "search", s | None -> () ] + let url = match m.onlyActive with Some true | None -> "" | _ -> "/inactive" |> sprintf "/prayer-requests%s" + let pg = defaultArg m.pageNbr 1 + match pg with + | 1 -> () + | _ -> + // button (_type "submit" :: attrs) [ icon ico; rawText "  "; locStr text ] + let withPage = match pg with 2 -> srch | _ -> ("page", string (pg - 1)) :: srch + yield a [ _href (makeUrl url withPage) ] + [ icon "keyboard_arrow_left"; space; raw l.["Previous Page"] ] + yield rawText "     " + match requests.Length = m.smallGroup.preferences.pageSize with + | true -> + yield a [ _href (makeUrl url (("page", string (pg + 1)) :: srch)) ] + [ raw l.["Next Page"]; space; icon "keyboard_arrow_right" ] + | false -> () ] yield form [ _id "DeleteForm"; _action ""; _method "post" ] [ csrfToken ctx ] ] |> Layout.Content.wide - |> Layout.standard vi "Maintain Requests" + |> Layout.standard vi (match m.searchTerm with Some _ -> "Search Results" | None -> "Maintain Requests") /// View for the printable prayer request list diff --git a/src/PrayerTracker.UI/PrayerTracker.UI.fsproj b/src/PrayerTracker.UI/PrayerTracker.UI.fsproj index aa959ca..5bf0a24 100644 --- a/src/PrayerTracker.UI/PrayerTracker.UI.fsproj +++ b/src/PrayerTracker.UI/PrayerTracker.UI.fsproj @@ -55,6 +55,9 @@ ResXFileCodeGenerator + + ResXFileCodeGenerator + ResXFileCodeGenerator diff --git a/src/PrayerTracker.UI/Resources/Common.es.resx b/src/PrayerTracker.UI/Resources/Common.es.resx index 978b6cf..f00ca4c 100644 --- a/src/PrayerTracker.UI/Resources/Common.es.resx +++ b/src/PrayerTracker.UI/Resources/Common.es.resx @@ -144,8 +144,8 @@ Verde Azulado Brillante - - ¿Está desea eliminar este {0}? Esta acción no se puede deshacer. + + ¿Seguro que desea eliminar este {0}? Esta acción no se puede deshacer. PDF Adjunto @@ -612,9 +612,6 @@ Eliminar Este Grupo - - No Muestran las Peticiones Inactivos - Correo Electrónico @@ -633,12 +630,6 @@ Las Preferencias del Grupo - - Peticiones inactivas no se muestra actualmente - - - Peticiones inactivas se muestra actualmente - Mantener los Grupos @@ -696,9 +687,6 @@ Enviar anuncio a - - Muestran las Peticiones Inactivos - Ordenar por Fecha de Última Actualización @@ -729,15 +717,6 @@ Peticiones Activas - - Eliminar esta petición - - - Editar esta petición de oración - - - Expirar esta petición de oración de inmediato - Mantener las Peticiones de Oración @@ -747,9 +726,6 @@ Acciones Rápidas - - Restaurar esta petición inactiva - Guardar @@ -822,7 +798,10 @@ Buscar - - Busca las peticiones... + + Petición de Oración + + + Resultados de la Búsqueda \ No newline at end of file diff --git a/src/PrayerTracker.UI/Resources/Views/Requests/Maintain.es.resx b/src/PrayerTracker.UI/Resources/Views/Requests/Maintain.es.resx new file mode 100644 index 0000000..ee5d48c --- /dev/null +++ b/src/PrayerTracker.UI/Resources/Views/Requests/Maintain.es.resx @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + (Si la solicitud de oración ha sido respondida o si un evento ha pasado, considere desactivarla.) + + + Borrar los Criterios de Búsqueda + + + Eliminar esta petición + + + No Muestran las Peticiones Inactivos + + + Editar esta petición de oración + + + Expirar esta petición de oración de inmediato + + + Peticiones inactivas no se muestra actualmente + + + Peticiones inactivas se muestra actualmente + + + Siguiente Página + + + Página Anterior + + + Restaurar esta petición inactiva + + + Busca las peticiones... + + + Muestran las Peticiones Inactivos + + \ No newline at end of file diff --git a/src/PrayerTracker.UI/SmallGroup.fs b/src/PrayerTracker.UI/SmallGroup.fs index 61a8e20..007ea6e 100644 --- a/src/PrayerTracker.UI/SmallGroup.fs +++ b/src/PrayerTracker.UI/SmallGroup.fs @@ -192,7 +192,7 @@ let maintain (grps : SmallGroup list) ctx vi = |> List.map (fun g -> let grpId = flatGuid g.smallGroupId let delAction = sprintf "/small-group/%s/delete" grpId - let delPrompt = s.["Are you want to delete this {0}? This action cannot be undone.", + let delPrompt = s.["Are you sure you want to delete this {0}? This action cannot be undone.", sprintf "%s (%s)" (s.["Small Group"].Value.ToLower ()) g.name].Value tr [] [ td [] [ @@ -246,8 +246,10 @@ let members (mbrs : Member list) (emailTyps : Map) ctx |> List.map (fun mbr -> let mbrId = flatGuid mbr.memberId let delAction = sprintf "/small-group/member/%s/delete" mbrId - let delPrompt = s.["Are you want to delete this {0} ({1})? This action cannot be undone.", - s.["group member"], mbr.memberName].Value + let delPrompt = + s.["Are you sure you want to delete this {0}? This action cannot be undone.", s.["group member"]] + .Value + .Replace("?", sprintf " (%s)?" mbr.memberName) tr [] [ td [] [ a [ _href (sprintf "/small-group/member/%s/edit" mbrId); _title s.["Edit This Group Member"].Value ] diff --git a/src/PrayerTracker.UI/User.fs b/src/PrayerTracker.UI/User.fs index e2119ae..b6527f8 100644 --- a/src/PrayerTracker.UI/User.fs +++ b/src/PrayerTracker.UI/User.fs @@ -190,7 +190,7 @@ let maintain (users : User list) ctx vi = |> List.map (fun user -> let userId = flatGuid user.userId let delAction = sprintf "/user/%s/delete" userId - let delPrompt = s.["Are you want to delete this {0}? This action cannot be undone.", + let delPrompt = s.["Are you sure you want to delete this {0}? This action cannot be undone.", (sprintf "%s (%s)" (s.["User"].Value.ToLower()) user.fullName)].Value tr [] [ td [] [ diff --git a/src/PrayerTracker.UI/Utils.fs b/src/PrayerTracker.UI/Utils.fs index cc1621e..dda074e 100644 --- a/src/PrayerTracker.UI/Utils.fs +++ b/src/PrayerTracker.UI/Utils.fs @@ -127,6 +127,20 @@ let htmlToPlainText html = /// Get the second portion of a tuple as a string let sndAsString x = (snd >> string) x + +/// Make a URL with query string parameters +let makeUrl (url : string) (qs : (string * string) list) = + let queryString = + qs + |> List.fold + (fun (acc : StringBuilder) (key, value) -> + acc.Append(key).Append("=").Append(WebUtility.UrlEncode value).Append "&") + (StringBuilder ()) + match queryString.Length with + | 0 -> url + | _ -> queryString.Insert(0, "?").Insert(0, url).Remove(queryString.Length - 1, 1).ToString () + + /// "Magic string" repository [] module Key = diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index 0f162eb..023b093 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -473,7 +473,32 @@ with } +/// Items needed to display the request maintenance page +[] +type MaintainRequests = + { /// The requests to be displayed + requests : PrayerRequest seq + /// The small group to which the requests belong + smallGroup : SmallGroup + /// Whether only active requests are included + onlyActive : bool option + /// The search term for the requests + searchTerm : string option + /// The page number of the results + pageNbr : int option + } +with + static member empty = + { requests = Seq.empty + smallGroup = SmallGroup.empty + onlyActive = None + searchTerm = None + pageNbr = None + } + + /// Items needed to display the small group overview page +[] type Overview = { /// The total number of active requests totalActiveReqs : int diff --git a/src/PrayerTracker/PrayerRequest.fs b/src/PrayerTracker/PrayerRequest.fs index 19d49aa..6f1d75b 100644 --- a/src/PrayerTracker/PrayerRequest.fs +++ b/src/PrayerTracker/PrayerRequest.fs @@ -31,7 +31,7 @@ let private generateRequestList ctx date = match date with | Some d -> d | None -> grp.localDateNow clock - let reqs = ctx.dbContext().AllRequestsForSmallGroup grp clock (Some listDate) true + let reqs = ctx.dbContext().AllRequestsForSmallGroup grp clock (Some listDate) true 0 { requests = reqs |> List.ofSeq date = listDate listGroup = grp @@ -155,7 +155,7 @@ let list groupId : HttpHandler = match grp with | Some g when g.preferences.isPublic -> let clock = ctx.GetService () - let reqs = db.AllRequestsForSmallGroup g clock None true + let reqs = db.AllRequestsForSmallGroup g clock None true 0 return! viewInfo ctx startTicks |> Views.PrayerRequest.list @@ -199,13 +199,27 @@ let maintain onlyActive : HttpHandler = let db = ctx.dbContext () let grp = currentGroup ctx task { - let reqs = + let pageNbr = + match ctx.GetQueryStringValue "page" with + | Ok pg -> match Int32.TryParse pg with true, p -> p | false, _ -> 1 + | Error _ -> 1 + let m = match ctx.GetQueryStringValue "search" with - | Ok srch -> db.SearchRequestsForSmallGroup grp srch 1 - | Error _ -> db.AllRequestsForSmallGroup grp (ctx.GetService ()) None onlyActive + | Ok srch -> + { MaintainRequests.empty with + requests = db.SearchRequestsForSmallGroup grp srch pageNbr + searchTerm = Some srch + pageNbr = Some pageNbr + } + | Error _ -> + { MaintainRequests.empty with + requests = db.AllRequestsForSmallGroup grp (ctx.GetService ()) None onlyActive pageNbr + onlyActive = Some onlyActive + pageNbr = match onlyActive with true -> None | false -> Some pageNbr + } return! { viewInfo ctx startTicks with helpLink = Some Help.maintainRequests } - |> Views.PrayerRequest.maintain reqs grp onlyActive ctx + |> Views.PrayerRequest.maintain { m with smallGroup = grp } ctx |> renderHtml next ctx } diff --git a/src/PrayerTracker/SmallGroup.fs b/src/PrayerTracker/SmallGroup.fs index 89d687d..00cfff2 100644 --- a/src/PrayerTracker/SmallGroup.fs +++ b/src/PrayerTracker/SmallGroup.fs @@ -208,7 +208,7 @@ let overview : HttpHandler = let db = ctx.dbContext () let clock = ctx.GetService () task { - let reqs = db.AllRequestsForSmallGroup (currentGroup ctx) clock None true |> List.ofSeq + let reqs = db.AllRequestsForSmallGroup (currentGroup ctx) clock None true 0 |> List.ofSeq let! reqCount = db.CountRequestsBySmallGroup (currentGroup ctx).smallGroupId let! mbrCount = db.CountMembersForSmallGroup (currentGroup ctx).smallGroupId let m = -- 2.45.1 From 047bc34a5fedcb3eb85f321d5f0a92b12071bdd9 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 16 Mar 2019 19:55:02 -0500 Subject: [PATCH 08/14] Added column for as-of date display --- src/PrayerTracker.Data/Entities.fs | 56 +++++++++++++++++++ .../20161217153124_InitialDatabase.fs | 6 +- .../Migrations/AppDbContextModelSnapshot.fs | 3 +- .../PrayerTracker.Data.fsproj | 4 +- src/PrayerTracker.Tests/Data/EntitiesTests.fs | 1 + .../PrayerTracker.Tests.fsproj | 2 + src/PrayerTracker.UI/PrayerTracker.UI.fsproj | 2 +- src/PrayerTracker/PrayerTracker.fsproj | 4 +- src/search-sql.txt | 1 + 9 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/PrayerTracker.Data/Entities.fs b/src/PrayerTracker.Data/Entities.fs index 50043d0..76a1f60 100644 --- a/src/PrayerTracker.Data/Entities.fs +++ b/src/PrayerTracker.Data/Entities.fs @@ -37,6 +37,51 @@ module RequestType = (*-- SUPPORT TYPES --*) +/// How as-of dates should (or should not) be displayed with requests +type AsOfDateDisplay = + /// No as-of date should be displayed + | NoDisplay + /// The as-of date should be displayed in the culture's short date format + | ShortDate + /// The as-of date should be displayed in the culture's long date format + | LongDate +with + /// Convert to a DU case from a single-character string + static member fromCode code = + match code with + | "N" -> NoDisplay + | "S" -> ShortDate + | "L" -> LongDate + | _ -> invalidArg "code" (sprintf "Unknown code %s" code) + /// Convert this DU case to a single-character string + member this.toCode () = + match this with + | NoDisplay -> "N" + | ShortDate -> "S" + | LongDate -> "L" + + +[] +module Converters = + open Microsoft.EntityFrameworkCore.Storage.ValueConversion + open Microsoft.FSharp.Linq.RuntimeHelpers + open System.Linq.Expressions + + let private fromDU = + <@ Func(fun (x : AsOfDateDisplay) -> x.toCode ()) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + + let private toDU = + <@ Func(AsOfDateDisplay.fromCode) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + + /// Conversion between a string and an AsOfDateDisplay DU value + type AsOfDateDisplayConverter () = + inherit ValueConverter (fromDU, toDU) + + /// Statistics for churches [] type ChurchStats = @@ -158,6 +203,8 @@ and [] ListPreferences = timeZone : TimeZone /// The number of requests displayed per page pageSize : int + /// How the as-of date should be automatically displayed + asOfDateDisplay : AsOfDateDisplay } with /// A set of preferences with their default values @@ -180,6 +227,7 @@ and [] ListPreferences = timeZoneId = "America/Denver" timeZone = TimeZone.empty pageSize = 100 + asOfDateDisplay = NoDisplay } /// Configure EF for this entity static member internal configureEF (mb : ModelBuilder) = @@ -268,8 +316,16 @@ and [] ListPreferences = .HasColumnName("PageSize") .IsRequired() .HasDefaultValue 100 + |> ignore + m.Property(fun e -> e.asOfDateDisplay) + .HasColumnName("AsOfDateDisplay") + .IsRequired() + .HasMaxLength(1) + .HasDefaultValue NoDisplay |> ignore) |> ignore + mb.Model.FindEntityType(typeof).FindProperty("asOfDateDisplay") + .SetValueConverter(AsOfDateDisplayConverter ()) /// A member of a small group diff --git a/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs b/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs index 14f6ddb..53e02dc 100644 --- a/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs +++ b/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs @@ -38,6 +38,7 @@ type ListPreferencesTable = textFontSize : OperationBuilder timeZoneId : OperationBuilder pageSize : OperationBuilder + asOfDateDisplay : OperationBuilder } type MemberTable = @@ -192,6 +193,7 @@ type InitialDatabase () = textFontSize = table.Column (name = "TextFontSize", nullable = false, defaultValue = 12) timeZoneId = table.Column (name = "TimeZoneId", nullable = false, defaultValue = "America/Denver") pageSize = table.Column (name = "PageSize", nullable = false, defaultValue = 100) + asOfDateDisplay = table.Column (name = "AsOfDateDisplay", nullable = false, defaultValue = "N", maxLength = Nullable 1) }), constraints = fun table -> @@ -359,9 +361,11 @@ type InitialDatabase () = b.Property("lineColor").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("navy") |> ignore b.Property("listFonts").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("Century Gothic,Tahoma,Luxi Sans,sans-serif") |> ignore b.Property("longTermUpdateWeeks").ValueGeneratedOnAdd().HasDefaultValue(4) |> ignore - b.Property("requestSort").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("D").HasMaxLength(1) |> ignore + b.Property("requestSort").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("D").HasMaxLength(1) |> ignore b.Property("textFontSize").ValueGeneratedOnAdd().HasDefaultValue(12) |> ignore b.Property("timeZoneId").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("America/Denver") |> ignore + b.Property("pageSize").IsRequired().ValueGeneratedOnAdd().HasDefaultValue(100) |> ignore + b.Property("asOfDateDisplay").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("N").HasMaxLength(1) |> ignore b.HasKey("smallGroupId") |> ignore b.HasIndex("timeZoneId") |> ignore b.ToTable("ListPreference") |> ignore) diff --git a/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs b/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs index 1c707ce..6df9c1c 100644 --- a/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs +++ b/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs @@ -46,10 +46,11 @@ type AppDbContextModelSnapshot () = b.Property("lineColor").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("navy") |> ignore b.Property("listFonts").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("Century Gothic,Tahoma,Luxi Sans,sans-serif") |> ignore b.Property("longTermUpdateWeeks").ValueGeneratedOnAdd().HasDefaultValue(4) |> ignore - b.Property("requestSort").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("D").HasMaxLength(1) |> ignore + b.Property("requestSort").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("D").HasMaxLength(1) |> ignore b.Property("textFontSize").ValueGeneratedOnAdd().HasDefaultValue(12) |> ignore b.Property("timeZoneId").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("America/Denver") |> ignore b.Property("pageSize").IsRequired().ValueGeneratedOnAdd().HasDefaultValue(100) |> ignore + b.Property("asOfDateDisplay").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("N").HasMaxLength(1) |> ignore b.HasKey("smallGroupId") |> ignore b.HasIndex("timeZoneId") |> ignore b.ToTable("ListPreference") |> ignore) diff --git a/src/PrayerTracker.Data/PrayerTracker.Data.fsproj b/src/PrayerTracker.Data/PrayerTracker.Data.fsproj index b915c43..d58b0cc 100644 --- a/src/PrayerTracker.Data/PrayerTracker.Data.fsproj +++ b/src/PrayerTracker.Data/PrayerTracker.Data.fsproj @@ -2,8 +2,8 @@ netstandard2.0 - 7.0.0.0 - 7.0.0.0 + 7.3.0.0 + 7.3.0.0 diff --git a/src/PrayerTracker.Tests/Data/EntitiesTests.fs b/src/PrayerTracker.Tests/Data/EntitiesTests.fs index 64bec37..688abbe 100644 --- a/src/PrayerTracker.Tests/Data/EntitiesTests.fs +++ b/src/PrayerTracker.Tests/Data/EntitiesTests.fs @@ -45,6 +45,7 @@ let listPreferencesTests = Expect.equal mt.timeZoneId "America/Denver" "The default time zone should have been America/Denver" Expect.equal mt.timeZone.timeZoneId "" "The default preferences should have included an empty time zone" Expect.equal mt.pageSize 100 "The default page size should have been 100" + Expect.equal mt.asOfDateDisplay NoDisplay "The as-of date display should have been No Display" } ] diff --git a/src/PrayerTracker.Tests/PrayerTracker.Tests.fsproj b/src/PrayerTracker.Tests/PrayerTracker.Tests.fsproj index e0281fe..ba90d4e 100644 --- a/src/PrayerTracker.Tests/PrayerTracker.Tests.fsproj +++ b/src/PrayerTracker.Tests/PrayerTracker.Tests.fsproj @@ -3,6 +3,8 @@ Exe netcoreapp2.2 + 7.3.0.0 + 7.3.0.0 diff --git a/src/PrayerTracker.UI/PrayerTracker.UI.fsproj b/src/PrayerTracker.UI/PrayerTracker.UI.fsproj index 5bf0a24..85fd473 100644 --- a/src/PrayerTracker.UI/PrayerTracker.UI.fsproj +++ b/src/PrayerTracker.UI/PrayerTracker.UI.fsproj @@ -2,7 +2,7 @@ netstandard2.0 - 7.0.0.0 + 7.3.0.0 7.0.0.0 diff --git a/src/PrayerTracker/PrayerTracker.fsproj b/src/PrayerTracker/PrayerTracker.fsproj index 516089e..1d3308e 100644 --- a/src/PrayerTracker/PrayerTracker.fsproj +++ b/src/PrayerTracker/PrayerTracker.fsproj @@ -2,8 +2,8 @@ netcoreapp2.2 - 7.2.0.0 - 7.0.0.0 + 7.3.0.0 + 7.3.0.0 Bit Badger Solutions diff --git a/src/search-sql.txt b/src/search-sql.txt index 801748d..d03bcec 100644 --- a/src/search-sql.txt +++ b/src/search-sql.txt @@ -3,3 +3,4 @@ set search_path=pt,public; create index "IX_PrayerRequest_Requestor_TRGM" on "PrayerRequest" using GIN (COALESCE("Requestor", '') gin_trgm_ops); create index "IX_PrayerRequest_Text_TRGM" on "PrayerRequest" using GIN ("Text" gin_trgm_ops); alter table "ListPreference" add column "PageSize" int not null default 100; +alter table "ListPreference" add column "AsOfDateDisplay" varchar(1) not null default 'N'; -- 2.45.1 From 50f8b56871e3b52b8215446c3fa2a8b3b4174040 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 16 Mar 2019 21:41:56 -0500 Subject: [PATCH 09/14] Added page size and as-of date display to prefs page --- src/PrayerTracker.Data/Entities.fs | 3 +-- src/PrayerTracker.UI/Resources/Common.es.resx | 15 +++++++++++++ src/PrayerTracker.UI/SmallGroup.fs | 19 ++++++++++++++--- src/PrayerTracker.UI/ViewModels.fs | 21 +++++++++++++++---- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/PrayerTracker.Data/Entities.fs b/src/PrayerTracker.Data/Entities.fs index 76a1f60..e881d13 100644 --- a/src/PrayerTracker.Data/Entities.fs +++ b/src/PrayerTracker.Data/Entities.fs @@ -61,7 +61,6 @@ with | LongDate -> "L" -[] module Converters = open Microsoft.EntityFrameworkCore.Storage.ValueConversion open Microsoft.FSharp.Linq.RuntimeHelpers @@ -325,7 +324,7 @@ and [] ListPreferences = |> ignore) |> ignore mb.Model.FindEntityType(typeof).FindProperty("asOfDateDisplay") - .SetValueConverter(AsOfDateDisplayConverter ()) + .SetValueConverter(Converters.AsOfDateDisplayConverter ()) /// A member of a small group diff --git a/src/PrayerTracker.UI/Resources/Common.es.resx b/src/PrayerTracker.UI/Resources/Common.es.resx index f00ca4c..2f3f9eb 100644 --- a/src/PrayerTracker.UI/Resources/Common.es.resx +++ b/src/PrayerTracker.UI/Resources/Common.es.resx @@ -798,10 +798,25 @@ Buscar + + Mostrar una fecha “como de” completa + + + Mostrar una fecha “como de” corta + + + No se muestran la fecha “como de” + + + Tamaño de Página + Petición de Oración Resultados de la Búsqueda + + Visualización de la Fecha “Como de” + \ No newline at end of file diff --git a/src/PrayerTracker.UI/SmallGroup.fs b/src/PrayerTracker.UI/SmallGroup.fs index 007ea6e..15a92ef 100644 --- a/src/PrayerTracker.UI/SmallGroup.fs +++ b/src/PrayerTracker.UI/SmallGroup.fs @@ -284,7 +284,7 @@ let members (mbrs : Member list) (emailTyps : Map) ctx let overview m vi = let s = I18N.localizer.Force () let linkSpacer = rawText "  " - let typs = ReferenceList.requestTypeList s |> Map.ofList + let typs = ReferenceList.requestTypeList s |> dict article [ _class "pt-overview" ] [ section [] [ header [ _role "heading" ] [ @@ -350,7 +350,7 @@ let preferences (m : EditPreferences) (tzs : TimeZone list) ctx vi = use sw = new StringWriter () let raw = rawLocText sw [ form [ _action "/small-group/preferences/save"; _method "post"; _class "pt-center-columns" ] [ - style [ _scoped ] [ rawText "#expireDays, #daysToKeepNew, #longTermUpdateWeeks, #headingFontSize, #listFontSize { width: 3rem; } #emailFromAddress { width: 20rem; } #listFonts { width: 40rem; } @media screen and (max-width: 40rem) { #listFonts { width: 100%; } }" ] + style [ _scoped ] [ rawText "#expireDays, #daysToKeepNew, #longTermUpdateWeeks, #headingFontSize, #listFontSize, #pageSize { width: 3rem; } #emailFromAddress { width: 20rem; } #listFonts { width: 40rem; } @media screen and (max-width: 40rem) { #listFonts { width: 100%; } }" ] csrfToken ctx fieldset [] [ legend [] [ strong [] [ icon "date_range"; rawText "  "; locStr s.["Dates"] ] ] @@ -479,7 +479,7 @@ let preferences (m : EditPreferences) (tzs : TimeZone list) ctx vi = legend [] [ strong [] [ icon "settings"; rawText "  "; locStr s.["Other Settings"] ] ] div [ _class "pt-field-row" ] [ div [ _class "pt-field" ] [ - label [ _for "TimeZone" ] [ locStr s.["Time Zone"] ] + label [ _for "timeZone" ] [ locStr s.["Time Zone"] ] seq { yield "", selectDefault s.["Select"].Value yield! tzs |> List.map (fun tz -> tz.timeZoneId, (TimeZones.name tz.timeZoneId s).Value) @@ -511,6 +511,19 @@ let preferences (m : EditPreferences) (tzs : TimeZone list) ctx vi = _value (match m.groupPassword with Some x -> x | None -> "") ] ] ] + div [ _class "pt-field-row" ] [ + div [ _class "pt-field" ] [ + label [ _for "pageSize" ] [ locStr s.["Page Size"] ] + input [ _type "number"; _name "pageSize"; _id "pageSize"; _min "10"; _max "255"; _required + _value (string m.pageSize) ] + ] + div [ _class "pt-field" ] [ + label [ _for "asOfDate" ] [ locStr s.["“As of” Date Display"] ] + ReferenceList.asOfDateList s + |> List.map (fun (code, desc) -> code, desc.Value) + |> selectList "asOfDate" m.asOfDate [ _required ] + ] + ] div [ _class "pt-field-row" ] [ submit [] "save" s.["Save Preferences"] ] ] ] diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index 023b093..d1f1248 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -10,6 +10,13 @@ open System /// Helper module to return localized reference lists module ReferenceList = + /// A localized list of the AsOfDateDisplay DU cases + let asOfDateList (s : IStringLocalizer) = + [ NoDisplay.toCode (), s.["Do not display the “as of” date"] + ShortDate.toCode (), s.["Display a short “as of” date"] + LongDate.toCode (), s.["Display a full “as of” date"] + ] + /// A list of e-mail type options let emailTypeList def (s : IStringLocalizer) = // Localize the default type @@ -27,12 +34,10 @@ module ReferenceList = /// A list of expiration options let expirationList (s : IStringLocalizer) includeExpireNow = - seq { - yield "N", s.["Expire Normally"] + [ yield "N", s.["Expire Normally"] yield "Y", s.["Request Never Expires"] match includeExpireNow with true -> yield "X", s.["Expire Immediately"] | false -> () - } - |> List.ofSeq + ] /// A list of request types let requestTypeList (s : IStringLocalizer) = @@ -273,6 +278,10 @@ type EditPreferences = listVisibility : int /// The small group password groupPassword : string option + /// The page size for search / inactive requests + pageSize : int + /// How the as-of date should be displayed + asOfDate : string } with static member fromPreferences (prefs : ListPreferences) = @@ -293,6 +302,8 @@ with listFontSize = prefs.textFontSize timeZone = prefs.timeZoneId groupPassword = Some prefs.groupPassword + pageSize = prefs.pageSize + asOfDate = prefs.asOfDateDisplay.toCode () listVisibility = match true with | _ when prefs.isPublic -> RequestVisibility.``public`` @@ -323,6 +334,8 @@ with timeZoneId = this.timeZone isPublic = isPublic groupPassword = grpPw + pageSize = this.pageSize + asOfDateDisplay = AsOfDateDisplay.fromCode this.asOfDate } -- 2.45.1 From bce2d5dbcc8535bd8bbab9b9d98de19607987caa Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 16 Mar 2019 23:08:46 -0500 Subject: [PATCH 10/14] Minor refactor, added another DU caught up on some tests as well --- src/PrayerTracker.Data/DataAccess.fs | 4 +- src/PrayerTracker.Data/Entities.fs | 52 ++++++++++++++++--- src/PrayerTracker.Tests/Data/EntitiesTests.fs | 49 ++++++++++++++++- src/PrayerTracker.Tests/UI/ViewModelsTests.fs | 18 ++++++- src/PrayerTracker.UI/ViewModels.fs | 16 +++--- 5 files changed, 118 insertions(+), 21 deletions(-) diff --git a/src/PrayerTracker.Data/DataAccess.fs b/src/PrayerTracker.Data/DataAccess.fs index 1567533..46a39f8 100644 --- a/src/PrayerTracker.Data/DataAccess.fs +++ b/src/PrayerTracker.Data/DataAccess.fs @@ -14,11 +14,11 @@ module private Helpers = /// Central place to append sort criteria for prayer request queries let reqSort sort (query : IQueryable) = match sort with - | "D" -> + | SortByDate -> query.OrderByDescending(fun pr -> pr.updatedDate) .ThenByDescending(fun pr -> pr.enteredDate) .ThenBy(fun pr -> pr.requestor) - | _ -> + | SortByRequestor -> query.OrderBy(fun pr -> pr.requestor) .ThenByDescending(fun pr -> pr.updatedDate) .ThenByDescending(fun pr -> pr.enteredDate) diff --git a/src/PrayerTracker.Data/Entities.fs b/src/PrayerTracker.Data/Entities.fs index e881d13..824a995 100644 --- a/src/PrayerTracker.Data/Entities.fs +++ b/src/PrayerTracker.Data/Entities.fs @@ -54,31 +54,65 @@ with | "L" -> LongDate | _ -> invalidArg "code" (sprintf "Unknown code %s" code) /// Convert this DU case to a single-character string - member this.toCode () = + member this.code = match this with | NoDisplay -> "N" | ShortDate -> "S" | LongDate -> "L" +/// How requests should be sorted +type RequestSort = + /// Sort by date, then by requestor/subject + | SortByDate + /// Sort by requestor/subject, then by date + | SortByRequestor +with + /// Convert to a DU case from a single-character string + static member fromCode code = + match code with + | "D" -> SortByDate + | "R" -> SortByRequestor + | _ -> invalidArg "code" (sprintf "Unknown code %s" code) + /// Convert this DU case to a single-character string + member this.code = + match this with + | SortByDate -> "D" + | SortByRequestor -> "R" + + module Converters = open Microsoft.EntityFrameworkCore.Storage.ValueConversion open Microsoft.FSharp.Linq.RuntimeHelpers open System.Linq.Expressions - let private fromDU = - <@ Func(fun (x : AsOfDateDisplay) -> x.toCode ()) @> + let private asOfFromDU = + <@ Func(fun (x : AsOfDateDisplay) -> x.code) @> |> LeafExpressionConverter.QuotationToExpression |> unbox>> - let private toDU = + let private asOfToDU = <@ Func(AsOfDateDisplay.fromCode) @> |> LeafExpressionConverter.QuotationToExpression |> unbox>> + let private sortFromDU = + <@ Func(fun (x : RequestSort) -> x.code) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + + let private sortToDU = + <@ Func(RequestSort.fromCode) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + /// Conversion between a string and an AsOfDateDisplay DU value type AsOfDateDisplayConverter () = - inherit ValueConverter (fromDU, toDU) + inherit ValueConverter (asOfFromDU, asOfToDU) + + /// Conversion between a string and a RequestSort DU value + type RequestSortConverter () = + inherit ValueConverter (sortFromDU, sortToDU) /// Statistics for churches @@ -189,7 +223,7 @@ and [] ListPreferences = /// The font size for the text on the prayer request list textFontSize : int /// The order in which the prayer requests are sorted - requestSort : string + requestSort : RequestSort /// The password used for "small group login" (view-only request list) groupPassword : string /// The default e-mail type for this class @@ -219,7 +253,7 @@ and [] ListPreferences = lineColor = "navy" headingFontSize = 16 textFontSize = 12 - requestSort = "D" + requestSort = SortByDate groupPassword = "" defaultEmailType = EmailType.Html isPublic = false @@ -289,7 +323,7 @@ and [] ListPreferences = .HasColumnName("RequestSort") .IsRequired() .HasMaxLength(1) - .HasDefaultValue "D" + .HasDefaultValue SortByDate |> ignore m.Property(fun e -> e.groupPassword) .HasColumnName("GroupPassword") @@ -323,6 +357,8 @@ and [] ListPreferences = .HasDefaultValue NoDisplay |> ignore) |> ignore + mb.Model.FindEntityType(typeof).FindProperty("requestSort") + .SetValueConverter(Converters.RequestSortConverter ()) mb.Model.FindEntityType(typeof).FindProperty("asOfDateDisplay") .SetValueConverter(Converters.AsOfDateDisplayConverter ()) diff --git a/src/PrayerTracker.Tests/Data/EntitiesTests.fs b/src/PrayerTracker.Tests/Data/EntitiesTests.fs index 688abbe..241c20d 100644 --- a/src/PrayerTracker.Tests/Data/EntitiesTests.fs +++ b/src/PrayerTracker.Tests/Data/EntitiesTests.fs @@ -5,6 +5,33 @@ open NodaTime.Testing open NodaTime open System +[] +let asOfDateDisplayTests = + testList "AsOfDateDisplay" [ + test "NoDisplay code is correct" { + Expect.equal NoDisplay.code "N" "The code for NoDisplay should have been \"N\"" + } + test "ShortDate code is correct" { + Expect.equal ShortDate.code "S" "The code for ShortDate should have been \"S\"" + } + test "LongDate code is correct" { + Expect.equal LongDate.code "L" "The code for LongDate should have been \"N\"" + } + test "fromCode N should return NoDisplay" { + Expect.equal (AsOfDateDisplay.fromCode "N") NoDisplay "\"N\" should have been converted to NoDisplay" + } + test "fromCode S should return ShortDate" { + Expect.equal (AsOfDateDisplay.fromCode "S") ShortDate "\"S\" should have been converted to ShortDate" + } + test "fromCode L should return LongDate" { + Expect.equal (AsOfDateDisplay.fromCode "L") LongDate "\"L\" should have been converted to LongDate" + } + test "fromCode X should raise" { + Expect.throws (fun () -> AsOfDateDisplay.fromCode "X" |> ignore) + "An unknown code should have raised an exception" + } + ] + [] let churchTests = testList "Church" [ @@ -38,7 +65,7 @@ let listPreferencesTests = Expect.equal mt.lineColor "navy" "The default heding line color should have been navy" Expect.equal mt.headingFontSize 16 "The default heading font size should have been 16" Expect.equal mt.textFontSize 12 "The default text font size should have been 12" - Expect.equal mt.requestSort "D" "The default request sort should have been D (date)" + Expect.equal mt.requestSort SortByDate "The default request sort should have been by date" Expect.equal mt.groupPassword "" "The default group password should have been blank" Expect.equal mt.defaultEmailType EmailType.Html "The default e-mail type should have been HTML" Expect.isFalse mt.isPublic "The isPublic flag should not have been set" @@ -130,6 +157,26 @@ let prayerRequestTests = } ] +[] +let requestSortTests = + testList "RequestSort" [ + test "SortByDate code is correct" { + Expect.equal SortByDate.code "D" "The code for SortByDate should have been \"D\"" + } + test "SortByRequestor code is correct" { + Expect.equal SortByRequestor.code "R" "The code for SortByRequestor should have been \"R\"" + } + test "fromCode D should return SortByDate" { + Expect.equal (RequestSort.fromCode "D") SortByDate "\"D\" should have been converted to SortByDate" + } + test "fromCode R should return SortByRequestor" { + Expect.equal (RequestSort.fromCode "R") SortByRequestor "\"R\" should have been converted to SortByRequestor" + } + test "fromCode Q should raise" { + Expect.throws (fun () -> RequestSort.fromCode "Q" |> ignore) "An unknown code should have raised an exception" + } + ] + [] let smallGroupTests = testList "SmallGroup" [ diff --git a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs index ba58dbe..c831f86 100644 --- a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs +++ b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs @@ -15,6 +15,18 @@ let countAll _ = true module ReferenceListTests = + [] + let asOfDateListTests = + testList "ReferenceList.asOfDateList" [ + test "has all three options listed" { + let asOf = ReferenceList.asOfDateList _s + Expect.hasCountOf asOf 3u countAll "There should have been 3 as-of choices returned" + Expect.exists asOf (fun (x, _) -> x = NoDisplay.code) "The option for no display was not found" + Expect.exists asOf (fun (x, _) -> x = ShortDate.code) "The option for a short date was not found" + Expect.exists asOf (fun (x, _) -> x = LongDate.code) "The option for a full date was not found" + } + ] + [] let emailTypeListTests = testList "ReferenceList.emailTypeList" [ @@ -248,7 +260,7 @@ let editPreferencesTests = Expect.equal edit.expireDays prefs.daysToExpire "The expiration days were not filled correctly" Expect.equal edit.daysToKeepNew prefs.daysToKeepNew "The days to keep new were not filled correctly" Expect.equal edit.longTermUpdateWeeks prefs.longTermUpdateWeeks "The weeks for update were not filled correctly" - Expect.equal edit.requestSort prefs.requestSort "The request sort was not filled correctly" + Expect.equal edit.requestSort prefs.requestSort.code "The request sort was not filled correctly" Expect.equal edit.emailFromName prefs.emailFromName "The e-mail from name was not filled correctly" Expect.equal edit.emailFromAddress prefs.emailFromAddress "The e-mail from address was not filled correctly" Expect.equal edit.defaultEmailType prefs.defaultEmailType "The default e-mail type was not filled correctly" @@ -572,7 +584,9 @@ let requestListTests = let newList = { reqList with listGroup = - { reqList.listGroup with preferences = { reqList.listGroup.preferences with requestSort = "R" } } + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with requestSort = SortByRequestor } + } } let reqs = newList.requestsInCategory RequestType.Current Expect.hasCountOf reqs 2u countAll "There should have been two requests" diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index d1f1248..fd9307c 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -12,9 +12,9 @@ module ReferenceList = /// A localized list of the AsOfDateDisplay DU cases let asOfDateList (s : IStringLocalizer) = - [ NoDisplay.toCode (), s.["Do not display the “as of” date"] - ShortDate.toCode (), s.["Display a short “as of” date"] - LongDate.toCode (), s.["Display a full “as of” date"] + [ NoDisplay.code, s.["Do not display the “as of” date"] + ShortDate.code, s.["Display a short “as of” date"] + LongDate.code, s.["Display a full “as of” date"] ] /// A list of e-mail type options @@ -289,7 +289,7 @@ with { expireDays = prefs.daysToExpire daysToKeepNew = prefs.daysToKeepNew longTermUpdateWeeks = prefs.longTermUpdateWeeks - requestSort = prefs.requestSort + requestSort = prefs.requestSort.code emailFromName = prefs.emailFromName emailFromAddress = prefs.emailFromAddress defaultEmailType = prefs.defaultEmailType @@ -303,7 +303,7 @@ with timeZone = prefs.timeZoneId groupPassword = Some prefs.groupPassword pageSize = prefs.pageSize - asOfDate = prefs.asOfDateDisplay.toCode () + asOfDate = prefs.asOfDateDisplay.code listVisibility = match true with | _ when prefs.isPublic -> RequestVisibility.``public`` @@ -322,7 +322,7 @@ with daysToExpire = this.expireDays daysToKeepNew = this.daysToKeepNew longTermUpdateWeeks = this.longTermUpdateWeeks - requestSort = this.requestSort + requestSort = RequestSort.fromCode this.requestSort emailFromName = this.emailFromName emailFromAddress = this.emailFromAddress defaultEmailType = this.defaultEmailType @@ -573,8 +573,8 @@ with |> Seq.ofList |> Seq.filter (fun req -> req.requestType = cat) match this.listGroup.preferences.requestSort with - | "D" -> reqs |> Seq.sortByDescending (fun req -> req.updatedDate) - | _ -> reqs |> Seq.sortBy (fun req -> req.requestor) + | SortByDate -> reqs |> Seq.sortByDescending (fun req -> req.updatedDate) + | SortByRequestor -> reqs |> Seq.sortBy (fun req -> req.requestor) |> List.ofSeq /// Is this request new? member this.isNew (req : PrayerRequest) = -- 2.45.1 From f71c3b8bb7408af2540440af20186f08b18af56f Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 19 Mar 2019 17:19:17 -0500 Subject: [PATCH 11/14] Changed magic strings to DUs Disconnected time = refactoring based on AsOfDateDisplay and RequestSort success --- src/PrayerTracker.Data/DataAccess.fs | 10 +- src/PrayerTracker.Data/Entities.fs | 234 ++++++++++++------ .../20161217153124_InitialDatabase.fs | 89 ++++--- .../Migrations/AppDbContextModelSnapshot.fs | 7 +- src/PrayerTracker.Tests/Data/EntitiesTests.fs | 116 +++++++-- src/PrayerTracker.Tests/UI/ViewModelsTests.fs | 74 +++--- src/PrayerTracker.UI/PrayerRequest.fs | 2 +- src/PrayerTracker.UI/SmallGroup.fs | 6 +- src/PrayerTracker.UI/ViewModels.fs | 40 ++- src/PrayerTracker/Email.fs | 11 +- src/PrayerTracker/PrayerRequest.fs | 13 +- src/PrayerTracker/SmallGroup.fs | 2 +- src/search-sql.txt | 21 ++ 13 files changed, 402 insertions(+), 223 deletions(-) diff --git a/src/PrayerTracker.Data/DataAccess.fs b/src/PrayerTracker.Data/DataAccess.fs index 46a39f8..b3a3ca0 100644 --- a/src/PrayerTracker.Data/DataAccess.fs +++ b/src/PrayerTracker.Data/DataAccess.fs @@ -98,11 +98,11 @@ type AppDbContext with | query when activeOnly -> let asOf = theDate.AddDays(-(float grp.preferences.daysToExpire)).Date query.Where(fun pr -> - (pr.updatedDate > asOf - || pr.doNotExpire - || RequestType.Recurring = pr.requestType - || RequestType.Expecting = pr.requestType) - && not pr.isManuallyExpired) + ( pr.updatedDate > asOf + || pr.expiration = Manual + || pr.requestType = LongTermRequest + || pr.requestType = Expecting) + && pr.expiration <> Forced) | query -> query |> reqSort grp.preferences.requestSort |> function diff --git a/src/PrayerTracker.Data/Entities.fs b/src/PrayerTracker.Data/Entities.fs index 824a995..442e974 100644 --- a/src/PrayerTracker.Data/Entities.fs +++ b/src/PrayerTracker.Data/Entities.fs @@ -6,35 +6,6 @@ open NodaTime open System open System.Collections.Generic -(*-- CONSTANTS --*) - -/// Constants to use for the e-mail type parameter -[] -module EmailType = - /// HTML e-mail - [] - let Html = "Html" - /// Plain Text e-mail - [] - let PlainText = "PlainText" - /// E-mail with the list as an attached PDF - [] - let AttachedPdf = "AttachedPdf" - -/// These values match those in the RequestType document store -[] -module RequestType = - /// Current Requests (follow expiration rules) - let Current = "Current" - /// Long-Term / Recurring Requests (do not automatically expire) - let Recurring = "Recurring" - /// Praise Reports (follow expiration rules) - let Praise = "Praise" - /// Expectant Mothers (do not automatically expire) - let Expecting = "Expecting" - /// Announcements (follow expiration rules) - let Announcement = "Announcement" - (*-- SUPPORT TYPES --*) /// How as-of dates should (or should not) be displayed with requests @@ -61,6 +32,82 @@ with | LongDate -> "L" +/// Acceptable e-mail formats +type EmailFormat = + /// HTML e-mail + | HtmlFormat + /// Plain-text e-mail + | PlainTextFormat +with + /// Convert to a DU case from a single-character string + static member fromCode code = + match code with + | "H" -> HtmlFormat + | "P" -> PlainTextFormat + | _ -> invalidArg "code" (sprintf "Unknown code %s" code) + /// Convert this DU case to a single-character string + member this.code = + match this with + | HtmlFormat -> "H" + | PlainTextFormat -> "P" + + +/// Expiration for requests +type Expiration = + /// Follow the rules for normal expiration + | Automatic + /// Do not expire via rules + | Manual + /// Force immediate expiration + | Forced +with + /// Convert to a DU case from a single-character string + static member fromCode code = + match code with + | "A" -> Automatic + | "M" -> Manual + | "F" -> Forced + | _ -> invalidArg "code" (sprintf "Unknown code %s" code) + /// Convert this DU case to a single-character string + member this.code = + match this with + | Automatic -> "A" + | Manual -> "M" + | Forced -> "F" + + +/// Types of prayer requests +type PrayerRequestType = + /// Current requests + | CurrentRequest + /// Long-term/ongoing request + | LongTermRequest + /// Expectant couples + | Expecting + /// Praise reports + | PraiseReport + /// Announcements + | Announcement +with + /// Convert to a DU case from a single-character string + static member fromCode code = + match code with + | "C" -> CurrentRequest + | "L" -> LongTermRequest + | "E" -> Expecting + | "P" -> PraiseReport + | "A" -> Announcement + | _ -> invalidArg "code" (sprintf "Unknown code %s" code) + /// Convert this DU case to a single-character string + member this.code = + match this with + | CurrentRequest -> "C" + | LongTermRequest -> "L" + | Expecting -> "E" + | PraiseReport -> "P" + | Announcement -> "A" + + /// How requests should be sorted type RequestSort = /// Sort by date, then by requestor/subject @@ -96,6 +143,26 @@ module Converters = |> LeafExpressionConverter.QuotationToExpression |> unbox>> + let private emailFromDU = + <@ Func(fun (x : EmailFormat) -> x.code) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + + let private emailToDU = + <@ Func(EmailFormat.fromCode) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + + let private expFromDU = + <@ Func(fun (x : Expiration) -> x.code) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + + let private expToDU = + <@ Func(Expiration.fromCode) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + let private sortFromDU = <@ Func(fun (x : RequestSort) -> x.code) @> |> LeafExpressionConverter.QuotationToExpression @@ -106,10 +173,32 @@ module Converters = |> LeafExpressionConverter.QuotationToExpression |> unbox>> + let private typFromDU = + <@ Func(fun (x : PrayerRequestType) -> x.code) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + + let private typToDU = + <@ Func(PrayerRequestType.fromCode) @> + |> LeafExpressionConverter.QuotationToExpression + |> unbox>> + /// Conversion between a string and an AsOfDateDisplay DU value type AsOfDateDisplayConverter () = inherit ValueConverter (asOfFromDU, asOfToDU) + /// Conversion between a string and an EmailFormat DU value + type EmailFormatConverter () = + inherit ValueConverter (emailFromDU, emailToDU) + + /// Conversion between a string and an Expiration DU value + type ExpirationConverter () = + inherit ValueConverter (expFromDU, expToDU) + + /// Conversion between a string and an AsOfDateDisplay DU value + type PrayerRequestTypeConverter () = + inherit ValueConverter (typFromDU, typToDU) + /// Conversion between a string and a RequestSort DU value type RequestSortConverter () = inherit ValueConverter (sortFromDU, sortToDU) @@ -227,7 +316,7 @@ and [] ListPreferences = /// The password used for "small group login" (view-only request list) groupPassword : string /// The default e-mail type for this class - defaultEmailType : string + defaultEmailType : EmailFormat /// Whether this class makes its request list public isPublic : bool /// The time zone which this class uses (use tzdata names) @@ -255,7 +344,7 @@ and [] ListPreferences = textFontSize = 12 requestSort = SortByDate groupPassword = "" - defaultEmailType = EmailType.Html + defaultEmailType = HtmlFormat isPublic = false timeZoneId = "America/Denver" timeZone = TimeZone.empty @@ -333,7 +422,7 @@ and [] ListPreferences = m.Property(fun e -> e.defaultEmailType) .HasColumnName("DefaultEmailType") .IsRequired() - .HasDefaultValue EmailType.Html + .HasDefaultValue HtmlFormat |> ignore m.Property(fun e -> e.isPublic) .HasColumnName("IsPublic") @@ -359,6 +448,8 @@ and [] ListPreferences = |> ignore mb.Model.FindEntityType(typeof).FindProperty("requestSort") .SetValueConverter(Converters.RequestSortConverter ()) + mb.Model.FindEntityType(typeof).FindProperty("defaultEmailType") + .SetValueConverter(Converters.EmailFormatConverter ()) mb.Model.FindEntityType(typeof).FindProperty("asOfDateDisplay") .SetValueConverter(Converters.AsOfDateDisplayConverter ()) @@ -374,7 +465,7 @@ and [] Member = /// The e-mail address for the member email : string /// The type of e-mail preferred by this member (see constants) - format : string option + format : string option // TODO - do I need a custom formatter for this? /// The small group to which this member belongs smallGroup : SmallGroup } @@ -405,64 +496,62 @@ and [] Member = /// This represents a single prayer request and [] PrayerRequest = { /// The Id of this request - prayerRequestId : PrayerRequestId + prayerRequestId : PrayerRequestId /// The type of the request - requestType : string + requestType : PrayerRequestType /// The user who entered the request - userId : UserId + userId : UserId /// The small group to which this request belongs - smallGroupId : SmallGroupId + smallGroupId : SmallGroupId /// The date/time on which this request was entered - enteredDate : DateTime + enteredDate : DateTime /// The date/time this request was last updated - updatedDate : DateTime + updatedDate : DateTime /// The name of the requestor or subject, or title of announcement - requestor : string option + requestor : string option /// The text of the request - text : string - /// Whether this request is exempt from standard expiration rules - doNotExpire : bool + text : string /// Whether the chaplain should be notified for this request - notifyChaplain : bool - /// Whether this request has been expired manually - isManuallyExpired : bool + notifyChaplain : bool /// The user who entered this request - user : User + user : User /// The small group to which this request belongs - smallGroup : SmallGroup + smallGroup : SmallGroup + /// Is this request expired? + expiration : Expiration } with /// An empty request static member empty = - { prayerRequestId = Guid.Empty - requestType = RequestType.Current - userId = Guid.Empty - smallGroupId = Guid.Empty - enteredDate = DateTime.MinValue - updatedDate = DateTime.MinValue - requestor = None - text = "" - doNotExpire = false - notifyChaplain = false - isManuallyExpired = false - user = User.empty - smallGroup = SmallGroup.empty + { prayerRequestId = Guid.Empty + requestType = CurrentRequest + userId = Guid.Empty + smallGroupId = Guid.Empty + enteredDate = DateTime.MinValue + updatedDate = DateTime.MinValue + requestor = None + text = "" + notifyChaplain = false + user = User.empty + smallGroup = SmallGroup.empty + expiration = Automatic } /// Is this request expired? member this.isExpired (curr : DateTime) expDays = - match this.isManuallyExpired with - | true -> true // Manual expiration - | false -> - let nonExpiringTypes = [ RequestType.Recurring; RequestType.Expecting ] - match this.doNotExpire || List.contains this.requestType nonExpiringTypes with - | true -> false // No expiration - | false -> curr.AddDays(-(float expDays)) > this.updatedDate // Automatic expiration + match this.expiration with + | Forced -> true + | Manual -> false + | Automatic -> + match this.requestType with + | LongTermRequest + | Expecting -> false + | _ -> curr.AddDays(-(float expDays)) > this.updatedDate // Automatic expiration /// Is an update required for this long-term request? member this.updateRequired curr expDays updWeeks = match this.isExpired curr expDays with | true -> false - | _ -> curr.AddDays(-(float (updWeeks * 7))) > this.updatedDate + | false -> curr.AddDays(-(float (updWeeks * 7))) > this.updatedDate /// Configure EF for this entity static member internal configureEF (mb : ModelBuilder) = @@ -477,12 +566,15 @@ and [] PrayerRequest = m.Property(fun e -> e.updatedDate).HasColumnName "UpdatedDate" |> ignore m.Property(fun e -> e.requestor).HasColumnName "Requestor" |> ignore m.Property(fun e -> e.text).HasColumnName("Text").IsRequired() |> ignore - m.Property(fun e -> e.doNotExpire).HasColumnName "DoNotExpire" |> ignore m.Property(fun e -> e.notifyChaplain).HasColumnName "NotifyChaplain" |> ignore - m.Property(fun e -> e.isManuallyExpired).HasColumnName "IsManuallyExpired" |> ignore) + m.Property(fun e -> e.expiration).HasColumnName "Expiration" |> ignore) |> ignore + mb.Model.FindEntityType(typeof).FindProperty("requestType") + .SetValueConverter(Converters.PrayerRequestTypeConverter ()) mb.Model.FindEntityType(typeof).FindProperty("requestor") .SetValueConverter(OptionConverter ()) + mb.Model.FindEntityType(typeof).FindProperty("expiration") + .SetValueConverter(Converters.ExpirationConverter ()) /// This represents a small group (Sunday School class, Bible study group, etc.) diff --git a/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs b/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs index 53e02dc..7f5b230 100644 --- a/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs +++ b/src/PrayerTracker.Data/Migrations/20161217153124_InitialDatabase.fs @@ -50,17 +50,16 @@ type MemberTable = } type PrayerRequestTable = - { prayerRequestId : OperationBuilder - doNotExpire : OperationBuilder - enteredDate : OperationBuilder - isManuallyExpired : OperationBuilder - notifyChaplain : OperationBuilder - requestType : OperationBuilder - requestor : OperationBuilder - smallGroupId : OperationBuilder - text : OperationBuilder - updatedDate : OperationBuilder - userId : OperationBuilder + { prayerRequestId : OperationBuilder + enteredDate : OperationBuilder + expiration : OperationBuilder + notifyChaplain : OperationBuilder + requestType : OperationBuilder + requestor : OperationBuilder + smallGroupId : OperationBuilder + text : OperationBuilder + updatedDate : OperationBuilder + userId : OperationBuilder } type SmallGroupTable = @@ -104,12 +103,12 @@ type InitialDatabase () = schema = "pt", columns = (fun table -> - { churchId = table.Column (name = "ChurchId", nullable = false) - city = table.Column (name = "City", nullable = false) + { churchId = table.Column (name = "ChurchId", nullable = false) + city = table.Column (name = "City", nullable = false) hasInterface = table.Column (name = "HasVirtualPrayerRoomInterface", nullable = false) interfaceAddress = table.Column (name = "InterfaceAddress", nullable = true) - name = table.Column (name = "Name", nullable = false) - st = table.Column (name = "ST", maxLength = Nullable 2, nullable = false) + name = table.Column (name = "Name", nullable = false) + st = table.Column (name = "ST", nullable = false, maxLength = Nullable 2) }), constraints = fun table -> @@ -121,10 +120,10 @@ type InitialDatabase () = schema = "pt", columns = (fun table -> - { timeZoneId = table.Column (name = "TimeZoneId", nullable = false) + { timeZoneId = table.Column (name = "TimeZoneId", nullable = false) description = table.Column (name = "Description", nullable = false) - isActive = table.Column (name = "IsActive", nullable = false) - sortOrder = table.Column (name = "SortOrder", nullable = false) + isActive = table.Column (name = "IsActive", nullable = false) + sortOrder = table.Column (name = "SortOrder", nullable = false) }), constraints = fun table -> @@ -136,13 +135,13 @@ type InitialDatabase () = schema = "pt", columns = (fun table -> - { userId = table.Column (name = "UserId", nullable = false) - emailAddress = table.Column (name = "EmailAddress", nullable = false) - firstName = table.Column (name = "FirstName", nullable = false) + { userId = table.Column (name = "UserId", nullable = false) + emailAddress = table.Column (name = "EmailAddress", nullable = false) + firstName = table.Column (name = "FirstName", nullable = false) isAdmin = table.Column (name = "IsSystemAdmin", nullable = false) - lastName = table.Column (name = "LastName", nullable = false) - passwordHash = table.Column (name = "PasswordHash", nullable = false) - salt = table.Column (name = "Salt", nullable = true) + lastName = table.Column (name = "LastName", nullable = false) + passwordHash = table.Column (name = "PasswordHash", nullable = false) + salt = table.Column (name = "Salt", nullable = true) }), constraints = fun table -> @@ -155,8 +154,8 @@ type InitialDatabase () = columns = (fun table -> { smallGroupId = table.Column (name = "SmallGroupId", nullable = false) - churchId = table.Column (name = "ChurchId", nullable = false) - name = table.Column (name = "Name", nullable = false) + churchId = table.Column (name = "ChurchId", nullable = false) + name = table.Column (name = "Name", nullable = false) }), constraints = fun table -> @@ -221,10 +220,10 @@ type InitialDatabase () = schema = "pt", columns = (fun table -> - { memberId = table.Column (name = "MemberId", nullable = false) - email = table.Column (name = "Email", nullable = false) - format = table.Column (name = "Format", nullable = true) - memberName = table.Column (name = "MemberName", nullable = false) + { memberId = table.Column (name = "MemberId", nullable = false) + email = table.Column (name = "Email", nullable = false) + format = table.Column (name = "Format", nullable = true) + memberName = table.Column (name = "MemberName", nullable = false) smallGroupId = table.Column (name = "SmallGroupId", nullable = false) }), constraints = @@ -246,16 +245,15 @@ type InitialDatabase () = columns = (fun table -> { prayerRequestId = table.Column (name = "PrayerRequestId", nullable = false) - doNotExpire = table.Column (name = "DoNotExpire", nullable = false) - enteredDate = table.Column (name = "EnteredDate", nullable = false) - isManuallyExpired = table.Column (name = "IsManuallyExpired", nullable = false) - notifyChaplain = table.Column (name = "NotifyChaplain", nullable = false) - requestType = table.Column (name = "RequestType", nullable = false) - requestor = table.Column (name = "Requestor", nullable = true) - smallGroupId = table.Column (name = "SmallGroupId", nullable = false) - text = table.Column (name = "Text", nullable = false) - updatedDate = table.Column (name = "UpdatedDate", nullable = false) - userId = table.Column (name = "UserId", nullable = false) + expiration = table.Column (name = "Expiration", nullable = false) + enteredDate = table.Column (name = "EnteredDate", nullable = false) + notifyChaplain = table.Column (name = "NotifyChaplain", nullable = false) + requestType = table.Column (name = "RequestType", nullable = false) + requestor = table.Column (name = "Requestor", nullable = true) + smallGroupId = table.Column (name = "SmallGroupId", nullable = false) + text = table.Column (name = "Text", nullable = false) + updatedDate = table.Column (name = "UpdatedDate", nullable = false) + userId = table.Column (name = "UserId", nullable = false) }), constraints = fun table -> @@ -283,7 +281,7 @@ type InitialDatabase () = schema = "pt", columns = (fun table -> - { userId = table.Column (name = "UserId", nullable = false) + { userId = table.Column (name = "UserId", nullable = false) smallGroupId = table.Column (name = "SmallGroupId", nullable = false) }), constraints = @@ -351,7 +349,7 @@ type InitialDatabase () = b.Property("smallGroupId") |> ignore b.Property("daysToExpire").ValueGeneratedOnAdd().HasDefaultValue(14) |> ignore b.Property("daysToKeepNew").ValueGeneratedOnAdd().HasDefaultValue(7) |> ignore - b.Property("defaultEmailType").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("Html") |> ignore + b.Property("defaultEmailType").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("H") |> ignore b.Property("emailFromAddress").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("prayer@djs-consulting.com") |> ignore b.Property("emailFromName").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("PrayerTracker") |> ignore b.Property("groupPassword").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("") |> ignore @@ -388,11 +386,10 @@ type InitialDatabase () = typeof, fun b -> b.Property("prayerRequestId").ValueGeneratedOnAdd() |> ignore - b.Property("doNotExpire") |> ignore - b.Property("enteredDate") |> ignore - b.Property("isManuallyExpired") |> ignore + b.Property("enteredDate").IsRequired() |> ignore + b.Property("expiration").IsRequired().HasMaxLength 1 |> ignore b.Property("notifyChaplain") |> ignore - b.Property("requestType").IsRequired() |> ignore + b.Property("requestType").IsRequired().HasMaxLength 1 |> ignore b.Property("requestor") |> ignore b.Property("smallGroupId") |> ignore b.Property("text").IsRequired() |> ignore diff --git a/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs b/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs index 6df9c1c..5ae5d5f 100644 --- a/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs +++ b/src/PrayerTracker.Data/Migrations/AppDbContextModelSnapshot.fs @@ -36,7 +36,7 @@ type AppDbContextModelSnapshot () = b.Property("smallGroupId") |> ignore b.Property("daysToExpire").ValueGeneratedOnAdd().HasDefaultValue(14) |> ignore b.Property("daysToKeepNew").ValueGeneratedOnAdd().HasDefaultValue(7) |> ignore - b.Property("defaultEmailType").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("Html") |> ignore + b.Property("defaultEmailType").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("H").HasMaxLength(1) |> ignore b.Property("emailFromAddress").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("prayer@djs-consulting.com") |> ignore b.Property("emailFromName").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("PrayerTracker") |> ignore b.Property("groupPassword").IsRequired().ValueGeneratedOnAdd().HasDefaultValue("") |> ignore @@ -73,11 +73,10 @@ type AppDbContextModelSnapshot () = typeof, fun b -> b.Property("prayerRequestId").ValueGeneratedOnAdd() |> ignore - b.Property("doNotExpire") |> ignore b.Property("enteredDate") |> ignore - b.Property("isManuallyExpired") |> ignore + b.Property("expiration").IsRequired().HasMaxLength(1) |> ignore b.Property("notifyChaplain") |> ignore - b.Property("requestType").IsRequired() |> ignore + b.Property("requestType").IsRequired().HasMaxLength(1) |> ignore b.Property("requestor") |> ignore b.Property("smallGroupId") |> ignore b.Property("text").IsRequired() |> ignore diff --git a/src/PrayerTracker.Tests/Data/EntitiesTests.fs b/src/PrayerTracker.Tests/Data/EntitiesTests.fs index 241c20d..d6bf322 100644 --- a/src/PrayerTracker.Tests/Data/EntitiesTests.fs +++ b/src/PrayerTracker.Tests/Data/EntitiesTests.fs @@ -48,6 +48,52 @@ let churchTests = } ] +[] +let emailFormatTests = + testList "EmailFormat" [ + test "HtmlFormat code is correct" { + Expect.equal HtmlFormat.code "H" "The code for HtmlFormat should have been \"H\"" + } + test "PlainTextFormat code is correct" { + Expect.equal PlainTextFormat.code "P" "The code for PlainTextFormat should have been \"P\"" + } + test "fromCode H should return HtmlFormat" { + Expect.equal (EmailFormat.fromCode "H") HtmlFormat "\"H\" should have been converted to HtmlFormat" + } + test "fromCode P should return ShortDate" { + Expect.equal (EmailFormat.fromCode "P") PlainTextFormat "\"P\" should have been converted to PlainTextFormat" + } + test "fromCode Z should raise" { + Expect.throws (fun () -> EmailFormat.fromCode "Z" |> ignore) "An unknown code should have raised an exception" + } + ] + +[] +let expirationTests = + testList "Expiration" [ + test "Automatic code is correct" { + Expect.equal Automatic.code "A" "The code for Automatic should have been \"A\"" + } + test "Manual code is correct" { + Expect.equal Manual.code "M" "The code for Manual should have been \"M\"" + } + test "Forced code is correct" { + Expect.equal Forced.code "F" "The code for Forced should have been \"F\"" + } + test "fromCode A should return Automatic" { + Expect.equal (Expiration.fromCode "A") Automatic "\"A\" should have been converted to Automatic" + } + test "fromCode M should return Manual" { + Expect.equal (Expiration.fromCode "M") Manual "\"M\" should have been converted to Manual" + } + test "fromCode F should return Forced" { + Expect.equal (Expiration.fromCode "F") Forced "\"F\" should have been converted to Forced" + } + test "fromCode V should raise" { + Expect.throws (fun () -> Expiration.fromCode "V" |> ignore) "An unknown code should have raised an exception" + } + ] + [] let listPreferencesTests = testList "ListPreferences" [ @@ -67,7 +113,7 @@ let listPreferencesTests = Expect.equal mt.textFontSize 12 "The default text font size should have been 12" Expect.equal mt.requestSort SortByDate "The default request sort should have been by date" Expect.equal mt.groupPassword "" "The default group password should have been blank" - Expect.equal mt.defaultEmailType EmailType.Html "The default e-mail type should have been HTML" + Expect.equal mt.defaultEmailType HtmlFormat "The default e-mail type should have been HTML" Expect.isFalse mt.isPublic "The isPublic flag should not have been set" Expect.equal mt.timeZoneId "America/Denver" "The default time zone should have been America/Denver" Expect.equal mt.timeZone.timeZoneId "" "The default preferences should have included an empty time zone" @@ -96,34 +142,33 @@ let prayerRequestTests = test "empty is as expected" { let mt = PrayerRequest.empty Expect.equal mt.prayerRequestId Guid.Empty "The request ID should have been an empty GUID" - Expect.equal mt.requestType RequestType.Current "The request type should have been Current" + Expect.equal mt.requestType CurrentRequest "The request type should have been Current" Expect.equal mt.userId Guid.Empty "The user ID should have been an empty GUID" Expect.equal mt.smallGroupId Guid.Empty "The small group ID should have been an empty GUID" Expect.equal mt.enteredDate DateTime.MinValue "The entered date should have been the minimum" Expect.equal mt.updatedDate DateTime.MinValue "The updated date should have been the minimum" Expect.isNone mt.requestor "The requestor should not exist" Expect.equal mt.text "" "The request text should have been blank" - Expect.isFalse mt.doNotExpire "The do not expire flag should not have been set" Expect.isFalse mt.notifyChaplain "The notify chaplain flag should not have been set" - Expect.isFalse mt.isManuallyExpired "The is manually expired flag should not have been set" + Expect.equal mt.expiration Automatic "The expiration should have been Automatic" Expect.equal mt.user.userId Guid.Empty "The user should have been an empty one" Expect.equal mt.smallGroup.smallGroupId Guid.Empty "The small group should have been an empty one" } test "isExpired always returns false for expecting requests" { - let req = { PrayerRequest.empty with requestType = RequestType.Expecting } + let req = { PrayerRequest.empty with requestType = Expecting } Expect.isFalse (req.isExpired DateTime.Now 0) "An expecting request should never be considered expired" } - test "isExpired always returns false for never-expired requests" { - let req = { PrayerRequest.empty with updatedDate = DateTime.Now.AddMonths -1; doNotExpire = true } + test "isExpired always returns false for manually-expired requests" { + let req = { PrayerRequest.empty with updatedDate = DateTime.Now.AddMonths -1; expiration = Manual } Expect.isFalse (req.isExpired DateTime.Now 4) "A never-expired request should never be considered expired" } - test "isExpired always returns false for recurring requests" { - let req = { PrayerRequest.empty with requestType = RequestType.Recurring } + test "isExpired always returns false for long term/recurring requests" { + let req = { PrayerRequest.empty with requestType = LongTermRequest } Expect.isFalse (req.isExpired DateTime.Now 0) "A recurring/long-term request should never be considered expired" } - test "isExpired always returns true for manually expired requests" { - let req = { PrayerRequest.empty with updatedDate = DateTime.Now; isManuallyExpired = true } - Expect.isTrue (req.isExpired DateTime.Now 5) "A manually expired request should always be considered expired" + test "isExpired always returns true for force-expired requests" { + let req = { PrayerRequest.empty with updatedDate = DateTime.Now; expiration = Forced } + Expect.isTrue (req.isExpired DateTime.Now 5) "A force-expired request should always be considered expired" } test "isExpired returns false for non-expired requests" { let req = { PrayerRequest.empty with updatedDate = DateTime.Now.AddDays -5. } @@ -134,13 +179,13 @@ let prayerRequestTests = Expect.isTrue (req.isExpired DateTime.Now 7) "A request updated 8 days ago should be considered expired" } test "updateRequired returns false for expired requests" { - let req = { PrayerRequest.empty with isManuallyExpired = true } + let req = { PrayerRequest.empty with expiration = Forced } Expect.isFalse (req.updateRequired DateTime.Now 7 4) "An expired request should not require an update" } test "updateRequired returns false when an update is not required for an active request" { let req = { PrayerRequest.empty with - requestType = RequestType.Recurring + requestType = LongTermRequest updatedDate = DateTime.Now.AddDays -14. } Expect.isFalse (req.updateRequired DateTime.Now 7 4) @@ -149,7 +194,7 @@ let prayerRequestTests = test "updateRequired returns true when an update is required for an active request" { let req = { PrayerRequest.empty with - requestType = RequestType.Recurring + requestType = LongTermRequest updatedDate = DateTime.Now.AddDays -34. } Expect.isTrue (req.updateRequired DateTime.Now 7 4) @@ -157,6 +202,47 @@ let prayerRequestTests = } ] +[] +let prayerRequestTypeTests = + testList "PrayerRequestType" [ + test "CurrentRequest code is correct" { + Expect.equal CurrentRequest.code "C" "The code for CurrentRequest should have been \"C\"" + } + test "LongTermRequest code is correct" { + Expect.equal LongTermRequest.code "L" "The code for LongTermRequest should have been \"L\"" + } + test "PraiseReport code is correct" { + Expect.equal PraiseReport.code "P" "The code for PraiseReport should have been \"P\"" + } + test "Expecting code is correct" { + Expect.equal Expecting.code "E" "The code for Expecting should have been \"E\"" + } + test "Announcement code is correct" { + Expect.equal Announcement.code "A" "The code for Announcement should have been \"A\"" + } + test "fromCode C should return CurrentRequest" { + Expect.equal (PrayerRequestType.fromCode "C") CurrentRequest + "\"C\" should have been converted to CurrentRequest" + } + test "fromCode L should return LongTermRequest" { + Expect.equal (PrayerRequestType.fromCode "L") LongTermRequest + "\"L\" should have been converted to LongTermRequest" + } + test "fromCode P should return PraiseReport" { + Expect.equal (PrayerRequestType.fromCode "P") PraiseReport "\"P\" should have been converted to PraiseReport" + } + test "fromCode E should return Expecting" { + Expect.equal (PrayerRequestType.fromCode "E") Expecting "\"E\" should have been converted to Expecting" + } + test "fromCode A should return Announcement" { + Expect.equal (PrayerRequestType.fromCode "A") Announcement "\"A\" should have been converted to Announcement" + } + test "fromCode R should raise" { + Expect.throws (fun () -> PrayerRequestType.fromCode "R" |> ignore) + "An unknown code should have raised an exception" + } + ] + [] let requestSortTests = testList "RequestSort" [ diff --git a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs index c831f86..ac4a513 100644 --- a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs +++ b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs @@ -31,15 +31,15 @@ module ReferenceListTests = let emailTypeListTests = testList "ReferenceList.emailTypeList" [ test "includes default type" { - let typs = ReferenceList.emailTypeList EmailType.Html _s + let typs = ReferenceList.emailTypeList HtmlFormat _s Expect.hasCountOf typs 3u countAll "There should have been 3 e-mail type options returned" let top = Seq.head typs Expect.equal (fst top) "" "The default option should have been blank" Expect.equal (snd top).Value "Group Default (HTML Format)" "The default option label was incorrect" let nxt = typs |> Seq.skip 1 |> Seq.head - Expect.equal (fst nxt) EmailType.Html "The 2nd option should have been HTML" + Expect.equal (fst nxt) HtmlFormat.code "The 2nd option should have been HTML" let lst = typs |> Seq.last - Expect.equal (fst lst) EmailType.PlainText "The 3rd option should have been plain text" + Expect.equal (fst lst) PlainTextFormat.code "The 3rd option should have been plain text" } ] @@ -49,15 +49,15 @@ module ReferenceListTests = test "excludes immediate expiration if not required" { let exps = ReferenceList.expirationList _s false Expect.hasCountOf exps 2u countAll "There should have been 2 expiration types returned" - Expect.exists exps (fun exp -> fst exp = "N") "The option for normal expiration was not found" - Expect.exists exps (fun exp -> fst exp = "Y") "The option for \"never expire\" was not found" + Expect.exists exps (fun (exp, _) -> exp = Automatic.code) "The option for automatic expiration was not found" + Expect.exists exps (fun (exp, _) -> exp = Manual.code) "The option for manual expiration was not found" } test "includes immediate expiration if required" { let exps = ReferenceList.expirationList _s true Expect.hasCountOf exps 3u countAll "There should have been 3 expiration types returned" - Expect.exists exps (fun exp -> fst exp = "N") "The option for normal expiration was not found" - Expect.exists exps (fun exp -> fst exp = "Y") "The option for \"never expire\" was not found" - Expect.exists exps (fun exp -> fst exp = "X") "The option for \"expire immediately\" was not found" + Expect.exists exps (fun (exp, _) -> exp = Automatic.code) "The option for automatic expiration was not found" + Expect.exists exps (fun (exp, _) -> exp = Manual.code) "The option for manual expiration was not found" + Expect.exists exps (fun (exp, _) -> exp = Forced.code) "The option for immediate expiration was not found" } ] @@ -69,14 +69,12 @@ module ReferenceListTests = yield! testFixture withList [ yield "returns 5 types", fun typs -> Expect.hasCountOf typs 5u countAll "There should have been 5 request types returned" - yield! [ RequestType.Current; RequestType.Recurring; RequestType.Praise; RequestType.Expecting; - RequestType.Announcement - ] - |> List.map (fun typ -> - sprintf "contains \"%s\"" typ, - fun typs -> - Expect.isSome (typs |> List.tryFind (fun x -> fst x = typ)) - (sprintf "The \"%s\" option was not found" typ)) + yield! [ CurrentRequest; LongTermRequest; PraiseReport; Expecting; Announcement ] + |> List.map (fun typ -> + sprintf "contains \"%O\"" typ, + fun typs -> + Expect.isSome (typs |> List.tryFind (fun x -> fst x = typ)) + (sprintf "The \"%O\" option was not found" typ)) ] ] @@ -232,8 +230,8 @@ let editMemberTests = Expect.equal edit.emailType "" "The e-mail type should have been blank for group default" } test "fromMember populates with specific format" { - let edit = EditMember.fromMember { Member.empty with format = Some EmailType.Html } - Expect.equal edit.emailType EmailType.Html "The e-mail type was not filled correctly" + let edit = EditMember.fromMember { Member.empty with format = Some HtmlFormat.code } + Expect.equal edit.emailType HtmlFormat.code "The e-mail type was not filled correctly" } test "empty is as expected" { let edit = EditMember.empty @@ -263,7 +261,7 @@ let editPreferencesTests = Expect.equal edit.requestSort prefs.requestSort.code "The request sort was not filled correctly" Expect.equal edit.emailFromName prefs.emailFromName "The e-mail from name was not filled correctly" Expect.equal edit.emailFromAddress prefs.emailFromAddress "The e-mail from address was not filled correctly" - Expect.equal edit.defaultEmailType prefs.defaultEmailType "The default e-mail type was not filled correctly" + Expect.equal edit.defaultEmailType prefs.defaultEmailType.code "The default e-mail type was not filled correctly" Expect.equal edit.headingLineType "Name" "The heading line color type was not derived correctly" Expect.equal edit.headingLineColor prefs.lineColor "The heading line color was not filled correctly" Expect.equal edit.headingTextType "Name" "The heading text color type was not derived correctly" @@ -303,39 +301,29 @@ let editRequestTests = test "empty is as expected" { let mt = EditRequest.empty Expect.equal mt.requestId Guid.Empty "The request ID should be an empty GUID" - Expect.equal mt.requestType "" "The request type should have been blank" + Expect.equal mt.requestType CurrentRequest.code "The request type should have been \"Current\"" Expect.isNone mt.enteredDate "The entered date should have been None" Expect.isNone mt.skipDateUpdate "The \"skip date update\" flag should have been None" Expect.isNone mt.requestor "The requestor should have been None" - Expect.equal mt.expiration "N" "The expiration should have been \"N\"" + Expect.equal mt.expiration Automatic.code "The expiration should have been \"A\" (Automatic)" Expect.equal mt.text "" "The text should have been blank" } - test "fromRequest succeeds when a request has the do-not-expire flag set" { + test "fromRequest succeeds" { let req = { PrayerRequest.empty with prayerRequestId = Guid.NewGuid () - requestType = RequestType.Current + requestType = CurrentRequest requestor = Some "Me" - doNotExpire = true + expiration = Manual text = "the text" } let edit = EditRequest.fromRequest req Expect.equal edit.requestId req.prayerRequestId "The request ID was not filled correctly" - Expect.equal edit.requestType req.requestType "The request type was not filled correctly" + Expect.equal edit.requestType req.requestType.code "The request type was not filled correctly" Expect.equal edit.requestor req.requestor "The requestor was not filled correctly" - Expect.equal edit.expiration "Y" "The expiration should have been \"Y\" since the do-not-expire flag was set" + Expect.equal edit.expiration Manual.code "The expiration was not filled correctly" Expect.equal edit.text req.text "The text was not filled correctly" } - test "fromRequest succeeds when a request has the do-not-expire flag unset" { - let req = - { PrayerRequest.empty with - requestor = None - doNotExpire = false - } - let edit = EditRequest.fromRequest req - Expect.equal edit.requestor req.requestor "The requestor was not filled correctly" - Expect.equal edit.expiration "N" "The expiration should have been \"N\" since the do-not-expire flag was not set" - } test "isNew works for a new request" { Expect.isTrue (EditRequest.empty.isNew ()) "An empty GUID should be flagged as a new request" } @@ -469,19 +457,19 @@ let requestListTests = let withRequestList f () = { requests = [ { PrayerRequest.empty with - requestType = RequestType.Current + requestType = CurrentRequest requestor = Some "Zeb" text = "zyx" updatedDate = DateTime.Today } { PrayerRequest.empty with - requestType = RequestType.Current + requestType = CurrentRequest requestor = Some "Aaron" text = "abc" updatedDate = DateTime.Today - TimeSpan.FromDays 9. } { PrayerRequest.empty with - requestType = RequestType.Praise + requestType = PraiseReport text = "nmo" updatedDate = DateTime.Today } @@ -566,19 +554,19 @@ let requestListTests = Expect.stringContains text " + nmo\n \n" "Last request not found" "isNew succeeds for both old and new requests", fun reqList -> - let reqs = reqList.requestsInCategory RequestType.Current + let reqs = reqList.requestsInCategory CurrentRequest Expect.hasCountOf reqs 2u countAll "There should have been two requests" Expect.isTrue (reqList.isNew (List.head reqs)) "The first request should have been new" Expect.isFalse (reqList.isNew (List.last reqs)) "The second request should not have been new" "requestsInCategory succeeds when requests exist", fun reqList -> - let reqs = reqList.requestsInCategory RequestType.Current + let reqs = reqList.requestsInCategory CurrentRequest Expect.hasCountOf reqs 2u countAll "There should have been two requests" let first = List.head reqs Expect.equal first.text "zyx" "The requests should be sorted by updated date descending" "requestsInCategory succeeds when requests do not exist", fun reqList -> - Expect.isEmpty (reqList.requestsInCategory "ABC") "There should have been no category \"ABC\" requests" + Expect.isEmpty (reqList.requestsInCategory Announcement) "There should have been no \"Announcement\" requests" "requestsInCategory succeeds and sorts by requestor", fun reqList -> let newList = @@ -588,7 +576,7 @@ let requestListTests = preferences = { reqList.listGroup.preferences with requestSort = SortByRequestor } } } - let reqs = newList.requestsInCategory RequestType.Current + let reqs = newList.requestsInCategory CurrentRequest Expect.hasCountOf reqs 2u countAll "There should have been two requests" let first = List.head reqs Expect.equal first.text "abc" "The requests should be sorted by requestor" diff --git a/src/PrayerTracker.UI/PrayerRequest.fs b/src/PrayerTracker.UI/PrayerRequest.fs index adc9956..9e4ec15 100644 --- a/src/PrayerTracker.UI/PrayerRequest.fs +++ b/src/PrayerTracker.UI/PrayerRequest.fs @@ -23,7 +23,7 @@ let edit (m : EditRequest) today ctx vi = label [ _for "requestType" ] [ locStr s.["Request Type"] ] ReferenceList.requestTypeList s |> Seq.ofList - |> Seq.map (fun item -> fst item, (snd item).Value) + |> Seq.map (fun (typ, desc) -> typ.code, desc.Value) |> selectList "requestType" m.requestType [ _required; _autofocus ] ] yield div [ _class "pt-field" ] [ diff --git a/src/PrayerTracker.UI/SmallGroup.fs b/src/PrayerTracker.UI/SmallGroup.fs index 15a92ef..8e5235e 100644 --- a/src/PrayerTracker.UI/SmallGroup.fs +++ b/src/PrayerTracker.UI/SmallGroup.fs @@ -45,7 +45,7 @@ let announcement isAdmin ctx vi = label [ _for "requestType" ] [ locStr s.["Request Type"] ] reqTypes |> Seq.ofList - |> Seq.map (fun item -> fst item, (snd item).Value) + |> Seq.map (fun (typ, desc) -> typ.code, desc.Value) |> selectList "requestType" "Announcement" [] ] ] @@ -407,7 +407,9 @@ let preferences (m : EditPreferences) (tzs : TimeZone list) ctx vi = label [ _for "defaultEmailType" ] [ locStr s.["E-mail Format"] ] seq { yield "", selectDefault s.["Select"].Value - yield! ReferenceList.emailTypeList "" s |> Seq.skip 1 |> Seq.map (fun typ -> fst typ, (snd typ).Value) + yield! ReferenceList.emailTypeList HtmlFormat s + |> Seq.skip 1 + |> Seq.map (fun typ -> fst typ, (snd typ).Value) } |> selectList "defaultEmailType" m.defaultEmailType [ _required ] ] diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index fd9307c..071f22d 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -22,30 +22,28 @@ module ReferenceList = // Localize the default type let defaultType = match def with - | EmailType.Html -> s.["HTML Format"].Value - | EmailType.PlainText -> s.["Plain-Text Format"].Value - | EmailType.AttachedPdf -> s.["Attached PDF"].Value - | _ -> "" + | HtmlFormat -> s.["HTML Format"].Value + | PlainTextFormat -> s.["Plain-Text Format"].Value seq { yield "", LocalizedString ("", sprintf "%s (%s)" s.["Group Default"].Value defaultType) - yield EmailType.Html, s.["HTML Format"] - yield EmailType.PlainText, s.["Plain-Text Format"] + yield HtmlFormat.code, s.["HTML Format"] + yield PlainTextFormat.code, s.["Plain-Text Format"] } /// A list of expiration options let expirationList (s : IStringLocalizer) includeExpireNow = - [ yield "N", s.["Expire Normally"] - yield "Y", s.["Request Never Expires"] - match includeExpireNow with true -> yield "X", s.["Expire Immediately"] | false -> () + [ yield Automatic.code, s.["Expire Normally"] + yield Manual.code, s.["Request Never Expires"] + match includeExpireNow with true -> yield Forced.code, s.["Expire Immediately"] | false -> () ] /// A list of request types let requestTypeList (s : IStringLocalizer) = - [ RequestType.Current, s.["Current Requests"] - RequestType.Recurring, s.["Long-Term Requests"] - RequestType.Praise, s.["Praise Reports"] - RequestType.Expecting, s.["Expecting"] - RequestType.Announcement, s.["Announcements"] + [ CurrentRequest, s.["Current Requests"] + LongTermRequest, s.["Long-Term Requests"] + PraiseReport, s.["Praise Reports"] + Expecting, s.["Expecting"] + Announcement, s.["Announcements"] ] @@ -292,7 +290,7 @@ with requestSort = prefs.requestSort.code emailFromName = prefs.emailFromName emailFromAddress = prefs.emailFromAddress - defaultEmailType = prefs.defaultEmailType + defaultEmailType = prefs.defaultEmailType.code headingLineType = setType prefs.lineColor headingLineColor = prefs.lineColor headingTextType = setType prefs.headingColor @@ -325,7 +323,7 @@ with requestSort = RequestSort.fromCode this.requestSort emailFromName = this.emailFromName emailFromAddress = this.emailFromAddress - defaultEmailType = this.defaultEmailType + defaultEmailType = EmailFormat.fromCode this.defaultEmailType lineColor = this.headingLineColor headingColor = this.headingTextColor listFonts = this.listFonts @@ -362,20 +360,20 @@ with /// An empty instance to use for new requests static member empty = { requestId = Guid.Empty - requestType = "" + requestType = CurrentRequest.code enteredDate = None skipDateUpdate = None requestor = None - expiration = "N" + expiration = Automatic.code text = "" } /// Create an instance from an existing request static member fromRequest req = { EditRequest.empty with requestId = req.prayerRequestId - requestType = req.requestType + requestType = req.requestType.code requestor = req.requestor - expiration = match req.doNotExpire with true -> "Y" | false -> "N" + expiration = req.expiration.code text = req.text } /// Is this a new request? @@ -516,7 +514,7 @@ type Overview = { /// The total number of active requests totalActiveReqs : int /// The numbers of active requests by category - activeReqsByCat : Map + activeReqsByCat : Map /// A count of all requests allReqs : int /// A count of all members diff --git a/src/PrayerTracker/Email.fs b/src/PrayerTracker/Email.fs index b103ffb..a27f5b7 100644 --- a/src/PrayerTracker/Email.fs +++ b/src/PrayerTracker/Email.fs @@ -67,18 +67,15 @@ let sendEmails (client : SmtpClient) (recipients : Member list) grp subj html te let plainTextMsg = createTextMessage grp subj text s for mbr in recipients do - let emailType = match mbr.format with Some f -> f | None -> grp.preferences.defaultEmailType - let emailTo = MailboxAddress (mbr.memberName, mbr.email) + let emailType = match mbr.format with Some f -> EmailFormat.fromCode f | None -> grp.preferences.defaultEmailType + let emailTo = MailboxAddress (mbr.memberName, mbr.email) match emailType with - | EmailType.Html -> + | HtmlFormat -> htmlMsg.To.Add emailTo do! client.SendAsync htmlMsg htmlMsg.To.Clear () - | EmailType.PlainText -> + | PlainTextFormat -> plainTextMsg.To.Add emailTo do! client.SendAsync plainTextMsg plainTextMsg.To.Clear () - | EmailType.AttachedPdf -> - raise <| NotImplementedException "Attached PDF format has not been implemented" - | _ -> invalidOp <| sprintf "Unknown e-mail type %s passed" emailType } diff --git a/src/PrayerTracker/PrayerRequest.fs b/src/PrayerTracker/PrayerRequest.fs index 6f1d75b..aaf638f 100644 --- a/src/PrayerTracker/PrayerRequest.fs +++ b/src/PrayerTracker/PrayerRequest.fs @@ -136,7 +136,7 @@ let expire reqId : HttpHandler = | Ok r -> let db = ctx.dbContext () let s = Views.I18N.localizer.Force () - db.UpdateEntry { r with isManuallyExpired = true } + db.UpdateEntry { r with expiration = Forced } let! _ = db.SaveChangesAsync () addInfo ctx s.["Successfully {0} prayer request", s.["Expired"].Value.ToLower ()] return! redirectTo false "/prayer-requests" next ctx @@ -247,7 +247,7 @@ let restore reqId : HttpHandler = | Ok r -> let db = ctx.dbContext () let s = Views.I18N.localizer.Force () - db.UpdateEntry { r with isManuallyExpired = false; updatedDate = DateTime.Now } + db.UpdateEntry { r with expiration = Automatic; updatedDate = DateTime.Now } let! _ = db.SaveChangesAsync () addInfo ctx s.["Successfully {0} prayer request", s.["Restored"].Value.ToLower ()] return! redirectTo false "/prayer-requests" next ctx @@ -273,11 +273,10 @@ let save : HttpHandler = | Some pr -> let upd8 = { pr with - requestType = m.requestType - requestor = m.requestor - text = ckEditorToText m.text - doNotExpire = m.expiration = "Y" - isManuallyExpired = m.expiration = "X" + requestType = PrayerRequestType.fromCode m.requestType + requestor = m.requestor + text = ckEditorToText m.text + expiration = Expiration.fromCode m.expiration } let grp = currentGroup ctx let now = grp.localDateNow (ctx.GetService ()) diff --git a/src/PrayerTracker/SmallGroup.fs b/src/PrayerTracker/SmallGroup.fs index 00cfff2..2384f48 100644 --- a/src/PrayerTracker/SmallGroup.fs +++ b/src/PrayerTracker/SmallGroup.fs @@ -387,7 +387,7 @@ let sendAnnouncement : HttpHandler = prayerRequestId = Guid.NewGuid () smallGroupId = grp.smallGroupId userId = usr.userId - requestType = Option.get m.requestType + requestType = (Option.get >> PrayerRequestType.fromCode) m.requestType text = requestText enteredDate = now updatedDate = now diff --git a/src/search-sql.txt b/src/search-sql.txt index d03bcec..6edad08 100644 --- a/src/search-sql.txt +++ b/src/search-sql.txt @@ -4,3 +4,24 @@ create index "IX_PrayerRequest_Requestor_TRGM" on "PrayerRequest" using GIN (COA create index "IX_PrayerRequest_Text_TRGM" on "PrayerRequest" using GIN ("Text" gin_trgm_ops); alter table "ListPreference" add column "PageSize" int not null default 100; alter table "ListPreference" add column "AsOfDateDisplay" varchar(1) not null default 'N'; +/* RequestType to 1 character code */ +update "PrayerRequest" set "RequestType" = 'C' where "RequestType" = 'Current'; +update "PrayerRequest" set "RequestType" = 'L' where "RequestType" = 'Recurring'; +update "PrayerRequest" set "RequestType" = 'P' where "RequestType" = 'Praise'; +update "PrayerRequest" set "RequestType" = 'E' where "RequestType" = 'Expecting'; +update "PrayerRequest" set "RequestType" = 'A' where "RequestType" = 'Announcement'; +alter table "PrayerRequest" alter column "RequestType" set data type varchar(1); +/* Change expiration to a 1-character code field */ +alter table "PrayerRequest" add column "Expiration" varchar(1); +update "PrayerRequest" set "Expiration" = case when "IsManuallyExpired" then 'F' when "DoNotExpire" then 'M' else 'A' end; +alter table "PrayerRequest" alter column "Expiration" set not null; +alter table "PrayerRequest" drop column "DoNotExpire"; +alter table "PrayerRequest" drop column "IsManuallyExpired"; +/* Change e-mail type to 1-character code field in list preferences and members */ +update "ListPreference" set "DefaultEmailType" = 'H' where "DefaultEmailType" = 'Html'; +update "ListPreference" set "DefaultEmailType" = 'P' where "DefaultEmailType" = 'Text'; +alter table "ListPreference" alter column "DefaultEmailType" set default 'H'; +alter table "ListPreference" alter column "DefaultEmailType" set data type varchar(1); +update "Member" set "Format" = 'H' where "Format" = 'Html'; +update "Member" set "Format" = 'P' where "Format" = 'Text'; +alter table "Member" alter column "Format" set data type varchar(1); -- 2.45.1 From a4436fd844232976285edcdd4c7a2af8d38f3e19 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 19 Mar 2019 21:15:32 -0500 Subject: [PATCH 12/14] Added "as of" date display logic --- src/PrayerTracker.UI/Resources/Common.es.resx | 3 +++ src/PrayerTracker.UI/ViewModels.fs | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/PrayerTracker.UI/Resources/Common.es.resx b/src/PrayerTracker.UI/Resources/Common.es.resx index 2f3f9eb..cfb46e0 100644 --- a/src/PrayerTracker.UI/Resources/Common.es.resx +++ b/src/PrayerTracker.UI/Resources/Common.es.resx @@ -819,4 +819,7 @@ Visualización de la Fecha “Como de” + + como de + \ No newline at end of file diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index 071f22d..750bdc7 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -579,7 +579,8 @@ with (this.date - req.updatedDate).Days <= this.listGroup.preferences.daysToKeepNew /// Generate this list as HTML member this.asHtml (s : IStringLocalizer) = - let prefs = this.listGroup.preferences + let prefs = this.listGroup.preferences + let asOfSize = Math.Round (float prefs.textFontSize * 0.8, 2) [ match this.showHeader with | true -> yield div [ _style (sprintf "text-align:center;font-family:%s" prefs.listFonts) ] [ @@ -626,6 +627,18 @@ with | Some _ -> () | None -> () yield rawText req.text + match prefs.asOfDateDisplay with + | NoDisplay -> () + | ShortDate + | LongDate -> + let dt = + match prefs.asOfDateDisplay with + | ShortDate -> req.updatedDate.ToShortDateString () + | LongDate -> req.updatedDate.ToLongDateString () + | _ -> "" + yield i [ _style (sprintf "font-size:%fpt" asOfSize) ] [ + rawText "  ("; str s.["as of "].Value; str dt; rawText ")" + ] ]) |> ul [] yield br [] -- 2.45.1 From 0cd60b34ca493079229c3ffba0516e24e742b634 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 19 Mar 2019 21:51:56 -0500 Subject: [PATCH 13/14] Updated docs; tweaked as-of date code --- docs/en/requests/maintain.md | 4 ++++ docs/en/small-group/preferences.md | 10 +++++++++- docs/es/requests/maintain.md | 4 ++++ docs/es/small-group/preferences.md | 8 ++++++++ src/PrayerTracker.UI/ViewModels.fs | 14 ++++++++++++-- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/docs/en/requests/maintain.md b/docs/en/requests/maintain.md index 1f8b826..b8e8509 100644 --- a/docs/en/requests/maintain.md +++ b/docs/en/requests/maintain.md @@ -8,6 +8,10 @@ From this page, you can add, edit, and delete your current requests. You can als To add a request, click the icon or text in the center of the page, below the title and above the list of requests for your group. +## Search Requests + +If you are looking for a particular requests, enter some text in the search box and click “Search”. PrayerTracker will search the Requestor/Subject and Request Text fields (case-insensitively) of both active and inactive requests. The results will be displayed in the same format as the original Maintain Requests page, so the buttons described below will work the same for those requests as well. They will also be displayed in pages, if there are a lot of results; the number per page is configurable by small group. + ## Edit Request To edit a request, click the blue pencil icon; it's the first icon under the “Actions” column heading. diff --git a/docs/en/small-group/preferences.md b/docs/en/small-group/preferences.md index 4f855d7..1c3b137 100644 --- a/docs/en/small-group/preferences.md +++ b/docs/en/small-group/preferences.md @@ -26,7 +26,7 @@ PrayerTracker must put an name and e-mail address in the “from” position of ## E-mail Format -"This is the default e-mail format for your group. The PrayerTracker default is HTML, which sends the list just as you see it online. However, some e-mail clients may not display this properly, so you can choose to default the email to a plain-text format, which does not have colors, italics, or other formatting. The setting on this page is the group default; you can select a format for each recipient on the “Maintain Group Members” page. +This is the default e-mail format for your group. The PrayerTracker default is HTML, which sends the list just as you see it online. However, some e-mail clients may not display this properly, so you can choose to default the email to a plain-text format, which does not have colors, italics, or other formatting. The setting on this page is the group default; you can select a format for each recipient on the “Maintain Group Members” page. ## Colors @@ -60,3 +60,11 @@ This is the time zone that you would like to use for your group. If you do not s ## Request List Visibility The group's request list can be either public, private, or password-protected. Public lists are available without logging in, and private lists are only available online to administrators (though the list can still be sent via e-mail by an administrator). Password-protected lists allow group members to log in and view the current request list online, using the “Group Log On” link and providing this password. As this is a shared password, it is stored in plain text, so you can easily see what it is. If you select “Password Protected” but do not enter a password, the list remains private, which is also the default value. (Changing this password will force all members of the group who logged in with the “Remember Me” box checked to provide the new password.) + +## Page Size + +As small groups use PrayerTracker, they accumulate many expired requests. When lists of requests that include expired requests, the results will be broken up into pages. The default value is 100 requests per page, but may be set as low as 10 or as high as 255. + +## "As of" Date Display + +PrayerTracker can display the last date a request was updated, at the end of the request text. By default, it does not. If you select a short date, it will show "(as of 10/11/2015)" (for October 11, 2015); if you select a long date, it will show "(as of Sunday, October 11, 2015)". diff --git a/docs/es/requests/maintain.md b/docs/es/requests/maintain.md index 0f14b49..470cc9f 100644 --- a/docs/es/requests/maintain.md +++ b/docs/es/requests/maintain.md @@ -8,6 +8,10 @@ Desde esta página, usted puede agregar, editar y borrar sus peticiones actuales Para agregar una petición, haga clic en el icono o el texto en el centro de la página, debajo del título y por encima de la lista de peticiones para su grupo. +## Busca las Peticiones + +Si está buscando una solicitud en particular, ingrese un texto en el cuadro de búsqueda y haga clic en “Buscar”. SeguidorOración buscará los campos de Solicitante / Asunto y Texto de solicitud (sin distinción de mayúsculas y minúsculas) de solicitudes activas e inactivas. Los resultados se mostrarán en el mismo formato que la página de solicitudes de mantenimiento original, por lo que los botones que se describen a continuación funcionarán igual para esas solicitudes. También se mostrarán en las páginas, si hay muchos resultados; el número por página es configurable por grupos pequeños. + ## Editar la Petición Para editar una petición, haga clic en el icono de lápiz azul, el primer icono bajo el título de columna “Acciones”. diff --git a/docs/es/small-group/preferences.md b/docs/es/small-group/preferences.md index 680fb34..3a46129 100644 --- a/docs/es/small-group/preferences.md +++ b/docs/es/small-group/preferences.md @@ -60,3 +60,11 @@ Esta es la zona horaria que desea utilizar para su clase. Si no puede ver la zon ## La Visibilidad del la Lista de las Peticiones La lista de peticiones del grupo puede ser pública, privada o protegida por contraseña. Las listas públicas están disponibles sin iniciar sesión, y listas privadas sólo están disponibles en línea a los administradores (aunque la lista todavía puede ser enviado por correo electrónico por el administrador). Protegidos con contraseña listas permiten miembros del grupo iniciar sesión y ver la lista de peticiones actual en el sito, utilizando el "Iniciar Sesión como Grupo" enlace y proporcionar la contraseña. Como se trata de una contraseña compartida, se almacena en texto plano, así que usted puede ver fácilmente lo que es. Si selecciona "Protegido por Contraseña" pero no introduce una contraseña, la lista sigue siendo privado, que también es el valor predeterminado. (Cambiar esta contraseña obligará a todos los miembros del grupo que se iniciar sesión en el "Acuérdate de Mí" caja marcada para proporcionar la nueva contraseña.) + +## Tamaño de Página + +A medida que los grupos pequeños utilizan SeguidorOración, acumulan muchas solicitudes caducadas. Cuando las listas de solicitudes que incluyen solicitudes caducadas, los resultados se dividirán en páginas. El valor predeterminado es de 100 solicitudes por página, pero se puede establecer tan bajo como 10 o tan alto como 255. + +## Visualización de la Fecha “Como de” + +SeguidorOración puede mostrar la última fecha en que se actualizó una solicitud, al final del texto de solicitud. Por defecto, no lo hace. Si selecciona una fecha corta, se mostrará "(como de 11/10/2015)" (para el 11 de octubre de 2015); si selecciona una fecha larga, se mostrará "(como de domingo, 11 de octubre de 2015)". \ No newline at end of file diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index 750bdc7..c9f3b6e 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -637,7 +637,7 @@ with | LongDate -> req.updatedDate.ToLongDateString () | _ -> "" yield i [ _style (sprintf "font-size:%fpt" asOfSize) ] [ - rawText "  ("; str s.["as of "].Value; str dt; rawText ")" + rawText "  ("; str s.["as of"].Value; str " "; str dt; rawText ")" ] ]) |> ul [] @@ -667,7 +667,17 @@ with for req in reqs do let bullet = match this.isNew req with true -> "+" | false -> "-" let requestor = match req.requestor with Some r -> sprintf "%s - " r | None -> "" - yield sprintf " %s %s%s" bullet requestor (htmlToPlainText req.text) + yield + match this.listGroup.preferences.asOfDateDisplay with + | NoDisplay -> "" + | _ -> + let dt = + match this.listGroup.preferences.asOfDateDisplay with + | ShortDate -> req.updatedDate.ToShortDateString () + | LongDate -> req.updatedDate.ToLongDateString () + | _ -> "" + sprintf " (%s %s)" s.["as of"].Value dt + |> sprintf " %s %s%s%s" bullet requestor (htmlToPlainText req.text) yield " " } |> String.concat "\n" -- 2.45.1 From 9c40af0765ece37d4b726aa4e4e5430624659a33 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 19 Mar 2019 23:53:05 -0500 Subject: [PATCH 14/14] Added tests for as-of date logic --- src/PrayerTracker.Tests/UI/ViewModelsTests.fs | 64 ++++++++++++++++++- src/PrayerTracker.UI/ViewModels.fs | 2 +- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs index ac4a513..64a783a 100644 --- a/src/PrayerTracker.Tests/UI/ViewModelsTests.fs +++ b/src/PrayerTracker.Tests/UI/ViewModelsTests.fs @@ -482,7 +482,7 @@ let requestListTests = } |> f yield! testFixture withRequestList [ - "asHtml succeeds without header", + "asHtml succeeds without header or as-of date", fun reqList -> let htmlList = { reqList with listGroup = { reqList.listGroup with name = "Test HTML Group" } } let html = htmlList.asHtml _s @@ -538,7 +538,37 @@ let requestListTests = Expect.stringContains html lstHeading "Expected HTML for the list heading not found" // spot check; without header test tests this exhaustively Expect.stringContains html "Zeb — zyx" "Expected requests not found" - "asText succeeds", + "asHtml succeeds with short as-of date", + fun reqList -> + let htmlList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = ShortDate } + } + } + let html = htmlList.asHtml _s + let expected = + htmlList.requests.[0].updatedDate.ToShortDateString () + |> sprintf "Zeb — zyx  (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains html expected "Expected short as-of date not found" + "asHtml succeeds with long as-of date", + fun reqList -> + let htmlList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = LongDate } + } + } + let html = htmlList.asHtml _s + let expected = + htmlList.requests.[0].updatedDate.ToLongDateString () + |> sprintf "Zeb — zyx  (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains html expected "Expected long as-of date not found" + "asText succeeds with no as-of date", fun reqList -> let textList = { reqList with listGroup = { reqList.listGroup with name = "Test Group" } } let text = textList.asText _s @@ -552,6 +582,36 @@ let requestListTests = Expect.stringContains text "------------------\n PRAISE REPORTS\n------------------\n" "Heading for category \"Praise Reports\" not found" Expect.stringContains text " + nmo\n \n" "Last request not found" + "asText succeeds with short as-of date", + fun reqList -> + let textList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = ShortDate } + } + } + let text = textList.asText _s + let expected = + textList.requests.[0].updatedDate.ToShortDateString () + |> sprintf " + Zeb - zyx (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains text expected "Expected short as-of date not found" + "asText succeeds with long as-of date", + fun reqList -> + let textList = + { reqList with + listGroup = + { reqList.listGroup with + preferences = { reqList.listGroup.preferences with asOfDateDisplay = LongDate } + } + } + let text = textList.asText _s + let expected = + textList.requests.[0].updatedDate.ToLongDateString () + |> sprintf " + Zeb - zyx (as of %s)" + // spot check; if one request has it, they all should + Expect.stringContains text expected "Expected long as-of date not found" "isNew succeeds for both old and new requests", fun reqList -> let reqs = reqList.requestsInCategory CurrentRequest diff --git a/src/PrayerTracker.UI/ViewModels.fs b/src/PrayerTracker.UI/ViewModels.fs index c9f3b6e..85701ad 100644 --- a/src/PrayerTracker.UI/ViewModels.fs +++ b/src/PrayerTracker.UI/ViewModels.fs @@ -636,7 +636,7 @@ with | ShortDate -> req.updatedDate.ToShortDateString () | LongDate -> req.updatedDate.ToLongDateString () | _ -> "" - yield i [ _style (sprintf "font-size:%fpt" asOfSize) ] [ + yield i [ _style (sprintf "font-size:%.2fpt" asOfSize) ] [ rawText "  ("; str s.["as of"].Value; str " "; str dt; rawText ")" ] ]) -- 2.45.1