1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-27 17:04:52 +09:00

DB: Rename entity WorkflowFieldEnum to WorkflowEnum

This commit is contained in:
fr33domlover 2020-01-05 12:04:17 +00:00
parent b78a0fa116
commit 8fc5e4b3c1
11 changed files with 72 additions and 64 deletions

View file

@ -295,9 +295,9 @@ WorkflowField
workflow WorkflowId workflow WorkflowId
ident FldIdent ident FldIdent
name Text name Text
desc Text Maybe desc Text Maybe
type WorkflowFieldType type WorkflowFieldType
enm WorkflowFieldEnumId Maybe enm WorkflowEnumId Maybe
required Bool required Bool
constant Bool constant Bool
filterNew Bool filterNew Bool
@ -306,20 +306,20 @@ WorkflowField
UniqueWorkflowField workflow ident UniqueWorkflowField workflow ident
WorkflowFieldEnum WorkflowEnum
workflow WorkflowId workflow WorkflowId
ident EnmIdent ident EnmIdent
name Text name Text
desc Text Maybe desc Text Maybe
UniqueWorkflowFieldEnum workflow ident UniqueWorkflowEnum workflow ident
WorkflowFieldEnumCtor WorkflowEnumCtor
enum WorkflowFieldEnumId enum WorkflowEnumId
name Text name Text
desc Text Maybe desc Text Maybe
UniqueWorkflowFieldEnumCtor enum name UniqueWorkflowEnumCtor enum name
TicketParamText TicketParamText
ticket TicketId ticket TicketId
@ -331,7 +331,7 @@ TicketParamText
TicketParamEnum TicketParamEnum
ticket TicketId ticket TicketId
field WorkflowFieldId field WorkflowFieldId
value WorkflowFieldEnumCtorId value WorkflowEnumCtorId
UniqueTicketParamEnum ticket field value UniqueTicketParamEnum ticket field value

View file

@ -90,8 +90,8 @@ checkEnmUniqueCI
checkEnmUniqueCI wid = checkM $ \ enm -> do checkEnmUniqueCI wid = checkM $ \ enm -> do
sames <- runDB $ select $ from $ \ enum -> do sames <- runDB $ select $ from $ \ enum -> do
where_ $ where_ $
enum ^. WorkflowFieldEnumWorkflow ==. val wid &&. enum ^. WorkflowEnumWorkflow ==. val wid &&.
lower_ (enum ^. WorkflowFieldEnumIdent) ==. lower_ (val enm) lower_ (enum ^. WorkflowEnumIdent) ==. lower_ (val enm)
limit 1 limit 1
return () return ()
return $ if null sames return $ if null sames
@ -113,9 +113,9 @@ checkCtorName =
in checkBool nameOk msg in checkBool nameOk msg
checkCtorUnique checkCtorUnique
:: WorkflowFieldEnumId -> Field Handler Text -> Field Handler Text :: WorkflowEnumId -> Field Handler Text -> Field Handler Text
checkCtorUnique eid = checkM $ \ name -> do checkCtorUnique eid = checkM $ \ name -> do
mc <- runDB $ getBy $ UniqueWorkflowFieldEnumCtor eid name mc <- runDB $ getBy $ UniqueWorkflowEnumCtor eid name
return $ case mc of return $ case mc of
Nothing -> Right name Nothing -> Right name
Just _ -> Left ("There is already an enum ctor by that name" :: Text) Just _ -> Left ("There is already an enum ctor by that name" :: Text)
@ -123,5 +123,5 @@ checkCtorUnique eid = checkM $ \ name -> do
ctorNameField :: Field Handler Text ctorNameField :: Field Handler Text
ctorNameField = checkCtorName textField ctorNameField = checkCtorName textField
newCtorNameField :: WorkflowFieldEnumId -> Field Handler Text newCtorNameField :: WorkflowEnumId -> Field Handler Text
newCtorNameField eid = checkCtorUnique eid ctorNameField newCtorNameField eid = checkCtorUnique eid ctorNameField

View file

