Highlight search menu tabs that contain data

Refs: #966
This commit is contained in:
eikek 2021-08-16 22:13:53 +02:00
parent 7f6bb6994d
commit f1445e797b
5 changed files with 145 additions and 61 deletions

View File

@ -154,14 +154,21 @@ tabState settings openTabs cfmodel toggle tab =
_ ->
False
state =
if hidden then
TB.Hidden
else if Set.member tab.name openTabs then
folded =
if Set.member tab.name openTabs then
TB.Open
else
TB.Closed
state =
{ folded = folded
, look =
if hidden then
TB.Hidden
else
TB.Normal
}
in
( state, toggle tab )

View File

@ -762,12 +762,19 @@ view2 texts flags extraClasses settings model =
, icon = Just "fa fa-play"
}
tabActive t =
tabLook t =
if Set.member t.name model.openTabs then
( Comp.Tabs.Open, ToggleAkkordionTab t.name )
{ folded = Comp.Tabs.Open
, look = Comp.Tabs.Normal
}
else
( Comp.Tabs.Closed, ToggleAkkordionTab t.name )
{ folded = Comp.Tabs.Closed
, look = Comp.Tabs.Normal
}
tabActive t =
( tabLook t, ToggleAkkordionTab t.name )
in
div
[ class extraClasses

View File

@ -1088,63 +1088,111 @@ findTab tab =
Nothing
tabLook :UiSettings -> Model -> SearchTab -> Comp.Tabs.Look
tabLook settings model tab =
let
isHidden f =
Data.UiSettings.fieldHidden settings f
hiddenOr fields default =
if List.all isHidden fields then
Comp.Tabs.Hidden
else
default
activeWhen flag =
if flag then
Comp.Tabs.Active
else
Comp.Tabs.Normal
activeWhenNotEmpty list1 list2 =
if List.isEmpty list1 && List.isEmpty list2 then
Comp.Tabs.Normal
else
Comp.Tabs.Active
activeWhenJust mx =
if mx == Nothing then
Comp.Tabs.Normal
else
Comp.Tabs.Active
in
case tab of
TabInbox ->
activeWhen model.inboxCheckbox
TabTags ->
hiddenOr [Data.Fields.Tag]
(activeWhenNotEmpty model.tagSelection.includeTags model.tagSelection.excludeTags)
TabTagCategories ->
hiddenOr [Data.Fields.Tag]
(activeWhenNotEmpty model.tagSelection.includeCats model.tagSelection.excludeCats)
TabFolder ->
hiddenOr [Data.Fields.Folder]
(activeWhenJust model.selectedFolder)
TabCorrespondent ->
hiddenOr [Data.Fields.CorrOrg, Data.Fields.CorrPerson] <|
activeWhenNotEmpty (Comp.Dropdown.getSelected model.orgModel)
(Comp.Dropdown.getSelected model.corrPersonModel)
TabConcerning ->
hiddenOr [Data.Fields.ConcPerson, Data.Fields.ConcEquip ] <|
activeWhenNotEmpty (Comp.Dropdown.getSelected model.concPersonModel)
(Comp.Dropdown.getSelected model.concEquipmentModel)
TabDate ->
hiddenOr [Data.Fields.Date] <|
activeWhenJust (Util.Maybe.or [model.fromDate, model.untilDate])
TabDueDate ->
hiddenOr [Data.Fields.DueDate] <|
activeWhenJust (Util.Maybe.or [model.fromDueDate, model.untilDueDate])
TabSource ->
hiddenOr [Data.Fields.SourceName] <|
activeWhenJust model.sourceModel
TabDirection ->
hiddenOr [Data.Fields.Direction] <|
activeWhenNotEmpty (Comp.Dropdown.getSelected model.directionModel) []
TabTrashed ->
activeWhen (model.searchMode == Data.SearchMode.Trashed)
_ ->
Comp.Tabs.Normal
searchTabState : UiSettings -> Model -> Comp.Tabs.Tab Msg -> ( Comp.Tabs.State, Msg )
searchTabState settings model tab =
let
isHidden f =
Data.UiSettings.fieldHidden settings f
hidden =
case findTab tab of
Just TabTags ->
isHidden Data.Fields.Tag
searchTab =
findTab tab
Just TabTagCategories ->
isHidden Data.Fields.Tag
Just TabFolder ->
isHidden Data.Fields.Folder
Just TabCorrespondent ->
isHidden Data.Fields.CorrOrg && isHidden Data.Fields.CorrPerson
Just TabConcerning ->
isHidden Data.Fields.ConcEquip && isHidden Data.Fields.ConcPerson
Just TabCustomFields ->
isHidden Data.Fields.CustomFields
|| Comp.CustomFieldMultiInput.isEmpty model.customFieldModel
Just TabDate ->
isHidden Data.Fields.Date
Just TabDueDate ->
isHidden Data.Fields.DueDate
Just TabSource ->
isHidden Data.Fields.SourceName
Just TabDirection ->
isHidden Data.Fields.Direction
Just TabInbox ->
False
Just TabTrashed ->
False
Nothing ->
False
state =
if hidden then
Comp.Tabs.Hidden
else if Set.member tab.name model.openTabs then
folded =
if Set.member tab.name model.openTabs then
Comp.Tabs.Open
else
Comp.Tabs.Closed
state =
{ folded = folded
, look = Maybe.map (tabLook settings model) searchTab
|> Maybe.withDefault Comp.Tabs.Normal
}
in
( state, ToggleAkkordionTab tab.name )

View File

@ -6,7 +6,9 @@
module Comp.Tabs exposing
( State(..)
( Folded(..)
, Look(..)
, State
, Style
, Tab
, akkordion
@ -37,10 +39,21 @@ type alias Style =
}
type State
type Folded
= Open
| Closed
| Hidden
type Look
= Hidden
| Active
| Normal
type alias State =
{ look : Look
, folded : Folded
}
defaultStyle : Style
@ -88,11 +101,14 @@ akkordionTab style state toggle tab =
]
(a
[ class "flex flex-row items-center flex-grow"
, classList
[ ( "font-bold text-indigo-600 dark:text-yellow-500", state.look == Active )
]
, href "#"
, onClick toggle
]
[ div [ class "inline-flex mr-2 w-2" ]
[ if state == Open then
[ if state.folded == Open then
i [ class "fa fa-caret-down" ] []
else
@ -112,7 +128,7 @@ akkordionTab style state toggle tab =
tabContent =
div
[ classList [ ( "hidden", state == Closed ) ]
[ classList [ ( "hidden", state.folded == Closed ) ]
, class style.bodyClasses
]
tab.body
@ -120,7 +136,9 @@ akkordionTab style state toggle tab =
div
[ class style.tabClasses
, class "flex flex-col"
, classList [ ( "hidden", state == Hidden ) ]
, classList
[ ( "hidden", state.look == Hidden )
]
]
[ tabTitle
, tabContent

View File

@ -489,10 +489,14 @@ view2 texts flags settings model =
let
state tab =
if Set.member tab.name model.openTabs then
Comp.Tabs.Open
{ folded = Comp.Tabs.Open
, look = Comp.Tabs.Normal
}
else
Comp.Tabs.Closed
{ folded = Comp.Tabs.Closed
, look = Comp.Tabs.Normal
}
in
div [ class "flex flex-col" ]
[ Comp.Tabs.akkordion