on master help sign in
wip
commit812de5e84ad6c52b0e0da138bcd956acf91b72d4 authoriko <ilyakooo0@gmail.com> dateFri 29 Jul 2022, 20:20 (4 years ago) parent7264c5a
6 files changed+193−22
backend/Bridge.purs+16−1 backend/Main.purs+13−2 bridge.yaml+5−1 frontend/Bridge.elm+27−3 frontend/Main.elm+63−5 frontend/Pages/Navigation.elm+69−10
backend/Bridge.purs+16−1
@@ -115,9 +115,24 @@ derive instance genericSub_LoadCipher :: Generic Sub_LoadCipher _
115115derive instance eqSub_LoadCipher :: Eq Sub_LoadCipher
116116derive instance ordSub_LoadCipher :: Ord Sub_LoadCipher
117117
118+data Sub_LoadCiphers_cipherType =
119+ CardType
120+ | IdentityType
121+ | LoginType
122+ | NoteType
123+
124+instance encodeJsonSub_LoadCiphers_cipherType :: EncodeJson Sub_LoadCiphers_cipherType where
125+ encodeJson = genericEncodeAeson Argonaut.defaultOptions
126+instance decodeJsonSub_LoadCiphers_cipherType :: DecodeJson Sub_LoadCiphers_cipherType where
127+ decodeJson = genericDecodeAeson Argonaut.defaultOptions
128+derive instance genericSub_LoadCiphers_cipherType :: Generic Sub_LoadCiphers_cipherType _
129+derive instance eqSub_LoadCiphers_cipherType :: Eq Sub_LoadCiphers_cipherType
130+derive instance ordSub_LoadCiphers_cipherType :: Ord Sub_LoadCiphers_cipherType
131+
118132newtype Sub_LoadCiphers =
119133 Sub_LoadCiphers {
120− date :: String
134+ cipherType :: Sub_LoadCiphers_cipherType
135+ , date :: String
121136 , id :: String
122137 , name :: String
123138 }
backend/Main.purs+13−2
@@ -8,11 +8,12 @@ import BW (ApiService, CryptoService, Hash, Services)
88import BW as WB
99import BW.Logic (decrypt, hashPassword, liftPromise)
1010import BW.Logic as Logic
11−import BW.Types (CipherResponse, Email(..), IdentityTokenResponse, Password(..), PreloginResponse, SyncResponse, Urls, cipherTypeCard, cipherTypeLogin, cipherTypeSecureNote)
11+import BW.Types (CipherResponse, Email(..), IdentityTokenResponse, Password(..), PreloginResponse, SyncResponse, Urls, cipherTypeCard, cipherTypeIdentity, cipherTypeLogin, cipherTypeSecureNote)
1212import Bridge (Sub_LoadCipher(..))
1313import Bridge as Bridge
1414import Control.El (class HasL, Al, L(..), l)
1515import Control.Monad.Error.Class (throwError)
16+import Control.Monad.List.Trans as List
1617import Control.Monad.Reader (runReaderT)
1718import Data.Argonaut (class DecodeJson)
1819import Data.Array as Array
@@ -194,9 +195,19 @@ processCipher ::
194195 CipherResponse -> Al r Bridge.Sub_LoadCiphers
195196processCipher cipher = do
196197 name <- decrypt cipher.name
198+ cipherType <- case cipher.type of
199+ n | n == cipherTypeLogin -> pure Bridge.LoginType
200+ n | n == cipherTypeSecureNote -> pure Bridge.NoteType
201+ n | n == cipherTypeCard -> pure Bridge.CardType
202+ n | n == cipherTypeIdentity -> pure Bridge.IdentityType
203+ n -> throwError $ error $ "Unsupported cipher type: " <> show n
197204 pure
198205 $ Bridge.Sub_LoadCiphers
199− { name: name, date: Timestamp.toLocalDateTimeString cipher.revisionDate, id: cipher.id }
206+ { name: name
207+ , date: Timestamp.toLocalDateTimeString cipher.revisionDate
208+ , id: cipher.id
209+ , cipherType
210+ }
200211
201212runElmAff :: FFI.Elm -> Aff Unit -> Effect Unit
202213runElmAff app =
bridge.yaml+5−1
@@ -6,6 +6,11 @@ Sub:
66 name: String
77 date: String
88 id: String
9+ cipherType:
10+ - LoginType
11+ - CardType
12+ - NoteType
13+ - IdentityType
914- LoginSuccessful
1015- NeedsMasterPassword:
1116 server: String
@@ -28,7 +33,6 @@ Sub:
2833 expYear: String
2934 code: String
3035
31−
3236Cmd:
3337- Init
3438- Login:
frontend/Bridge.elm+27−3
@@ -179,15 +179,38 @@ jsonEncSub_LoadCipher val =
179179
180180
181181
182+type Sub_LoadCiphers_cipherType =
183+ CardType
184+ | IdentityType
185+ | LoginType
186+ | NoteType
187+
188+jsonDecSub_LoadCiphers_cipherType : Json.Decode.Decoder ( Sub_LoadCiphers_cipherType )
189+jsonDecSub_LoadCiphers_cipherType =
190+ let jsonDecDictSub_LoadCiphers_cipherType = Dict.fromList [("CardType", CardType), ("IdentityType", IdentityType), ("LoginType", LoginType), ("NoteType", NoteType)]
191+ in decodeSumUnaries "Sub_LoadCiphers_cipherType" jsonDecDictSub_LoadCiphers_cipherType
192+
193+jsonEncSub_LoadCiphers_cipherType : Sub_LoadCiphers_cipherType -> Value
194+jsonEncSub_LoadCiphers_cipherType val =
195+ case val of
196+ CardType -> Json.Encode.string "CardType"
197+ IdentityType -> Json.Encode.string "IdentityType"
198+ LoginType -> Json.Encode.string "LoginType"
199+ NoteType -> Json.Encode.string "NoteType"
200+
201+
202+
182203type alias Sub_LoadCiphers =
183− { date: String
204+ { cipherType: Sub_LoadCiphers_cipherType
205+ , date: String
184206 , id: String
185207 , name: String
186208 }
187209
188210jsonDecSub_LoadCiphers : Json.Decode.Decoder ( Sub_LoadCiphers )
189211jsonDecSub_LoadCiphers =
190− Json.Decode.succeed (\pdate pid pname -> {date = pdate, id = pid, name = pname})
212+ Json.Decode.succeed (\pcipherType pdate pid pname -> {cipherType = pcipherType, date = pdate, id = pid, name = pname})
213+ |> required "cipherType" (jsonDecSub_LoadCiphers_cipherType)
191214 |> required "date" (Json.Decode.string)
192215 |> required "id" (Json.Decode.string)
193216 |> required "name" (Json.Decode.string)
@@ -195,7 +218,8 @@ jsonDecSub_LoadCiphers =
195218jsonEncSub_LoadCiphers : Sub_LoadCiphers -> Value
196219jsonEncSub_LoadCiphers val =
197220 Json.Encode.object
198− [ ("date", Json.Encode.string val.date)
221+ [ ("cipherType", jsonEncSub_LoadCiphers_cipherType val.cipherType)
222+ , ("date", Json.Encode.string val.date)
199223 , ("id", Json.Encode.string val.id)
200224 , ("name", Json.Encode.string val.name)
201225 ]
frontend/Main.elm+63−5
@@ -34,6 +34,8 @@ type Msg
3434 | ShowCipherPage Bridge.Sub_LoadCipher
3535 | RequestCipher CipherId
3636 | PopView
37+ | ToggleMenu
38+ | ChangeFilter CipherFilter
3739
3840
3941type alias CipherId =
@@ -43,6 +45,9 @@ type alias CipherId =
4345type alias Model =
4446 { notifications : List Notification.Config
4547 , pageStack : Navigation.PageStack PageModel
48+ , menuShown : Bool
49+ , email : Maybe String
50+ , filter : CipherFilter
4651 }
4752
4853
@@ -132,27 +137,77 @@ subscriptions _ =
132137 )
133138
134139
140+type CipherFilter
141+ = AnyCipher
142+ | Specific Bridge.Sub_LoadCiphers_cipherType
143+
144+
145+applyCipherFilter : CipherFilter -> Bridge.Sub_LoadCiphers_List -> Bridge.Sub_LoadCiphers_List
146+applyCipherFilter filter list =
147+ case filter of
148+ AnyCipher ->
149+ list
150+
151+ Specific t ->
152+ list |> List.filter (.cipherType >> (==) t)
153+
154+
135155init : ( Model, Cmd Msg )
136156init =
137157 ( { notifications = []
138158 , pageStack = Nonempty.singleton LoadingPage
159+ , menuShown = False
160+ , email = Nothing
161+ , filter = AnyCipher
139162 }
140163 , FFI.sendBridge Bridge.Init
141164 )
142165
143166
167+pageShouldShowMenu : PageModel -> Bool
168+pageShouldShowMenu page =
169+ case page of
170+ CiphersModel _ ->
171+ True
172+
173+ _ ->
174+ False
175+
176+
144177view : Model -> Html Msg
145178view model =
146− Navigation.showNavigationView { popStack = PopView }
179+ Navigation.showNavigationView
180+ { popStack = PopView
181+ , toggleMenu = ToggleMenu
182+ }
147183 model.pageStack
148184 (\page ->
149185 let
150186 ( title, body ) =
151− showPage page
187+ case page of
188+ CiphersModel m ->
189+ CiphersModel { m | ciphers = m.ciphers |> applyCipherFilter model.filter }
190+ |> showPage
191+
192+ _ ->
193+ showPage page
152194 in
153− ( title
154− , maybeList (List.head model.notifications) (Notification.notification CloseNotification) ++ body
155− )
195+ { title = title
196+ , body = maybeList (List.head model.notifications) (Notification.notification CloseNotification) ++ body
197+ , menuConfig =
198+ if pageShouldShowMenu page && model.menuShown then
199+ Just
200+ { title = Maybe.withDefault "" model.email
201+ , items =
202+ [ { icons = "", name = "", trigger = ChangeFilter AnyCipher }
203+ ]
204+ , close = ToggleMenu
205+ }
206+
207+ else
208+ Nothing
209+ , menuPossible = pageShouldShowMenu page
210+ }
156211 )
157212
158213
@@ -302,6 +357,9 @@ update msg model =
302357 , Cmd.none
303358 )
304359
360+ ToggleMenu ->
361+ ( { model | menuShown = not model.menuShown }, Cmd.none )
362+
305363
306364loginCallbacks : Login.Callbacks Msg
307365loginCallbacks =
frontend/Pages/Navigation.elm+69−10
@@ -14,20 +14,50 @@ import List.Nonempty as Nonempty exposing (Nonempty)
1414import Utils exposing (..)
1515
1616
17+type TopButton
18+ = BackButton
19+ | MenuButton
20+
21+
1722type alias Config msg =
18− { back : Bool
23+ { topButton : Maybe TopButton
1924 , title : String
2025 , pop : msg
26+ , toggleMenu : msg
2127 }
2228
2329
2430navigation : Config msg -> Html msg
25−navigation { back, title, pop } =
31+navigation { topButton, title, pop, toggleMenu } =
2632 nav [ Attr.class "p-tabs p-tabs__list" ]
2733 [ h3 [ Attr.class "u-no-margin u-no-padding" ]
2834 [ button
29− (Attr.class "p-button--base is-inline u-no-margin" :: optional (not back) (Attr.style "visibility" "hidden"))
30− [ i [ Attr.class "p-icon--chevron-up ninety-counter", Ev.onClick pop ] []
35+ (Attr.class "p-button--base is-inline u-no-margin" :: optional (Nothing == topButton) (Attr.style "visibility" "hidden"))
36+ [ i
37+ [ Attr.class
38+ (case topButton of
39+ Just BackButton ->
40+ "p-icon--chevron-up ninety-counter"
41+
42+ Just MenuButton ->
43+ "p-icon--menu"
44+
45+ Nothing ->
46+ ""
47+ )
48+ , Ev.onClick
49+ (case topButton of
50+ Nothing ->
51+ pop
52+
53+ Just BackButton ->
54+ pop
55+
56+ Just MenuButton ->
57+ toggleMenu
58+ )
59+ ]
60+ []
3161 ]
3262 , text title
3363 ]
@@ -79,13 +109,42 @@ popView stack =
79109 Nonempty.tail stack |> Nonempty.fromList |> Maybe.withDefault stack
80110
81111
82−showNavigationView : { popStack : msg } -> PageStack model -> (model -> ( String, List (Html msg) )) -> Html msg
83−showNavigationView { popStack } stack render =
112+showNavigationView :
113+ { popStack : msg
114+ , toggleMenu : msg
115+ }
116+ -> PageStack model
117+ ->
118+ (model
119+ ->
120+ { title : String
121+ , body : List (Html msg)
122+ , menuConfig : Maybe (MenuConfig msg)
123+ , menuPossible : Bool
124+ }
125+ )
126+ -> Html msg
127+showNavigationView { popStack, toggleMenu } stack render =
84128 let
85− ( title, body ) =
129+ { title, body, menuConfig, menuPossible } =
86130 render (Nonempty.head stack)
87131 in
88132 div []
89− [ navigation { back = Nonempty.length stack > 1, title = title, pop = popStack }
90− , main_ [] body
91− ]
133+ (maybeList menuConfig menu
134+ ++ [ navigation
135+ { topButton =
136+ if menuPossible then
137+ Just MenuButton
138+
139+ else if Nonempty.length stack > 1 then
140+ Just BackButton
141+
142+ else
143+ Nothing
144+ , title = title
145+ , pop = popStack
146+ , toggleMenu = toggleMenu
147+ }
148+ , main_ [] body
149+ ]
150+ )