From a00afa2150a05db518376bb37e508f46604f0546 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Sat, 4 Dec 2021 00:39:12 +0100 Subject: [PATCH] chore(profile): add (currently no-op) massinput for label-creation --- .../courses/exam/exam_office/de-de-formal.msg | 1 + .../courses/exam/exam_office/en-eu.msg | 1 + .../utils/table_column/de-de-formal.msg | 5 ++- messages/uniworx/utils/table_column/en-eu.msg | 5 ++- src/Handler/Profile.hs | 42 ++++++++++++++----- .../profile/exam-office-labels/add.hamlet | 6 +++ .../profile/exam-office-labels/cell.hamlet | 8 ++++ .../profile/exam-office-labels/layout.hamlet | 17 ++++++++ 8 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 templates/profile/exam-office-labels/add.hamlet create mode 100644 templates/profile/exam-office-labels/cell.hamlet create mode 100644 templates/profile/exam-office-labels/layout.hamlet diff --git a/messages/uniworx/categories/courses/exam/exam_office/de-de-formal.msg b/messages/uniworx/categories/courses/exam/exam_office/de-de-formal.msg index ffb0fb974..ae3c2c7ab 100644 --- a/messages/uniworx/categories/courses/exam/exam_office/de-de-formal.msg +++ b/messages/uniworx/categories/courses/exam/exam_office/de-de-formal.msg @@ -65,3 +65,4 @@ ExamOfficeLabelsTip: Sie können hier Labels anlegen und verwalten, welche sie e ExamOfficeLabelName !ident-ok: Name ExamOfficeLabelStatus !ident-ok: Status ExamOfficeLabelPriority: Priorität +ExamOfficeLabelAlreadyExists: Es existiert bereits ein Prüfungs-Label mit diesem Namen! diff --git a/messages/uniworx/categories/courses/exam/exam_office/en-eu.msg b/messages/uniworx/categories/courses/exam/exam_office/en-eu.msg index 65fdd1cca..b499f22fe 100644 --- a/messages/uniworx/categories/courses/exam/exam_office/en-eu.msg +++ b/messages/uniworx/categories/courses/exam/exam_office/en-eu.msg @@ -63,3 +63,4 @@ ExamOfficeLabelsTip: Here you can add and manage labels, which you can assign ex ExamOfficeLabelName: Name ExamOfficeLabelStatus: Status ExamOfficeLabelPriority: Priority +ExamOfficeLabelAlreadyExists: There already exists an exam label with this name! diff --git a/messages/uniworx/utils/table_column/de-de-formal.msg b/messages/uniworx/utils/table_column/de-de-formal.msg index e91267835..a402d6591 100644 --- a/messages/uniworx/utils/table_column/de-de-formal.msg +++ b/messages/uniworx/utils/table_column/de-de-formal.msg @@ -61,4 +61,7 @@ SelectColumn: Auswahl CsvExport: CSV-Export TableProportion c@Text of'@Text prop@Rational !ident-ok: #{c}/#{of'} (#{rationalToFixed2 (100 * prop)}%) TableProportionNoRatio c@Text of'@Text !ident-ok: #{c}/#{of'} -TableExamFinished: Ergebnisse sichtbar ab \ No newline at end of file +TableExamFinished: Ergebnisse sichtbar ab +TableExamOfficeLabel: Prüfungs-Label +TableExamOfficeLabelStatus: Label-Farbe +TableExamOfficeLabelPriority: Label-Priorität \ No newline at end of file diff --git a/messages/uniworx/utils/table_column/en-eu.msg b/messages/uniworx/utils/table_column/en-eu.msg index 5913fddca..e377432b2 100644 --- a/messages/uniworx/utils/table_column/en-eu.msg +++ b/messages/uniworx/utils/table_column/en-eu.msg @@ -61,4 +61,7 @@ SelectColumn: Selection CsvExport: CSV export TableProportion c of' prop: #{c}/#{of'} (#{rationalToFixed2 (100 * prop)}%) TableProportionNoRatio c of': #{c}/#{of'} -TableExamFinished: Results visible from \ No newline at end of file +TableExamFinished: Results visible from +TableExamOfficeLabel: Exam label +TableExamOfficeLabelStatus: Label colour +TableExamOfficeLabelPriority: Label priority \ No newline at end of file diff --git a/src/Handler/Profile.hs b/src/Handler/Profile.hs index 98e081d96..957ed3e99 100644 --- a/src/Handler/Profile.hs +++ b/src/Handler/Profile.hs @@ -329,29 +329,49 @@ allocationNotificationForm = maybe (pure mempty) allocationNotificationForm' . ( examOfficeForm :: Maybe ExamOfficeSettings -> AForm Handler ExamOfficeSettings examOfficeForm template = wFormToAForm $ do (_uid, User{userExamOfficeGetSynced,userExamOfficeGetLabels}) <- requireAuthPair + currentRoute <- fromMaybe (error "examOfficeForm called from 404-handler") <$> liftHandler getCurrentRoute + mr <- getMessageRender let userExamOfficeLabels = fromMaybe mempty $ eosettingsLabels <$> template - eoLabelForm :: AForm Handler EOLabels - eoLabelForm = wFormToAForm $ do + eoLabelsForm :: AForm Handler EOLabels + eoLabelsForm = wFormToAForm $ do let miAdd :: ListPosition -> Natural -> ListLength -> (Text -> Text) -> FieldView UniWorX -> Maybe (Form (Map ListPosition (Either ExamOfficeLabelName ExamOfficeLabelId) -> FormResult (Map ListPosition (Either ExamOfficeLabelName ExamOfficeLabelId)))) - miAdd = error "WIP" + miAdd _ _ _ nudge submitView = Just $ \csrf -> do + (addRes, addView) <- mpreq textField (fslI MsgExamOfficeLabelName & addName (nudge "name")) Nothing + let + addRes' = addRes <&> \nLabel oldData@(maybe 0 (succ . fst) . Map.lookupMax -> kStart) -> if + | Set.member (Left nLabel) . Set.fromList $ Map.elems oldData + -> FormFailure [mr MsgExamOfficeLabelAlreadyExists] + | otherwise + -> FormSuccess . Map.fromList $ [(kStart, Left nLabel)] + return (addRes', $(widgetFile "profile/exam-office-labels/add")) miCell :: ListPosition -> Either ExamOfficeLabelName ExamOfficeLabelId -> Maybe EOLabelData -> (Text -> Text) -> Form EOLabelData - miCell = error "WIP" + miCell _ eoLabel initRes nudge csrf = do + labelIdent <- case eoLabel of + Left lblName -> return lblName + Right lblId -> do + ExamOfficeLabel{examOfficeLabelName} <- liftHandler . runDB $ getJust lblId + return examOfficeLabelName + (statusRes, statusView) <- mreq (selectField optionsFinite) (fslI MsgExamOfficeLabelStatus & addName (nudge "status")) ((\(_,x,_) -> x) <$> initRes) + (priorityRes, priorityView) <- mreq intField (fslI MsgExamOfficeLabelPriority & addName (nudge "priority")) (((\(_,_,x) -> x) <$> initRes) <|> Just 0) + let + res :: FormResult EOLabelData + res = (,,) <$> (FormSuccess labelIdent) <*> statusRes <*> priorityRes + return (res, $(widgetFile "profile/exam-office-labels/cell")) miDelete :: Map ListPosition (Either ExamOfficeLabelName ExamOfficeLabelId) -> ListPosition -> MaybeT (MForm Handler) (Map ListPosition ListPosition) - miDelete = error "WIP" + miDelete = miDeleteList miAddEmpty :: ListPosition -> Natural -> ListLength -> Set ListPosition - miAddEmpty = error "WIP" + miAddEmpty _ _ _ = Set.empty - miButtonAction :: forall p. p -> Maybe (SomeRoute UniWorX) - -- miButtonAction :: forall p. PathPiece p => p -> Maybe (SomeRoute UniWorX) - miButtonAction = error "WIP" + miButtonAction :: forall p. PathPiece p => p -> Maybe (SomeRoute UniWorX) + miButtonAction frag = Just . SomeRoute $ currentRoute :#: frag miLayout :: ListLength -> Map ListPosition (Either ExamOfficeLabelName ExamOfficeLabelId, FormResult EOLabelData) -> Map ListPosition Widget -> Map ListPosition (FieldView UniWorX) -> Map (Natural, ListPosition) Widget -> Widget - miLayout = error "WIP" + miLayout lLength _ cellWdgts delButtons addWdgets = $(widgetFile "profile/exam-office-labels/layout") miIdent :: Text miIdent = "exam-office-labels" @@ -370,7 +390,7 @@ examOfficeForm template = wFormToAForm $ do <$ aformSection MsgFormExamOffice <*> apopt checkBoxField (fslI MsgExamOfficeGetSynced & setTooltip MsgExamOfficeGetSyncedTip) (eosettingsGetSynced <$> template) <*> apopt checkBoxField (fslI MsgExamOfficeGetLabels & setTooltip MsgExamOfficeGetLabelsTip) (eosettingsGetLabels <$> template) - <*> eoLabelForm + <*> eoLabelsForm else return . pure . fromMaybe (ExamOfficeSettings userExamOfficeGetSynced userExamOfficeGetLabels userExamOfficeLabels) $ template diff --git a/templates/profile/exam-office-labels/add.hamlet b/templates/profile/exam-office-labels/add.hamlet new file mode 100644 index 000000000..03342b9a2 --- /dev/null +++ b/templates/profile/exam-office-labels/add.hamlet @@ -0,0 +1,6 @@ +$newline never + + #{csrf} + ^{fvWidget addView} + + ^{fvWidget submitView} diff --git a/templates/profile/exam-office-labels/cell.hamlet b/templates/profile/exam-office-labels/cell.hamlet new file mode 100644 index 000000000..ab926a48c --- /dev/null +++ b/templates/profile/exam-office-labels/cell.hamlet @@ -0,0 +1,8 @@ +$newline never + + ^{labelIdent} + + #{csrf} + ^{fvWidget statusView} + + ^{fvWidget priorityView} diff --git a/templates/profile/exam-office-labels/layout.hamlet b/templates/profile/exam-office-labels/layout.hamlet new file mode 100644 index 000000000..95f9a9c00 --- /dev/null +++ b/templates/profile/exam-office-labels/layout.hamlet @@ -0,0 +1,17 @@ +$newline never + + + + + $forall coord <- review liveCoords lLength + + ^{cellWdgts ! coord} + + + ^{addWdgets ! (0, 0)}
_{MsgTableExamOfficeLabel} + _{MsgTableExamOfficeLabelStatus} + _{MsgTableExamOfficeLabelPriority} + +
+ ^{fvWidget (delButtons ! coord)} +