Search works on request text
This commit is contained in:
parent
7ba7fede69
commit
8b46a670fa
@ -8,6 +8,22 @@ open PrayerTracker.Entities
|
|||||||
open System.Collections.Generic
|
open System.Collections.Generic
|
||||||
open System.Linq
|
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
|
type AppDbContext with
|
||||||
|
|
||||||
(*-- DISCONNECTED DATA EXTENSIONS --*)
|
(*-- DISCONNECTED DATA EXTENSIONS --*)
|
||||||
@ -79,7 +95,6 @@ type AppDbContext with
|
|||||||
upcast (
|
upcast (
|
||||||
this.PrayerRequests.AsNoTracking().Where(fun pr -> pr.smallGroupId = grp.smallGroupId)
|
this.PrayerRequests.AsNoTracking().Where(fun pr -> pr.smallGroupId = grp.smallGroupId)
|
||||||
|> function
|
|> function
|
||||||
// Filter
|
|
||||||
| query when activeOnly ->
|
| query when activeOnly ->
|
||||||
let asOf = theDate.AddDays(-(float grp.preferences.daysToExpire)).Date
|
let asOf = theDate.AddDays(-(float grp.preferences.daysToExpire)).Date
|
||||||
query.Where(fun pr ->
|
query.Where(fun pr ->
|
||||||
@ -89,16 +104,7 @@ type AppDbContext with
|
|||||||
|| RequestType.Expecting = pr.requestType)
|
|| RequestType.Expecting = pr.requestType)
|
||||||
&& not pr.isManuallyExpired)
|
&& not pr.isManuallyExpired)
|
||||||
| query -> query
|
| query -> query
|
||||||
|> function
|
|> reqSort grp.preferences.requestSort)
|
||||||
// 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))
|
|
||||||
|
|
||||||
/// Count prayer requests for the given small group Id
|
/// Count prayer requests for the given small group Id
|
||||||
member this.CountRequestsBySmallGroup gId =
|
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
|
/// 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 =
|
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 (
|
upcast (
|
||||||
this.PrayerRequests
|
this.PrayerRequests.FromSql(sql, grp.smallGroupId, like searchTerm).AsNoTracking ()
|
||||||
.AsNoTracking()
|
|> reqSort grp.preferences.requestSort
|
||||||
.Where(fun pr -> pr.smallGroupId = grp.smallGroupId && pr.text.Contains(searchTerm.ToLowerInvariant()))
|
|> function query -> (query.Skip skip).Take pgSz)
|
||||||
|> 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 --*)
|
(*-- SMALL GROUP EXTENSIONS --*)
|
||||||
|
|
||||||
|
@ -819,4 +819,10 @@
|
|||||||
<data name="Click for Help on This Page" xml:space="preserve">
|
<data name="Click for Help on This Page" xml:space="preserve">
|
||||||
<value>Haga Clic para Obtener Ayuda en Esta Página</value>
|
<value>Haga Clic para Obtener Ayuda en Esta Página</value>
|
||||||
</data>
|
</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>
|
</root>
|
@ -201,8 +201,7 @@ let maintain onlyActive : HttpHandler =
|
|||||||
task {
|
task {
|
||||||
let reqs =
|
let reqs =
|
||||||
match ctx.GetQueryStringValue "search" with
|
match ctx.GetQueryStringValue "search" with
|
||||||
| Ok srch ->
|
| Ok srch -> db.SearchRequestsForSmallGroup grp srch 1
|
||||||
Seq.empty
|
|
||||||
| Error _ -> db.AllRequestsForSmallGroup grp (ctx.GetService<IClock> ()) None onlyActive
|
| Error _ -> db.AllRequestsForSmallGroup grp (ctx.GetService<IClock> ()) None onlyActive
|
||||||
return!
|
return!
|
||||||
{ viewInfo ctx startTicks with helpLink = Some Help.maintainRequests }
|
{ viewInfo ctx startTicks with helpLink = Some Help.maintainRequests }
|
||||||
|
Loading…
Reference in New Issue
Block a user