From f1445e797be2e054c18a1cd52c59a496c648029c Mon Sep 17 00:00:00 2001 From: eikek Date: Mon, 16 Aug 2021 22:13:53 +0200 Subject: [PATCH] Highlight search menu tabs that contain data Refs: #966 --- .../elm/Comp/ItemDetail/FieldTabState.elm | 17 ++- .../src/main/elm/Comp/ScanMailboxForm.elm | 13 +- .../webapp/src/main/elm/Comp/SearchMenu.elm | 138 ++++++++++++------ modules/webapp/src/main/elm/Comp/Tabs.elm | 30 +++- .../src/main/elm/Comp/UiSettingsForm.elm | 8 +- 5 files changed, 145 insertions(+), 61 deletions(-) diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/FieldTabState.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/FieldTabState.elm index ca11e29e..25d52efd 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/FieldTabState.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/FieldTabState.elm @@ -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 ) diff --git a/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm b/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm index e6c69809..d9a5c3bf 100644 --- a/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm +++ b/modules/webapp/src/main/elm/Comp/ScanMailboxForm.elm @@ -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 diff --git a/modules/webapp/src/main/elm/Comp/SearchMenu.elm b/modules/webapp/src/main/elm/Comp/SearchMenu.elm index a4a00daf..d74b532f 100644 --- a/modules/webapp/src/main/elm/Comp/SearchMenu.elm +++ b/modules/webapp/src/main/elm/Comp/SearchMenu.elm @@ -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 ) diff --git a/modules/webapp/src/main/elm/Comp/Tabs.elm b/modules/webapp/src/main/elm/Comp/Tabs.elm index 18f54d0c..3bb9652f 100644 --- a/modules/webapp/src/main/elm/Comp/Tabs.elm +++ b/modules/webapp/src/main/elm/Comp/Tabs.elm @@ -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 diff --git a/modules/webapp/src/main/elm/Comp/UiSettingsForm.elm b/modules/webapp/src/main/elm/Comp/UiSettingsForm.elm index 29202295..c9e6fe4d 100644 --- a/modules/webapp/src/main/elm/Comp/UiSettingsForm.elm +++ b/modules/webapp/src/main/elm/Comp/UiSettingsForm.elm @@ -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