refactor(letter): extract user processing for letter meta data
This commit is contained in:
parent
94feda10c2
commit
cfc1609eac
@ -82,8 +82,6 @@ validateMetaPinRenewal = do
|
|||||||
guardValidation MsgMppBadLanguage $ isDe mppLang || isEn mppLang
|
guardValidation MsgMppBadLanguage $ isDe mppLang || isEn mppLang
|
||||||
|
|
||||||
|
|
||||||
-- TODO: formatTimeUser SelFormatDate now (Entity <$> printJobRecipient recipient)
|
|
||||||
|
|
||||||
mprToMeta :: MetaPinRenewal -> P.Meta
|
mprToMeta :: MetaPinRenewal -> P.Meta
|
||||||
mprToMeta MetaPinRenewal{..} = P.Meta $ mconcat
|
mprToMeta MetaPinRenewal{..} = P.Meta $ mconcat
|
||||||
-- formatTimeUser SelFormatDate mppDate mppRecipient
|
-- formatTimeUser SelFormatDate mppDate mppRecipient
|
||||||
@ -92,7 +90,7 @@ mprToMeta MetaPinRenewal{..} = P.Meta $ mconcat
|
|||||||
, toMeta "login" mppLogin
|
, toMeta "login" mppLogin
|
||||||
, toMeta "pin" mppPin
|
, toMeta "pin" mppPin
|
||||||
, mbMeta "url" (mppURL <&> tshow)
|
, mbMeta "url" (mppURL <&> tshow)
|
||||||
, toMeta "date" (mppDate & tshow) -- TODO: render according to user preference
|
, toMeta "date" (mppDate & tshow) -- rendering according to user preference requires Handler Monad; deferred to Post-processing of P.Meta
|
||||||
, toMeta "lang" mppLang
|
, toMeta "lang" mppLang
|
||||||
, mbMeta keyOpening mppOpening
|
, mbMeta keyOpening mppOpening
|
||||||
, mbMeta keyClosing mppClosing
|
, mbMeta keyClosing mppClosing
|
||||||
@ -108,6 +106,15 @@ mprToMeta MetaPinRenewal{..} = P.Meta $ mconcat
|
|||||||
html2textlines :: StoredMarkup -> [Text]
|
html2textlines :: StoredMarkup -> [Text]
|
||||||
html2textlines sm = T.lines . LT.toStrict $ markupInput sm
|
html2textlines sm = T.lines . LT.toStrict $ markupInput sm
|
||||||
|
|
||||||
|
mprToMetaUser :: (MonadHandler m, HandlerSite m ~ UniWorX) => Entity User -> MetaPinRenewal -> m P.Meta
|
||||||
|
mprToMetaUser entUser@Entity{entityVal = u} mpr = do
|
||||||
|
let userLang = userLanguages u >>= (listToMaybe . view _Wrapped) -- auch möglich `op Languages` statt `view _Wrapped`
|
||||||
|
meta = mprToMeta mpr{ mppRecipient = userDisplayName u
|
||||||
|
-- , mppAddress = --TODO once we have User addresses within the DB
|
||||||
|
, mppLang = fromMaybe (mppLang mpr) userLang -- check if this is the desired behaviour!
|
||||||
|
}
|
||||||
|
userDate <- formatTimeUser SelFormatDate (mppDate mpr) (Just entUser)
|
||||||
|
return $ P.setMeta "date" userDate meta
|
||||||
|
|
||||||
|
|
||||||
data PJTableAction = PJActAcknowledge
|
data PJTableAction = PJActAcknowledge
|
||||||
@ -287,24 +294,15 @@ getPrintSendR = postPrintSendR
|
|||||||
postPrintSendR = do
|
postPrintSendR = do
|
||||||
((sendResult, sendWidget), sendEnctype) <- runFormPost $ makeRenewalForm $ Just def
|
((sendResult, sendWidget), sendEnctype) <- runFormPost $ makeRenewalForm $ Just def
|
||||||
let procFormSend mpr = do
|
let procFormSend mpr = do
|
||||||
-- addMessage Info . toHtml $ "Brief wird gesendet an " <> mppRecipient
|
|
||||||
let meta = mprToMeta mpr
|
|
||||||
receivers <- runDB $ Ex.select $ do
|
receivers <- runDB $ Ex.select $ do
|
||||||
user <- Ex.from $ Ex.table @User
|
user <- Ex.from $ Ex.table @User
|
||||||
Ex.where_ $ E.val (mppRecipient mpr) `E.isInfixOf` (user E.^. UserIdent)
|
Ex.where_ $ E.val (mppRecipient mpr) `E.isInfixOf` (user E.^. UserIdent)
|
||||||
pure user
|
pure user
|
||||||
letters <- case receivers of
|
letters <- case receivers of
|
||||||
[] -> pure . (Nothing ,) <$> pdfRenewal meta
|
[] -> pure . (Nothing ,) <$> pdfRenewal (mprToMeta mpr)
|
||||||
_ -> forM receivers $ \usr -> do
|
_ -> forM receivers $ \usr -> do
|
||||||
mDate <- formatTimeUser SelFormatDate (mppDate mpr) (Just usr)
|
meta <- mprToMetaUser usr mpr
|
||||||
let u = entityVal usr
|
pdf <- pdfRenewal meta
|
||||||
paras = [(k,v) | (k, Just v) <- [
|
|
||||||
("lang" , userLanguages u >>= (listToMaybe . view _Wrapped)) -- auch möglich `op Languages` statt `view _Wrapped`
|
|
||||||
]] ++
|
|
||||||
[ ("date" , mDate)
|
|
||||||
, ("recipient" , userDisplayName u)
|
|
||||||
]
|
|
||||||
pdf <- pdfRenewal $ applyMetas paras meta
|
|
||||||
return (Just $ entityKey usr, pdf)
|
return (Just $ entityKey usr, pdf)
|
||||||
oks <- forM letters $ \case
|
oks <- forM letters $ \case
|
||||||
(mbRecipient, Right bs) -> do
|
(mbRecipient, Right bs) -> do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user