@ -52,7 +52,7 @@ data NewTicket = NewTicket
{ ntTitle :: Text { ntTitle :: Text
, ntDesc :: Text , ntDesc :: Text
, ntTParams :: [(WorkflowFieldId, Text)] , ntTParams :: [(WorkflowFieldId, Text)]
, ntEParams :: [(WorkflowFieldId, WorkflowFieldEnumCtorId)] , ntEParams :: [(WorkflowFieldId, WorkflowEnumCtorId)]
} }
fieldSettings :: Text -> Bool -> FieldSettings App fieldSettings :: Text -> Bool -> FieldSettings App
@ -72,7 +72,7 @@ tfield (Entity fid f) =
efield efield
:: Entity WorkflowField :: Entity WorkflowField
-> Maybe (AForm Handler (Maybe (WorkflowFieldId, WorkflowFieldEnumCtorId))) -> Maybe (AForm Handler (Maybe (WorkflowFieldId, WorkflowEnumCtorId)))
efield (Entity fid f) = efield (Entity fid f) =
case workflowFieldEnm f of case workflowFieldEnm f of
Nothing -> Nothing Nothing -> Nothing
@ -84,9 +84,9 @@ efield (Entity fid f) =
sel = sel =
selectField $ selectField $
optionsPersistKey optionsPersistKey
[WorkflowFieldEnumCtorEnum ==. eid] [WorkflowEnumCtorEnum ==. eid]
[] []
workflowFieldEnumCtorName workflowEnumCtorName
in fmap (fid, ) <$> in fmap (fid, ) <$>
if workflowFieldRequired f if workflowFieldRequired f
then Just <$> areq sel sets Nothing then Just <$> areq sel sets Nothing
@ -157,16 +157,16 @@ eEditField
-> AForm -> AForm
Handler Handler
( Maybe TicketParamEnumId ( Maybe TicketParamEnumId
, Maybe (WorkflowFieldId, WorkflowFieldEnumCtorId) , Maybe (WorkflowFieldId, WorkflowEnumCtorId)
) )
eEditField (TicketEnumParam (WorkflowFieldSummary fid _ name req _ _) e mv) = eEditField (TicketEnumParam (WorkflowFieldSummary fid _ name req _ _) e mv) =
let sets = fieldSettings name req let sets = fieldSettings name req
sel = sel =
selectField $ selectField $
optionsPersistKey optionsPersistKey
[WorkflowFieldEnumCtorEnum ==. wesId e] [WorkflowEnumCtorEnum ==. wesId e]
[] []
workflowFieldEnumCtorName workflowEnumCtorName
in (tepvId <$> mv, ) . fmap (fid, ) <$> in (tepvId <$> mv, ) . fmap (fid, ) <$>
if req if req
then Just <$> areq sel sets (tepvVal <$> mv) then Just <$> areq sel sets (tepvVal <$> mv)
@ -191,7 +191,7 @@ editTicketContentForm
) )
] ]
, [ ( Maybe TicketParamEnumId , [ ( Maybe TicketParamEnumId
, Maybe (WorkflowFieldId, WorkflowFieldEnumCtorId) , Maybe (WorkflowFieldId, WorkflowEnumCtorId)
) )
] ]
) )

View file

@ -59,7 +59,7 @@ data NewField = NewField
, nfName :: Text , nfName :: Text
, nfDesc :: Maybe Text , nfDesc :: Maybe Text
, nfType :: WorkflowFieldType , nfType :: WorkflowFieldType
, nfEnum :: Maybe WorkflowFieldEnumId , nfEnum :: Maybe WorkflowEnumId
, nfReq :: Bool , nfReq :: Bool
, nfConst :: Bool , nfConst :: Bool
, nfNew :: Bool , nfNew :: Bool
@ -82,9 +82,9 @@ newFieldAForm wid = NewField
where where
selectEnum = selectEnum =
optionsPersistKey optionsPersistKey
[WorkflowFieldEnumWorkflow ==. wid] [WorkflowEnumWorkflow ==. wid]
[Asc WorkflowFieldEnumName] [Asc WorkflowEnumName]
workflowFieldEnumName workflowEnumName
newFieldForm :: WorkflowId -> Form NewField newFieldForm :: WorkflowId -> Form NewField
newFieldForm wid = renderDivs $ newFieldAForm wid newFieldForm wid = renderDivs $ newFieldAForm wid
@ -109,10 +109,10 @@ data NewCtor = NewCtor
, ncDesc :: Maybe Text , ncDesc :: Maybe Text
} }
newCtorAForm :: WorkflowFieldEnumId -> AForm Handler NewCtor newCtorAForm :: WorkflowEnumId -> AForm Handler NewCtor
newCtorAForm eid = NewCtor newCtorAForm eid = NewCtor
<$> areq (newCtorNameField eid) "name*" Nothing <$> areq (newCtorNameField eid) "name*" Nothing
<*> aopt textField "Description" Nothing <*> aopt textField "Description" Nothing
newCtorForm :: WorkflowFieldEnumId -> Form NewCtor newCtorForm :: WorkflowEnumId -> Form NewCtor
newCtorForm eid = renderDivs $ newCtorAForm eid newCtorForm eid = renderDivs $ newCtorAForm eid

