From c784c9e91e08408a99f6de4f73b73736b669843f Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 15 Mar 2019 20:05:51 -0500 Subject: [PATCH] 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)