feat(csv): add export-exam-label as csv option

This commit is contained in:
Sarah Vaupel 2022-01-26 19:24:04 +01:00
parent da39b05627
commit de917a8d86
5 changed files with 32 additions and 10 deletions

View File

@ -3,6 +3,8 @@ CsvOptionsTip: Diese Einstellungen betreffen primär den CSV-Export; beim Import
CsvFormatOptions: Dateiformat
CsvTimestamp: Zeitstempel
CsvTimestampTip: Soll an den Namen jeder exportierten CSV-Datei ein Zeitstempel vorne angehängt werden?
CsvExportLabel: Prüfungs-Label bei Export
CsvExportLabelTip: Soll beim CSV-Export von Prüfungsleistungen automatisch ein gegebenes Label für diese Prüfung gesetzt werden?
CsvPresetRFC: Standard-Konform (RFC 4180)
CsvPresetExcel: Excel-Kompatibel
CsvCustom: Benutzerdefiniert

View File

@ -3,6 +3,8 @@ CsvOptionsTip: These settings primarily affect CSV export. During import most se
CsvFormatOptions: File format
CsvTimestamp: Timestamp
CsvTimestampTip: Should the name of every exported csv file contain a timestamp?
CsvExportLabel: Exam label on export
CsvExportLabelTip: Should a given label be automatically set for an exam of which results are exported to CSV?
CsvPresetRFC: Standards-compliant (RFC 4180)
CsvPresetExcel: Excel compatible
CsvCustom: User defined

View File

@ -1061,8 +1061,14 @@ getCsvOptionsR = postCsvOptionsR
postCsvOptionsR = do
Entity uid User{userCsvOptions} <- requireAuth
userIsExamOffice <- hasReadAccessTo $ ExamOfficeR EOExamsR
examOfficeLabels <- if not userIsExamOffice then return mempty else runDB . E.select . E.from $ \examOfficeLabel -> do
E.where_ $ examOfficeLabel E.^. ExamOfficeLabelUser E.==. E.val uid
E.orderBy [ E.asc (examOfficeLabel E.^. ExamOfficeLabelName) ]
return $ examOfficeLabel E.^. ExamOfficeLabelName
((optionsRes, optionsWgt'), optionsEnctype) <- runFormPost . renderAForm FormStandard $
csvOptionsForm (Just userCsvOptions)
csvOptionsForm (Just userCsvOptions) (Set.fromList $ E.unValue <$> examOfficeLabels)
formResultModal optionsRes CsvOptionsR $ \opts -> do
lift . runDB $ update uid [ UserCsvOptions =. opts ]

View File

@ -2125,10 +2125,18 @@ csvOptionsForm :: forall m.
, HandlerSite m ~ UniWorX
)
=> Maybe CsvOptions
-> Set ExamOfficeLabelName
-> AForm m CsvOptions
csvOptionsForm mPrev = hoistAForm liftHandler $ CsvOptions
csvOptionsForm mPrev (Set.toList -> exportLabels) = hoistAForm liftHandler $ CsvOptions
<$> csvFormatOptionsForm (fslI MsgCsvFormatOptions & setTooltip MsgCsvOptionsTip) (csvFormat <$> mPrev)
<*> apopt checkBoxField (fslI MsgCsvTimestamp & setTooltip MsgCsvTimestampTip) (csvTimestamp <$> mPrev)
<*> bool (aopt (selectField $ return exportLabelOptions) (fslI MsgCsvExportLabel & setTooltip MsgCsvExportLabelTip) (csvExportLabel <$> mPrev)) (pure Nothing) (null exportLabels)
where
exportLabelOptions = mkOptionList $ exportLabels <&> \exportLabel -> Option
{ optionDisplay = exportLabel
, optionInternalValue = exportLabel
, optionExternalValue = exportLabel
}
courseSelectForm :: forall ident handler.

View File

@ -51,8 +51,9 @@ nullaryPathPiece ''Quoting $ \q -> if
data CsvOptions
= CsvOptions
{ csvFormat :: CsvFormatOptions
, csvTimestamp :: Bool
{ csvFormat :: CsvFormatOptions
, csvTimestamp :: Bool
, csvExportLabel :: Maybe Text
}
deriving (Eq, Ord, Read, Show, Generic, Typeable)
deriving anyclass (Hashable, NFData)
@ -73,8 +74,9 @@ makeLenses_ ''CsvFormatOptions
instance Default CsvOptions where
def = CsvOptions
{ csvFormat = def
, csvTimestamp = False
{ csvFormat = def
, csvTimestamp = False
, csvExportLabel = Nothing
}
instance Default CsvFormatOptions where
@ -128,14 +130,16 @@ _CsvEncodeOptions = prism' fromEncode toEncode
instance ToJSON CsvOptions where
toJSON CsvOptions{..} = JSON.object
[ "format" JSON..= csvFormat
, "timestamp" JSON..= csvTimestamp
[ "format" JSON..= csvFormat
, "timestamp" JSON..= csvTimestamp
, "export-label" JSON..= csvExportLabel
]
instance FromJSON CsvOptions where
parseJSON = JSON.withObject "CsvOptions" $ \o -> do
csvFormat <- o JSON..:? "format" JSON..!= csvFormat def
csvTimestamp <- o JSON..:? "timestamp" JSON..!= csvTimestamp def
csvFormat <- o JSON..:? "format" JSON..!= csvFormat def
csvTimestamp <- o JSON..:? "timestamp" JSON..!= csvTimestamp def
csvExportLabel <- o JSON..:? "export-label" JSON..!= csvExportLabel def
return CsvOptions{..}
data CsvFormat = FormatCsv | FormatXlsx