From efc13f4498fe61e88ca75e4839887def1157ffae Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Fri, 15 Jul 2022 17:45:40 +0200 Subject: [PATCH] chore(letter): implement print center acknowledging list --- .../uniworx/categories/print/de-de-formal.msg | 18 ++--- messages/uniworx/categories/print/en-eu.msg | 18 ++--- .../categories/qualification/de-de-formal.msg | 4 +- .../utils/navigation/menu/de-de-formal.msg | 1 + .../uniworx/utils/navigation/menu/en-eu.msg | 5 +- models/print.model | 3 +- routes | 1 + src/CryptoID.hs | 1 + src/Foundation/Navigation.hs | 5 +- src/Handler/LMS.hs | 2 +- src/Handler/PrintCenter.hs | 66 +++++++++++++------ src/Model.hs | 1 - templates/print-center.hamlet | 2 +- 13 files changed, 82 insertions(+), 45 deletions(-) diff --git a/messages/uniworx/categories/print/de-de-formal.msg b/messages/uniworx/categories/print/de-de-formal.msg index e370bbd55..a74940bdf 100644 --- a/messages/uniworx/categories/print/de-de-formal.msg +++ b/messages/uniworx/categories/print/de-de-formal.msg @@ -1,9 +1,11 @@ PJActAcknowledge: Druck und Versand bestätigen -PrintJobName: Dummy TODO EN -PrintJobId: Dummy TODO EN -PrintJobCreated: Dummy TODO EN -PrintJobAcknowledged: Dummy TODO EN -PrintRecipient: Dummy TODO EN -PrintSender: Dummy TODO EN -PrintCourse: Dummy TODO EN -PrintQualification: Dummy TODO EN \ No newline at end of file +PrintJobName: Bezeichnung +PrintJobId !ident-ok: Id +PrintJobCreated: Gesendet +PrintJobAcknowledged: Bestätigt +PrintJobAcknowledge n@Int64: #{n} #{pluralDE n "Druckauftrag" "Druckaufräge"} als gedruckt und versendet bestätigt +PrintRecipient: Empfänger +PrintSender !ident-ok: Sender +PrintCourse: Kurse +PrintQualification: Qualifikation +PrintPDF !ident-ok: pdf \ No newline at end of file diff --git a/messages/uniworx/categories/print/en-eu.msg b/messages/uniworx/categories/print/en-eu.msg index 519bbf7e4..3be983bf7 100644 --- a/messages/uniworx/categories/print/en-eu.msg +++ b/messages/uniworx/categories/print/en-eu.msg @@ -1,9 +1,11 @@ PJActAcknowledge: Acknowledge printing and mailing -PrintJobName: Dummy TODO DE -PrintJobId: Dummy TODO DE -PrintJobCreated: Dummy TODO DE -PrintJobAcknowledged: Dummy TODO DE -PrintRecipient: Dummy TODO DE -PrintSender: Dummy TODO DE -PrintCourse: Dummy TODO DE -PrintQualification: Dummy TODO DE \ No newline at end of file +PrintJobName: Description +PrintJobId: Id +PrintJobCreated: Created +PrintJobAcknowledged: Acknowledged +PrintJobAcknowledge n@Int64: #{n} #{pluralENs n "print-job"} marked as printed and mailed +PrintRecipient: Recipient +PrintSender: Sender +PrintCourse: Course +PrintQualification: Qualification +PrintPDF: pdf \ No newline at end of file diff --git a/messages/uniworx/categories/qualification/de-de-formal.msg b/messages/uniworx/categories/qualification/de-de-formal.msg index 8a2c57f2b..06364ca2b 100644 --- a/messages/uniworx/categories/qualification/de-de-formal.msg +++ b/messages/uniworx/categories/qualification/de-de-formal.msg @@ -56,8 +56,8 @@ MppOpening: Anrede MppClosing: Grußformel MppDate: Datum MppURL: Link Prüfung -MppLogin: LOGIN -MppPin: PIN +MppLogin !ident-ok: Login +MppPin !ident-ok: Pin MppRecipient: Empfänger MppAddress: Adresse MppLang: Sprache diff --git a/messages/uniworx/utils/navigation/menu/de-de-formal.msg b/messages/uniworx/utils/navigation/menu/de-de-formal.msg index d576f6651..83fa124e1 100644 --- a/messages/uniworx/utils/navigation/menu/de-de-formal.msg +++ b/messages/uniworx/utils/navigation/menu/de-de-formal.msg @@ -135,6 +135,7 @@ MenuLmsDirect: Direkter Upload MenuAvs: Schnittstelle AVS MenuApc: Druckerei MenuPrintSend: Manueller Briefversand +MenuPrintDownload: Brief herunterladen MenuApiDocs: API-Dokumentation (Englisch) MenuSwagger !ident-ok: OpenAPI 2.0 (Swagger) \ No newline at end of file diff --git a/messages/uniworx/utils/navigation/menu/en-eu.msg b/messages/uniworx/utils/navigation/menu/en-eu.msg index 30cc8c04b..1570ce735 100644 --- a/messages/uniworx/utils/navigation/menu/en-eu.msg +++ b/messages/uniworx/utils/navigation/menu/en-eu.msg @@ -45,7 +45,7 @@ MenuMessageList: System messages MenuAdminErrMsg: Decrypt error message MenuAdminTokens: Issue tokens MenuProfileData: Personal information -MenuTermCreate: Create new semester +MenuTermCreate: Create new semester MenuCourseNew: Create new course MenuTermEdit: Edit semester MenuTermCurrent: Current semester @@ -128,7 +128,7 @@ MenuQualifications: Qualifcations MenuLms: E-Learning MenuLmsEdit: Edit E-Learning MenuLmsUsers: Download E-Learning Users -MenuLmsUserlist: Upload E-Learning Users +MenuLmsUserlist: Upload E-Learning Users MenuLmsResult: Upload E-Learning Results MenuLmsUpload: Upload MenuLmsDirect: Direct Upload @@ -136,6 +136,7 @@ MenuLmsDirect: Direct Upload MenuAvs: AVS Interface MenuApc: Printing MenuPrintSend: Send Letter +MenuPrintDownload: Download Letter MenuApiDocs: API documentation MenuSwagger: OpenAPI 2.0 (Swagger) diff --git a/models/print.model b/models/print.model index 82dd0ddfb..6f5ff28c9 100644 --- a/models/print.model +++ b/models/print.model @@ -1,6 +1,7 @@ PrintJob name Text - file FileContentReference + filename FilePath + file ByteString -- stores plain pdf; otherwise use FileContentReference Maybe created UTCTime acknowledged UTCTime Maybe recipient UserId Maybe -- optional as some letters may contain just an address diff --git a/routes b/routes index 888d08982..9c7b89ae8 100644 --- a/routes +++ b/routes @@ -63,6 +63,7 @@ /print PrintCenterR GET POST /print/send PrintSendR GET POST +/print/download/#CryptoUUIDPrintJob PrintDownloadR GET /health HealthR GET !free /instance InstanceR GET !free diff --git a/src/CryptoID.hs b/src/CryptoID.hs index 2e57178c8..b8ef9c70b 100644 --- a/src/CryptoID.hs +++ b/src/CryptoID.hs @@ -56,6 +56,7 @@ decCryptoIDs [ ''SubmissionId , ''ExternalExamId , ''MaterialFileId , ''AllocationMatchingId + , ''PrintJobId ] decCryptoIDKeySize diff --git a/src/Foundation/Navigation.hs b/src/Foundation/Navigation.hs index 2f39d3ffd..f63c1093f 100644 --- a/src/Foundation/Navigation.hs +++ b/src/Foundation/Navigation.hs @@ -106,8 +106,9 @@ breadcrumb AdminTokensR = i18nCrumb MsgMenuAdminTokens $ Just AdminR breadcrumb AdminCrontabR = i18nCrumb MsgBreadcrumbAdminCrontab $ Just AdminR breadcrumb AdminAvsR = i18nCrumb MsgMenuAvs $ Just AdminR -breadcrumb PrintCenterR = i18nCrumb MsgMenuApc Nothing -breadcrumb PrintSendR = i18nCrumb MsgMenuPrintSend $ Just PrintCenterR +breadcrumb PrintCenterR = i18nCrumb MsgMenuApc Nothing +breadcrumb PrintSendR = i18nCrumb MsgMenuPrintSend $ Just PrintCenterR +breadcrumb (PrintDownloadR _) = i18nCrumb MsgMenuPrintDownload $ Just PrintCenterR breadcrumb SchoolListR = i18nCrumb MsgMenuSchoolList $ Just AdminR breadcrumb (SchoolR ssh sRoute) = case sRoute of diff --git a/src/Handler/LMS.hs b/src/Handler/LMS.hs index 86fc9e4df..dab02b9cd 100644 --- a/src/Handler/LMS.hs +++ b/src/Handler/LMS.hs @@ -369,7 +369,7 @@ postLmsR sid qsh = do forM_ okUsers $ \(Entity lid LmsUser {lmsUserUser = uid, lmsUserQualification = qid'}) -> do when (isRenewPinAct action) $ do newPin <- liftIO randomLMSpw - update lid [LmsUserPin =. newPin, LmsUserDatePin =. now] -- must be within its own runDB + update lid [LmsUserPin =. newPin, LmsUserDatePin =. now] when (isNotifyAct action) $ queueDBJob $ JobSendNotification { jRecipient = uid, jNotification = NotificationQualificationRenewal qid' } return $ length okUsers diff --git a/src/Handler/PrintCenter.hs b/src/Handler/PrintCenter.hs index 8a697c7a1..8be6937ef 100644 --- a/src/Handler/PrintCenter.hs +++ b/src/Handler/PrintCenter.hs @@ -3,21 +3,23 @@ module Handler.PrintCenter ( getPrintCenterR, postPrintCenterR , getPrintSendR , postPrintSendR + , getPrintDownloadR -- TODO: for testing only, remove exports , mprToMeta ) where import Import ---import qualified Data.Set as Set +import qualified Data.Set as Set import qualified Data.Map as Map import qualified Data.Text as T import qualified Data.Text.Lazy as LT -import qualified Data.ByteString.Lazy as LBS +-- import qualified Data.ByteString.Lazy as LBS import qualified Text.Pandoc as P import qualified Text.Pandoc.Builder as P +import Database.Persist.Sql (updateWhereCount) import qualified Database.Esqueleto.Legacy as E import qualified Database.Esqueleto.Utils as E import Database.Esqueleto.Utils.TH @@ -181,20 +183,21 @@ mkPJTable = do dbtProj = dbtProjFilteredPostId dbtColonnade = mconcat [ dbSelectIf (applying _2) id (return . view (resultPrintJob . _entityKey)) (\r -> isNothing $ r ^? resultPrintJob . _entityVal . _printJobAcknowledged) - , sortable (Just "pj-name") (i18nCell MsgPrintJobName) $ \( view $ resultPrintJob . _entityVal . _printJobName -> n) -> textCell n - , sortable (Just "pj-id") (i18nCell MsgPrintJobId) $ \( view $ resultPrintJob . _entityKey -> k) -> textCell (tshow k) - , sortable (Just "pj-created") (i18nCell MsgPrintJobCreated) $ \( view $ resultPrintJob . _entityVal . _printJobCreated -> t) -> dateTimeCell t - , sortable (Just "pj-acknowledged") (i18nCell MsgPrintJobAcknowledged) $ \( view $ resultPrintJob . _entityVal . _printJobAcknowledged -> t) -> maybeDateTimeCell t + , sortable (Just "pj-name") (i18nCell MsgPrintJobName) $ \( view $ resultPrintJob . _entityVal . _printJobName -> n) -> textCell n + , sortable (Just "pj-id") (i18nCell MsgPrintJobId) $ \( view $ resultPrintJob . _entityKey -> k) -> textCell (tshow k) + , sortable (Just "pj-created") (i18nCell MsgPrintJobCreated) $ \( view $ resultPrintJob . _entityVal . _printJobCreated -> t) -> dateTimeCell t + , sortable (Just "pj-acknowledged") (i18nCell MsgPrintJobAcknowledged) $ \( view $ resultPrintJob . _entityVal . _printJobAcknowledged -> t) -> maybeDateTimeCell t + , sortable (toNothingS "pdf") (i18nCell MsgPrintPDF) $ \( view $ resultPrintJob . _entityKey -> k) -> anchorCellM (PrintDownloadR <$> encrypt k) (text2widget "pdf") , sortable (Just "pj-recipient") (i18nCell MsgPrintRecipient) $ \(preview resultRecipient -> u) -> maybeCell u $ cellHasUserLink AdminUserR - , sortable (Just "pj-sender") (i18nCell MsgPrintSender) $ \(preview resultSender -> u) -> maybeCell u $ cellHasUserLink AdminUserR - , sortable (Just "pj-course") (i18nCell MsgPrintCourse) $ \(preview $ resultCourse . _entityVal -> c) -> maybeCell c courseCell - , sortable (Just "pj-qualification")(i18nCell MsgPrintQualification) $ \(preview $ resultQualification . _entityVal -> q) -> maybeCell q qualificationCell + , sortable (Just "pj-sender") (i18nCell MsgPrintSender) $ \(preview resultSender -> u) -> maybeCell u $ cellHasUserLink AdminUserR + , sortable (Just "pj-course") (i18nCell MsgPrintCourse) $ \(preview $ resultCourse . _entityVal -> c) -> maybeCell c courseCell + , sortable (Just "pj-qualification")(i18nCell MsgPrintQualification) $ \(preview $ resultQualification . _entityVal -> q) -> maybeCell q qualificationCell ] dbtSorting = mconcat [ single ("pj-name" , SortColumn $ queryPrintJob >>> (E.^. PrintJobName)) , single ("pj-id" , SortColumn $ queryPrintJob >>> (E.^. PrintJobId)) , single ("pj-created" , SortColumn $ queryPrintJob >>> (E.^. PrintJobCreated)) - , single ("pj-acknowledged" , SortColumn $ queryPrintJob >>> (E.^. PrintJobAcknowledged)) + , single ("pj-acknowledged" , SortColumn $ queryPrintJob >>> (E.^. PrintJobAcknowledged)) , single ("pj-recipient" , sortUserNameBareM queryRecipient) , single ("pj-sender" , sortUserNameBareM querySender ) , single ("pj-course" , SortColumn $ queryCourse >>> (E.?. CourseName)) @@ -243,18 +246,23 @@ mkPJTable = do getPrintCenterR, postPrintCenterR :: Handler Html getPrintCenterR = postPrintCenterR postPrintCenterR = do - _currentRoute <- fromMaybe (error "printCenterR called from 404-handler") <$> getCurrentRoute -- This should never be called from a 404 handler - (_pjRes, _pjTable) <- runDB mkPJTable - -- actionUrl <- fromMaybe AdminAvsR <$> getCurrentRoute - -- TODO: continue here - -- formResult pjRes $ \case - -- (PJActAcknowledgeData, pjIds) -> error "continue here" + currentRoute <- fromMaybe (error "printCenterR called from 404-handler") <$> getCurrentRoute -- This should never be called from a 404 handler + (pjRes, pjTable) <- runDB mkPJTable + + formResult pjRes $ \case + (PJActAcknowledgeData, pjIds) -> do + let setPJIds = Set.toList pjIds + now <- liftIO getCurrentTime + num <- runDB $ updateWhereCount [PrintJobAcknowledged ==. Nothing, PrintJobId <-. setPJIds] [PrintJobAcknowledged =. Just now] + addMessageI Success $ MsgPrintJobAcknowledge num + redirect currentRoute + siteLayoutMsg MsgMenuApc $ do setTitleI MsgMenuApc $(widgetFile "print-center") -getPrintSendR, postPrintSendR:: Handler Html +getPrintSendR, postPrintSendR :: Handler Html getPrintSendR = postPrintSendR postPrintSendR = do ((sendResult, sendWidget), sendEnctype) <- runFormPost $ makeRenewalForm Nothing @@ -264,8 +272,11 @@ postPrintSendR = do -- now <- liftIO getCurrentTime case e_pdf of Right bs -> do - liftIO $ LBS.writeFile "/tmp/generated.pdf" bs - addMessage Warning "PDF momentan nur gespeicher unter /tmp/generated.pdf" + -- liftIO $ LBS.writeFile "/tmp/generated.pdf" bs -- DEBUGGING ONLY + -- addMessage Warning "PDF momentan nur gespeicher unter /tmp/generated.pdf" + uID <- maybeAuthId + filepath <- runDB $ sendLetter "Test-Brief" bs Nothing uID Nothing Nothing + addMessage Success $ toHtml $ "Druckauftrag angelegt für " <> filepath Left err -> addMessage Error . toHtml $ P.renderError err -- TODO: continue here with acutal letter sending! return $ Just () @@ -279,3 +290,20 @@ postPrintSendR = do } -- TODO: use i18nWidgetFile instead if this is to become permanent $(widgetFile "print-send") + +getPrintDownloadR :: CryptoUUIDPrintJob -> Handler TypedContent +getPrintDownloadR cupj = do + pjId <- decrypt cupj + PrintJob {..} <- runDB $ get404 pjId + sendByteStringAsFile printJobFilename printJobFile printJobCreated +{- for PrintJobFile :: FileContentReference use this code, however, requires instances + HasFileReference PrintJob and IsFileReference PrintJob which seemed to complicated... :( + serveOneFile $ fileQuery .| C.map entityVal + where + fileQuery = E.selectSource $ E.from $ + \pj -> do + -- filter to requested file + E.where_ (pj E.^. PrintJobId E.==. E.val pjId) + -- return file entity + return pj +-} \ No newline at end of file diff --git a/src/Model.hs b/src/Model.hs index f94678455..6dc11066d 100644 --- a/src/Model.hs +++ b/src/Model.hs @@ -296,4 +296,3 @@ instance IsFileReference MaterialFile where fileReferenceTitleField = MaterialFileTitle fileReferenceContentField = MaterialFileContent fileReferenceModifiedField = MaterialFileModified - diff --git a/templates/print-center.hamlet b/templates/print-center.hamlet index df9d1833e..064bee77c 100644 --- a/templates/print-center.hamlet +++ b/templates/print-center.hamlet @@ -1,3 +1,3 @@

- Hier soll bald eine Tabelle mit allen Druckaufträgen einsehbar sein. \ No newline at end of file + ^{pjTable} \ No newline at end of file