Allow to specify ordering when retrieving meta data

The query now searches in more fields. For example, when getting a
list of tags, the query is applied to the tag name *and* category.
When listing persons, the query now also looks in the associated
organization name.

This has been used to make some headers in the meta data tables
clickable to sort the list accordingly.

Refs: #965, #538
This commit is contained in:
eikek
2021-08-24 21:35:57 +02:00
parent 5926565267
commit cf88f5c2de
52 changed files with 1236 additions and 208 deletions

View File

@ -16,9 +16,11 @@ module Comp.PersonTable exposing
import Api.Model.Person exposing (Person)
import Comp.Basic as B
import Data.Flags exposing (Flags)
import Data.PersonOrder exposing (PersonOrder)
import Data.PersonUse
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Messages.Comp.PersonTable exposing (Texts)
import Styles as S
import Util.Contact
@ -41,27 +43,75 @@ type Msg
= SetPersons (List Person)
| Select Person
| Deselect
| ToggleOrder PersonOrder
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
update : Flags -> Msg -> Model -> ( Model, Cmd Msg, Maybe PersonOrder )
update _ msg model =
case msg of
SetPersons list ->
( { model | equips = list, selected = Nothing }, Cmd.none )
( { model | equips = list, selected = Nothing }, Cmd.none, Nothing )
Select equip ->
( { model | selected = Just equip }, Cmd.none )
( { model | selected = Just equip }, Cmd.none, Nothing )
Deselect ->
( { model | selected = Nothing }, Cmd.none )
( { model | selected = Nothing }, Cmd.none, Nothing )
ToggleOrder order ->
( model, Cmd.none, Just order )
type Header
= Name
| Org
newOrder : Header -> PersonOrder -> PersonOrder
newOrder header current =
case ( header, current ) of
( Name, Data.PersonOrder.NameAsc ) ->
Data.PersonOrder.NameDesc
( Name, _ ) ->
Data.PersonOrder.NameAsc
( Org, Data.PersonOrder.OrgAsc ) ->
Data.PersonOrder.OrgDesc
( Org, _ ) ->
Data.PersonOrder.OrgAsc
--- View2
view2 : Texts -> Model -> Html Msg
view2 texts model =
view2 : Texts -> PersonOrder -> Model -> Html Msg
view2 texts order model =
let
nameSortIcon =
case order of
Data.PersonOrder.NameAsc ->
"fa fa-sort-alpha-up"
Data.PersonOrder.NameDesc ->
"fa fa-sort-alpha-down-alt"
_ ->
"invisible fa fa-sort-alpha-down-alt"
orgSortIcon =
case order of
Data.PersonOrder.OrgAsc ->
"fa fa-sort-alpha-up"
Data.PersonOrder.OrgDesc ->
"fa fa-sort-alpha-down-alt"
_ ->
"invisible fa fa-sort-alpha-down-alt"
in
table [ class S.tableMain ]
[ thead []
[ tr []
@ -69,8 +119,18 @@ view2 texts model =
, th [ class "text-left pr-1 md:px-2" ]
[ text texts.use
]
, th [ class "text-left" ] [ text texts.basics.name ]
, th [ class "text-left hidden sm:table-cell" ] [ text texts.basics.organization ]
, th [ class "text-left" ]
[ a [ href "#", onClick (ToggleOrder <| newOrder Name order) ]
[ i [ class nameSortIcon, class "mr-1" ] []
, text texts.basics.name
]
]
, th [ class "text-left hidden sm:table-cell" ]
[ a [ href "#", onClick (ToggleOrder <| newOrder Org order) ]
[ i [ class orgSortIcon, class "mr-1" ] []
, text texts.basics.organization
]
]
, th [ class "text-left hidden md:table-cell" ] [ text texts.contact ]
]
]