SheetType refactoring (Halfway only)
This commit is contained in:
parent
712589192f
commit
1b021259cc
@ -882,7 +882,7 @@ defaultLinks = -- Define the menu items of the header.
|
|||||||
, menuItemAccessCallback' = return True
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
, NavbarRight $ MenuItem
|
, NavbarRight $ MenuItem
|
||||||
{ menuItemLabel = "Einstellungen"
|
{ menuItemLabel = "Anpassen"
|
||||||
, menuItemIcon = Just "cogs"
|
, menuItemIcon = Just "cogs"
|
||||||
, menuItemRoute = ProfileR
|
, menuItemRoute = ProfileR
|
||||||
, menuItemModal = False
|
, menuItemModal = False
|
||||||
@ -917,7 +917,7 @@ defaultLinks = -- Define the menu items of the header.
|
|||||||
, menuItemAccessCallback' = return True
|
, menuItemAccessCallback' = return True
|
||||||
}
|
}
|
||||||
, NavbarAside $ MenuItem
|
, NavbarAside $ MenuItem
|
||||||
{ menuItemLabel = "Korrekturen"
|
{ menuItemLabel = "Korrektur"
|
||||||
, menuItemIcon = Just "check"
|
, menuItemIcon = Just "check"
|
||||||
, menuItemRoute = CorrectionsR
|
, menuItemRoute = CorrectionsR
|
||||||
, menuItemModal = False
|
, menuItemModal = False
|
||||||
|
|||||||
@ -65,7 +65,7 @@ import Control.Lens
|
|||||||
-- import Utils.Lens
|
-- import Utils.Lens
|
||||||
|
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import qualified Data.Aeson as Aeson
|
--import qualified Data.Aeson as Aeson
|
||||||
|
|
||||||
import Control.Monad.Random.Class (MonadRandom(..))
|
import Control.Monad.Random.Class (MonadRandom(..))
|
||||||
import Utils.Sql
|
import Utils.Sql
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import Utils (lastMaybe)
|
|||||||
|
|
||||||
import Model
|
import Model
|
||||||
import Model.Migration.Version
|
import Model.Migration.Version
|
||||||
|
import qualified Model.Migration.Types as Legacy
|
||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
@ -196,6 +197,11 @@ customMigrations = Map.fromListWith (>>)
|
|||||||
UPDATE "user" SET "notification_settings" = (#{def :: NotificationSettings} :: json) WHERE "notification_settings" is null;
|
UPDATE "user" SET "notification_settings" = (#{def :: NotificationSettings} :: json) WHERE "notification_settings" is null;
|
||||||
|]
|
|]
|
||||||
)
|
)
|
||||||
|
, ( AppliedMigrationKey [migrationVersion|5.0.0|] [version|6.0.0|]
|
||||||
|
, whenM (tableExists "sheet") $ do
|
||||||
|
sheets <- [sqlQQ| SELECT "id", "type" FROM "sheet"; |]
|
||||||
|
forM_ sheets $ \(sid, Single lsty) -> update sid [SheetType =. Legacy.sheetType lsty]
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
17
src/Model/Migration/Types.hs
Normal file
17
src/Model/Migration/Types.hs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module Model.Migration.Types where
|
||||||
|
|
||||||
|
import qualified Model as Current
|
||||||
|
|
||||||
|
data SheetType
|
||||||
|
= Bonus { maxPoints :: Current.Points } -- Erhöht nicht das Maximum, wird gutgeschrieben
|
||||||
|
| Normal { maxPoints :: Current.Points } -- Erhöht das Maximum, wird gutgeschrieben
|
||||||
|
| Pass { maxPoints, passingPoints :: Current.Points }
|
||||||
|
| NotGraded
|
||||||
|
deriving (Show, Read, Eq)
|
||||||
|
|
||||||
|
sheetType :: SheetType -> Current.SheetType
|
||||||
|
sheetType = undefined
|
||||||
|
|
||||||
|
|
||||||
|
deriveJSON defaultOptions ''SheetType
|
||||||
|
derivePersistFieldJSON ''SheetType
|
||||||
@ -123,24 +123,34 @@ fromPoints = round
|
|||||||
|
|
||||||
instance DisplayAble Points
|
instance DisplayAble Points
|
||||||
|
|
||||||
data SheetType
|
|
||||||
= Bonus { maxPoints :: Points } -- Erhöht nicht das Maximum, wird gutgeschrieben
|
data SheetGrading
|
||||||
| Normal { maxPoints :: Points } -- Erhöht das Maximum, wird gutgeschrieben
|
= Points { maxPoints :: Points }
|
||||||
-- | Informational { maxPoints :: Points } -- Erhöht nicht das Maximum Keine Gutschrift
|
| PassPoints { maxPoints, passingPoints :: Points }
|
||||||
| Pass { maxPoints, passingPoints :: Points }
|
| PassBinary
|
||||||
|
deriving (Eq, Read, Show)
|
||||||
|
|
||||||
|
deriveJSON defaultOptions
|
||||||
|
{ constructorTagModifier = intercalate "-" . map toLower . splitCamel
|
||||||
|
, fieldLabelModifier = intercalate "-" . map toLower . drop 1 . splitCamel
|
||||||
|
, sumEncoding = TaggedObject "type" "data"
|
||||||
|
} ''SheetGrading
|
||||||
|
derivePersistFieldJSON ''SheetGrading
|
||||||
|
|
||||||
|
data SheetType
|
||||||
|
= Bonus { grading :: SheetGrading }
|
||||||
|
| Normal { grading :: SheetGrading }
|
||||||
|
| Informational { grading :: SheetGrading }
|
||||||
| NotGraded
|
| NotGraded
|
||||||
deriving (Show, Read, Eq)
|
deriving (Eq, Read, Show)
|
||||||
|
|
||||||
instance DisplayAble SheetType where
|
deriveJSON defaultOptions
|
||||||
display (Bonus {..}) = tshow maxPoints <> " Bonuspunkte"
|
{ constructorTagModifier = intercalate "-" . map toLower . splitCamel
|
||||||
display (Normal{..}) = tshow maxPoints <> " Punkte"
|
, fieldLabelModifier = intercalate "-" . map toLower . drop 1 . splitCamel
|
||||||
display (Pass {..}) = "Bestanden ab " <> tshow (pToI passingPoints) <> " von " <> tshow maxPoints
|
, sumEncoding = TaggedObject "type" "data"
|
||||||
display (NotGraded) = "Unbewertet"
|
} ''SheetType
|
||||||
|
|
||||||
deriveJSON defaultOptions ''SheetType
|
|
||||||
derivePersistFieldJSON ''SheetType
|
derivePersistFieldJSON ''SheetType
|
||||||
|
|
||||||
makeLenses_ ''SheetType
|
|
||||||
|
|
||||||
data SheetTypeSummary = SheetTypeSummary
|
data SheetTypeSummary = SheetTypeSummary
|
||||||
{ sumBonusPoints :: Sum Points
|
{ sumBonusPoints :: Sum Points
|
||||||
|
|||||||
@ -29,6 +29,10 @@ makeLenses_ ''SheetCorrector
|
|||||||
|
|
||||||
makeLenses_ ''SubmissionGroup
|
makeLenses_ ''SubmissionGroup
|
||||||
|
|
||||||
|
makeLenses_ ''SheetGrading
|
||||||
|
|
||||||
|
makeLenses_ ''SheetType
|
||||||
|
|
||||||
-- makeClassy_ ''Load
|
-- makeClassy_ ''Load
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user