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 Utils.Form
|
||||||
|
|
||||||
import Web.PathPieces (readFromPathPiece)
|
|
||||||
|
|
||||||
|
|
||||||
data ScheduleOptions = ScheduleOptions
|
data ScheduleOptions = ScheduleOptions
|
||||||
{ scheduleView :: ScheduleView
|
{ scheduleView :: ScheduleView
|
||||||
@ -38,19 +36,14 @@ instance Button UniWorX ScheduleView where
|
|||||||
|
|
||||||
|
|
||||||
data ScheduleOffset = ScheduleOffsetNone
|
data ScheduleOffset = ScheduleOffsetNone
|
||||||
| ScheduleOffsetDays Int
|
| ScheduleOffsetDays
|
||||||
-- | ScheduleOffsetMonths Int
|
{ sodDays :: Int
|
||||||
|
, sodCurr :: Maybe Int
|
||||||
|
}
|
||||||
deriving (Eq, Ord, Show, Read, Generic, Typeable)
|
deriving (Eq, Ord, Show, Read, Generic, Typeable)
|
||||||
|
|
||||||
instance PathPiece ScheduleOffset where
|
deriveJSON defaultOptions
|
||||||
toPathPiece ScheduleOffsetNone = "none"
|
{ constructorTagModifier = camelToPathPiece' 2
|
||||||
toPathPiece (ScheduleOffsetDays d) = tshow d <> "d"
|
, fieldLabelModifier = camelToPathPiece' 1
|
||||||
--toPathPiece (ScheduleOffsetMonths m) = tshow m <> "m"
|
, omitNothingFields = True
|
||||||
fromPathPiece "none" = Just ScheduleOffsetNone
|
} ''ScheduleOffset
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user