Search works on request text

This commit is contained in:
Daniel J. Summers 2019-03-15 22:22:32 -05:00
parent 7ba7fede69
commit 8b46a670fa
3 changed files with 31 additions and 30 deletions

View File

@ -8,6 +8,22 @@ open PrayerTracker.Entities
open System.Collections.Generic
open System.Linq
[<AutoOpen>]
module private Helpers =
/// Central place to append sort criteria for prayer request queries
let reqSort sort (query : IQueryable<PrayerRequest>) =
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 --*)

View File

@ -819,4 +819,10 @@
<data name="Click for Help on This Page" xml:space="preserve">
<value>Haga Clic para Obtener Ayuda en Esta Página</value>
</data>
<data name="Search" xml:space="preserve">
<value>Buscar</value>
</data>
<data name="Search requests..." xml:space="preserve">
<value>Busca las peticiones...</value>
</data>
</root>

View File

@ -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<IClock> ()) None onlyActive
return!
{ viewInfo ctx startTicks with helpLink = Some Help.maintainRequests }