@@ -1,10 +1,11 @@
1−module Pages.Ciphers exposing (Callbacks, Model, Msg, page)
1+module Pages.Ciphers exposing (Callbacks, Model, Msg, menuConfig, page)
3import Bridge
3import Bridge
4import Html exposing (..)
4import Html exposing (..)
5import Html.Attributes as Attr
5import Html.Attributes as Attr
6import Html.Events as Ev
6import Html.Events as Ev
7import Page exposing (..)
7import Page exposing (..)
8+import Pages.Navigation as Navigation
8import Search
9import Search
9import Utils exposing (..)
10import Utils exposing (..)
@@ -12,12 +13,66 @@ import Utils exposing (..)
12type alias Model =
13type alias Model =
13 { ciphers : Bridge.Sub_LoadCiphers_List
14 { ciphers : Bridge.Sub_LoadCiphers_List
14 , search : String
15 , search : String
17+ , ciphersListFilter : CiphersFilter
23+ | SpecificCiphers Bridge.Sub_LoadCiphers_cipherType
26+applyCipherFilter : CiphersFilter -> Bridge.Sub_LoadCiphers_List -> Bridge.Sub_LoadCiphers_List
27+applyCipherFilter filter list =
33+ list |> List.filter (.cipherType >> (==) t)
36+menuConfig : Model -> Navigation.MenuConfig Msg
37+menuConfig { ciphersListFilter, menuVisible } =
42+ , trigger = UpdateFilter AllCiphers
43+ , current = ciphersListFilter == AllCiphers
45+ , { icon = "security"
47+ , trigger = UpdateFilter (SpecificCiphers Bridge.LoginType)
48+ , current = ciphersListFilter == SpecificCiphers Bridge.LoginType
52+ , trigger = UpdateFilter (SpecificCiphers Bridge.NoteType)
53+ , current = ciphersListFilter == SpecificCiphers Bridge.NoteType
55+ , { icon = "containers"
57+ , trigger = UpdateFilter (SpecificCiphers Bridge.CardType)
58+ , current = ciphersListFilter == SpecificCiphers Bridge.CardType
61+ , name = "Identities"
62+ , trigger = UpdateFilter (SpecificCiphers Bridge.IdentityType)
63+ , current = ciphersListFilter == SpecificCiphers Bridge.IdentityType
66+ , toggle = ToggleMenu
67+ , visible = menuVisible
20 | UpdateSearch String
73 | UpdateSearch String
75+ | UpdateFilter CiphersFilter
23type alias Callbacks msg =
78type alias Callbacks msg =
@@ -31,13 +86,35 @@ page callbacks liftMsg =
31 , view = view callbacks liftMsg
86 , view = view callbacks liftMsg
32 , update = \msg model -> update callbacks liftMsg msg model
87 , update = \msg model -> update callbacks liftMsg msg model
33 , subscriptions = \model -> subscriptions model |> Sub.map liftMsg
88 , subscriptions = \model -> subscriptions model |> Sub.map liftMsg
90+ \{ ciphersListFilter } ->
91+ case ciphersListFilter of
95+ SpecificCiphers cipherType ->
100+ Bridge.IdentityType ->
34− , title = always "Passwords"
104+ "Passwords"
38init : Bridge.Sub_LoadCiphers_List -> ( Model, Cmd Msg )
111init : Bridge.Sub_LoadCiphers_List -> ( Model, Cmd Msg )
39init ciphers =
112init ciphers =
40− ( { ciphers = ciphers, search = "" }
113+ ( { ciphers = ciphers
115+ , menuVisible = False
116+ , ciphersListFilter = AllCiphers
41 , Cmd.none
118 , Cmd.none
@@ -51,6 +128,12 @@ update {} liftMsg msg model =
51 UpdateSearch s ->
128 UpdateSearch s ->
52 ( Ok { model | search = s }, Cmd.none )
129 ( Ok { model | search = s }, Cmd.none )
132+ ( Ok { model | menuVisible = not model.menuVisible }, Cmd.none )
134+ UpdateFilter filter ->
135+ ( Ok { model | ciphersListFilter = filter, menuVisible = False }, Cmd.none )
55subscriptions : Model -> Sub Msg
138subscriptions : Model -> Sub Msg
56subscriptions model =
139subscriptions model =
@@ -58,7 +141,7 @@ subscriptions model =
60view : Callbacks emsg -> (Msg -> emsg) -> Model -> List (Html emsg)
143view : Callbacks emsg -> (Msg -> emsg) -> Model -> List (Html emsg)
61−view { selected } liftMsg { ciphers, search } =
144+view { selected } liftMsg { ciphers, search, ciphersListFilter } =
63 [ Attr.type_ "search"
146 [ Attr.type_ "search"
64 , Attr.value search
147 , Attr.value search
@@ -69,6 +152,7 @@ view { selected } liftMsg { ciphers, search } =
70 , ul [ Attr.class "p-list--divided" ]
153 , ul [ Attr.class "p-list--divided" ]
155+ |> applyCipherFilter ciphersListFilter
72 |> Search.searchList (cipherSearch search)
156 |> Search.searchList (cipherSearch search)
73 |> List.map
157 |> List.map
74 (\{ name, date, id } ->
158 (\{ name, date, id } ->