View file

@ -221,7 +221,7 @@ getWorkflowEnumsR shr wfl = do
es <- runDB $ do es <- runDB $ do
Entity sid _ <- getBy404 $ UniqueSharer shr Entity sid _ <- getBy404 $ UniqueSharer shr
Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl
selectList [WorkflowFieldEnumWorkflow ==. wid] [] selectList [WorkflowEnumWorkflow ==. wid] []
defaultLayout $(widgetFile "workflow/enum/list") defaultLayout $(widgetFile "workflow/enum/list")
postWorkflowEnumsR :: ShrIdent -> WflIdent -> Handler Html postWorkflowEnumsR :: ShrIdent -> WflIdent -> Handler Html
@ -233,11 +233,11 @@ postWorkflowEnumsR shr wfl = do
((result, widget), enctype) <- runFormPost $ newEnumForm wid ((result, widget), enctype) <- runFormPost $ newEnumForm wid
case result of case result of
FormSuccess ne -> do FormSuccess ne -> do
let enum = WorkflowFieldEnum let enum = WorkflowEnum
{ workflowFieldEnumWorkflow = wid { workflowEnumWorkflow = wid
, workflowFieldEnumIdent = neIdent ne , workflowEnumIdent = neIdent ne
, workflowFieldEnumName = neName ne , workflowEnumName = neName ne
, workflowFieldEnumDesc = neDesc ne , workflowEnumDesc = neDesc ne
} }
runDB $ insert_ enum runDB $ insert_ enum
setMessage "Workflow field enum added." setMessage "Workflow field enum added."
@ -263,7 +263,7 @@ getWorkflowEnumR shr wfl enm = do
e <- runDB $ do e <- runDB $ do
Entity sid _ <- getBy404 $ UniqueSharer shr Entity sid _ <- getBy404 $ UniqueSharer shr
Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl
Entity _ e <- getBy404 $ UniqueWorkflowFieldEnum wid enm Entity _ e <- getBy404 $ UniqueWorkflowEnum wid enm
return e return e
defaultLayout $(widgetFile "workflow/enum/one") defaultLayout $(widgetFile "workflow/enum/one")
@ -287,8 +287,8 @@ getWorkflowEnumCtorsR shr wfl enm = do
cs <- runDB $ do cs <- runDB $ do
Entity sid _ <- getBy404 $ UniqueSharer shr Entity sid _ <- getBy404 $ UniqueSharer shr
Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl
Entity eid _ <- getBy404 $ UniqueWorkflowFieldEnum wid enm Entity eid _ <- getBy404 $ UniqueWorkflowEnum wid enm
selectList [WorkflowFieldEnumCtorEnum ==. eid] [] selectList [WorkflowEnumCtorEnum ==. eid] []
defaultLayout $(widgetFile "workflow/enum/ctor/list") defaultLayout $(widgetFile "workflow/enum/ctor/list")
postWorkflowEnumCtorsR :: ShrIdent -> WflIdent -> EnmIdent -> Handler Html postWorkflowEnumCtorsR :: ShrIdent -> WflIdent -> EnmIdent -> Handler Html
@ -296,15 +296,15 @@ postWorkflowEnumCtorsR shr wfl enm = do
eid <- runDB $ do eid <- runDB $ do
Entity sid _ <- getBy404 $ UniqueSharer shr Entity sid _ <- getBy404 $ UniqueSharer shr
Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl
Entity eid _ <- getBy404 $ UniqueWorkflowFieldEnum wid enm Entity eid _ <- getBy404 $ UniqueWorkflowEnum wid enm
return eid return eid
((result, widget), etype) <- runFormPost $ newCtorForm eid ((result, widget), etype) <- runFormPost $ newCtorForm eid
case result of case result of
FormSuccess nc -> do FormSuccess nc -> do
let ctor = WorkflowFieldEnumCtor let ctor = WorkflowEnumCtor
{ workflowFieldEnumCtorEnum = eid { workflowEnumCtorEnum = eid
, workflowFieldEnumCtorName = ncName nc , workflowEnumCtorName = ncName nc
, workflowFieldEnumCtorDesc = ncDesc nc , workflowEnumCtorDesc = ncDesc nc
} }
runDB $ insert_ ctor runDB $ insert_ ctor
setMessage "Workflow field enum ctor added." setMessage "Workflow field enum ctor added."
@ -321,7 +321,7 @@ getWorkflowEnumCtorNewR shr wfl enm = do
eid <- runDB $ do eid <- runDB $ do
Entity sid _ <- getBy404 $ UniqueSharer shr Entity sid _ <- getBy404 $ UniqueSharer shr
Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl
Entity eid _ <- getBy404 $ UniqueWorkflowFieldEnum wid enm Entity eid _ <- getBy404 $ UniqueWorkflowEnum wid enm
return eid return eid
((_result, widget), etype) <- runFormPost $ newCtorForm eid ((_result, widget), etype) <- runFormPost $ newCtorForm eid
defaultLayout $(widgetFile "workflow/enum/ctor/new") defaultLayout $(widgetFile "workflow/enum/ctor/new")

