Filter member directory by HereFor

This commit is contained in:
Noah Petherbridge 2023-08-29 21:10:00 -07:00
parent f52fa47f3e
commit 6eb51cf545
3 changed files with 55 additions and 19 deletions

View File

@ -21,7 +21,9 @@ func Search() http.HandlerFunc {
"last_login_at desc", "last_login_at desc",
"created_at desc", "created_at desc",
"username", "username",
"username desc",
"lower(name)", "lower(name)",
"lower(name) desc",
"distance", "distance",
} }
@ -33,6 +35,7 @@ func Search() http.HandlerFunc {
gender = r.FormValue("gender") gender = r.FormValue("gender")
orientation = r.FormValue("orientation") orientation = r.FormValue("orientation")
maritalStatus = r.FormValue("marital_status") maritalStatus = r.FormValue("marital_status")
hereFor = r.FormValue("here_for")
sort = r.FormValue("sort") sort = r.FormValue("sort")
sortOK bool sortOK bool
ageMin int ageMin int
@ -87,6 +90,7 @@ func Search() http.HandlerFunc {
Gender: gender, Gender: gender,
Orientation: orientation, Orientation: orientation,
MaritalStatus: maritalStatus, MaritalStatus: maritalStatus,
HereFor: hereFor,
Certified: isCertified != "false", Certified: isCertified != "false",
InnerCircle: isCertified == "circle", InnerCircle: isCertified == "circle",
AgeMin: ageMin, AgeMin: ageMin,
@ -109,6 +113,7 @@ func Search() http.HandlerFunc {
"Gender": gender, "Gender": gender,
"Orientation": orientation, "Orientation": orientation,
"MaritalStatus": maritalStatus, "MaritalStatus": maritalStatus,
"HereFor": hereFor,
"EmailOrUsername": username, "EmailOrUsername": username,
"AgeMin": ageMin, "AgeMin": ageMin,
"AgeMax": ageMax, "AgeMax": ageMax,

View File

@ -188,6 +188,7 @@ type UserSearch struct {
Gender string Gender string
Orientation string Orientation string
MaritalStatus string MaritalStatus string
HereFor string
Certified bool Certified bool
InnerCircle bool InnerCircle bool
AgeMin int AgeMin int
@ -278,6 +279,16 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er
placeholders = append(placeholders, "marital_status", search.MaritalStatus) placeholders = append(placeholders, "marital_status", search.MaritalStatus)
} }
if search.HereFor != "" {
wheres = append(wheres, `
EXISTS (
SELECT 1 FROM profile_fields
WHERE user_id = users.id AND name = ? AND value = ?
)
`)
placeholders = append(placeholders, "here_for", search.HereFor)
}
if search.Certified { if search.Certified {
wheres = append(wheres, "certified = ?", "status = ?") wheres = append(wheres, "certified = ?", "status = ?")
placeholders = append(placeholders, search.Certified, UserStatusActive) placeholders = append(placeholders, search.Certified, UserStatusActive)

View File

@ -70,7 +70,7 @@
</button> </button>
</header> </header>
<div class="card-content"> <div class="card-content">
<div class="columns is-multiline"> <div class="columns">
<div class="column"> <div class="column">
<div class="field"> <div class="field">
@ -100,9 +100,9 @@
<div class="column"> <div class="column">
<div class="field"> <div class="field">
<label class="label">Age:</label> <label class="label">Age:</label>
<div class="columns is-mobile"> <div class="columns is-mobile is-gapless">
<div class="column"> <div class="column">
<div class="select"> <div class="select is-fullwidth">
<select name="age_min"> <select name="age_min">
<option value="">Min</option> <option value="">Min</option>
{{range IterRange 18 120}} {{range IterRange 18 120}}
@ -110,7 +110,9 @@
{{end}} {{end}}
</select> </select>
</div> </div>
<div class="select"> </div>
<div class="column">
<div class="select is-fullwidth">
<select name="age_max"> <select name="age_max">
<option value="">Max</option> <option value="">Max</option>
{{range IterRange 18 120}} {{range IterRange 18 120}}
@ -137,6 +139,9 @@
</div> </div>
</div> </div>
</div>
<div class="columns is-centered">
<div class="column"> <div class="column">
<div class="field"> <div class="field">
<label class="label" for="orientation">Orientation:</label> <label class="label" for="orientation">Orientation:</label>
@ -165,23 +170,38 @@
</div> </div>
</div> </div>
</div> <div class="column">
<div class="columns is-centered"> <div class="field">
<div class="column is-narrow pr-1"> <label class="label" for="here_for">Here for:</label>
<strong>Sort by:</strong> <div class="select is-fullwidth">
</div> <select id="here_for" name="here_for">
<div class="column is-narrow pl-1"> <option value=""></option>
<div class="select is-full-width"> {{range .Enum.HereFor}}
<select id="sort" name="sort"> <option value="{{.}}"{{if eq $Root.HereFor .}} selected{{end}}>{{.}}</option>
<option value="last_login_at desc"{{if eq .Sort "last_login_at desc"}} selected{{end}}>Last login</option> {{end}}
<option value="created_at desc"{{if eq .Sort "created_at desc"}} selected{{end}}>Signup date</option> </select>
<option value="username"{{if eq .Sort "username"}} selected{{end}}>Username (a-z)</option> </div>
<option value="lower(name)"{{if eq .Sort "lower(name)"}} selected{{end}}>Name (a-z)</option>
<option value="distance"{{if eq .Sort "distance"}} selected{{end}}>Distance to me</option>
</select>
</div> </div>
</div> </div>
<div class="column is-narrow">
<div class="column">
<div class="field">
<label class="label" for="sort">Sort by:</label>
<div class="select is-full-width">
<select id="sort" name="sort">
<option value="last_login_at desc"{{if eq .Sort "last_login_at desc"}} selected{{end}}>Last login</option>
<option value="created_at desc"{{if eq .Sort "created_at desc"}} selected{{end}}>Signup date</option>
<option value="username"{{if eq .Sort "username"}} selected{{end}}>Username (a-z)</option>
<option value="username desc"{{if eq .Sort "username desc"}} selected{{end}}>Username (z-a)</option>
<option value="lower(name)"{{if eq .Sort "lower(name)"}} selected{{end}}>Name (a-z)</option>
<option value="lower(name) desc"{{if eq .Sort "lower(name) desc"}} selected{{end}}>Name (z-a)</option>
<option value="distance"{{if eq .Sort "distance"}} selected{{end}}>Distance to me</option>
</select>
</div>
</div>
</div>
<div class="column has-text-right">
<a href="/members" class="button">Reset</a> <a href="/members" class="button">Reset</a>
<button type="submit" class="button is-success"> <button type="submit" class="button is-success">
<span>Search</span> <span>Search</span>