Allow to create and set ticket params of enum type, fixes #111
This commit is contained in:
parent
64cf836b47
commit
b78a0fa116
3 changed files with 43 additions and 27 deletions
|
@ -1,6 +1,6 @@
|
||||||
{- This file is part of Vervis.
|
{- This file is part of Vervis.
|
||||||
-
|
-
|
||||||
- Written in 2016, 2019 by fr33domlover <fr33domlover@riseup.net>.
|
- Written in 2016, 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.
|
||||||
-
|
-
|
||||||
|
@ -26,6 +26,7 @@ module Vervis.Form.Workflow
|
||||||
where
|
where
|
||||||
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
import Database.Persist
|
||||||
import Yesod.Form.Fields
|
import Yesod.Form.Fields
|
||||||
import Yesod.Form.Functions
|
import Yesod.Form.Functions
|
||||||
import Yesod.Form.Types
|
import Yesod.Form.Types
|
||||||
|
@ -58,6 +59,7 @@ data NewField = NewField
|
||||||
, nfName :: Text
|
, nfName :: Text
|
||||||
, nfDesc :: Maybe Text
|
, nfDesc :: Maybe Text
|
||||||
, nfType :: WorkflowFieldType
|
, nfType :: WorkflowFieldType
|
||||||
|
, nfEnum :: Maybe WorkflowFieldEnumId
|
||||||
, nfReq :: Bool
|
, nfReq :: Bool
|
||||||
, nfConst :: Bool
|
, nfConst :: Bool
|
||||||
, nfNew :: Bool
|
, nfNew :: Bool
|
||||||
|
@ -71,11 +73,18 @@ newFieldAForm wid = NewField
|
||||||
<*> areq textField "Name*" Nothing
|
<*> areq textField "Name*" Nothing
|
||||||
<*> aopt textField "Description" Nothing
|
<*> aopt textField "Description" Nothing
|
||||||
<*> areq (selectField optionsEnum) "Type*" Nothing
|
<*> areq (selectField optionsEnum) "Type*" Nothing
|
||||||
|
<*> aopt (selectField selectEnum) "Enum*" (Just Nothing)
|
||||||
<*> areq checkBoxField "Required*" Nothing
|
<*> areq checkBoxField "Required*" Nothing
|
||||||
<*> areq checkBoxField "Constant*" Nothing
|
<*> areq checkBoxField "Constant*" Nothing
|
||||||
<*> areq checkBoxField "Applies to New*" (Just True)
|
<*> areq checkBoxField "Applies to New*" (Just True)
|
||||||
<*> areq checkBoxField "Applies to Todo*" (Just True)
|
<*> areq checkBoxField "Applies to Todo*" (Just True)
|
||||||
<*> areq checkBoxField "Applies to Closed*" (Just True)
|
<*> areq checkBoxField "Applies to Closed*" (Just True)
|
||||||
|
where
|
||||||
|
selectEnum =
|
||||||
|
optionsPersistKey
|
||||||
|
[WorkflowFieldEnumWorkflow ==. wid]
|
||||||
|
[Asc WorkflowFieldEnumName]
|
||||||
|
workflowFieldEnumName
|
||||||
|
|
||||||
newFieldForm :: WorkflowId -> Form NewField
|
newFieldForm :: WorkflowId -> Form NewField
|
||||||
newFieldForm wid = renderDivs $ newFieldAForm wid
|
newFieldForm wid = renderDivs $ newFieldAForm wid
|
||||||
|
|
|
@ -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.
|
||||||
-
|
-
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{- This file is part of Vervis.
|
{- This file is part of Vervis.
|
||||||
-
|
-
|
||||||
- Written in 2016, 2018 by fr33domlover <fr33domlover@riseup.net>.
|
- Written in 2016, 2018, 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.
|
||||||
-
|
-
|
||||||
|
@ -45,7 +45,7 @@ module Vervis.Handler.Workflow
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Database.Persist
|
import Database.Persist
|
||||||
import Network.HTTP.Types (StdMethod (DELETE, PUT))
|
import Network.HTTP.Types (StdMethod (DELETE, PUT))
|
||||||
|
@ -144,30 +144,37 @@ postWorkflowFieldsR shr wfl = do
|
||||||
Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl
|
Entity wid _ <- getBy404 $ UniqueWorkflow sid wfl
|
||||||
return wid
|
return wid
|
||||||
((result, widget), enctype) <- runFormPost $ newFieldForm wid
|
((result, widget), enctype) <- runFormPost $ newFieldForm wid
|
||||||
case result of
|
identOrMsg <-
|
||||||
FormSuccess nf -> do
|
case result of
|
||||||
let field = WorkflowField
|
FormSuccess nf ->
|
||||||
{ workflowFieldWorkflow = wid
|
if (nfType nf == WFTEnum) == isJust (nfEnum nf)
|
||||||
, workflowFieldIdent = nfIdent nf
|
then do
|
||||||
, workflowFieldName = nfName nf
|
let field = WorkflowField
|
||||||
, workflowFieldDesc = nfDesc nf
|
{ workflowFieldWorkflow = wid
|
||||||
, workflowFieldType = nfType nf
|
, workflowFieldIdent = nfIdent nf
|
||||||
, workflowFieldEnm = Nothing
|
, workflowFieldName = nfName nf
|
||||||
, workflowFieldRequired = nfReq nf
|
, workflowFieldDesc = nfDesc nf
|
||||||
, workflowFieldConstant = nfConst nf
|
, workflowFieldType = nfType nf
|
||||||
, workflowFieldFilterNew = nfNew nf
|
, workflowFieldEnm = nfEnum nf
|
||||||
, workflowFieldFilterTodo = nfTodo nf
|
, workflowFieldRequired = nfReq nf
|
||||||
, workflowFieldFilterClosed = nfClosed nf
|
, workflowFieldConstant = nfConst nf
|
||||||
}
|
, workflowFieldFilterNew = nfNew nf
|
||||||
runDB $ insert_ field
|
, workflowFieldFilterTodo = nfTodo nf
|
||||||
|
, workflowFieldFilterClosed = nfClosed nf
|
||||||
|
}
|
||||||
|
runDB $ insert_ field
|
||||||
|
return $ Right $ nfIdent nf
|
||||||
|
else return $ Left "Type/Enum mismatch"
|
||||||
|
FormMissing -> return $ Left "Field(s) missing"
|
||||||
|
FormFailure _l ->
|
||||||
|
return $ Left "Workflow field creation failed, see below"
|
||||||
|
case identOrMsg of
|
||||||
|
Left msg -> do
|
||||||
|
setMessage msg
|
||||||
|
defaultLayout $(widgetFile "workflow/field/new")
|
||||||
|
Right fld -> do
|
||||||
setMessage "Workflow field added."
|
setMessage "Workflow field added."
|
||||||
redirect $ WorkflowFieldR shr wfl (nfIdent nf)
|
redirect $ WorkflowFieldR shr wfl fld
|
||||||
FormMissing -> do
|
|
||||||
setMessage "Field(s) missing"
|
|
||||||
defaultLayout $(widgetFile "workflow/field/new")
|
|
||||||
FormFailure _l -> do
|
|
||||||
setMessage "Workflow field creation failed, see below"
|
|
||||||
defaultLayout $(widgetFile "workflow/field/new")
|
|
||||||
|
|
||||||
getWorkflowFieldNewR :: ShrIdent -> WflIdent -> Handler Html
|
getWorkflowFieldNewR :: ShrIdent -> WflIdent -> Handler Html
|
||||||
getWorkflowFieldNewR shr wfl = do
|
getWorkflowFieldNewR shr wfl = do
|
||||||
|
|
Loading…
Reference in a new issue