mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Allow to hide fields in menus based on ui settings
This commit is contained in:
142
modules/webapp/src/main/elm/Data/Fields.elm
Normal file
142
modules/webapp/src/main/elm/Data/Fields.elm
Normal file
@ -0,0 +1,142 @@
|
||||
module Data.Fields exposing
|
||||
( Field(..)
|
||||
, all
|
||||
, fromList
|
||||
, fromString
|
||||
, label
|
||||
, sort
|
||||
, toString
|
||||
)
|
||||
|
||||
|
||||
type Field
|
||||
= Tag
|
||||
| Folder
|
||||
| CorrOrg
|
||||
| CorrPerson
|
||||
| ConcPerson
|
||||
| ConcEquip
|
||||
| Date
|
||||
| DueDate
|
||||
| Direction
|
||||
|
||||
|
||||
all : List Field
|
||||
all =
|
||||
sort
|
||||
[ Tag
|
||||
, Folder
|
||||
, CorrOrg
|
||||
, CorrPerson
|
||||
, ConcPerson
|
||||
, ConcEquip
|
||||
, Date
|
||||
, DueDate
|
||||
, Direction
|
||||
]
|
||||
|
||||
|
||||
sort : List Field -> List Field
|
||||
sort fields =
|
||||
List.sortBy toString fields
|
||||
|
||||
|
||||
fromString : String -> Maybe Field
|
||||
fromString str =
|
||||
case String.toLower str of
|
||||
"tag" ->
|
||||
Just Tag
|
||||
|
||||
"folder" ->
|
||||
Just Folder
|
||||
|
||||
"corrorg" ->
|
||||
Just CorrOrg
|
||||
|
||||
"corrperson" ->
|
||||
Just CorrPerson
|
||||
|
||||
"concperson" ->
|
||||
Just ConcPerson
|
||||
|
||||
"concequip" ->
|
||||
Just ConcEquip
|
||||
|
||||
"date" ->
|
||||
Just Date
|
||||
|
||||
"duedate" ->
|
||||
Just DueDate
|
||||
|
||||
"direction" ->
|
||||
Just Direction
|
||||
|
||||
_ ->
|
||||
Nothing
|
||||
|
||||
|
||||
toString : Field -> String
|
||||
toString field =
|
||||
case field of
|
||||
Tag ->
|
||||
"tag"
|
||||
|
||||
Folder ->
|
||||
"folder"
|
||||
|
||||
CorrOrg ->
|
||||
"corrorg"
|
||||
|
||||
CorrPerson ->
|
||||
"corrperson"
|
||||
|
||||
ConcPerson ->
|
||||
"concperson"
|
||||
|
||||
ConcEquip ->
|
||||
"concequip"
|
||||
|
||||
Date ->
|
||||
"date"
|
||||
|
||||
DueDate ->
|
||||
"duedate"
|
||||
|
||||
Direction ->
|
||||
"direction"
|
||||
|
||||
|
||||
label : Field -> String
|
||||
label field =
|
||||
case field of
|
||||
Tag ->
|
||||
"Tag"
|
||||
|
||||
Folder ->
|
||||
"Folder"
|
||||
|
||||
CorrOrg ->
|
||||
"Correspondent Organization"
|
||||
|
||||
CorrPerson ->
|
||||
"Correspondent Person"
|
||||
|
||||
ConcPerson ->
|
||||
"Concerning Person"
|
||||
|
||||
ConcEquip ->
|
||||
"Concerned Equipment"
|
||||
|
||||
Date ->
|
||||
"Date"
|
||||
|
||||
DueDate ->
|
||||
"Due Date"
|
||||
|
||||
Direction ->
|
||||
"Direction"
|
||||
|
||||
|
||||
fromList : List String -> List Field
|
||||
fromList strings =
|
||||
List.filterMap fromString strings
|
@ -5,6 +5,8 @@ module Data.UiSettings exposing
|
||||
, catColor
|
||||
, catColorString
|
||||
, defaults
|
||||
, fieldHidden
|
||||
, fieldVisible
|
||||
, merge
|
||||
, mergeDefaults
|
||||
, posFromString
|
||||
@ -16,6 +18,7 @@ module Data.UiSettings exposing
|
||||
|
||||
import Api.Model.Tag exposing (Tag)
|
||||
import Data.Color exposing (Color)
|
||||
import Data.Fields exposing (Field)
|
||||
import Dict exposing (Dict)
|
||||
|
||||
|
||||
@ -36,6 +39,7 @@ type alias StoredUiSettings =
|
||||
, searchMenuFolderCount : Maybe Int
|
||||
, searchMenuTagCount : Maybe Int
|
||||
, searchMenuTagCatCount : Maybe Int
|
||||
, formFields : Maybe (List String)
|
||||
}
|
||||
|
||||
|
||||
@ -55,6 +59,7 @@ type alias UiSettings =
|
||||
, searchMenuFolderCount : Int
|
||||
, searchMenuTagCount : Int
|
||||
, searchMenuTagCatCount : Int
|
||||
, formFields : List Field
|
||||
}
|
||||
|
||||
|
||||
@ -96,6 +101,7 @@ defaults =
|
||||
, searchMenuFolderCount = 3
|
||||
, searchMenuTagCount = 6
|
||||
, searchMenuTagCatCount = 3
|
||||
, formFields = Data.Fields.all
|
||||
}
|
||||
|
||||
|
||||
@ -124,6 +130,10 @@ merge given fallback =
|
||||
choose given.searchMenuTagCount fallback.searchMenuTagCount
|
||||
, searchMenuTagCatCount =
|
||||
choose given.searchMenuTagCatCount fallback.searchMenuTagCatCount
|
||||
, formFields =
|
||||
choose
|
||||
(Maybe.map Data.Fields.fromList given.formFields)
|
||||
fallback.formFields
|
||||
}
|
||||
|
||||
|
||||
@ -144,6 +154,9 @@ toStoredUiSettings settings =
|
||||
, searchMenuFolderCount = Just settings.searchMenuFolderCount
|
||||
, searchMenuTagCount = Just settings.searchMenuTagCount
|
||||
, searchMenuTagCatCount = Just settings.searchMenuTagCatCount
|
||||
, formFields =
|
||||
List.map Data.Fields.toString settings.formFields
|
||||
|> Just
|
||||
}
|
||||
|
||||
|
||||
@ -171,6 +184,16 @@ tagColorString tag settings =
|
||||
|> Maybe.withDefault ""
|
||||
|
||||
|
||||
fieldVisible : UiSettings -> Field -> Bool
|
||||
fieldVisible settings field =
|
||||
List.member field settings.formFields
|
||||
|
||||
|
||||
fieldHidden : UiSettings -> Field -> Bool
|
||||
fieldHidden settings field =
|
||||
fieldVisible settings field |> not
|
||||
|
||||
|
||||
|
||||
--- Helpers
|
||||
|
||||
|
Reference in New Issue
Block a user