diff --git a/config/models b/config/models index e4ffe6d..8f6db68 100644 --- a/config/models +++ b/config/models @@ -166,7 +166,7 @@ Workflow ident WflIdent name Text Maybe desc Text Maybe - -- scope WorkflowScope -- sharer / public / featured + scope WorkflowScope UniqueWorkflow sharer ident diff --git a/src/Vervis/Form/Project.hs b/src/Vervis/Form/Project.hs index 06f1e11..a89161b 100644 --- a/src/Vervis/Form/Project.hs +++ b/src/Vervis/Form/Project.hs @@ -26,12 +26,13 @@ import Vervis.Import hiding (on, isNothing) import Database.Esqueleto hiding ((==.)) -import qualified Database.Esqueleto as E ((==.)) +import qualified Database.Esqueleto as E import Vervis.Field.Project import Vervis.Model import Vervis.Model.Ident import Vervis.Model.Repo +import Vervis.Model.Workflow data NewProject = NewProject { npIdent :: PrjIdent @@ -53,10 +54,23 @@ newProjectAForm sid = NewProject selectField $ optionsPersistKey [ProjectRoleSharer ==. sid] [] $ rl2text . projectRoleIdent - selectWorkflow = - selectField $ - optionsPersistKey [WorkflowSharer ==. sid] [] $ - \ w -> fromMaybe (wfl2text $ workflowIdent w) $ workflowName w + selectWorkflow = selectField $ do + l <- runDB $ select $ from $ \ (w `InnerJoin` s) -> do + on $ w ^. WorkflowSharer E.==. s ^. SharerId + where_ $ + w ^. WorkflowSharer E.==. val sid E.||. + w ^. WorkflowScope E.!=. val WSSharer + return + ( s ^. SharerIdent + , w ^. WorkflowId + , w ^. WorkflowIdent + , w ^. WorkflowName + ) + let mkpair (Value sident, Value wid, Value wident, Value wname) = + ( shr2text sident <> " / " <> fromMaybe (wfl2text wident) wname + , wid + ) + optionsPairs $ map mkpair l newProjectForm :: SharerId -> Form NewProject newProjectForm sid = renderDivs $ newProjectAForm sid diff --git a/src/Vervis/Form/Workflow.hs b/src/Vervis/Form/Workflow.hs index cdb216b..8e6627d 100644 --- a/src/Vervis/Form/Workflow.hs +++ b/src/Vervis/Form/Workflow.hs @@ -37,9 +37,10 @@ import Vervis.Model.Ident import Vervis.Model.Workflow data NewWorkflow = NewWorkflow - { nwIdent :: WflIdent - , nwName :: Maybe Text - , nwDesc :: Maybe Text + { nwIdent :: WflIdent + , nwName :: Maybe Text + , nwDesc :: Maybe Text + , nwPublic :: Bool } newWorkflowAForm :: SharerId -> AForm Handler NewWorkflow @@ -47,6 +48,7 @@ newWorkflowAForm sid = NewWorkflow <$> areq (newWorkflowIdentField sid) "Identifier*" Nothing <*> aopt textField "Name" Nothing <*> aopt textField "Description" Nothing + <*> areq checkBoxField "Public*" Nothing newWorkflowForm :: SharerId -> Form NewWorkflow newWorkflowForm sid = renderDivs $ newWorkflowAForm sid diff --git a/src/Vervis/Handler/Workflow.hs b/src/Vervis/Handler/Workflow.hs index b80d440..ea9bec9 100644 --- a/src/Vervis/Handler/Workflow.hs +++ b/src/Vervis/Handler/Workflow.hs @@ -88,6 +88,8 @@ postWorkflowsR shr = do , workflowIdent = nwIdent nw , workflowName = nwName nw , workflowDesc = nwDesc nw + , workflowScope = + if nwPublic nw then WSPublic else WSSharer } runDB $ insert_ workflow setMessage "Workflow added." diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 574a024..2d42b6b 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -65,7 +65,9 @@ runMigrations sb migrations = do changes :: MonadIO m => [SchemaT SqlBackend m ()] changes = - [ + [ addField "Workflow" + (Field "scope" (FTPrim SqlString) NotNull) + (Just "'WSSharer'") ] migrateDB :: MonadIO m => ReaderT SqlBackend m () diff --git a/src/Vervis/Model/Workflow.hs b/src/Vervis/Model/Workflow.hs index c0717cf..e85c3e7 100644 --- a/src/Vervis/Model/Workflow.hs +++ b/src/Vervis/Model/Workflow.hs @@ -14,7 +14,8 @@ -} module Vervis.Model.Workflow - ( WorkflowFieldType (..) + ( WorkflowScope (..) + , WorkflowFieldType (..) ) where @@ -22,6 +23,11 @@ import Prelude import Database.Persist.TH +data WorkflowScope = WSSharer | WSPublic | WSFeatured + deriving (Eq, Show, Read, Bounded, Enum) + +derivePersistField "WorkflowScope" + data WorkflowFieldType = WFTText | WFTEnum deriving (Eq, Show, Read, Bounded, Enum) diff --git a/templates/workflow/one.hamlet b/templates/workflow/one.hamlet index 737f4b6..c01acdb 100644 --- a/templates/workflow/one.hamlet +++ b/templates/workflow/one.hamlet @@ -18,6 +18,8 @@ $# .