Skip to content

Commit

Permalink
Don't show "successful removal" message when field wasn't set
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed May 14, 2024
1 parent 2b5a0e1 commit 7c2160d
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 29 deletions.
131 changes: 105 additions & 26 deletions tasklite-core/source/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ reviewTasksIn conf connection duration ids = do
pure $
if numOfChanges == 0
then warningStart <+> "could not be reviewed"
else getResultMsg "🔎 Finished review" task
else getResultMsg task "🔎 Finished review"

pure $ vsep docs

Expand Down Expand Up @@ -1689,7 +1689,7 @@ deleteTag conf connection tag ids = do
<+> dquotes (pretty tag)
<+> "is not set for task"
<+> dquotes (pretty task.ulid)
else getResultMsg ("💥 Removed tag \"" <> pretty tag <> "\"") task
else getResultMsg task ("💥 Removed tag \"" <> pretty tag <> "\"")

pure $ vsep docs

Expand Down Expand Up @@ -1792,15 +1792,25 @@ setDueUtc conf connection datetime ids = do
pure $ vsep docs


getResultMsg :: Doc AnsiStyle -> Task -> Doc AnsiStyle
getResultMsg msg task = do
getResultMsg :: Task -> Doc AnsiStyle -> Doc AnsiStyle
getResultMsg task msg = do
let
prettyBody = dquotes $ pretty task.body
prettyId = dquotes $ pretty task.ulid

msg <+> "of task" <+> prettyBody <+> "with id" <+> prettyId


getWarnMsg :: Task -> Doc AnsiStyle -> Doc AnsiStyle
getWarnMsg task msg = do
let
prettyBody = dquotes $ pretty task.body
prettyId = dquotes $ pretty task.ulid

annotate (color Yellow) $
"⚠️ Task" <+> prettyBody <+> "with id" <+> prettyId <+> msg


uncloseTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
uncloseTasks conf connection ids = do
docs <- forM ids $ \idSubstr -> do
Expand All @@ -1812,11 +1822,18 @@ uncloseTasks conf connection ids = do
SET
closed_utc = NULL,
state = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
closed_utc IS NOT NULL AND
state IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed close timestamp and state field" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "is still open"
else getResultMsg task "💥 Removed close timestamp and state field"

pure $ vsep docs

Expand All @@ -1830,11 +1847,17 @@ undueTasks conf connection ids = do
[sql|
UPDATE tasks
SET due_utc = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
due_utc IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed due timestamp" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have a due timestamp"
else getResultMsg task "💥 Removed due timestamp"

pure $ vsep docs

Expand All @@ -1848,11 +1871,17 @@ unwaitTasks conf connection ids = do
[sql|
UPDATE tasks
SET waiting_utc = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
waiting_utc IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed waiting and review timestamps" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have a waiting timestamp"
else getResultMsg task "💥 Removed waiting and review timestamps"

pure $ vsep docs

Expand All @@ -1866,11 +1895,17 @@ unwakeTasks conf connection ids = do
[sql|
UPDATE tasks
SET awake_utc = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
awake_utc IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed awake timestamp" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have an awake timestamp"
else getResultMsg task "💥 Removed awake timestamp"

pure $ vsep docs

Expand All @@ -1884,11 +1919,17 @@ unreadyTasks conf connection ids = do
[sql|
UPDATE tasks
SET ready_utc = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
ready_utc IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed ready timestamp" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have a ready timestamp"
else getResultMsg task "💥 Removed ready timestamp"

pure $ vsep docs

Expand All @@ -1902,11 +1943,17 @@ unreviewTasks conf connection ids = do
[sql|
UPDATE tasks
SET review_utc = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
review_utc IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed review timestamp" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have a review timestamp"
else getResultMsg task "💥 Removed review timestamp"

pure $ vsep docs

Expand All @@ -1920,11 +1967,17 @@ unrepeatTasks conf connection ids = do
[sql|
UPDATE tasks
SET repetition_duration = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
repetition_duration IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed repetition duration" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have a repetition duration"
else getResultMsg task "💥 Removed repetition duration"

pure $ vsep docs

Expand All @@ -1938,11 +1991,17 @@ unrecurTasks conf connection ids = do
[sql|
UPDATE tasks
SET recurrence_duration = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
recurrence_duration IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed recurrence duration" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have a recurrence duration"
else getResultMsg task "💥 Removed recurrence duration"

pure $ vsep docs

Expand All @@ -1959,7 +2018,11 @@ untagTasks conf connection ids = do
|]
[":task_ulid" := task.ulid]

pure $ getResultMsg "💥 Removed all tags" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have any tags"
else getResultMsg task "💥 Removed all tags"

pure $ vsep docs

Expand All @@ -1976,7 +2039,11 @@ unnoteTasks conf connection ids = do
|]
[":task_ulid" := task.ulid]

pure $ getResultMsg "💥 Deleted all notes" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have any notes"
else getResultMsg task "💥 Deleted all notes"

pure $ vsep docs

Expand All @@ -1990,11 +2057,17 @@ unprioTasks conf connection ids = do
[sql|
UPDATE tasks
SET priority_adjustment = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
priority_adjustment IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed priority adjustment" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have a priority adjustment"
else getResultMsg task "💥 Removed priority adjustment"

pure $ vsep docs

Expand All @@ -2008,11 +2081,17 @@ unmetaTasks conf connection ids = do
[sql|
UPDATE tasks
SET metadata = NULL
WHERE ulid == :ulid
WHERE
ulid == :ulid AND
metadata IS NOT NULL
|]
[":ulid" := task.ulid]

pure $ getResultMsg "💥 Removed metadata" task
numOfChanges <- changes connection
pure $
if numOfChanges == 0
then getWarnMsg task "does not have any metadata"
else getResultMsg task "💥 Removed metadata"

pure $ vsep docs

Expand Down
8 changes: 5 additions & 3 deletions tasklite-core/test/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ spec = do
withMemoryDb defaultConfig $ \memConn -> do
Lib.insertRecord "tasks" memConn sampleTask
let tags = [0 .. 9] <&> \(i :: P.Int) -> "tag-" <> P.show i
warnings <- Lib.insertTags memConn Nothing sampleTask tags
P.show warnings `shouldBe` T.empty
Lib.insertNotes memConn Nothing sampleTask sampleNotes
tagWarnings <- Lib.insertTags memConn Nothing sampleTask tags
P.show tagWarnings `shouldBe` T.empty

noteWarnings <- Lib.insertNotes memConn Nothing sampleTask sampleNotes
P.show noteWarnings `shouldBe` T.empty

taskYaml <- taskToEditableYaml memConn sampleTask
let
Expand Down

0 comments on commit 7c2160d

Please sign in to comment.