refactor(schedule-offset): add current offset to offset type
This commit is contained in:
parent
3cf0188d2a
commit
1de2c7f9d3
@ -8,8 +8,6 @@ import Import
|
||||
|
||||
import Utils.Form
|
||||
|
||||
import Web.PathPieces (readFromPathPiece)
|
||||
|
||||
|
||||
data ScheduleOptions = ScheduleOptions
|
||||
{ scheduleView :: ScheduleView
|
||||
@ -38,19 +36,14 @@ instance Button UniWorX ScheduleView where
|
||||
|
||||
|
||||
data ScheduleOffset = ScheduleOffsetNone
|
||||
| ScheduleOffsetDays Int
|
||||
-- | ScheduleOffsetMonths Int
|
||||
| ScheduleOffsetDays
|
||||
{ sodDays :: Int
|
||||
, sodCurr :: Maybe Int
|
||||
}
|
||||
deriving (Eq, Ord, Show, Read, Generic, Typeable)
|
||||
|
||||
instance PathPiece ScheduleOffset where
|
||||
toPathPiece ScheduleOffsetNone = "none"
|
||||
toPathPiece (ScheduleOffsetDays d) = tshow d <> "d"
|
||||
--toPathPiece (ScheduleOffsetMonths m) = tshow m <> "m"
|
||||
fromPathPiece "none" = Just ScheduleOffsetNone
|
||||
fromPathPiece t
|
||||
| Just t' <- fromNullable t
|
||||
, Just n <- readFromPathPiece (init t') = case last t' of
|
||||
'd' -> Just $ ScheduleOffsetDays n
|
||||
--'m' -> Just $ ScheduleOffsetMonths n
|
||||
_ -> Nothing
|
||||
| otherwise = Nothing
|
||||
deriveJSON defaultOptions
|
||||
{ constructorTagModifier = camelToPathPiece' 2
|
||||
, fieldLabelModifier = camelToPathPiece' 1
|
||||
, omitNothingFields = True
|
||||
} ''ScheduleOffset
|
||||
|
||||
Reference in New Issue
Block a user