Improve sorting
This commit is contained in:
parent
0dd4a723be
commit
d028256893
|
@ -8,9 +8,9 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||
|
@ -19,14 +19,6 @@ import (
|
|||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
type GroupsByName []groupstorage.Group
|
||||
|
||||
func (a GroupsByName) Len() int { return len(a) }
|
||||
func (a GroupsByName) Less(i, j int) bool {
|
||||
return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0
|
||||
}
|
||||
func (a GroupsByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
request := &groupsmanagement.GetGroupsRequest{
|
||||
|
@ -47,7 +39,7 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
|
|||
groups = append(groups, g)
|
||||
}
|
||||
|
||||
sort.Sort(GroupsByName(groups))
|
||||
sort.Sort(sorting.GroupsByName(groups))
|
||||
|
||||
h.Renderer.Administration(w, r, groups)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
|
@ -21,12 +22,6 @@ import (
|
|||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
type EventsByStartdate []agendastorage.Event
|
||||
|
||||
func (e EventsByStartdate) Len() int { return len(e) }
|
||||
func (e EventsByStartdate) Less(i, j int) bool { return e[i].Startdate.Before(e[j].Startdate) }
|
||||
func (e EventsByStartdate) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
|
||||
|
||||
type EventsForm struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Type string `json:"type" validate:"required"`
|
||||
|
@ -60,7 +55,7 @@ func (h *ApplicationHandler) AgendaHome(w http.ResponseWriter, r *http.Request)
|
|||
responses = append(responses, e.ToStorageType())
|
||||
}
|
||||
|
||||
sort.Sort(EventsByStartdate(responses))
|
||||
sort.Sort(sorting.EventsByStartdate(responses))
|
||||
|
||||
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||
Groupids: groupids,
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
formvalidators "git.coopgo.io/coopgo-apps/parcoursmob/utils/form-validators"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
profilepictures "git.coopgo.io/coopgo-apps/parcoursmob/utils/profile-pictures"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
|
||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
|
@ -40,14 +41,6 @@ type BeneficiariesForm struct {
|
|||
Gender string `json:"gender"`
|
||||
}
|
||||
|
||||
type BeneficiariesByName []mobilityaccountsstorage.Account
|
||||
|
||||
func (e BeneficiariesByName) Len() int { return len(e) }
|
||||
func (e BeneficiariesByName) Less(i, j int) bool {
|
||||
return e[i].Data["first_name"].(string) < e[j].Data["first_name"].(string)
|
||||
}
|
||||
func (e BeneficiariesByName) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
|
||||
|
||||
func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
accounts, err := h.beneficiaries(r)
|
||||
|
@ -57,7 +50,7 @@ func (h *ApplicationHandler) BeneficiariesList(w http.ResponseWriter, r *http.Re
|
|||
return
|
||||
}
|
||||
|
||||
sort.Sort(BeneficiariesByName(accounts))
|
||||
sort.Sort(sorting.BeneficiariesByName(accounts))
|
||||
|
||||
cacheid := uuid.NewString()
|
||||
h.cache.PutWithTTL(cacheid, accounts, 1*time.Hour)
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"sort"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
|
@ -69,7 +70,7 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
|||
events = append(events, e.ToStorageType())
|
||||
}
|
||||
|
||||
sort.Sort(EventsByStartdate(events))
|
||||
sort.Sort(sorting.EventsByStartdate(events))
|
||||
|
||||
h.Renderer.Dashboard(w, r, accounts, count, count_members, events)
|
||||
|
||||
|
|
|
@ -4,9 +4,11 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
|
@ -72,6 +74,8 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
|
|||
return
|
||||
}
|
||||
|
||||
sort.Sort(sorting.BeneficiariesByName(accounts))
|
||||
|
||||
h.Renderer.VehiclesSearch(w, r, accounts, searched, vehicles, beneficiary, r.FormValue("startdate"), r.FormValue("enddate"))
|
||||
}
|
||||
|
||||
|
|
|
@ -23,14 +23,15 @@
|
|||
<div class="border-t border-gray-200 px-4 py-5 sm:px-6">
|
||||
<form method="GET">
|
||||
|
||||
|
||||
<div x-data="{
|
||||
text: '{{if .ViewState.search}}{{.ViewState.search.beneficiary.Data.first_name}} {{.ViewState.search.beneficiary.Data.last_name}}{{end}}',
|
||||
beneficiariesListOpen: false,
|
||||
beneficiaries: {{json .ViewState.beneficiaries}},
|
||||
filteredBeneficiaries: (text) => {
|
||||
if(text=='') return beneficiaries
|
||||
return this.beneficiaries.filter(b => b['data']['first_name'].includes(text) || b['data']['last_name'].includes(text))
|
||||
filteredBeneficiaries: (beneficiaries, text) => {
|
||||
if(text=='') {
|
||||
return beneficiaries
|
||||
}
|
||||
return beneficiaries.filter(b => b['data']['first_name'].toLowerCase().includes(text.toLowerCase()) || b['data']['last_name'].toLowerCase().includes(text.toLowerCase()))
|
||||
},
|
||||
fields: {
|
||||
beneficiaryid: {{if .ViewState.search}}'{{.ViewState.search.beneficiary.ID}}'{{else}}null{{end}},
|
||||
|
@ -45,7 +46,7 @@
|
|||
<input type="hidden" name="beneficiaryid" x-model="fields.beneficiaryid">
|
||||
<label for="combobox" class="block text-sm font-medium text-gray-700">Bénéficiaire</label>
|
||||
<div class="relative mt-1 mb-4">
|
||||
<input @focus="beneficiariesListOpen = true" x-model="text" id="combobox" type="text" class="w-full rounded-2xl border border-gray-300 bg-white py-2 pl-3 pr-12 shadow-sm focus:border-co-blue focus:outline-none focus:ring-1 focus:ring-co-blue sm:text-sm" role="combobox" aria-controls="options" aria-expanded="false">
|
||||
<input autocomplete="off" @focus="beneficiariesListOpen = true" x-model="text" id="combobox" type="text" class="w-full rounded-2xl border border-gray-300 bg-white py-2 pl-3 pr-12 shadow-sm focus:border-co-blue focus:outline-none focus:ring-1 focus:ring-co-blue sm:text-sm" role="combobox" aria-controls="options" aria-expanded="false">
|
||||
|
||||
<button @click="beneficiariesListOpen = ! beneficiariesListOpen" type="button" class="absolute inset-y-0 right-0 flex items-center rounded-r-2xl px-2 focus:outline-none">
|
||||
<!-- Heroicon name: solid/selector -->
|
||||
|
@ -60,7 +61,7 @@
|
|||
|
||||
Active: "text-white bg-indigo-600", Not Active: "text-gray-900"
|
||||
-->
|
||||
<template x-for="beneficiary in beneficiaries">
|
||||
<template x-for="beneficiary in filteredBeneficiaries(beneficiaries, text)">
|
||||
<li @click="selectbeneficiary(beneficiary)" class="relative cursor-default hover:bg-gray-100 select-none py-2 pl-3 pr-9 text-gray-900" id="option-0" role="option" tabindex="-1">
|
||||
<!-- Selected: "font-semibold" -->
|
||||
<span class="truncate" x-text="beneficiary.data.first_name"></span> <span class="truncate" x-text="beneficiary.data.last_name"></span>
|
||||
|
|
|
@ -1689,10 +1689,6 @@ html {
|
|||
padding: 0.375rem;
|
||||
}
|
||||
|
||||
.p-8 {
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.px-4 {
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
|
@ -1824,6 +1820,10 @@ html {
|
|||
padding-top: 2rem;
|
||||
}
|
||||
|
||||
.pb-6 {
|
||||
padding-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.pt-4 {
|
||||
padding-top: 1rem;
|
||||
}
|
||||
|
@ -1848,10 +1848,6 @@ html {
|
|||
padding-left: 0.375rem;
|
||||
}
|
||||
|
||||
.pb-6 {
|
||||
padding-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.text-left {
|
||||
text-align: left;
|
||||
}
|
||||
|
@ -2282,6 +2278,11 @@ html {
|
|||
color: rgb(55 65 81 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.hover\:text-indigo-500:hover {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(99 102 241 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.hover\:text-gray-900:hover {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(17 24 39 / var(--tw-text-opacity));
|
||||
|
@ -2296,11 +2297,6 @@ html {
|
|||
color: inherit;
|
||||
}
|
||||
|
||||
.hover\:text-indigo-500:hover {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(99 102 241 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.focus\:border-transparent:focus {
|
||||
border-color: transparent;
|
||||
}
|
||||
|
@ -2633,14 +2629,6 @@ html {
|
|||
grid-column: span 2 / span 2;
|
||||
}
|
||||
|
||||
.md\:col-span-3 {
|
||||
grid-column: span 3 / span 3;
|
||||
}
|
||||
|
||||
.md\:col-span-6 {
|
||||
grid-column: span 6 / span 6;
|
||||
}
|
||||
|
||||
.md\:mx-0 {
|
||||
margin-left: 0px;
|
||||
margin-right: 0px;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package sorting
|
||||
|
||||
import (
|
||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
)
|
||||
|
||||
type BeneficiariesByName []mobilityaccountsstorage.Account
|
||||
|
||||
func (e BeneficiariesByName) Len() int { return len(e) }
|
||||
func (e BeneficiariesByName) Less(i, j int) bool {
|
||||
return e[i].Data["first_name"].(string) < e[j].Data["first_name"].(string)
|
||||
}
|
||||
func (e BeneficiariesByName) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
|
|
@ -0,0 +1,11 @@
|
|||
package sorting
|
||||
|
||||
import (
|
||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||
)
|
||||
|
||||
type EventsByStartdate []agendastorage.Event
|
||||
|
||||
func (e EventsByStartdate) Len() int { return len(e) }
|
||||
func (e EventsByStartdate) Less(i, j int) bool { return e[i].Startdate.Before(e[j].Startdate) }
|
||||
func (e EventsByStartdate) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
|
|
@ -0,0 +1,15 @@
|
|||
package sorting
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
)
|
||||
|
||||
type GroupsByName []groupstorage.Group
|
||||
|
||||
func (a GroupsByName) Len() int { return len(a) }
|
||||
func (a GroupsByName) Less(i, j int) bool {
|
||||
return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0
|
||||
}
|
||||
func (a GroupsByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
Loading…
Reference in New Issue