Order columns in people list
This commit is contained in:
parent
9dda517b03
commit
56a2d30189
4 changed files with 171 additions and 22 deletions
|
|
@ -68,6 +68,9 @@ func Contacts(c *fiber.Ctx) error {
|
|||
params.PageSize = 50
|
||||
params.PersonType = "contacts"
|
||||
|
||||
params.OrderColumn = c.Query("c")
|
||||
params.OrderDirection = c.Query("o")
|
||||
|
||||
var sections []models.Section
|
||||
db.Order("name asc").Find(§ions, "contains_contacts = ? AND id IN ?", true, allowedSections)
|
||||
params.AllowedSections = allowedSections
|
||||
|
|
@ -100,6 +103,8 @@ func Contacts(c *fiber.Ctx) error {
|
|||
"SearchJSON": searchJSON,
|
||||
"Sections": sections,
|
||||
"Fields": fields,
|
||||
"OrderCol": params.OrderColumn,
|
||||
"OrderDir": params.OrderDirection,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ func Members(c *fiber.Ctx) error {
|
|||
params.PageSize = 50
|
||||
params.PersonType = "members"
|
||||
|
||||
params.OrderColumn = c.Query("c")
|
||||
params.OrderDirection = c.Query("o")
|
||||
|
||||
var sections []models.Section
|
||||
db.Order("name asc").Find(§ions, "contains_members = ? AND id IN ?", true, allowedSections)
|
||||
params.AllowedSections = allowedSections
|
||||
|
|
@ -115,6 +118,8 @@ func Members(c *fiber.Ctx) error {
|
|||
"SearchJSON": searchJSON,
|
||||
"Sections": sections,
|
||||
"Fields": fields,
|
||||
"OrderCol": params.OrderColumn,
|
||||
"OrderDir": params.OrderDirection,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ type PeopleSearchParams struct {
|
|||
PageSize int `json:"-"`
|
||||
PageNumber int `json:"-"`
|
||||
AllowedSections []uint `json:"-"`
|
||||
OrderColumn string `json:"-"`
|
||||
OrderDirection string `json:"-"`
|
||||
}
|
||||
|
||||
type PeopleSearchResults struct {
|
||||
|
|
@ -43,6 +45,27 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
|
|||
return results, nil
|
||||
}
|
||||
|
||||
if strings.EqualFold(params.OrderDirection, "DESC") {
|
||||
params.OrderDirection = "DESC"
|
||||
} else {
|
||||
params.OrderDirection = "ASC"
|
||||
}
|
||||
|
||||
switch strings.ToLower(params.OrderColumn) {
|
||||
case "address":
|
||||
params.OrderColumn = "people.address1"
|
||||
case "npa":
|
||||
params.OrderColumn = "people.postal_code"
|
||||
case "section":
|
||||
params.OrderColumn = "people.section_id"
|
||||
case "created":
|
||||
params.OrderColumn = "people.created_at"
|
||||
case "updated":
|
||||
params.OrderColumn = "people.updated_at"
|
||||
default:
|
||||
params.OrderColumn = "CONCAT(people.last_name, people.first_name)"
|
||||
}
|
||||
|
||||
// SQL qeury for results
|
||||
sqlQuery := `
|
||||
SELECT people.*
|
||||
|
|
@ -353,9 +376,9 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
|
|||
%s
|
||||
%s
|
||||
GROUP BY people.id
|
||||
ORDER BY CONCAT(people.last_name, people.first_name) ASC
|
||||
ORDER BY %s %s
|
||||
%s
|
||||
`, sqlQuery, sqlFieldJoins, sqlFilters, sqlPagination)
|
||||
`, sqlQuery, sqlFieldJoins, sqlFilters, params.OrderColumn, params.OrderDirection, sqlPagination)
|
||||
|
||||
sqlResult := db.Raw(sqlQuery, sqlParams...).Preload("Section").Find(&results.Results)
|
||||
if sqlResult.Error != nil {
|
||||
|
|
|
|||
|
|
@ -244,16 +244,124 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<!--
|
||||
<div class="row">
|
||||
<div class="col">Nom</div>
|
||||
<div class="col">Adresse</div>
|
||||
<div class="col">Lieu</div>
|
||||
<div class="col">Section</div>
|
||||
<div class="col">Création</div>
|
||||
<div class="col">Modification</div>
|
||||
<div class="card card-body my-2 py-2 bg-body-tertiary">
|
||||
<div class="row">
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-1 order-md-1 order-lg-1 order-xxl-1">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
{% if OrderCol == "name" || OrderCol == "" %}
|
||||
{% if OrderDir == "asc" || OrderDir == "" %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=name&o=desc">
|
||||
Nom <i class="bi-arrow-down"></i>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=name&o=asc">
|
||||
Nom <i class="bi-arrow-up"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=name&o=asc">
|
||||
Nom
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-2 order-md-3 order-lg-2 order-xxl-2">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
{% if OrderCol == "address" %}
|
||||
{% if OrderDir == "asc" || OrderDir == "" %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=address&o=desc">
|
||||
Adresse <i class="bi-arrow-down"></i>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=address&o=asc">
|
||||
Adresse <i class="bi-arrow-up"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=address&o=asc">
|
||||
Adresse
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-3 order-md-5 order-lg-5 order-xxl-3">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
{% if OrderCol == "npa" %}
|
||||
{% if OrderDir == "asc" || OrderDir == "" %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=npa&o=desc">
|
||||
Lieu <i class="bi-arrow-down"></i>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=npa&o=asc">
|
||||
Lieu <i class="bi-arrow-up"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=npa&o=asc">
|
||||
Lieu
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-4 order-md-2 order-lg-4 order-xxl-4">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
{% if OrderCol == "section" %}
|
||||
{% if OrderDir == "asc" || OrderDir == "" %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=section&o=desc">
|
||||
Section <i class="bi-arrow-down"></i>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=section&o=asc">
|
||||
Section <i class="bi-arrow-up"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=section&o=asc">
|
||||
Section
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-5 order-md-3 order-lg-4 order-xxl-5">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
{% if OrderCol == "created" %}
|
||||
{% if OrderDir == "asc" || OrderDir == "" %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=created&o=desc">
|
||||
Création <i class="bi-arrow-down"></i>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=created&o=asc">
|
||||
Création <i class="bi-arrow-up"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=created&o=asc">
|
||||
Création
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-last order-md-last order-lg-last order-xxl-last">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
{% if OrderCol == "updated" %}
|
||||
{% if OrderDir == "asc" || OrderDir == "" %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=updated&o=desc">
|
||||
Modification <i class="bi-arrow-down"></i>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=updated&o=asc">
|
||||
Modification <i class="bi-arrow-up"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href="?p=1&s={{ SearchJSON|urlencode }}&c=updated&o=asc">
|
||||
Modification
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
{% for Person in People %}
|
||||
<div class="card card-body my-2 py-2 bg-body-tertiary">
|
||||
|
|
@ -298,20 +406,28 @@
|
|||
{{ Person.Section.Name }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-5 order-md-3 order-lg-4 order-xxl-5" data-key="created_at" data-value="{{ Person.CreatedAt|date:"2006-01-02 15:04" }}">
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-5 order-md-3 order-lg-4 order-xxl-5">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
Création
|
||||
</div>
|
||||
<div>
|
||||
{{ Person.CreatedAt|date:"02.01.2006 - 15:04" }}
|
||||
{% if Person.CreatedAt|date:"2006-01-02" == "1970-01-01" %}
|
||||
<code>Inconnu</code>
|
||||
{% else %}
|
||||
<code>{{ Person.CreatedAt|date:"02.01.2006 15:04" }}</code>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-last order-md-last order-lg-last order-xxl-last" data-key="created_at" data-value="{{ Person.UpdatedAt|date:"2006-01-02 15:04" }}">
|
||||
<div class="col-xxl col-lg-4 col-md-6 order-last order-md-last order-lg-last order-xxl-last">
|
||||
<div class="text-bold fs-7 mt-xxl-0 mt-2">
|
||||
Mise à jour
|
||||
Modification
|
||||
</div>
|
||||
<div>
|
||||
{{ Person.UpdatedAt|date:"02.01.2006 - 15:04" }}
|
||||
{% if Person.UpdatedAt|date:"2006-01-02" == "1970-01-01" %}
|
||||
<code>Inconnu</code>
|
||||
{% else %}
|
||||
<code>{{ Person.UpdatedAt|date:"02.01.2006 15:04" }}</code>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -334,14 +450,14 @@
|
|||
</li>
|
||||
{% else %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?p=1&s={{ SearchJSON|urlencode }}">
|
||||
<a class="page-link" href="?p=1&s={{ SearchJSON|urlencode }}&c={{ OrderCol }}&o={{ OrderDir }}">
|
||||
<i class="bi-rewind"></i>
|
||||
</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a
|
||||
class="page-link"
|
||||
href="?&p={{ Pagination.CurrentPage - 1 }}&s={{ SearchJSON|urlencode }}"
|
||||
href="?&p={{ Pagination.CurrentPage - 1 }}&s={{ SearchJSON|urlencode }}&c={{ OrderCol }}&o={{ OrderDir }}"
|
||||
>
|
||||
<i class="bi-caret-left"></i>
|
||||
</a>
|
||||
|
|
@ -356,7 +472,7 @@
|
|||
{% else %}
|
||||
class="page-link"
|
||||
{% endif %}
|
||||
href="?&p={{ i }}&s={{ SearchJSON|urlencode }}"
|
||||
href="?&p={{ i }}&s={{ SearchJSON|urlencode }}&c={{ OrderCol }}&o={{ OrderDir }}"
|
||||
>
|
||||
{{ i }}
|
||||
</a>
|
||||
|
|
@ -378,7 +494,7 @@
|
|||
<li class="page-item">
|
||||
<a
|
||||
class="page-link"
|
||||
href="?&p={{ Pagination.CurrentPage + 1 }}&s={{ SearchJSON|urlencode }}"
|
||||
href="?&p={{ Pagination.CurrentPage + 1 }}&s={{ SearchJSON|urlencode }}&c={{ OrderCol }}&o={{ OrderDir }}"
|
||||
>
|
||||
<i class="bi-caret-right"></i>
|
||||
</a>
|
||||
|
|
@ -386,7 +502,7 @@
|
|||
<li class="page-item">
|
||||
<a
|
||||
class="page-link"
|
||||
href="?p={{ Pagination.MaxPages }}&s={{ SearchJSON|urlencode }}"
|
||||
href="?p={{ Pagination.MaxPages }}&s={{ SearchJSON|urlencode }}&c={{ OrderCol }}&o={{ OrderDir }}"
|
||||
>
|
||||
<i class="bi-fast-forward"></i>
|
||||
</a>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue