chore(avs): add person status query demo interface
This commit is contained in:
parent
5b56017683
commit
a0cfe7807b
@ -3,4 +3,5 @@ AvsFirstName: Vorname
|
|||||||
AvsLastName: Nachname
|
AvsLastName: Nachname
|
||||||
AvsInternalPersonalNo: Personalnummer (nur Fraport AG)
|
AvsInternalPersonalNo: Personalnummer (nur Fraport AG)
|
||||||
AvsVersionNo: Versionsnummer
|
AvsVersionNo: Versionsnummer
|
||||||
AvsQueryEmpty: Bitte mindestens ein Anfragefeld ausfüllen!
|
AvsQueryEmpty: Bitte mindestens ein Anfragefeld ausfüllen!
|
||||||
|
AvsStatusQueryInvalid t@Text: Nur numerische IDs eingeben, durch Komma! #{show t}
|
||||||
@ -3,4 +3,5 @@ AvsFirstName: First name
|
|||||||
AvsLastName: Last name
|
AvsLastName: Last name
|
||||||
AvsInternalPersonalNo: Personnel number (Fraport AG only)
|
AvsInternalPersonalNo: Personnel number (Fraport AG only)
|
||||||
AvsVersionNo: Version number
|
AvsVersionNo: Version number
|
||||||
AvsQueryEmpty: At least one query field must be filled!
|
AvsQueryEmpty: At least one query field must be filled!
|
||||||
|
AvsStatusQueryInvalid t: Numeric IDs only, comma seperated! #{show t}
|
||||||
@ -6,6 +6,8 @@ module Handler.Admin.Avs
|
|||||||
import Import
|
import Import
|
||||||
import qualified Control.Monad.State.Class as State
|
import qualified Control.Monad.State.Class as State
|
||||||
-- import Data.Aeson (encode)
|
-- import Data.Aeson (encode)
|
||||||
|
import qualified Data.Text as Text
|
||||||
|
import qualified Data.Set as Set
|
||||||
|
|
||||||
import Handler.Utils
|
import Handler.Utils
|
||||||
import Handler.Utils.Servant.Avs
|
import Handler.Utils.Servant.Avs
|
||||||
@ -31,46 +33,53 @@ validateAvsPersonQuery = do
|
|||||||
is _Just avsPersonQueryInternalPersonalNo ||
|
is _Just avsPersonQueryInternalPersonalNo ||
|
||||||
is _Just avsPersonQueryVersionNo
|
is _Just avsPersonQueryVersionNo
|
||||||
|
|
||||||
{-
|
makeAvsStatusForm :: Maybe AvsStatusQuery -> Form AvsStatusQuery
|
||||||
|
makeAvsStatusForm tmpl = identifyForm FIDAvsStatusQuery . validateForm validateAvsStatusQuery $ \html ->
|
||||||
makeAvsForm :: Maybe AvsStatusQuery -> Form AvsStatusQuery
|
flip (renderAForm FormStandard) html $
|
||||||
makeAvsForm tmpl = identifyForm FIDAvsStatusQuery . validateForm validateAvsStatusQuery $ \html ->
|
parseAvsIds <$> areq textField (fslI MsgAvsCardNo) (unparseAvsIds <$> tmpl)
|
||||||
flip (renderAForm FormStandard) html $ AvsStatusQuery
|
where
|
||||||
<$> aopt textField (fslI MsgAvsCardNo) (avsPersonQueryCardNo <$> tmpl)
|
parseAvsIds :: Text -> AvsStatusQuery
|
||||||
<*> aopt textField (fslI MsgAvsFirstName) (avsPersonQueryFirstName <$> tmpl)
|
parseAvsIds txt = AvsStatusQuery $ Set.fromList ids
|
||||||
<*> aopt textField (fslI MsgAvsLastName) (avsPersonQueryLastName <$> tmpl)
|
where
|
||||||
<*> aopt textField (fslI MsgAvsInternalPersonalNo) (avsPersonQueryInternalPersonalNo <$> tmpl)
|
nonemptys = filter (not . Text.null) $ Text.strip <$> Text.split (==',') txt
|
||||||
<*> aopt textField (fslI MsgAvsVersionNo) (avsPersonQueryVersionNo <$> tmpl)
|
ids = catMaybes $ readMay <$> nonemptys
|
||||||
|
unparseAvsIds :: AvsStatusQuery -> Text
|
||||||
validateAvsPersonQuery :: FormValidator AvsPersonQuery Handler ()
|
unparseAvsIds (AvsStatusQuery ids) = Text.intercalate ", " $ tshow <$> Set.toAscList ids
|
||||||
validateAvsPersonQuery = do
|
|
||||||
AvsPersonQuery{..} <- State.get
|
|
||||||
guardValidation MsgAvsQueryEmpty $
|
|
||||||
is _Just avsPersonQueryCardNo ||
|
|
||||||
is _Just avsPersonQueryFirstName ||
|
|
||||||
is _Just avsPersonQueryLastName ||
|
|
||||||
is _Just avsPersonQueryInternalPersonalNo ||
|
|
||||||
is _Just avsPersonQueryVersionNo
|
|
||||||
-}
|
|
||||||
|
|
||||||
|
validateAvsStatusQuery :: FormValidator AvsStatusQuery Handler ()
|
||||||
|
validateAvsStatusQuery = do
|
||||||
|
AvsStatusQuery ids <- State.get
|
||||||
|
guardValidation (MsgAvsStatusQueryInvalid $ tshow ids) $ not (null ids)
|
||||||
|
|
||||||
getAdminAvsR, postAdminAvsR :: Handler Html
|
getAdminAvsR, postAdminAvsR :: Handler Html
|
||||||
getAdminAvsR = postAdminAvsR
|
getAdminAvsR = postAdminAvsR
|
||||||
postAdminAvsR = do
|
postAdminAvsR = do
|
||||||
((result,widget), enctype) <- runFormPost $ makeAvsPersonForm Nothing
|
((presult, pwidget), penctype) <- runFormPost $ makeAvsPersonForm Nothing
|
||||||
let procForm fr = do
|
let procFormPerson fr = do
|
||||||
res <- runAvsPersonSearch fr
|
res <- runAvsPersonSearch fr
|
||||||
case res of
|
case res of
|
||||||
Left err -> return $ Just err
|
Left err -> return $ Just err
|
||||||
Right jsn -> return $ Just $ tshow jsn
|
Right jsn -> return $ Just $ tshow jsn
|
||||||
mbAnswer <- formResultMaybe result procForm
|
mbPerson <- formResultMaybe presult procFormPerson
|
||||||
|
|
||||||
|
((sresult, swidget), senctype) <- runFormPost $ makeAvsStatusForm Nothing
|
||||||
|
let procFormStatus fr = do
|
||||||
|
res <- runAvsStatusSearch fr
|
||||||
|
case res of
|
||||||
|
Left err -> return $ Just err
|
||||||
|
Right jsn -> return $ Just $ tshow jsn
|
||||||
|
mbStatus <- formResultMaybe sresult procFormStatus
|
||||||
|
|
||||||
actionUrl <- fromMaybe AdminAvsR <$> getCurrentRoute
|
actionUrl <- fromMaybe AdminAvsR <$> getCurrentRoute
|
||||||
siteLayoutMsg MsgMenuAvs $ do
|
siteLayoutMsg MsgMenuAvs $ do
|
||||||
setTitleI MsgMenuAvs
|
setTitleI MsgMenuAvs
|
||||||
let formWidget = wrapForm widget def
|
let personForm = wrapForm pwidget def
|
||||||
{ formAction = Just $ SomeRoute actionUrl
|
{ formAction = Just $ SomeRoute actionUrl
|
||||||
, formEncoding = enctype
|
, formEncoding = penctype
|
||||||
|
}
|
||||||
|
statusForm = wrapForm swidget def
|
||||||
|
{ formAction = Just $ SomeRoute actionUrl
|
||||||
|
, formEncoding = senctype
|
||||||
}
|
}
|
||||||
-- TODO: use i18nWidgetFile instead if this is to become permanent
|
-- TODO: use i18nWidgetFile instead if this is to become permanent
|
||||||
$(widgetFile "avs")
|
$(widgetFile "avs")
|
||||||
|
|||||||
@ -38,7 +38,7 @@ deriveJSON defaultOptions
|
|||||||
-}
|
-}
|
||||||
|
|
||||||
-- data StatusQuery = StatusQuery
|
-- data StatusQuery = StatusQuery
|
||||||
newtype AvsStatusQuery = AvsStatusQuery (Set UserMatriculation)
|
newtype AvsStatusQuery = AvsStatusQuery (Set Int)
|
||||||
deriveJSON defaultOptions ''AvsStatusQuery
|
deriveJSON defaultOptions ''AvsStatusQuery
|
||||||
|
|
||||||
type AvsPersonResponse = Value
|
type AvsPersonResponse = Value
|
||||||
@ -102,6 +102,27 @@ runAvsPersonSearch qry = do
|
|||||||
fullQuery = avsPersonSearch avsAuth qry
|
fullQuery = avsPersonSearch avsAuth qry
|
||||||
liftIO $ over _Left tshow <$> runClientM fullQuery avsClient
|
liftIO $ over _Left tshow <$> runClientM fullQuery avsClient
|
||||||
|
|
||||||
|
runAvsStatusSearch :: AvsStatusQuery -> Import.Handler (Either Text AvsStatusResponse)
|
||||||
|
runAvsStatusSearch qry = do
|
||||||
|
manager <- getsYesod $ view _appHttpManager
|
||||||
|
mbAvsConf <- getsYesod $ view _appAvsConf
|
||||||
|
case mbAvsConf of
|
||||||
|
Nothing -> return $ Left "appAvsConfig is empty, i.e. invalid AVS configuration settings."
|
||||||
|
Just avsConf -> do
|
||||||
|
-- TODO: consider using Servant.Client.Core.parseBaseUrl within Settings already at Startup!
|
||||||
|
let avsServer = BaseUrl
|
||||||
|
{ baseUrlScheme = Https
|
||||||
|
, baseUrlHost = avsHost avsConf
|
||||||
|
, baseUrlPort = avsPort avsConf
|
||||||
|
, baseUrlPath = ""
|
||||||
|
}
|
||||||
|
avsAuth = BasicAuthData
|
||||||
|
{ basicAuthUsername = avsUser avsConf
|
||||||
|
, basicAuthPassword = avsPass avsConf
|
||||||
|
}
|
||||||
|
avsClient = mkClientEnv manager avsServer
|
||||||
|
fullQuery = avsPersonStatus avsAuth qry
|
||||||
|
liftIO $ over _Left tshow <$> runClientM fullQuery avsClient
|
||||||
|
|
||||||
-- DEMO to check that it types
|
-- DEMO to check that it types
|
||||||
run :: IO ()
|
run :: IO ()
|
||||||
|
|||||||
@ -1,8 +1,17 @@
|
|||||||
<section>
|
<section>
|
||||||
<p>
|
<p>
|
||||||
Abfrage:
|
Person Search:
|
||||||
^{formWidget}
|
^{personForm}
|
||||||
$maybe answer <- mbAnswer
|
$maybe answer <- mbPerson
|
||||||
<p>
|
<p>
|
||||||
Unverarbeitete Antwort: #
|
Unverarbeitete Antwort: #
|
||||||
#{answer}
|
#{answer}
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<p>
|
||||||
|
Person Status:
|
||||||
|
^{statusForm}
|
||||||
|
$maybe answer <- mbStatus
|
||||||
|
<p>
|
||||||
|
Unverarbeitete Antwort: #
|
||||||
|
#{answer}
|
||||||
Loading…
Reference in New Issue
Block a user