More work on the new people search

This commit is contained in:
William Bouzourène 2025-03-25 21:55:54 +01:00
parent fac4e695fc
commit e6eec0dfaf
6 changed files with 337 additions and 121 deletions

View file

@ -297,3 +297,25 @@ func FieldMoveDown(c *fiber.Ctx) error {
return c.Redirect("/admin/fields")
}
func FieldJSON(c *fiber.Ctx) error {
id := c.Params("id")
db, err := helpers.GetDatabase()
if err != nil {
return err
}
var field models.Field
result := db.Preload("List").Preload("List.ListItems").Find(&field, "id = ?", id)
if result.Error != nil {
return result.Error
}
if result.RowsAffected < 1 {
return fiber.NewError(fiber.StatusNotFound, "Not found")
}
return c.JSON(field)
}

View file

@ -1,6 +1,7 @@
package controllers
import (
"encoding/json"
"errors"
"fmt"
"strconv"
@ -8,6 +9,7 @@ import (
"time"
"git.readonly.ch/bouzoure/pop-camarades/helpers"
"git.readonly.ch/bouzoure/pop-camarades/helpers/database"
"git.readonly.ch/bouzoure/pop-camarades/models"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
@ -59,11 +61,7 @@ func Members(c *fiber.Ctx) error {
return err
}
filterSection := c.Query("se")
filterArchive := c.Query("a")
filterSearch := c.Query("s")
sqlFilterSections := allowedSections
/*sqlFilterSections := allowedSections
sqlFilterAppend := "IS NULL"
if filterArchive == "1" {
sqlFilterAppend = "IS NOT NULL"
@ -116,9 +114,6 @@ func Members(c *fiber.Ctx) error {
).Count(&count)
}
page, _ := strconv.Atoi(c.Query("p"))
pagination := helpers.Paginate(50, int(count), page)
var people []models.Person
if len(filterSearch) > 0 {
result := db.Unscoped().Offset(
@ -162,28 +157,50 @@ func Members(c *fiber.Ctx) error {
if result.Error != nil && !errors.Is(result.Error, gorm.ErrRecordNotFound) {
return err
}
}
}*/
var sections []models.Section
/*var sections []models.Section
db.Order(
"name collate nocase asc",
).Find(
&sections,
"contains_members = ? AND id IN ?",
true, sqlFilterSections,
)
)*/
searchJSON := c.Query("s")
var params database.PeopleSearchParams
if len(searchJSON) > 0 {
err = json.Unmarshal([]byte(searchJSON), &params)
if err != nil {
return err
}
}
page, _ := strconv.Atoi(c.Query("p"))
results, err := database.PeopleSearch(params, "members", 50, page)
if err != nil {
return err
}
var sections []models.Section
db.Order("name collate nocase asc").Find(&sections, "contains_members = ?", true)
var fields []models.Field
db.Order("position asc").Find(&fields, "person_type = ?", "member")
return c.Render("people", fiber.Map{
"PageTitle": "Membres",
"MembersPage": true,
"People": people,
"Pagination": pagination,
"People": results.Results,
"Pagination": results.Pagination,
"PermShow": permShow,
"PermShowArchived": permShowArchived,
"SearchJSON": searchJSON,
"Sections": sections,
"FilterArchive": filterArchive,
"FilterSection": filterSectionUint,
"FilterSearch": filterSearch,
"Fields": fields,
})
}