From c550daaa113299c31ea0807eca8cc762a69c698a Mon Sep 17 00:00:00 2001 From: Christopher Bertels Date: Sun, 30 Dec 2018 17:39:52 +0100 Subject: [PATCH] WIP: add search to vault log / history --- src/Translation.elm | 7 +++++++ src/VaultDialog/Model.elm | 24 ++++++++++++++++++++++++ src/VaultDialog/Update.elm | 14 ++++++++++++++ src/VaultDialog/View.elm | 18 ++++++++++++++++-- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Translation.elm b/src/Translation.elm index 550fc57..95bc742 100644 --- a/src/Translation.elm +++ b/src/Translation.elm @@ -196,6 +196,7 @@ type VaultDialogText | HistoryFilter | LogFilter | LogLevels + | SearchFilter | InviteWithSelectedKeys | Folder | Name @@ -853,6 +854,9 @@ translateEnglishVaultDialogText vt = LogLevels -> "Log Levels" + SearchFilter -> + "Search" + InviteWithSelectedKeys -> "Invite with selected keys" @@ -1741,6 +1745,9 @@ translateGermanVaultDialogText vt = LogLevels -> "Log Level" + SearchFilter -> + "Suche" + InviteWithSelectedKeys -> "Nutzer mit ausgewählten Schlüsseln einladen" diff --git a/src/VaultDialog/Model.elm b/src/VaultDialog/Model.elm index 3bc8ed9..114ee40 100644 --- a/src/VaultDialog/Model.elm +++ b/src/VaultDialog/Model.elm @@ -88,6 +88,7 @@ type alias State = , logItems : List Data.Vault.LogItem , historyItems : WebData (List Data.Vault.HistoryItem) , eventFilters : List EventFilter + , showLogSearchBox : Bool , eventSortBy : EventSortBy , eventSortOrder : EventSortOrder , usersToAdd : Dict User.Email (List User.UserKey) @@ -150,6 +151,8 @@ type Msg | ToggleViewLogLevelFilters | ToggleInfoBox TabId | CloseInfoBox TabId + | ToggleLogSearch + | SearchLog String init : State @@ -185,6 +188,7 @@ init = , logItems = [] , historyItems = NotAsked , eventFilters = [ Level Debug, IsLogItem ] + , showLogSearchBox = False , eventSortOrder = Descending , eventSortBy = eventSortByCreatedAt , usersToAdd = Dict.empty @@ -679,3 +683,23 @@ closeAllInfoBoxes state = isInfoBoxOpen : TabId -> State -> Bool isInfoBoxOpen tabId { openInfoBoxes } = Set.member tabId openInfoBoxes + + +toggleLogSearch : State -> State +toggleLogSearch s = + { s | showLogSearchBox = not s.showLogSearchBox } + + +isCurrentlySearching : State -> Bool +isCurrentlySearching { eventFilters } = + List.any isSearchFilter eventFilters + + +isSearchFilter : EventFilter -> Bool +isSearchFilter f = + case f of + Search _ _ -> + True + + _ -> + False diff --git a/src/VaultDialog/Update.elm b/src/VaultDialog/Update.elm index bd0b965..5b091ab 100644 --- a/src/VaultDialog/Update.elm +++ b/src/VaultDialog/Update.elm @@ -557,6 +557,20 @@ update msg vaultId ({ vaultDialogs } as model) = , Cmd.none ) + ToggleLogSearch -> + ( state + |> VaultDialog.Model.toggleLogSearch + |> asStateIn vaultId model + , Cmd.none + ) + + SearchLog searchStr -> + ( state + |> VaultDialog.Model.filterEventsBy (VaultDialog.Model.Search searchStr False) + |> asStateIn vaultId model + , Cmd.none + ) + getVaultFingerprints : VaultId -> Model -> Cmd Model.Msg getVaultFingerprints vaultId model = diff --git a/src/VaultDialog/View.elm b/src/VaultDialog/View.elm index 5e49ed2..c3ff2bd 100644 --- a/src/VaultDialog/View.elm +++ b/src/VaultDialog/View.elm @@ -33,8 +33,8 @@ import Html , th , tr ) -import Html.Attributes exposing (class, classList, src) -import Html.Events exposing (onClick) +import Html.Attributes exposing (class, classList, src, type_) +import Html.Events exposing (onClick, onInput) import Language exposing (HasLanguage, Language) import Model exposing (Model) import Path exposing (Path) @@ -586,9 +586,23 @@ eventFilterButtons vaultId state vt = , onClick = rootMsg ToggleViewLogLevelFilters } + logSearchInput title = + if state.showLogSearchBox then + Html.input + [ type_ "text" + , onInput <| (rootMsg << SearchLog) + , onEnter <| rootMsg ToggleLogSearch + ] + [] + else + -- TODO: conditionally add Filter-Active class ? + button [] + { label = title, onClick = rootMsg ToggleLogSearch } + buttons = [ filterButton (vt HistoryFilter) IsHistoryItem , filterButton (vt LogFilter) IsLogItem + , logSearchInput (vt SearchFilter) , span [ class "LogLevelButtons" ] <| if isFilterEnabled IsLogItem state then []