feat(csv): add export-exam-label as csv option
This commit is contained in:
parent
da39b05627
commit
de917a8d86
@ -3,6 +3,8 @@ CsvOptionsTip: Diese Einstellungen betreffen primär den CSV-Export; beim Import
|
|||||||
CsvFormatOptions: Dateiformat
|
CsvFormatOptions: Dateiformat
|
||||||
CsvTimestamp: Zeitstempel
|
CsvTimestamp: Zeitstempel
|
||||||
CsvTimestampTip: Soll an den Namen jeder exportierten CSV-Datei ein Zeitstempel vorne angehängt werden?
|
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)
|
CsvPresetRFC: Standard-Konform (RFC 4180)
|
||||||
CsvPresetExcel: Excel-Kompatibel
|
CsvPresetExcel: Excel-Kompatibel
|
||||||
CsvCustom: Benutzerdefiniert
|
CsvCustom: Benutzerdefiniert
|
||||||
|
|||||||
@ -3,6 +3,8 @@ CsvOptionsTip: These settings primarily affect CSV export. During import most se
|
|||||||
CsvFormatOptions: File format
|
CsvFormatOptions: File format
|
||||||
CsvTimestamp: Timestamp
|
CsvTimestamp: Timestamp
|
||||||
CsvTimestampTip: Should the name of every exported csv file contain a 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)
|
CsvPresetRFC: Standards-compliant (RFC 4180)
|
||||||
CsvPresetExcel: Excel compatible
|
CsvPresetExcel: Excel compatible
|
||||||
CsvCustom: User defined
|
CsvCustom: User defined
|
||||||
|
|||||||
@ -1061,8 +1061,14 @@ getCsvOptionsR = postCsvOptionsR
|
|||||||
postCsvOptionsR = do
|
postCsvOptionsR = do
|
||||||
Entity uid User{userCsvOptions} <- requireAuth
|
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 $
|
((optionsRes, optionsWgt'), optionsEnctype) <- runFormPost . renderAForm FormStandard $
|
||||||
csvOptionsForm (Just userCsvOptions)
|
csvOptionsForm (Just userCsvOptions) (Set.fromList $ E.unValue <$> examOfficeLabels)
|
||||||
|
|
||||||
formResultModal optionsRes CsvOptionsR $ \opts -> do
|
formResultModal optionsRes CsvOptionsR $ \opts -> do
|
||||||
lift . runDB $ update uid [ UserCsvOptions =. opts ]
|
lift . runDB $ update uid [ UserCsvOptions =. opts ]
|
||||||
|
|||||||
@ -2125,10 +2125,18 @@ csvOptionsForm :: forall m.
|
|||||||
, HandlerSite m ~ UniWorX
|
, HandlerSite m ~ UniWorX
|
||||||
)
|
)
|
||||||
=> Maybe CsvOptions
|
=> Maybe CsvOptions
|
||||||
|
-> Set ExamOfficeLabelName
|
||||||
-> AForm m CsvOptions
|
-> AForm m CsvOptions
|
||||||
csvOptionsForm mPrev = hoistAForm liftHandler $ CsvOptions
|
csvOptionsForm mPrev (Set.toList -> exportLabels) = hoistAForm liftHandler $ CsvOptions
|
||||||
<$> csvFormatOptionsForm (fslI MsgCsvFormatOptions & setTooltip MsgCsvOptionsTip) (csvFormat <$> mPrev)
|
<$> csvFormatOptionsForm (fslI MsgCsvFormatOptions & setTooltip MsgCsvOptionsTip) (csvFormat <$> mPrev)
|
||||||
<*> apopt checkBoxField (fslI MsgCsvTimestamp & setTooltip MsgCsvTimestampTip) (csvTimestamp <$> 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.
|
courseSelectForm :: forall ident handler.
|
||||||
|
|||||||
@ -51,8 +51,9 @@ nullaryPathPiece ''Quoting $ \q -> if
|
|||||||
|
|
||||||
data CsvOptions
|
data CsvOptions
|
||||||
= CsvOptions
|
= CsvOptions
|
||||||
{ csvFormat :: CsvFormatOptions
|
{ csvFormat :: CsvFormatOptions
|
||||||
, csvTimestamp :: Bool
|
, csvTimestamp :: Bool
|
||||||
|
, csvExportLabel :: Maybe Text
|
||||||
}
|
}
|
||||||
deriving (Eq, Ord, Read, Show, Generic, Typeable)
|
deriving (Eq, Ord, Read, Show, Generic, Typeable)
|
||||||
deriving anyclass (Hashable, NFData)
|
deriving anyclass (Hashable, NFData)
|
||||||
@ -73,8 +74,9 @@ makeLenses_ ''CsvFormatOptions
|
|||||||
|
|
||||||
instance Default CsvOptions where
|
instance Default CsvOptions where
|
||||||
def = CsvOptions
|
def = CsvOptions
|
||||||
{ csvFormat = def
|
{ csvFormat = def
|
||||||
, csvTimestamp = False
|
, csvTimestamp = False
|
||||||
|
, csvExportLabel = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
instance Default CsvFormatOptions where
|
instance Default CsvFormatOptions where
|
||||||
@ -128,14 +130,16 @@ _CsvEncodeOptions = prism' fromEncode toEncode
|
|||||||
|
|
||||||
instance ToJSON CsvOptions where
|
instance ToJSON CsvOptions where
|
||||||
toJSON CsvOptions{..} = JSON.object
|
toJSON CsvOptions{..} = JSON.object
|
||||||
[ "format" JSON..= csvFormat
|
[ "format" JSON..= csvFormat
|
||||||
, "timestamp" JSON..= csvTimestamp
|
, "timestamp" JSON..= csvTimestamp
|
||||||
|
, "export-label" JSON..= csvExportLabel
|
||||||
]
|
]
|
||||||
|
|
||||||
instance FromJSON CsvOptions where
|
instance FromJSON CsvOptions where
|
||||||
parseJSON = JSON.withObject "CsvOptions" $ \o -> do
|
parseJSON = JSON.withObject "CsvOptions" $ \o -> do
|
||||||
csvFormat <- o JSON..:? "format" JSON..!= csvFormat def
|
csvFormat <- o JSON..:? "format" JSON..!= csvFormat def
|
||||||
csvTimestamp <- o JSON..:? "timestamp" JSON..!= csvTimestamp def
|
csvTimestamp <- o JSON..:? "timestamp" JSON..!= csvTimestamp def
|
||||||
|
csvExportLabel <- o JSON..:? "export-label" JSON..!= csvExportLabel def
|
||||||
return CsvOptions{..}
|
return CsvOptions{..}
|
||||||
|
|
||||||
data CsvFormat = FormatCsv | FormatXlsx
|
data CsvFormat = FormatCsv | FormatXlsx
|
||||||
|
|||||||
Reference in New Issue
Block a user