Add base addressbook to GUI #102
1 changed files with 47 additions and 5 deletions
|
@ -118,12 +118,15 @@ data AppEvent
|
|||
| CheckValidAddress !T.Text
|
||||
| CheckValidDescrip !T.Text
|
||||
| SaveNewABEntry
|
||||
| SaveABDescription !T.Text
|
||||
| UpdateABEntry !T.Text !T.Text
|
||||
| CloseUpdABEntry
|
||||
| ShowMessage !T.Text
|
||||
| ShowABAddress !T.Text !T.Text
|
||||
| CloseShowABAddress
|
||||
| CopyABAdress !T.Text
|
||||
| DeleteABEntry !T.Text
|
||||
| UpdateABDescrip !T.Text !T.Text
|
||||
deriving (Eq, Show)
|
||||
|
||||
data AppModel = AppModel
|
||||
|
@ -887,8 +890,8 @@ buildUI wenv model = widgetTree
|
|||
, spacer
|
||||
, hstack
|
||||
[ filler
|
||||
, button "Save" NotImplemented
|
||||
-- ((model ^. abAddressValid) && (model ^. abDescripValid))
|
||||
, button "Save" (UpdateABDescrip abd aba) `nodeEnabled`
|
||||
(model ^. abDescripValid)
|
||||
, spacer
|
||||
, button "Cancel" CloseUpdABEntry `nodeEnabled` True
|
||||
, filler
|
||||
|
@ -921,7 +924,7 @@ buildUI wenv model = widgetTree
|
|||
, spacer
|
||||
, button "Copy Address" $ CopyABAdress aba
|
||||
, spacer
|
||||
, button "Delete Entry" $ NotImplemented
|
||||
, button "Delete Entry" $ DeleteABEntry aba
|
||||
, filler
|
||||
]
|
||||
]
|
||||
|
@ -1292,6 +1295,14 @@ handleEvent wenv node model evt =
|
|||
, setClipboardData $ ClipboardText a
|
||||
, Event $ ShowMessage "Address copied!!"
|
||||
]
|
||||
DeleteABEntry a ->
|
||||
[ Task $ deleteAdrBook (model ^. configuration) a
|
||||
, Model $ model & abdescrip .~ "" & abaddress .~ "" & showABAddress .~ False
|
||||
, Task $ do
|
||||
dbPool <- runNoLoggingT $ initPool $ c_dbPath $ model ^. configuration
|
||||
abList <- getAdrBook dbPool $ model ^. network
|
||||
return $ LoadAbList abList
|
||||
]
|
||||
ShowMessage a -> [Model $ model & msgAB ?~ a & menuPopup .~ False]
|
||||
NotImplemented ->
|
||||
[ Model $
|
||||
|
@ -1299,6 +1310,22 @@ handleEvent wenv node model evt =
|
|||
]
|
||||
CloseMsgAB -> [Model $ model & msgAB .~ Nothing & inError .~ False]
|
||||
LoadAbList a -> [Model $ model & abaddressList .~ a]
|
||||
UpdateABDescrip d a ->
|
||||
[ Task $
|
||||
updAddrBookDescrip
|
||||
(model ^. configuration)
|
||||
d
|
||||
a
|
||||
, Model $
|
||||
model & abdescrip .~ ""
|
||||
& abaddress .~ ""
|
||||
& updateABAddress .~ False
|
||||
& showABAddress .~ False
|
||||
, Task $ do
|
||||
dbPool <- runNoLoggingT $ initPool $ c_dbPath $ model ^. configuration
|
||||
abList <- getAdrBook dbPool $ model ^. network
|
||||
return $ LoadAbList abList
|
||||
]
|
||||
where
|
||||
currentWallet =
|
||||
if null (model ^. wallets)
|
||||
|
@ -1394,9 +1421,24 @@ handleEvent wenv node model evt =
|
|||
pool <- runNoLoggingT $ initPool $ c_dbPath config
|
||||
res <- liftIO $ saveAdrsInAdrBook pool $ AddressBook n d a
|
||||
case res of
|
||||
Nothing -> return $ ShowMessage "Error saving the AddressBook entry..."
|
||||
Nothing -> return $ ShowMessage "Error saving AddressBook entry..."
|
||||
Just _ -> return $ ShowMessage "New Address Book entry added!!"
|
||||
-- |
|
||||
-- | Address Book -> save new entry into database
|
||||
-- |
|
||||
deleteAdrBook :: Config -> T.Text -> IO AppEvent
|
||||
deleteAdrBook config a = do
|
||||
pool <- runNoLoggingT $ initPool $ c_dbPath config
|
||||
res <- liftIO $ deleteAdrsFromAB pool a
|
||||
return $ ShowMessage "Address Book entry deleted!!"
|
||||
-- |
|
||||
-- | Address Book -> save new entry into database
|
||||
-- |
|
||||
updAddrBookDescrip :: Config -> T.Text -> T.Text -> IO AppEvent
|
||||
updAddrBookDescrip config d a = do
|
||||
pool <- runNoLoggingT $ initPool $ c_dbPath config
|
||||
res <- liftIO $ updateAdrsInAdrBook pool d a a
|
||||
return $ ShowMessage "Address Book entry updated!!"
|
||||
|
||||
scanZebra :: T.Text -> T.Text -> Int -> (AppEvent -> IO ()) -> IO ()
|
||||
scanZebra dbPath zHost zPort sendMsg = do
|
||||
|
|
Loading…
Reference in a new issue