View file

@ -1,6 +1,6 @@
{- This file is part of Vervis. {- This file is part of Vervis.
- -
- Written in 2016, 2018, 2019 by fr33domlover <fr33domlover@riseup.net>. - Written in 2016, 2018, 2019, 2020 by fr33domlover <fr33domlover@riseup.net>.
- -
- Copying is an act of love. Please copy, reuse and share. - Copying is an act of love. Please copy, reuse and share.
- -
@ -1216,6 +1216,14 @@ changes hLocal ctx =
, removeField "RemoteCollection" "ident" , removeField "RemoteCollection" "ident"
-- 179 -- 179
, renameField "RemoteCollection" "identNew" "ident" , renameField "RemoteCollection" "identNew" "ident"
-- 180
, renameEntity "WorkflowFieldEnum" "WorkflowEnum"
-- 181
, renameEntity "WorkflowFieldEnumCtor" "WorkflowEnumCtor"
-- 182
, renameUnique "WorkflowEnum" "UniqueWorkflowFieldEnum" "UniqueWorkflowEnum"
-- 183
, renameUnique "WorkflowEnumCtor" "UniqueWorkflowFieldEnumCtor" "UniqueWorkflowEnumCtor"
] ]
migrateDB migrateDB

View file

@ -209,13 +209,13 @@ getTicketTextParams tid wid = fmap (map toTParam) $
) )
data WorkflowEnumSummary = WorkflowEnumSummary data WorkflowEnumSummary = WorkflowEnumSummary
{ wesId :: WorkflowFieldEnumId { wesId :: WorkflowEnumId
, wesIdent :: EnmIdent , wesIdent :: EnmIdent
} }
data TicketEnumParamValue = TicketEnumParamValue data TicketEnumParamValue = TicketEnumParamValue
{ tepvId :: TicketParamEnumId { tepvId :: TicketParamEnumId
, tepvVal :: WorkflowFieldEnumCtorId , tepvVal :: WorkflowEnumCtorId
, tepvName :: Text , tepvName :: Text
} }
@ -234,10 +234,10 @@ toEParam
, Value Bool , Value Bool
, Value Bool , Value Bool
, Value Bool , Value Bool
, Value WorkflowFieldEnumId , Value WorkflowEnumId
, Value EnmIdent , Value EnmIdent
, Value (Maybe TicketParamEnumId) , Value (Maybe TicketParamEnumId)
, Value (Maybe WorkflowFieldEnumCtorId) , Value (Maybe WorkflowEnumCtorId)
, Value (Maybe Text) , Value (Maybe Text)
) )
-> TicketEnumParam -> TicketEnumParam
@ -289,16 +289,16 @@ getTicketEnumParams :: TicketId -> WorkflowId -> AppDB [TicketEnumParam]
getTicketEnumParams tid wid = fmap (map toEParam) $ getTicketEnumParams tid wid = fmap (map toEParam) $
select $ from $ \ (p `InnerJoin` c `RightOuterJoin` f `InnerJoin` e) -> do select $ from $ \ (p `InnerJoin` c `RightOuterJoin` f `InnerJoin` e) -> do
on $ on $
e ^. WorkflowFieldEnumWorkflow ==. val wid &&. e ^. WorkflowEnumWorkflow ==. val wid &&.
f ^. WorkflowFieldEnm ==. just (e ^. WorkflowFieldEnumId) f ^. WorkflowFieldEnm ==. just (e ^. WorkflowEnumId)
on $ on $
f ^. WorkflowFieldWorkflow ==. val wid &&. f ^. WorkflowFieldWorkflow ==. val wid &&.
f ^. WorkflowFieldType ==. val WFTEnum &&. f ^. WorkflowFieldType ==. val WFTEnum &&.
p ?. TicketParamEnumField ==. just (f ^. WorkflowFieldId) &&. p ?. TicketParamEnumField ==. just (f ^. WorkflowFieldId) &&.
c ?. WorkflowFieldEnumCtorEnum ==. f ^. WorkflowFieldEnm c ?. WorkflowEnumCtorEnum ==. f ^. WorkflowFieldEnm
on $ on $
p ?. TicketParamEnumTicket ==. just (val tid) &&. p ?. TicketParamEnumTicket ==. just (val tid) &&.
p ?. TicketParamEnumValue ==. c ?. WorkflowFieldEnumCtorId p ?. TicketParamEnumValue ==. c ?. WorkflowEnumCtorId
return return
( f ^. WorkflowFieldId ( f ^. WorkflowFieldId
, f ^. WorkflowFieldIdent , f ^. WorkflowFieldIdent
@ -308,9 +308,9 @@ getTicketEnumParams tid wid = fmap (map toEParam) $
, f ^. WorkflowFieldFilterNew , f ^. WorkflowFieldFilterNew
, f ^. WorkflowFieldFilterTodo , f ^. WorkflowFieldFilterTodo
, f ^. WorkflowFieldFilterClosed , f ^. WorkflowFieldFilterClosed
, e ^. WorkflowFieldEnumId , e ^. WorkflowEnumId
, e ^. WorkflowFieldEnumIdent , e ^. WorkflowEnumIdent
, p ?. TicketParamEnumId , p ?. TicketParamEnumId
, c ?. WorkflowFieldEnumCtorId , c ?. WorkflowEnumCtorId
, c ?. WorkflowFieldEnumCtorName , c ?. WorkflowEnumCtorName
) )

