We planned to upgrade GitLab and Mattermost to the latest version this Friday morning (early). You may experience some downtime!

Commit 453e8ce3 authored by Bas Lijnse's avatar Bas Lijnse

Moved everything from iTasks.API.Core.* except for some leftover types and...

Moved everything from iTasks.API.Core.* except for some leftover types and derives in iTasks.API.Core.Types that should be distributed over other modules once everything has been moved.
parent f9905e93
......@@ -22,6 +22,7 @@ import
, iTasks.WF.Combinators.Core
, iTasks.WF.Combinators.SDS
, iTasks.WF.Combinators.Tune
, iTasks.WF.Combinators.Overloaded
, iTasks.API
// Miscellaneous machinery
......
......@@ -5,6 +5,7 @@ import iTasks._Framework.Generic, iTasks._Framework.Task, iTasks._Framework.SDS
import iTasks._Framework.Util
import iTasks.API.Core.Types
import iTasks.API.Common.TaskCombinators
import iTasks.WF.Combinators.Overloaded
from iTasks.WF.Tasks.SDS import get, set
......
......@@ -3,8 +3,7 @@ definition module iTasks.API.Common.ExportTasks
* This module provides tasks for exporting data from a workflow to an external source
*/
from System.FilePath import :: FilePath
import iTasks.API.Core.Types
import iTasks._Framework.Task
import iTasks.API.Extensions.Document
/**
* Export a document to the server's filesystem.
......
......@@ -3,8 +3,8 @@ definition module iTasks.API.Common.ImportTasks
* This module provides tasks for importing external data into a workflow.
*/
from System.FilePath import :: FilePath
import iTasks.API.Core.Types
import iTasks._Framework.Task
import iTasks.API.Extensions.Document
/**
* Import a file on the server's filesystem as a Document
*
......
......@@ -4,6 +4,8 @@ import StdBool, _SystemArray, StdInt
import Text.Encodings.MIME, Text, Text.CSV, System.File, Text.JSON, Data.Error, System.FilePath
import iTasks._Framework.IWorld, iTasks._Framework.Task, iTasks._Framework.TaskState, iTasks._Framework.TaskStore
import iTasks._Framework.Util
import iTasks.API.Core.Types
from StdFunc import id
CHUNK_SIZE :== 1048576 // 1M
......
......@@ -2,7 +2,6 @@ definition module iTasks.API.Common.InteractionTasks
import iTasks.WF.Definition
from iTasks.WF.Combinators.Core import :: Action
from iTasks.API.Core.Types import :: Date, :: Time, :: DateTime
from Data.Functor import class Functor
from iTasks.UI.Prompt import class toPrompt
from iTasks.UI.Editor.Builtin import :: ChoiceText, :: ChoiceGrid, :: ChoiceNode
......@@ -172,42 +171,6 @@ editSharedMultipleChoiceWithSharedAs :: !d ![ChoiceOption o] !(ReadWriteShared [
*/
wait :: !d (r -> Bool) !(ReadWriteShared r w) -> Task r | toPrompt d & iTask r
/*** Special wait tasks ***/
/**
* Creates a task which blocks a workflow until a specified time.
*
* @param Time: The specified time at which the task should complete
*
* @return The time to wait for
*
*/
waitForTime :: !Time -> Task Time
/**
* Creates a task which blocks a workflow until a specified date.
*
* @param Date: The specified date at which the task should complete
*
* @return The date to wait for
*/
waitForDate :: !Date -> Task Date
/**
* Creates a task which blocks a workflow until a specified date and time.
*
* @param DateTime: The specified date and time at which the task should complete
*
* @return The date and time to wait for
*/
waitForDateTime :: !DateTime -> Task DateTime
/**
* Task completes after specified amount of time has passed
* since the creation of the task.
*
* @param The time to wait (in seconds before the task should complete
*
* @return The time the timer went off
*
*/
waitForTimer :: !Int -> Task DateTime
/*** Special tasks for choosing actions ***/
......
......@@ -9,6 +9,7 @@ from Data.Map import qualified get, put
import StdBool, StdList, StdMisc, StdTuple, Data.Functor
import iTasks.WF.Tasks.Core
import iTasks.WF.Tasks.SDS
import iTasks.WF.Combinators.Overloaded
import iTasks.API.Common.TaskCombinators
import iTasks.SDS.Sources.Core, iTasks.SDS.Sources.System
import iTasks.SDS.Combinators.Common
......@@ -302,27 +303,6 @@ wait desc pred shared
= viewSharedInformation desc [ViewAs (const "Waiting for information update")] shared
>>* [OnValue (ifValue pred return)]
waitForTime :: !Time -> Task Time
waitForTime time =
viewSharedInformation ("Wait for time", ("Wait until " +++ toString time)) [] currentTime >>* [OnValue (ifValue (\now -> time < now) return)]
waitForDate :: !Date -> Task Date
waitForDate date =
viewSharedInformation ("Wait for date", ("Wait until " +++ toString date)) [] currentDate >>* [OnValue (ifValue (\now -> date < now) return)]
waitForDateTime :: !DateTime -> Task DateTime
waitForDateTime datetime =
viewSharedInformation ("Wait for date and time", ("Wait until " +++ toString datetime)) [] currentDateTime >>* [OnValue (ifValue (\now -> datetime < now) return)]
waitForUTCDateTime :: !DateTime -> Task DateTime
waitForUTCDateTime datetime =
viewSharedInformation ("Wait for date and time", ("Wait until " +++ toString datetime)) [] currentUTCDateTime >>* [OnValue (ifValue (\now -> datetime < now) return)]
waitForTimer :: !Int -> Task DateTime
waitForTimer interval = get currentDateTime >>- \now -> waitForUTCDateTime (endTime interval now)
where
endTime interval now = let (Timestamp ts) = datetimeToTimestamp now in timestampToGmDateTime (Timestamp (ts + interval))
chooseAction :: ![(!Action,a)] -> Task a | iTask a
chooseAction actions
= viewInformation () [] ()
......
......@@ -15,7 +15,7 @@ import qualified Data.Map as DM
import iTasks.WF.Tasks.Core
import iTasks.WF.Tasks.SDS
import iTasks.WF.Combinators.Core, iTasks.WF.Combinators.Tune
import iTasks.WF.Combinators.Core, iTasks.WF.Combinators.Tune, iTasks.WF.Combinators.Overloaded
import iTasks.API.Common.InteractionTasks, iTasks.UI.Layout, iTasks.UI.Prompt
import iTasks.UI.Layout.Common, iTasks.UI.Layout.Default
......
......@@ -45,100 +45,15 @@ 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
class TMonad m | TApplicative m where
(>>=) infixl 1 :: (m a) (a -> m b) -> m b | iTask a & iTask b
(>>|) infixl 1 :: (m a) ( m b) -> m b | iTask a & iTask b
instance Functor Task
instance TApplicative Task
instance TMonad Task
instance TApplicative Maybe
instance TMonad Maybe
instance TApplicative []
instance TMonad []
instance TApplicative (Either e)
instance TMonad (Either e)
//* local date and time
:: Date =
{ year :: !Int
, mon :: !Int
, day :: !Int
}
:: Time =
{ hour :: !Int
, min :: !Int
, sec :: !Int
}
:: DateTime =
{ year :: !Int
, mon :: !Int
, day :: !Int
, hour :: !Int
, min :: !Int
, sec :: !Int
}
//Conversion
toTime :: DateTime -> Time
toDate :: DateTime -> Date
toDateTime :: Date Time -> DateTime
//Printing and parsing
instance toString Date, Time, DateTime
parseDate :: String -> MaybeErrorString Date //Expected format: "yyyy-mm-dd"
parseTime :: String -> MaybeErrorString Time //Expected format: "hh:mm:ss"
parseDateTime :: String -> MaybeErrorString DateTime //Expected format: "yyyy-mm-dd hh:mm:ss"
instance fromString Date, Time, DateTime //Assumes parse* succeeds
//Comparison
instance == Date, Time, DateTime
instance < Date, Time, DateTime
//* Documents
:: Document =
{ documentId :: !DocumentId //*A unique identifier of the document
, contentUrl :: !String //*A url to where the document can be downloaded
, name :: !String //*The filename of a document
, mime :: !String //*The mime type of the document
, size :: !Int //*The filesize in bytes
}
:: DocumentId :== String
instance toString Document
instance == Document
derive JSONEncode Date, Time, DateTime, Document
derive JSONDecode Date, Time, DateTime, Document
derive gDefault Date, Time, DateTime, Document
derive gEq Date, Time, DateTime, Document
derive gText Date, Time, DateTime, Document
derive gEditor Date, Time, DateTime, Document
//* Common exceptions used by API tasks
:: FileException = FileException !FilePath !FileError
:: ParseException = CannotParse !String
:: CallException = CallFailed !OSError
:: SharedException = SharedException !String
:: RPCException = RPCException !String
:: OSException = OSException !OSError
:: AttachException = InstanceNotFound | InstanceEvalError
derive class iTask FileException, ParseException, CallException, SharedException, RPCException, OSException, AttachException
instance toString FileException, ParseException, CallException, SharedException, RPCException, OSException, AttachException
derive class iTask FileException, ParseException, CallException, RPCException, OSException
instance toString FileException, ParseException, CallException, RPCException, OSException
//****************************************************************************//
// Framework types.
......@@ -147,51 +62,10 @@ instance toString FileException, ParseException, CallException, SharedException,
// you may read them when interacting with the framework
//****************************************************************************//
instance Functor TaskValue
:: SessionId :== String
class toInstanceNo t :: t -> InstanceNo
instance toInstanceNo InstanceNo
instance toInstanceNo TaskId
instance toString TaskId
instance fromString TaskId
instance == TaskId
instance < TaskId
//* Access to parallel task lists
derive class iTask TaskListFilter
//* Framework configuration
:: Config =
{ sessionTime :: !Int //* Time (in seconds) before inactive sessions are garbage collected. Default is 3600 (one hour).
, smtpServer :: !String //* The smtp server to use for sending e-mails
}
//Common action constants with predefined options
ActionOk :== Action "Ok"
ActionCancel :== Action "Cancel"
ActionYes :== Action "Yes"
ActionNo :== Action "No"
ActionNext :== Action "Next"
ActionPrevious :== Action "Previous"
ActionFinish :== Action "Finish"
ActionContinue :== Action "Continue"
ActionOpen :== Action "/File/Open"
ActionSave :== Action "/File/Save"
ActionSaveAs :== Action "/File/Save as"
ActionQuit :== Action "/File/Quit"
ActionHelp :== Action "/Help/Help"
ActionAbout :== Action "/Help/About"
ActionFind :== Action "/Edit/Find"
ActionNew :== Action "New"
ActionEdit :== Action "Edit"
ActionDelete :== Action "Delete"
ActionRefresh :== Action "Refresh"
ActionClose :== Action "Close"
derive JSONEncode TaskValue, TaskListItem, InstanceConstants, InstanceProgress, ValueStatus, TaskInstance, Action
derive JSONDecode TaskValue, TaskListItem, InstanceConstants, InstanceProgress, ValueStatus, TaskInstance, Action
derive gDefault TaskValue, TaskListItem, InstanceConstants, InstanceProgress, ValueStatus, TaskInstance, Action
......@@ -200,7 +74,7 @@ derive gEq TaskValue, TaskListItem, InstanceConstants, InstanceProgress, Valu
derive gText TaskValue, TaskListItem, InstanceConstants, InstanceProgress, ValueStatus, TaskInstance, Action
derive gEditor TaskValue, TaskListItem, InstanceConstants, InstanceProgress, ValueStatus, TaskInstance, Action
derive class iTask TaskId, Config
derive class iTask TaskId
//****************************************************************************//
// Types for task meta-data
......
This diff is collapsed.
......@@ -10,6 +10,7 @@ import iTasks._Framework.Tonic.AbsSyn
import iTasks._Framework.Tonic.Pretty
import iTasks._Framework.Tonic.Images
import iTasks.UI.Definition
import iTasks.API.Extensions.DateTime
from StdFunc import seq
import qualified Data.Map as DM
from Data.Map import instance Functor (Map a)
......
......@@ -9,6 +9,7 @@ from StdFunc import seq
import qualified Data.Map as DM
import Data.List, Data.Tuple
import iTasks.UI.Definition, iTasks.UI.Editor, iTasks.UI.Editor.Builtin, iTasks.UI.Editor.Common, iTasks.UI.Layout.Default, iTasks.UI.Layout.Common
import iTasks.API.Extensions.DateTime
// SPECIALIZATIONS
derive class iTask Workflow, AttachmentStatus
......
......@@ -5,6 +5,7 @@ implementation module iTasks.API.Extensions.Clock
import iTasks
import iTasks.UI.Definition, iTasks.UI.Editor
import iTasks.UI.JS.Interface
import iTasks.API.Extensions.DateTime
import qualified Data.Map as DM, Data.Tuple
import Text.HTML
......
definition module iTasks.API.Extensions.DateTime
/**
* This module provides types for working with dates and times
*/
import iTasks.WF.Definition
from Data.Error import :: MaybeError, :: MaybeErrorString
from StdString import class toString, class fromString
from StdClass import class <
//* local date and time
:: Date =
{ year :: !Int
, mon :: !Int
, day :: !Int
}
:: Time =
{ hour :: !Int
, min :: !Int
, sec :: !Int
}
:: DateTime =
{ year :: !Int
, mon :: !Int
, day :: !Int
, hour :: !Int
, min :: !Int
, sec :: !Int
}
//Conversion
toTime :: DateTime -> Time
toDate :: DateTime -> Date
toDateTime :: Date Time -> DateTime
//Printing and parsing
instance toString Date, Time, DateTime
parseDate :: String -> MaybeErrorString Date //Expected format: "yyyy-mm-dd"
parseTime :: String -> MaybeErrorString Time //Expected format: "hh:mm:ss"
parseDateTime :: String -> MaybeErrorString DateTime //Expected format: "yyyy-mm-dd hh:mm:ss"
instance fromString Date, Time, DateTime //Assumes parse* succeeds
//Comparison
instance == Date, Time, DateTime
instance < Date, Time, DateTime
derive JSONEncode Date, Time, DateTime
derive JSONDecode Date, Time, DateTime
derive gDefault Date, Time, DateTime
derive gEq Date, Time, DateTime
derive gText Date, Time, DateTime
derive gEditor Date, Time, DateTime
//Util
timestampToGmDateTime :: !Timestamp -> DateTime
dateToTimestamp :: !Date -> Timestamp
datetimeToTimestamp :: !DateTime -> Timestamp
/*** Special wait tasks ***/
/**
* Creates a task which blocks a workflow until a specified time.
*
* @param Time: The specified time at which the task should complete
*
* @return The time to wait for
*
*/
waitForTime :: !Time -> Task Time
/**
* Creates a task which blocks a workflow until a specified date.
*
* @param Date: The specified date at which the task should complete
*
* @return The date to wait for
*/
waitForDate :: !Date -> Task Date
/**
* Creates a task which blocks a workflow until a specified date and time.
*
* @param DateTime: The specified date and time at which the task should complete
*
* @return The date and time to wait for
*/
waitForDateTime :: !DateTime -> Task DateTime
/**
* Task completes after specified amount of time has passed
* since the creation of the task.
*
* @param The time to wait (in seconds before the task should complete
*
* @return The time the timer went off
*
*/
waitForTimer :: !Int -> Task DateTime
implementation module iTasks.API.Extensions.DateTime
import iTasks.WF.Definition
import iTasks.WF.Tasks.SDS
import iTasks.WF.Combinators.Core
import iTasks.WF.Combinators.Overloaded
import iTasks.SDS.Sources.System
import iTasks.UI.Definition
import iTasks.UI.Prompt
import iTasks.UI.Editor
import iTasks.UI.Editor.Builtin
import iTasks.UI.Editor.Combinators
import iTasks.API.Common.TaskCombinators
import iTasks.API.Common.InteractionTasks
import StdBool, StdArray, StdEnum, StdList
import Text, Text.JSON, System.Time
import Data.Maybe, Data.Error
import qualified Data.Map as DM
from iTasks.API.Extensions.Form.Pikaday import pikadayDateField
//* (Local) date and time
toTime :: DateTime -> Time
toTime {DateTime|hour,min,sec} = {Time|hour=hour,min=min,sec=sec}
toDate :: DateTime -> Date
toDate {DateTime|year,mon,day} = {Date|year=year,mon=mon,day=day}
toDateTime :: Date Time -> DateTime
toDateTime {Date|year,mon,day} {Time|hour,min,sec} = {DateTime|year=year,mon=mon,day=day,hour=hour,min=min,sec=sec}
instance toString Date
where
toString {Date|year,mon,day} = lpad (toString year) 4 '0' +++ "-" +++ lpad (toString mon) 2 '0' +++ "-" +++ lpad (toString day) 2 '0'
parseDate :: String -> MaybeErrorString Date //Expected format: "yyyy-mm-dd"
parseDate s
//Check format
| size s == 10 && foldl (\ok i -> ok && (if (i == 4 || i == 7) (s.[i] == '-') (isDigit s.[i]))) True [0..9]
= Ok {Date|year = toInt (s %(0,3)), mon = toInt (s %(5,6)), day = toInt (s %(8,9))}
| otherwise = Error "date needs to be formatted as yyyy-mm-dd"
instance fromString Date
where
fromString s = fromOk (parseDate s)
instance == Date
where
(==) x y = x.Date.year == y.Date.year && x.Date.mon == y.Date.mon && x.Date.day == y.Date.day
instance < Date
where
(<) x y
| x.Date.year < y.Date.year = True
| x.Date.year == y.Date.year && x.Date.mon < y.Date.mon = True
| x.Date.year == y.Date.year && x.Date.mon == y.Date.mon && x.Date.day < y.Date.day = True
| otherwise = False
JSONEncode{|Date|} _ d = [JSONString (toString d)]
JSONDecode{|Date|} _ [JSONString s:c] = case parseDate s of (Ok d) = (Just d,c) ; _ = (Nothing,c)
JSONDecode{|Date|} _ c = (Nothing, c)
gText{|Date|} _ val = [maybe "" toString val]
gEditor{|Date|} = pikadayDateField /*whenDisabled
(liftEditor toString fromString (textView 'DM'.newMap))
(liftEditorAsymmetric toString parseDate (withHintAttributes "date (yyyy-mm-dd)" (textField 'DM'.newMap)))
*/
gDefault{|Date|} = {Date|day = 1, mon = 1, year = 2017}
derive gEq Date
instance toString Time
where
toString {Time|hour,min,sec} = lpad (toString hour) 2 '0' +++ ":" +++ lpad (toString min) 2 '0' +++ ":" +++ lpad (toString sec) 2 '0'
parseTime :: String -> MaybeErrorString Time // Expected format: "hh:mm:ss"
parseTime s
//Check format
| size s == 8 && foldl (\ok i -> ok && (if (i == 2 || i == 5) (s.[i] == ':') (isDigit s.[i]))) True [0..7]
= Ok {Time|hour = toInt (s %(0,1)), min = toInt (s %(3,4)), sec = toInt (s %(6,7)) }
| otherwise = Error "time needs to be formatted as hh:mm:ss"
instance fromString Time
where
fromString s = fromOk (parseTime s)
instance == Time
where
(==) x y = x.Time.hour == y.Time.hour && x.Time.min == y.Time.min && x.Time.sec == y.Time.sec
instance < Time
where
(<) x y
| x.Time.hour < y.Time.hour = True
| x.Time.hour == y.Time.hour && x.Time.min < y.Time.min = True
| x.Time.hour == y.Time.hour && x.Time.min == y.Time.min && x.Time.sec < y.Time.sec = True
| otherwise = False
JSONEncode{|Time|} _ t = [JSONString (toString t)]
JSONDecode{|Time|} _ [JSONString s:c] = case parseTime s of (Ok t) = (Just t, c) ; _ = (Nothing,c)
JSONDecode{|Time|} _ c = (Nothing, c)
gText{|Time|} _ val = [maybe "" toString val]
gEditor{|Time|} = whenDisabled
(liftEditor toString fromString (textView 'DM'.newMap))
(liftEditorAsymmetric toString parseTime (withHintAttributes "time (hh:mm:ss)" (textField 'DM'.newMap)))
derive gDefault Time
derive gEq Time
instance toString DateTime
where
toString {DateTime|year,mon,day,hour,min,sec}
= toString {Date|year=year,mon=mon,day=day} +++ " " +++ toString {Time|hour=hour,min=min,sec=sec}
parseDateTime :: String -> MaybeErrorString DateTime //Expected format: "yyyy-mm-dd hh:mm:ss"
parseDateTime s
//Check format
| size s == 19 && foldl (\ok i -> ok && check i s.[i]) True [0..18]
= Ok {DateTime|year = toInt (s %(0,3)), mon = toInt (s %(5,6)), day = toInt (s %(8,9))
,hour = toInt (s %(11,12)), min = toInt (s %(14,15)), sec = toInt (s %(17,18))}
| otherwise = Error "date/time needs to be formatted as yyyy-mm-dd hh:mm:ss"
where
check i c
| i == 4 || i == 7 = c == '-'
| i == 10 = c == ' '
| i == 13 || i == 16 = c == ':'
| otherwise = isDigit c