Commit 4ebf810e authored by Bas Lijnse's avatar Bas Lijnse

Separated iTasks.API.Core.Tasks into iTasks.WF.Tasks.*

parent 3c04f363
......@@ -3,14 +3,21 @@ definition module iTasks
/**
* Main iTask module exporting all end user iTask modules
*/
import iTasks._Framework.Engine // iTasks engine
import
// iTasks engine
iTasks._Framework.Engine
// iTasks API
, iTasks.SDS.Definition
, iTasks.SDS.Combinators.Core
, iTasks.SDS.Combinators.Common
, iTasks.SDS.Sources.Core
, iTasks.SDS.Sources.Store
, iTasks.SDS.Sources.System
, iTasks.SDS.Combinators.Core
, iTasks.SDS.Combinators.Common
, iTasks.WF.Tasks.Core
, iTasks.WF.Tasks.SDS
, iTasks.WF.Tasks.IO
, iTasks.WF.Tasks.System
, iTasks.API
// Miscellaneous machinery
......
......@@ -5,7 +5,6 @@ import
iTasks.API.Core.Types
// Basic tasks
, iTasks.API.Core.Tasks // Core basic tasks
, iTasks.API.Core.IntegrationTasks // Tasks for integration with other systems
, iTasks.API.Common.InteractionTasks // Tasks for interaction with users
......
......@@ -4,9 +4,10 @@ import StdList, StdOrdList, Data.List
import iTasks._Framework.Generic, iTasks._Framework.Task, iTasks._Framework.SDS
import iTasks._Framework.Util
import iTasks.API.Core.Types
from iTasks.API.Core.Tasks import get, set
import iTasks.API.Common.TaskCombinators
from iTasks.WF.Tasks.SDS import get, set
// Convenient operations on databases
eqItemId :: a a -> Bool | DB a
eqItemId a b = getItemId a == getItemId b
......
definition module iTasks.API.Common.InteractionTasks
import iTasks.API.Core.Tasks
import iTasks.WF.Definition
from iTasks.API.Core.Types import :: Date, :: Time, :: DateTime, :: Action
from Data.Functor import class Functor
from iTasks.UI.Prompt import class toPrompt
from iTasks.UI.Editor.Builtin import :: ChoiceText, :: ChoiceGrid, :: ChoiceNode
from iTasks.SDS.Definition import :: Shared
from iTasks.SDS.Definition import :: Shared, :: SDS, :: RWShared, :: ReadWriteShared
/*** General input/update/output tasks ***/
......
......@@ -7,7 +7,9 @@ from System.Time import :: Timestamp(..)
from Data.Map import qualified get, put
import StdBool, StdList, StdMisc, StdTuple, Data.Functor
import iTasks.API.Core.Tasks, iTasks.API.Core.TaskCombinators
import iTasks.WF.Tasks.Core
import iTasks.WF.Tasks.SDS
import iTasks.API.Core.TaskCombinators
import iTasks.API.Common.TaskCombinators
import iTasks.SDS.Sources.Core, iTasks.SDS.Sources.System
import iTasks.SDS.Combinators.Common
......
......@@ -13,7 +13,9 @@ from iTasks._Framework.TaskState import :: TaskTree(..), :: DeferredJSON
from iTasks._Framework.TaskEval import :: TaskTime
import qualified Data.Map as DM
import iTasks.API.Core.Tasks, iTasks.API.Core.TaskCombinators, iTasks.API.Common.InteractionTasks, iTasks.UI.Layout, iTasks.UI.Prompt
import iTasks.WF.Tasks.Core
import iTasks.WF.Tasks.SDS
import iTasks.API.Core.TaskCombinators, iTasks.API.Common.InteractionTasks, iTasks.UI.Layout, iTasks.UI.Prompt
import iTasks.UI.Layout.Common, iTasks.UI.Layout.Default
(>>*) infixl 1 :: !(Task a) ![TaskCont a (Task b)] -> Task b | iTask a & iTask b
......
......@@ -10,7 +10,7 @@ from Internet.HTTP import :: HTTPMethod, :: HTTPResponse
from Text.URI import :: URI
import iTasks._Framework.Generic
from iTasks._Framework.Task import :: Task
from iTasks.WF.Definition import :: Task, class iTask
from iTasks.API.Core.Types import :: ProcessStatus, :: Document
from iTasks.UI.Prompt import class toPrompt
from iTasks.API.Common.InteractionTasks import :: ViewOption //TODO: We shouldn't import from Common in Core
......
......@@ -8,7 +8,8 @@ import qualified Data.Map as DM
import iTasks._Framework.IWorld, iTasks._Framework.Task, iTasks._Framework.TaskState
import iTasks._Framework.SDS, iTasks._Framework.TaskStore, iTasks._Framework.TaskEval
import iTasks.API.Core.Types, iTasks.API.Core.Tasks, iTasks.UI.Layout
import iTasks.WF.Definition, iTasks.WF.Tasks.Core, iTasks.WF.Tasks.IO
import iTasks.API.Core.Types, iTasks.UI.Layout
import iTasks.SDS.Sources.Core
import iTasks.API.Common.InteractionTasks, iTasks.API.Common.TaskCombinators //TODO don't import from Common in Core
import iTasks.UI.Editor, iTasks.UI.Prompt, iTasks.UI.Editor.Builtin, iTasks.UI.Editor.Combinators
......
definition module iTasks.API.Core.Tasks
/**
* This module provides the core 'basic tasks' from which more specialized tasks can be derived.
*/
import iTasks._Framework.Generic
from iTasks.WF.Definition import :: Task, :: Event
from iTasks._Framework.Task import :: ExternalProcessHandlers, :: ConnectionHandlers
from iTasks.UI.Definition import :: UI, :: UINodeType, :: UIChange
from iTasks.UI.Prompt import class toPrompt
from iTasks.SDS.Definition import :: RWShared, :: ReadWriteShared
from Data.Error import :: MaybeError(..)
from System.OSError import :: MaybeOSError, ::OSError, ::OSErrorCode, ::OSErrorMessage
from System.FilePath import :: FilePath
/**
* Lifts a value to the task domain. The task finishes immediately and yields its parameter
* as result of the task.
*
* @param Value: The value to be returned
* @default ()
* @return A task that will return the value defined by the parameter
*
* @gin-icon return
* @gin-shape return
*/
treturn :: !a -> Task a | iTask a
/**
* Exception throwing. This will throw an exception of arbitrary type e which has to be caught
* by a higher level exception handler combinator.
*
* @param Value: The exception value
* @return The combined task
*
* @gin-title Raise exception
* @gin-icon error
*/
throw :: !e -> Task a | iTask a & iTask, toString e
/**
* Reads shared data once.
*
* @param Shared: A shared reference
* @return The value read
* @throws SharedException
*
* @gin-title Read shared
* @gin-icon shared_read
*/
get :: !(ReadWriteShared a w) -> Task a | iTask a
/**
* Writes shared data.
*
* @param Value: A value to write
* @param Shared: A shared reference
* @return The value written
* @throws SharedException
*
* @gin-title Write shared
* @gin-icon shared_update
*/
set :: !a !(ReadWriteShared r a) -> Task a | iTask a
/**
* Updates shared data in one atomic operation.
*
* @param Shared: A shared reference
* @param Update function: A function modifying the shared value
* @return The value written
* @throws SharedException
*
* @gin-title Update shared
* @gin-icon shared_update
*/
upd :: !(r -> w) !(ReadWriteShared r w) -> Task w | iTask r & iTask w
/**
* Reads shared data continously
*
* @param Shared: A shared reference
* @return The value read
* @throws SharedException
*
* @gin-title Read shared
* @gin-icon shared_read
*/
watch :: !(ReadWriteShared r w) -> Task r | iTask r
/**
* Core interaction task. All other interaction tasks are derived from this one.
*
* An interaction tasks works on a local state and has read-only access to shared data.
*
* @param Description: A description of the task to display to the user
* @param Edit mode: The type of interaction: viewing, entering or updating information
* @param ReadOnlyShared: A reference to shared data the task has access to
* @param Initialization function: Computes the initial local state and view
* @param Refresh function: Recomputes the local state and view when either the view is edited or the shared data changes.
* @param Custom editor: Optional custom editor for the interaction
*
* @return The local state
*
* @gin False
*/
interact :: !d !EditMode !(RWShared () r w)
(r -> (l, v)) //On init
(v l v -> (l, v, Maybe (r -> w))) //On edit
(r l v -> (l, v, Maybe (r -> w))) //On refresh
(Maybe (Editor v)) -> Task (l,v) | toPrompt d & iTask l & iTask r & iTask v
/**
* Execute an external process. This task's value becomes stable when the process is terminated.
* @param Path to the executable
* @param a list of command-line arguments
* @param (optional) startup directory
* @param A reference to shared data the task has access to
* @param The event handler functions
*/
externalProcess :: !FilePath ![String] !(Maybe FilePath) !(RWShared () r w) !(ExternalProcessHandlers l r w) -> Task l | iTask l & TC r & TC w
/**
* Connect to an external system using TCP. This task's value becomes stable when the connection is closed
* @param Hostname
* @param Port
* @param A reference to shared data the task has access to
* @param The event handler functions
*/
tcpconnect :: !String !Int !(RWShared () r w) (ConnectionHandlers l r w) -> Task l | iTask l & iTask r & iTask w
/**
* Listen for connections from external systems using TCP.
* @param Port
* @param Remove closed connections. If this is true, closed connections are removed from the task value, if not they are kept in the list
* @param A reference to shared data the task has access to
* @param Initialization function: function that is called when a new connection is established
* @param Communication function: function that is called when data arrives, the connection is closed or the observed share changes.
*/
tcplisten :: !Int !Bool !(RWShared () r w) (ConnectionHandlers l r w) -> Task [l] | iTask l & iTask r & iTask w
/**
* Evaluate a "World" function that does not yield any result once.
*
* @param World function: The function to evaluate
* @return A () task that evaluates the function
*
* @gin False
*/
appWorld :: !(*World -> *World) -> Task ()
/**
* Evaluate a "World" function that also returns a value once.
*
* @param World function: The function to evaluate
* @return A task that evaluates the function and yield a
*
* @gin False
*/
accWorld :: !(*World -> *(!a,!*World)) -> Task a | iTask a
/**
* Evaluate a "World" function that also returns a MaybeError value.
* If the MaybeError value is Error, the error is transformed.
* @param World function: The function to evaluate
* @param Error function: Error transformation function
*
* @return A task that evaluates the function
*
* @gin False
*/
accWorldError :: !(*World -> (!MaybeError e a, !*World)) !(e -> err) -> Task a | iTask a & TC, toString err
/**
* Evaluate a "World" function that also returns a MaybeOSError value.
* If the MaybeError value is Error, the error is transformed.
* @param World function: The function to evaluate
* @param Error function: Error transformation function
*
* @return A task that evaluates the function
*
* @gin False
*/
accWorldOSError :: !(*World -> (!MaybeOSError a, !*World)) -> Task a | iTask a
/**
* Write a value to the server console output for tracing
*/
traceValue :: a -> Task a | iTask a
/**
* Terminates a running task server
*
* @param The exit code of the server process
*/
shutDown :: Int -> Task ()
......@@ -24,10 +24,8 @@ from iTasks._Framework.IWorld import :: IWorld
from iTasks.UI.Definition import :: UI, :: UINodeType, :: UISize, :: UIDirection, :: UISideSizes, :: UIBound, :: UIAttributes
from iTasks.UI.Editor import :: Editor, :: EditMask, :: Masked
from iTasks.UI.Editor.Generic import generic gEditor, :: VSt
from iTasks.WF.Definition import :: Task, :: TaskId, :: InstanceNo, :: TaskValue, :: Stability
from iTasks._Framework.Generic import class iTask
from iTasks._Framework.Generic.Visualization import generic gText, :: TextFormat(..), toMultiLineText
from iTasks._Framework.Generic.Defaults import generic gDefault
from iTasks.WF.Definition import :: Task, :: TaskId, :: InstanceNo, :: TaskValue, :: Stability, class iTask
from iTasks.SDS.Definition import :: SDS, :: ReadWriteShared, :: ReadOnlyShared
from iTasks.UI.JS.Interface import :: JSWorld, :: JSVal
from iTasks.UI.Prompt import class toPrompt
......@@ -36,6 +34,13 @@ from Text.HTML import :: SVGElt, :: SVGAttr, :: SVGAlign, :: SVGColor, :: SVGDef
from Text.HTML import :: SVGLengthUnit, :: SVGLineCap, :: SVGFillRule, :: SVGLineJoin, :: SVGMeetOrSlice, :: SVGStrokeMiterLimit, :: SVGPaint
from Text.HTML import :: SVGStrokeDashArray, :: SVGStrokeDashOffset, :: SVGStrokeWidth, :: SVGTransform, :: SVGZoomAndPan
from iTasks.UI.Editor import :: Editor
from iTasks.UI.Editor.Generic import generic gEditor
from iTasks._Framework.Generic.Visualization import generic gText, :: TextFormat
from iTasks._Framework.Generic.Defaults import generic gDefault
from Text.JSON import generic JSONEncode, generic JSONDecode
from GenEq import generic gEq
class TApplicative f | Functor f where
(<#>) :: (f (a -> b)) (f a) -> f b | iTask a & iTask b
return :: a -> f a | iTask a
......
......@@ -17,7 +17,7 @@ import iTasks._Framework.IWorld
import System.Time, System.File, System.FilePath
import iTasks.SDS.Definition
from iTasks.UI.Definition import :: UI(..), :: UIDirection(..), stringDisplay
from iTasks.API.Core.Tasks import treturn
from iTasks.WF.Tasks.Core import treturn
from iTasks.API.Common.TaskCombinators import tbind, @
from iTasks.API.Extensions.Form.Pikaday import pikadayDateField
......
......@@ -3,8 +3,8 @@ definition module iTasks.SDS.Combinators.Common
* This module provides common patterns for composing shared sources defined on top of the core set
*/
from iTasks.SDS.Definition import :: SDS, :: RWShared, :: ROShared, :: SDSNotifyPred, :: Shared, :: ReadOnlyShared, :: ReadWriteShared
from iTasks.WF.Definition import :: TaskException, :: TaskValue, :: TaskId
from iTasks._Framework.Generic import class iTask, generic gEditor, generic gEq, generic gDefault, generic gText
from iTasks.WF.Definition import :: TaskException, :: TaskValue, :: TaskId, class iTask
from iTasks.WF.Definition import generic gEditor, generic gEq, generic gDefault, generic gText, generic JSONEncode, generic JSONDecode
from iTasks._Framework.Generic.Visualization import :: TextFormat
from iTasks.UI.Editor import :: Editor, :: EditMask, :: Masked
from iTasks.API.Core.Types import :: TaskList, :: TaskListFilter, :: TaskListItem, :: SharedTaskList, :: TaskAttributes, :: InstanceProgress
......
......@@ -4,12 +4,14 @@ definition module iTasks.SDS.Combinators.Core
*/
from iTasks.SDS.Definition import :: SDS, :: SDSLensRead, :: SDSLensWrite, :: SDSLensNotify, :: SDSNotifyPred
from Data.Either import :: Either
from Data.Maybe import :: Maybe
from Text.JSON import :: JSONNode
from iTasks._Framework.Generic import class iTask
import iTasks._Framework.Generic.Visualization
import iTasks._Framework.Generic.Defaults
import iTasks.UI.Editor.Generic
import GenEq
from iTasks.WF.Definition import class iTask
from iTasks.WF.Definition import generic gEditor, generic gEq, generic gDefault, generic gText, generic JSONEncode, generic JSONDecode
from iTasks.UI.Editor import :: Editor
from iTasks._Framework.Generic.Visualization import :: TextFormat
//Apply a parametric lens
sdsLens :: !String (p -> ps) (SDSLensRead p r rs) (SDSLensWrite p w rs ws) (SDSLensNotify p w rs) !(SDS ps rs ws) -> SDS p r w | iTask ps
......
......@@ -2,10 +2,9 @@ definition module iTasks.SDS.Definition
/**
* This module provides the types that define a shared data source
*/
from iTasks.WF.Definition import :: TaskException
from iTasks.WF.Definition import :: TaskException, class iTask
from iTasks._Framework.IWorld import :: IWorld
from iTasks._Framework.Generic import class iTask
import iTasks._Framework.Generic.Visualization
import iTasks._Framework.Generic.Defaults
import iTasks.UI.Editor.Generic
......
......@@ -16,10 +16,11 @@ from Text.HTML import :: HtmlTag
from Data.Map import :: Map
from iTasks.API.Core.Types import :: Document, :: DocumentId, :: Date, :: Time, :: Action
from iTasks._Framework.Generic import class iTask(..)
from iTasks.WF.Definition import class iTask
from iTasks._Framework.Generic.Visualization import generic gText, :: TextFormat(..)
from iTasks._Framework.Generic.Defaults import generic gDefault
from iTasks.UI.Editor import :: Editor, :: EditMask, :: Masked
from iTasks.UI.Editor.Generic import generic gEditor
from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
from GenEq import generic gEq
......
......@@ -7,7 +7,7 @@ import qualified Data.Map as DM
import qualified Data.List as DL
from iTasks.API.Core.Types import :: Document, :: DocumentId, :: Date, :: Time, :: Action(..)
from iTasks._Framework.Generic import class iTask(..)
from iTasks.WF.Definition import class iTask(..)
from iTasks._Framework.Generic.Visualization import generic gText, :: TextFormat(..)
from iTasks._Framework.Generic.Defaults import generic gDefault
from iTasks.UI.Editor import :: Editor, :: EditMask, :: Masked
......
......@@ -8,6 +8,14 @@ from iTasks._Framework.TaskState import :: TaskTree
from iTasks._Framework.TaskEval import :: TaskEvalOpts, :: TaskEvalInfo
from iTasks.UI.Definition import :: UIChange
from Text.JSON import :: JSONNode
from Data.Maybe import :: Maybe
from iTasks.UI.Editor import :: Editor
from iTasks.UI.Editor.Generic import generic gEditor
from iTasks._Framework.Generic.Visualization import generic gText, :: TextFormat
from iTasks._Framework.Generic.Defaults import generic gDefault
from Text.JSON import generic JSONEncode, generic JSONDecode
from GenEq import generic gEq
// Task definition:
:: Task a = Task !(Event TaskEvalOpts TaskTree *IWorld -> *(!TaskResult a, !*IWorld))
......@@ -48,3 +56,19 @@ exception :: !e -> TaskException | TC, toString e
:: TaskId = TaskId !InstanceNo !TaskNo
:: InstanceNo :== Int
:: TaskNo :== Int
//The iTask context restriction contains all generic functions that need to
//be available for a type to be used in tasks
class iTask a
//Interaction
| gEditor{|*|}
//Visualization
, gText{|*|}
//Serialization
, JSONEncode{|*|}
, JSONDecode{|*|}
//Data
, gDefault{|*|}
, gEq{|*|}
, TC a
......@@ -2,3 +2,101 @@ definition module iTasks.WF.Tasks.Core
/**
* This module provis the builtin basic tasks
*/
import iTasks.WF.Definition
from Data.Error import :: MaybeError
from System.OSError import :: MaybeOSError, :: OSError, :: OSErrorCode, :: OSErrorMessage
from iTasks.UI.Editor import :: EditMode
from iTasks.UI.Prompt import class toPrompt
from iTasks.SDS.Definition import :: SDS, :: RWShared
/**
* Lifts a value to the task domain. The task finishes immediately and yields its parameter
* as result of the task.
*
* @param Value: The value to be returned
* @default ()
* @return A task that will return the value defined by the parameter
*
* @gin-icon return
* @gin-shape return
*/
treturn :: !a -> Task a | iTask a
/**
* Exception throwing. This will throw an exception of arbitrary type e which has to be caught
* by a higher level exception handler combinator.
*
* @param Value: The exception value
* @return The combined task
*
* @gin-title Raise exception
* @gin-icon error
*/
throw :: !e -> Task a | iTask a & iTask, toString e
/**
* Evaluate a "World" function that does not yield any result once.
*
* @param World function: The function to evaluate
* @return A () task that evaluates the function
*
* @gin False
*/
appWorld :: !(*World -> *World) -> Task () //TODO (All of these versions should be one core)
/**
* Evaluate a "World" function that also returns a value once.
*
* @param World function: The function to evaluate
* @return A task that evaluates the function and yield a
*
* @gin False
*/
accWorld :: !(*World -> *(!a,!*World)) -> Task a | iTask a
/**
* Evaluate a "World" function that also returns a MaybeError value.
* If the MaybeError value is Error, the error is transformed.
* @param World function: The function to evaluate
* @param Error function: Error transformation function
*
* @return A task that evaluates the function
*
* @gin False
*/
accWorldError :: !(*World -> (!MaybeError e a, !*World)) !(e -> err) -> Task a | iTask a & TC, toString err
/**
* Evaluate a "World" function that also returns a MaybeOSError value.
* If the MaybeError value is Error, the error is transformed.
* @param World function: The function to evaluate
* @param Error function: Error transformation function
*
* @return A task that evaluates the function
*
* @gin False
*/
accWorldOSError :: !(*World -> (!MaybeOSError a, !*World)) -> Task a | iTask a
/**
* Core interaction task. All other interaction tasks are derived from this one.
*
* An interaction tasks works on a local state and has read-only access to shared data.
*
* @param Description: A description of the task to display to the user
* @param Edit mode: The type of interaction: viewing, entering or updating information
* @param ReadOnlyShared: A reference to shared data the task has access to
* @param Initialization function: Computes the initial local state and view
* @param Refresh function: Recomputes the local state and view when either the view is edited or the shared data changes.
* @param Custom editor: Optional custom editor for the interaction
*
* @return The local state
*
* @gin False
*/
interact :: !d !EditMode !(RWShared () r w)
(r -> (l, v)) //On init
(v l v -> (l, v, Maybe (r -> w))) //On edit
(r l v -> (l, v, Maybe (r -> w))) //On refresh
(Maybe (Editor v)) -> Task (l,v) | toPrompt d & iTask l & iTask r & iTask v
implementation module iTasks.WF.Tasks.Core
import iTasks.WF.Definition
import iTasks.UI.Definition
import iTasks.UI.Prompt
import iTasks.SDS.Definition
import iTasks._Framework.Task
import iTasks._Framework.TaskState
import iTasks._Framework.TaskEval
import iTasks._Framework.IWorld
import qualified iTasks._Framework.SDS as SDS
import Data.Error, Data.Maybe
import Text.JSON
import StdString
treturn :: !a -> (Task a) | iTask a
treturn a = mkInstantTask (\taskId iworld-> (Ok a, iworld))
throw :: !e -> Task a | iTask a & iTask, toString e
throw e = mkInstantTask (\taskId iworld -> (Error (dynamic e,toString e), iworld))
appWorld :: !(*World -> *World) -> Task ()
appWorld fun = mkInstantTask eval
where
eval taskId iworld=:{IWorld|world}
= (Ok (), {IWorld|iworld & world = fun world})
accWorld :: !(*World -> *(!a,!*World)) -> Task a | iTask a
accWorld fun = mkInstantTask eval
where
eval taskId iworld=:{IWorld|world}
# (res,world) = fun world
= (Ok res, {IWorld|iworld & world = world})
accWorldError :: !(*World -> (!MaybeError e a, !*World)) !(e -> err) -> Task a | iTask a & TC, toString err
accWorldError fun errf = mkInstantTask eval
where
eval taskId iworld=:{IWorld|current={taskTime},world}
# (res,world) = fun world