summaryrefslogtreecommitdiff
path: root/Omni
diff options
context:
space:
mode:
Diffstat (limited to 'Omni')
-rw-r--r--Omni/Task.hs7
-rw-r--r--Omni/Task/Core.hs12
2 files changed, 11 insertions, 8 deletions
diff --git a/Omni/Task.hs b/Omni/Task.hs
index 10136c9..9b89a1d 100644
--- a/Omni/Task.hs
+++ b/Omni/Task.hs
@@ -318,7 +318,12 @@ unitTests =
child1 <- createTask "Child 1" WorkTask (Just (taskId parent)) Nothing P2 []
child2 <- createTask "Child 2" WorkTask (Just (taskId parent)) Nothing P2 []
taskId child1 Test.@?= taskId parent <> ".1"
- taskId child2 Test.@?= taskId parent <> ".2"
+ taskId child2 Test.@?= taskId parent <> ".2",
+ Test.unit "grandchild task gets sequential ID" <| do
+ parent <- createTask "Grandparent" Epic Nothing Nothing P2 []
+ child <- createTask "Parent" Epic (Just (taskId parent)) Nothing P2 []
+ grandchild <- createTask "Grandchild" WorkTask (Just (taskId child)) Nothing P2 []
+ taskId grandchild Test.@?= taskId parent <> ".1.1"
]
-- | Test CLI argument parsing to ensure docopt string matches actual usage
diff --git a/Omni/Task/Core.hs b/Omni/Task/Core.hs
index 798f8fe..31c0981 100644
--- a/Omni/Task/Core.hs
+++ b/Omni/Task/Core.hs
@@ -117,7 +117,7 @@ generateChildId parentId = do
tasks <- loadTasks
let children = filter (\t -> taskParent t == Just parentId) tasks
-- Find the max suffix
- suffixes = mapMaybe (\t -> getSuffix parentId (taskId t)) children
+ suffixes = mapMaybe (getSuffix parentId <. taskId) children
nextSuffix = case suffixes of
[] -> 1
s -> maximum s + 1
@@ -127,10 +127,10 @@ getSuffix :: Text -> Text -> Maybe Int
getSuffix parent childId =
if parent `T.isPrefixOf` childId && T.length childId > T.length parent
then
- let rest = T.drop (T.length parent) childId
+ let rest = T.drop (T.length parent) childId
in if T.head rest == '.'
- then readMaybe (T.unpack (T.tail rest))
- else Nothing
+ then readMaybe (T.unpack (T.tail rest))
+ else Nothing
else Nothing
-- Convert number to base62 (0-9, a-z, A-Z)
@@ -214,9 +214,7 @@ saveTask task = do
-- Create a new task
createTask :: Text -> TaskType -> Maybe Text -> Maybe Text -> Priority -> [Dependency] -> IO Task
createTask title taskType parent namespace priority deps = do
- tid <- case parent of
- Nothing -> generateId
- Just pid -> generateChildId pid
+ tid <- maybe generateId generateChildId parent
now <- getCurrentTime
let task =
Task