Commit e75d4263 authored by Bas Lijnse's avatar Bas Lijnse

Basic general refactoring. Renamed functions, added comments and moved some...

Basic general refactoring. Renamed functions, added comments and moved some functions to other modules.

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/branches/fancyTasks@334 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent 23406dbc
......@@ -27,23 +27,19 @@ instance == GarbageCollect
// Here follow some commonly used internal functions
/* Support for user defined combinators
incNr :: increment task number
mkTask :: to promote a function of proper type to a task
mkParSubTask :: create a subtask with indicated task nr
iTaskId :: generate an id based on the task nr, important for garbage collection and family relation
toStringTaskNr :: convert TaskNr to more compact string representation
parseTaskNr :: convert string representation back to TaskNr
deleteAllSubTasks :: collects all related tasks
*/
incNr :: !TaskNr -> TaskNr
mkTask :: !String !(Task a) -> Task a | iCreateAndPrint a
mkParSubTask :: !String !Int (Task a) -> (Task a) | iCreateAndPrint a // two shifts are needed
iTaskId :: !Int !TaskNr !String -> String
toStringTaskNr :: !TaskNr -> TaskNrId
parseTaskNr :: !String -> TaskNr
deleteAllSubTasks :: ![TaskNr] TSt -> TSt
// general iTask store, session store, page store, store but no form generation
......
......@@ -16,36 +16,14 @@ import DrupBasic
:: TCl a = TCl !.(Task a) // task closure, container for a task used for higher order tasks (task which deliver a task)
toStringTaskNr :: !TaskNr -> TaskNrId
toStringTaskNr [] = ""
toStringTaskNr [i] = toString i
toStringTaskNr [i:is] = toStringTaskNr is <+++ "." <+++ toString i
parseTaskNr :: !String -> TaskNr
parseTaskNr "" = []
parseTaskNr string = reverse (parseTaskNr` [char \\ char <-: string])
where
parseTaskNr` :: ![Char] -> TaskNr
parseTaskNr` [] = []
parseTaskNr` list
# (front,end) = span (\c -> c <> '.') list
= [toInt (toString front) : parseTaskNr` (stl end)]
toString :: [Char] -> String
toString list = {c \\ c <- list}
stl :: [Char] -> [Char]
stl [] = []
stl xs = tl xs
iTaskId :: !Int !TaskNr !String -> String
iTaskId userid tasknr postfix
# postfix = { c \\ c <-: postfix | not (isMember c ['\\\"/:*?<>|"']) } // throw away characters not allowed in a file name
| postfix == ""
| userid < 0 = "iLog_" <+++ (toStringTaskNr tasknr)
| otherwise = "iTask_" <+++ (toStringTaskNr tasknr)
| userid < 0 = "iLog_" <+++ (toStringTaskNr tasknr) <+++ "-" <+++ postfix
| otherwise = "iTask_" <+++ (toStringTaskNr tasknr) <+++ "-" <+++ postfix // MJP:info removed to allow dynamic realloc of users: <+++ "+" <+++ userid
| userid < 0 = "iLog_" <+++ (taskNrToString tasknr)
| otherwise = "iTask_" <+++ (taskNrToString tasknr)
| userid < 0 = "iLog_" <+++ (taskNrToString tasknr) <+++ "-" <+++ postfix
| otherwise = "iTask_" <+++ (taskNrToString tasknr) <+++ "-" <+++ postfix // MJP:info removed to allow dynamic realloc of users: <+++ "+" <+++ userid
deleteAllSubTasks :: ![TaskNr] TSt -> TSt
deleteAllSubTasks [] tst = tst
......@@ -57,11 +35,7 @@ deleteAllSubTasks [tx:txs] tst=:{hst,userId}
// Task creation and printing
// ******************************************************************************************************
incTaskNr tst = {tst & tasknr = incNr tst.tasknr}
incNr :: !TaskNr -> TaskNr
incNr [] = [0]
incNr [i:is] = [i+1:is]
// mkTask is an important wrapper function which should be wrapped around any task
// It takes care of
......@@ -74,7 +48,9 @@ incNr [i:is] = [i+1:is]
// If a task j is a subtask of task i, than it will get number i.j in reverse order
mkTask :: !String !(Task a) -> (Task a) | iCreateAndPrint a
mkTask taskname mytask = Task (appTaskTSt (mkTaskNoInc taskname mytask) o incTaskNr)
mkTask taskname mytask = Task (appTaskTSt (mkTaskNoInc taskname mytask) o incTStTaskNr)
where
incTStTaskNr tst = {tst & tasknr = incTaskNr tst.tasknr}
mkTaskNoInc :: !String !(Task a) -> (Task a) | iCreateAndPrint a // common second part of task wrappers
mkTaskNoInc taskname mytask = Task mkTaskNoInc`
......@@ -84,7 +60,7 @@ where
# (val,tst=:{activated,html}) = appTaskTSt mytask tst // active, so perform task and get its result
# tst = {tst & tasknr = tasknr, options = options, userId = userId}
| trace || taskname == "" = (val,tst) // no trace, just return value
# tst = {tst & html = TaskTrace {trTaskNr = toStringTaskNr tasknr, trTaskName = taskname, trActivated = activated, trUserId = userId, trValue = printToString val, trOptions = options} html}
# tst = {tst & html = TaskTrace {trTaskNr = taskNrToString tasknr, trTaskName = taskname, trActivated = activated, trUserId = userId, trValue = printToString val, trOptions = options} html}
= (val,tst)
mkParSubTask :: !String !Int (Task a) -> (Task a) | iCreateAndPrint a // two shifts are needed
......
......@@ -337,7 +337,7 @@ where
| activated // thread is finished, delete the entry...
# tst = deleteThreads thrTaskNr {tst & html = html +|+ nhtml} // remove thread from administration
= (a,{tst & tasknr = tasknr, options = options, userId = userId}) // remove entry from table
= (a,{tst & tasknr = tasknr, options = options, userId = userId,html = html +|+ DivCode (toStringTaskNr thrTaskNr) nhtml})
= (a,{tst & tasknr = tasknr, options = options, userId = userId,html = html +|+ DivCode (taskNrToString thrTaskNr) nhtml})
administrateNewThread :: !UserId !*TSt -> *TSt
......@@ -461,7 +461,7 @@ where
lookupThread tableKey n []
= -1 // no, cannot find thread
lookupThread tasknrToFind n [entry:next]
| (toStringTaskNr tasknrToFind == toStringTaskNr entry.thrTaskNr && foundThread threadkind entry.thrKind) = n // yes, thread is administrated
| (taskNrToString tasknrToFind == taskNrToString entry.thrTaskNr && foundThread threadkind entry.thrKind) = n // yes, thread is administrated
= lookupThread tasknrToFind (inc n) next
// TODO foundThread kan niet kloppen !!!
......@@ -662,8 +662,8 @@ where
showThreadNr :: !TaskNr -> String
showThreadNr [-1] = "Root"
showThreadNr [-1:is] = toStringTaskNr is
showThreadNr else = "*" <+++ toStringTaskNr else
showThreadNr [-1:is] = taskNrToString is
showThreadNr else = "*" <+++ taskNrToString else
// ******************************************************************************************************
// Global Effects Storage Management
......
......@@ -89,7 +89,7 @@ where
# (currtasknr,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId tasknr) id) tst // fetch actual tasknr
# (val,tst=:{activated}) = appTaskTSt task {tst & tasknr = [-1:currtasknr.Form.value]}
| activated // task is completed
# ntasknr = incNr currtasknr.Form.value // incr tasknr
# ntasknr = incTaskNr currtasknr.Form.value // incr tasknr
# (currtasknr,tst) = liftHst (mkStoreForm (Init,storageFormId options taskId tasknr) (\_ -> ntasknr)) tst // store next task nr
= foreverTask` {tst & tasknr = tasknr, options = options/*, html = html*/} // initialize new task
= (val,tst)
......@@ -127,7 +127,7 @@ where
taskDescriptor currtime activated
= { delegatorId = userId
, taskWorkerId = nuserId
, taskNrId = toStringTaskNr tasknr
, taskNrId = taskNrToString tasknr
, processNr = processNr
, workflowLabel = workflowLabel
, taskPriority = NormalPriority
......@@ -192,7 +192,7 @@ displayAsTab :: DisplaySubTasks
displayAsTab = displayAsTab`
where
displayAsTab` label tasknr htmls
= CondAnd label nrSubTasks [({ caTaskNrId = toStringTaskNr [0,i:tasknr]
= CondAnd label nrSubTasks [({ caTaskNrId = taskNrToString [0,i:tasknr]
, caIndex = nrSubTasks
, caStatus = finished
},html) \\ (finished,html) <- htmls & i <- [0..]
......
definition module TSt
/**
* This module defines the core task state data structure
* which is transformed by tasks
* This module defines the core task state data structure which is transformed by tasks.
*
* Additionally it provides utility functions to manipulate the state.
*/
import StdMaybe
import Time, Html
......@@ -46,7 +47,7 @@ import HSt
| DivCode !String !HtmlTree // code that should be labeled with a div, used for Ajax and Client technology
| TaskTrace TraceInfo !HtmlTree // trace information used for displaying the task tree
:: TraceInfo = { trTaskNr :: !TaskNrId // tasknr
:: TraceInfo = { trTaskNr :: !String // tasknr
, trTaskName :: !String // name of the combinator
, trActivated :: !Bool // is the task finshed or not
, trUserId :: !UserId // who is performing the task (can also be determined from the contect)
......@@ -56,7 +57,7 @@ import HSt
// Task meta information
:: CondAndDescription
= { caTaskNrId :: !TaskNrId // tasknr as string
= { caTaskNrId :: !String // tasknr as string
, caIndex :: !Int // index of and task
, caStatus :: !Bool // is sub task finished
}
......@@ -64,7 +65,7 @@ import HSt
:: TaskDescription
= { delegatorId :: !UserId // id of the work delegator
, taskWorkerId :: !UserId // id of worker on the task
, taskNrId :: !TaskNrId // tasknr as string
, taskNrId :: !String // tasknr as string
, processNr :: !ProcessNr // entry in process table
, workflowLabel :: !WorkflowLabel // name of the workflow
, taskLabel :: !String // name of the task
......@@ -73,18 +74,57 @@ import HSt
, curStatus :: !Bool
}
:: TaskNrId :== String
:: TaskPriority = HighPriority | NormalPriority | LowPriority
//Tasks are packed TSt transition functions
// The task monad
:: Task a = Task !(*TSt -> *(!a,!*TSt))
//Initialization
/**
* Creates an initial task state.
*
* @param The user id of the current user
* @param The default storage location of task states
* @param The default storage location of threads
* @param The iData HSt state for creating editors and doing IO
*
* @return a TSt iTask state
*/
mkTst :: !UserId !Lifespan !Lifespan !*HSt -> *TSt
//Apply a task state transition
/**
* Applies a task to the task state.
*
* @param The task that is applied
* @param The task state
*
* @return The value produced by the task
* @return The modified task state
*/
appTaskTSt :: !(Task a) !*TSt -> (!a,!*TSt)
/**
* Utility function to increment the last segment a task number
*
* @param The original task number
*
* @return The incremented task number
*/
incTaskNr :: !TaskNr -> TaskNr
/**
* Converts a task number to its dotted string representation
*
* @param The task number as integer list
*
* @return The formatted task number
*/
taskNrToString :: !TaskNr -> String
/**
* Parses a formatted task number to its integer list representation
*
* @param The task nr as formatted string
*
* @return The task nr as integer list
*/
taskNrFromString :: !String -> TaskNr
\ No newline at end of file
......@@ -32,4 +32,30 @@ initialOptions location
}
appTaskTSt :: !(Task a) !*TSt -> (!a,!*TSt)
appTaskTSt (Task fn) tst = fn tst
\ No newline at end of file
appTaskTSt (Task fn) tst = fn tst
incTaskNr :: !TaskNr -> TaskNr
incTaskNr [] = [0]
incTaskNr [i:is] = [i+1:is]
taskNrToString :: !TaskNr -> String
taskNrToString [] = ""
taskNrToString [i] = toString i
taskNrToString [i:is] = taskNrToString is <+++ "." <+++ toString i
taskNrFromString :: !String -> TaskNr
taskNrFromString "" = []
taskNrFromString string = reverse (parseTaskNr` [char \\ char <-: string])
where
parseTaskNr` :: ![Char] -> TaskNr
parseTaskNr` [] = []
parseTaskNr` list
# (front,end) = span (\c -> c <> '.') list
= [toInt (toString front) : parseTaskNr` (stl end)]
toString :: [Char] -> String
toString list = {c \\ c <- list}
stl :: [Char] -> [Char]
stl [] = []
stl xs = tl xs
......@@ -7,11 +7,11 @@ import iTasksTypes
instance == TaskStatus
determineTaskList :: !UserId !HtmlTree -> [([Bool],Bool,TaskDescription)]
determineTaskForTab :: !UserId !TaskNrId !HtmlTree -> (!TaskStatus,![HtmlTag],![InputId])
determineTaskForTab :: !UserId !String !HtmlTree -> (!TaskStatus,![HtmlTag],![InputId])
// Showing Trace from Task Tree
getFullTraceFromTaskTree:: !HtmlTree -> HtmlTag
getTraceFromTaskTree :: !UserId !TaskNrId !HtmlTree -> HtmlTag
getTraceFromTaskTree :: !UserId !String !HtmlTree -> HtmlTag
......@@ -75,7 +75,7 @@ defaultTaskDescriptor
, curStatus = True
}
determineTaskForTab :: !UserId !TaskNrId !HtmlTree -> (!TaskStatus,![HtmlTag],![InputId])
determineTaskForTab :: !UserId !String !HtmlTree -> (!TaskStatus,![HtmlTag],![InputId])
determineTaskForTab thisuser thistaskid tree
= case determineMyTaskTree thisuser thistaskid tree of //Find the subtree by task id
Nothing
......@@ -144,7 +144,7 @@ where
// Search for that part of the task tree which is applicable for a given user and a given task
// ******************************************************************************************************
determineMyTaskTree :: !UserId !TaskNrId !HtmlTree -> Maybe HtmlTree
determineMyTaskTree :: !UserId !String !HtmlTree -> Maybe HtmlTree
determineMyTaskTree thisuser thistaskid tree = determineMyTaskTree` thisuser thistaskid tree defaultTaskDescriptor
where
determineMyTaskTree` thisuser thistaskid (BT bdtg inputs) taskDescr
......@@ -192,7 +192,7 @@ where
:: Trace = Trace !(Maybe !TraceInfo) ![Trace] // traceinfo with possibly subprocess
getTraceFromTaskTree :: !UserId !TaskNrId !HtmlTree -> HtmlTag
getTraceFromTaskTree :: !UserId !String !HtmlTree -> HtmlTag
getTraceFromTaskTree userId taskNrId tree
# mbtree = determineMyTaskTree userId taskNrId tree
| isNothing mbtree = Text "Error: Cannot find task tree !"
......@@ -223,7 +223,7 @@ where
insertTraces [i:is] traces = insertTraces is (insertTrace i traces)
insertTrace :: !TraceInfo ![Trace] -> [Trace]
insertTrace info trace = insertTrace` (reverse (parseTaskNr info.trTaskNr)) trace
insertTrace info trace = insertTrace` (reverse (taskNrFromString info.trTaskNr)) trace
where
insertTrace` :: !TaskNr ![Trace] -> [Trace]
insertTrace` [i] traces
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment