From db753699b893976ec08712e4c7c009580f891d35 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Mon, 2 Aug 2021 23:14:48 -0400 Subject: [PATCH] First cut of public profile search Also tweak logged-on profile search --- src/JobsJobsJobs/Api/Data.fs | 68 +++++---- src/JobsJobsJobs/Api/Handlers.fs | 2 - src/JobsJobsJobs/App/src/App.vue | 10 ++ src/JobsJobsJobs/App/src/api/index.ts | 19 +++ src/JobsJobsJobs/App/src/api/types.ts | 32 +++- .../components/profile/PublicSearchForm.vue | 82 +++++++++++ .../App/src/components/profile/SearchForm.vue | 4 +- src/JobsJobsJobs/App/src/router/index.ts | 12 ++ .../App/src/views/profile/ProfileSearch.vue | 30 ++-- .../App/src/views/profile/Seeking.vue | 138 +++++++++++++++++- src/JobsJobsJobs/Domain/SharedTypes.fs | 1 + 11 files changed, 343 insertions(+), 55 deletions(-) create mode 100644 src/JobsJobsJobs/App/src/components/profile/PublicSearchForm.vue diff --git a/src/JobsJobsJobs/Api/Data.fs b/src/JobsJobsJobs/Api/Data.fs index 33140ac..1f719b5 100644 --- a/src/JobsJobsJobs/Api/Data.fs +++ b/src/JobsJobsJobs/Api/Data.fs @@ -279,34 +279,46 @@ module Profile = .RunResultAsync conn) // Search profiles (public) - let publicSearch (srch : PublicSearch) conn = task { - let results = - seq { - match srch.continentId with - | Some conId -> - yield (fun (q : ReqlExpr) -> - q.Filter(r.HashMap(nameof srch.continentId, ContinentId.ofString conId)) :> ReqlExpr) - | None -> () - match srch.region with - | Some reg -> - yield (fun q -> - q.Filter(ReqlFunction1(fun it -> - upcast it.G("region").Downcase().Match(reg.ToLowerInvariant ()))) :> ReqlExpr) - | None -> () - match srch.remoteWork with - | "" -> () - | _ -> yield (fun q -> q.Filter(r.HashMap(nameof srch.remoteWork, srch.remoteWork = "yes")) :> ReqlExpr) - match srch.skill with - | Some skl -> - yield (fun q -> q.Filter(ReqlFunction1(fun it -> - upcast it.G("skills.description").Downcase().Match(skl.ToLowerInvariant ()))) :> ReqlExpr) - | None -> () - } - |> Seq.toList - |> List.fold (fun q f -> f q) (r.Table(Table.Profile) :> ReqlExpr) - // TODO: pluck fields, compile skills - return! results.RunResultAsync conn - } + let publicSearch (srch : PublicSearch) conn = + withReconn(conn).ExecuteAsync(fun () -> + (seq { + match srch.continentId with + | Some conId -> + yield (fun (q : ReqlExpr) -> + q.Filter(r.HashMap(nameof srch.continentId, ContinentId.ofString conId)) :> ReqlExpr) + | None -> () + match srch.region with + | Some reg -> + yield (fun q -> + q.Filter(ReqlFunction1(fun it -> + upcast it.G("region").Downcase().Match(reg.ToLowerInvariant ()))) :> ReqlExpr) + | None -> () + match srch.remoteWork with + | "" -> () + | _ -> yield (fun q -> q.Filter(r.HashMap(nameof srch.remoteWork, srch.remoteWork = "yes")) :> ReqlExpr) + match srch.skill with + | Some skl -> + yield (fun q -> q.Filter(ReqlFunction1(fun it -> + upcast it.G("skills.description").Downcase().Match(skl.ToLowerInvariant ()))) :> ReqlExpr) + | None -> () + } + |> Seq.toList + |> List.fold + (fun q f -> f q) + (r.Table(Table.Profile) + .EqJoin("continentId", r.Table(Table.Continent)) + .Without(r.HashMap("right", "id")) + .Zip() + .Filter(r.HashMap("isPublic", true)) :> ReqlExpr)) + .Merge(ReqlFunction1(fun it -> + upcast r + .HashMap("skills", + it.G("skills").Map(ReqlFunction1(fun skill -> + upcast r.Branch(skill.G("notes").Default_("").Eq(""), skill.G("description"), + sprintf "%O (%O)" (skill.G("description")) (skill.G("notes")))))) + .With("continent", it.G("name")))) + .Pluck("continent", "region", "skills", "remoteWork") + .RunResultAsync conn) /// Citizen data access functions diff --git a/src/JobsJobsJobs/Api/Handlers.fs b/src/JobsJobsJobs/Api/Handlers.fs index 9e2c8f3..2aff18f 100644 --- a/src/JobsJobsJobs/Api/Handlers.fs +++ b/src/JobsJobsJobs/Api/Handlers.fs @@ -20,7 +20,6 @@ module Vue = module Error = open System.Threading.Tasks - open Microsoft.Extensions.Logging /// Handler that will return a status code 404 and the text "Not Found" let notFound : HttpHandler = @@ -49,7 +48,6 @@ module Helpers = open NodaTime open Microsoft.Extensions.Configuration - open Microsoft.Extensions.Logging open RethinkDb.Driver.Net open System.Security.Claims diff --git a/src/JobsJobsJobs/App/src/App.vue b/src/JobsJobsJobs/App/src/App.vue index 5c2b3f0..e61c272 100644 --- a/src/JobsJobsJobs/App/src/App.vue +++ b/src/JobsJobsJobs/App/src/App.vue @@ -35,6 +35,16 @@ export default defineComponent({ TitleBar } }) + +/** + * Return "Yes" for true and "No" for false + * + * @param cond The condition to be checked + * @returns "Yes" for true, "No" for false + */ +export function yesOrNo (cond : boolean) : string { + return cond ? 'Yes' : 'No' +}