View file

@ -18,12 +18,12 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<ul> <ul>
$forall Entity _cid c <- cs $forall Entity _cid c <- cs
$with name <- workflowFieldEnumCtorName c $with name <- workflowEnumCtorName c
<li> <li>
<div> <div>
#{name} #{name}
<div> <div>
#{fromMaybe "(none)" $ workflowFieldEnumCtorDesc c} #{fromMaybe "(none)" $ workflowEnumCtorDesc c}
<div> <div>
^{buttonW PUT "Edit this ctor" (WorkflowEnumCtorR shr wfl enm name)} ^{buttonW PUT "Edit this ctor" (WorkflowEnumCtorR shr wfl enm name)}
^{buttonW DELETE "Delete this ctor" (WorkflowEnumCtorR shr wfl enm name)} ^{buttonW DELETE "Delete this ctor" (WorkflowEnumCtorR shr wfl enm name)}

View file

@ -19,5 +19,5 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<ul> <ul>
$forall Entity _eid e <- es $forall Entity _eid e <- es
<li> <li>
<a href=@{WorkflowEnumR shr wfl $ workflowFieldEnumIdent e}> <a href=@{WorkflowEnumR shr wfl $ workflowEnumIdent e}>
#{workflowFieldEnumName e} #{workflowEnumName e}

View file

@ -17,9 +17,9 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
<ul> <ul>
<li> <li>
Display name: #{workflowFieldEnumName e} Display name: #{workflowEnumName e}
<li> <li>
Description: #{fromMaybe "(none)" $ workflowFieldEnumDesc e} Description: #{fromMaybe "(none)" $ workflowEnumDesc e}
<li> <li>
<a href=@{WorkflowEnumCtorsR shr wfl enm}> <a href=@{WorkflowEnumCtorsR shr wfl enm}>
Ctors Ctors

View file

@ -26,8 +26,8 @@ $# <http://creativecommons.org/publicdomain/zero/1.0/>.
$of Left typ $of Left typ
#{show typ} #{show typ}
$of Right enum $of Right enum
<a href=@{WorkflowEnumR shr wfl $ workflowFieldEnumIdent enum}> <a href=@{WorkflowEnumR shr wfl $ workflowEnumIdent enum}>
#{workflowFieldEnumName enum} #{workflowEnumName enum}
<li> <li>
Required: #{workflowFieldRequired f} Required: #{workflowFieldRequired f}
<li> <li>