Skip to content

Commit

Permalink
Add command "reviewin" to set review date in x days
Browse files Browse the repository at this point in the history
Fix: Don't change review timestamp if task is already closed
  • Loading branch information
ad-si committed Mar 18, 2020
1 parent 0daf8f6 commit b05c81a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
17 changes: 14 additions & 3 deletions tasklite-core/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ data Command
| WaitTasks [IdText]
| WaitFor Duration [IdText]
| ReviewTasks [IdText]
| ReviewTasksIn Duration [IdText]
| DoTasks [IdText]
| DoOneTask IdText (Maybe [Text])
| EndTasks [IdText]
Expand Down Expand Up @@ -273,11 +274,18 @@ commandParser conf =
(metavar "NUM_OF_DAYS" <> help "Duration in days \
\(supports fractional values)")
<*> some (strArgument idsVar))
"Wait specified number of days until it's ready for review")
"Wait x days until it's ready for review")

<> command "review" (toParserInfo (ReviewTasks
<$> some (strArgument idsVar))
"Finish review of task and set new review date in 3 days")
"Finish review and set new review date in 3 days")

<> command "reviewin" (toParserInfo (ReviewTasksIn
<$> argument (maybeReader parseDurationInDays)
(metavar "NUM_OF_DAYS" <> help "Duration in days \
\(supports fractional values)")
<*> some (strArgument idsVar))
"Finish review and set new review date in x days")

<> command "do" (toParserInfo (DoOneTask
<$> strArgument idsVar
Expand Down Expand Up @@ -794,6 +802,8 @@ executeCLiCommand conf now connection cmd =
prettyUlid ulid = pretty $ fmap
(T.pack . timePrint (toFormat ("YYYY-MM-DD H:MI:S.ms" :: [Char])))
(ulidTextToDateTime ulid)
days3 = mempty {durationHours = 72}

in case cmd of
ListAll -> listAll conf now connection
ListHead -> headTasks conf now connection
Expand Down Expand Up @@ -833,7 +843,8 @@ executeCLiCommand conf now connection cmd =
ReadyOn datetime ids -> setReadyUtc conf connection datetime ids
WaitTasks ids -> waitTasks conf connection ids
WaitFor duration ids -> waitFor conf connection duration ids
ReviewTasks ids -> reviewTasks conf connection ids
ReviewTasks ids -> reviewTasksIn conf connection days3 ids
ReviewTasksIn days ids -> reviewTasksIn conf connection days ids
DoTasks ids -> doTasks conf connection Nothing ids
DoOneTask id noteWords -> doTasks conf connection noteWords [id]
EndTasks ids -> endTasks conf connection ids
Expand Down
32 changes: 17 additions & 15 deletions tasklite-core/source/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -375,31 +375,33 @@ waitTasks conf connection =
waitFor conf connection $ mempty { durationHours = 72 }


reviewTasks :: Config -> Connection -> [Text] -> IO (Doc AnsiStyle)
reviewTasks conf connection ids = do
reviewTasksIn :: Config -> Connection
-> Duration -> [Text] -> IO (Doc AnsiStyle)
reviewTasksIn conf connection days ids = do
docs <- forM ids $ \idSubstr -> do
execWithTask conf connection idSubstr $ \task -> do
now <- timeCurrentP
let
taskUlid@(TaskUlid idText) = primaryKey task
threeDays = (pack . timePrint (utcFormat conf))
(now `timeAdd` mempty { durationHours = 72 })
xDays = (pack . timePrint (utcFormat conf)) (now `timeAdd` days)
prettyBody = dquotes (pretty $ Task.body task)
prettyId = dquotes (pretty idText)
warningStart = "⚠️ Task" <+> prettyBody <+> "with id" <+> prettyId

runBeamSqlite connection $ runUpdate $
update (_tldbTasks taskLiteDb)
(\theTask -> mconcat
[(Task.review_utc theTask) <-. val_ (Just threeDays)])
(\theTask -> primaryKey theTask ==. val_ taskUlid)
if Task.closed_utc task /= Nothing
then pure $ warningStart <+> "is already closed"
else do
runBeamSqlite connection $ runUpdate $
update (_tldbTasks taskLiteDb)
(\theTask -> (Task.review_utc theTask) <-. val_ (Just xDays))
(\theTask -> primaryKey theTask ==. val_ taskUlid)

numOfChanges <- changes connection
numOfChanges <- changes connection

pure $ if numOfChanges == 0
then "⚠️ Task" <+> prettyBody <+> "with id" <+> prettyId
<+> "could not be reviewed"
else "🔎 Finished review for task" <+> prettyBody
<+> "with id" <+> prettyId
pure $
if numOfChanges == 0
then warningStart <+> "could not be reviewed"
else getResultMsg "🔎 Finished review" task

pure $ vsep docs

Expand Down

0 comments on commit b05c81a

Please sign in to comment.