Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0f09c3d

Browse files
committed
Add several un* commands to erase fields
1 parent 395a8e0 commit 0f09c3d

File tree

2 files changed

+178
-25
lines changed

2 files changed

+178
-25
lines changed

tasklite-core/app/Main.hs

+43-17
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ data Command
125125
-- | Unblocked -- Tasks that are not blocked
126126

127127
{- Unset -}
128+
| UnCloseTasks [IdText]
128129
| UnDueTasks [IdText]
130+
| UnWaitTasks [IdText]
131+
-- | UnWakeTasks [IdText]
132+
| UnRepeatTasks [IdText]
133+
| UnTagTasks [IdText]
134+
| UnNoteTasks [IdText]
135+
| UnPrioTasks [IdText]
136+
| UnMetaTasks [IdText]
129137

130138
{- Misc -}
131139
-- | Demo -- Switch to demo mode
@@ -593,31 +601,41 @@ commandParser conf =
593601
( metavar (T.unpack $ snd unset_sec)
594602
<> commandGroup (T.unpack $ fst unset_sec)
595603

596-
-- <> command "unclose"
597-
-- "Delete closed UTC and delete Obsolete / Done state"
604+
<> command "unclose" (toParserInfo (UnCloseTasks
605+
<$> some (strArgument idsVar))
606+
"Erase closed timestamp and erase Done / Obsolete / Deletable state")
598607

599-
-- <> command "untag"
600-
-- "Delete all tags"
608+
<> command "undue" (toParserInfo (UnDueTasks
609+
<$> some (strArgument idsVar))
610+
"Erase due timestamp for specified tasks")
601611

602-
-- <> command "unnote"
603-
-- "Delete all notes"
612+
<> command "unwait" (toParserInfo (UnWaitTasks
613+
<$> some (strArgument idsVar))
614+
"Erase wait timestamp for specified tasks")
604615

605-
<> command "undue" (toParserInfo (UnDueTasks <$> some (strArgument idsVar))
606-
"Delete due UTC")
616+
-- <> command "unwake" (toParserInfo (UnWakeTasks
617+
-- <$> some (strArgument idsVar))
618+
-- "Erase awake timestamp for specified tasks")
607619

608-
-- <> command "unwait"
609-
-- "Delete wait UTC"
620+
<> command "unrepeat" (toParserInfo (UnRepeatTasks
621+
<$> some (strArgument idsVar))
622+
"Erase repetition duration value for specified tasks")
610623

611-
-- <> command "unprioritize"
612-
-- "Delete priority adjustment"
624+
<> command "untag" (toParserInfo (UnTagTasks
625+
<$> some (strArgument idsVar))
626+
"Erase all tags")
613627

614-
-- <> command "unmeta"
615-
-- "Delete metadata"
616-
)
628+
<> command "unnote" (toParserInfo (UnNoteTasks
629+
<$> some (strArgument idsVar))
630+
"Erase all notes")
617631

618-
<|> subparser ( commandGroup (T.unpack $ fst alias_sec)
632+
<> command "unprio" (toParserInfo (UnPrioTasks
633+
<$> some (strArgument idsVar))
634+
"Erase manual priority adjustment")
619635

620-
<> fold (fmap getCommand nameToAliasList)
636+
<> command "unmeta" (toParserInfo (UnMetaTasks
637+
<$> some (strArgument idsVar))
638+
"Erase metadata")
621639
)
622640

623641
<|> subparser (internal <> fold (fmap getCommand nameToAliasList))
@@ -829,7 +847,15 @@ executeCLiCommand conf now connection cmd =
829847
CountFiltered taskFilter -> countTasks conf connection taskFilter
830848

831849
{- Unset -}
850+
UnCloseTasks ids -> uncloseTasks conf connection ids
832851
UnDueTasks ids -> undueTasks conf connection ids
852+
UnWaitTasks ids -> unwaitTasks conf connection ids
853+
-- UnWakeTasks ids -> unwakeTasks conf connection ids
854+
UnRepeatTasks ids -> unrepeatTasks conf connection ids
855+
UnTagTasks ids -> untagTasks conf connection ids
856+
UnNoteTasks ids -> unnoteTasks conf connection ids
857+
UnPrioTasks ids -> unprioTasks conf connection ids
858+
UnMetaTasks ids -> unmetaTasks conf connection ids
833859

834860
Version -> pure $ pretty versionSlug <> hardline
835861
Help -> pure $ helpText conf

tasklite-core/source/Lib.hs

+135-8
Original file line numberDiff line numberDiff line change
@@ -823,22 +823,149 @@ setDueUtc conf connection datetime ids = do
823823
pure $ vsep docs
824824

825825

826+
getResultMsg :: Doc AnsiStyle -> Task -> Doc AnsiStyle
827+
getResultMsg msg task =
828+
let
829+
TaskUlid idText = primaryKey task
830+
prettyBody = dquotes (pretty $ Task.body task)
831+
prettyId = dquotes (pretty idText)
832+
in
833+
msg <+> "of task" <+> prettyBody <+> "with id" <+> prettyId
834+
835+
836+
uncloseTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
837+
uncloseTasks conf connection ids = do
838+
docs <- forM ids $ \idSubstr -> do
839+
execWithTask conf connection idSubstr $ \task -> do
840+
runBeamSqlite connection $ runUpdate $
841+
update (_tldbTasks taskLiteDb)
842+
(\task_ -> mconcat
843+
[ (Task.closed_utc task_) <-. (val_ Nothing)
844+
, (Task.state task_) <-. (val_ Nothing)
845+
]
846+
)
847+
(\task_ -> primaryKey task_ ==. val_ (primaryKey task))
848+
849+
pure $ getResultMsg "💥 Removed close timestamp and state field" task
850+
851+
pure $ vsep docs
852+
853+
826854
undueTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
827855
undueTasks conf connection ids = do
828856
docs <- forM ids $ \idSubstr -> do
829857
execWithTask conf connection idSubstr $ \task -> do
830-
let
831-
taskUlid@(TaskUlid idText) = primaryKey task
832-
prettyBody = dquotes (pretty $ Task.body task)
833-
prettyId = dquotes (pretty idText)
834-
835858
runBeamSqlite connection $ runUpdate $
836859
update (_tldbTasks taskLiteDb)
837860
(\task_ -> mconcat [(Task.due_utc task_) <-. (val_ Nothing)])
838-
(\task_ -> primaryKey task_ ==. val_ taskUlid)
861+
(\task_ -> primaryKey task_ ==. val_ (primaryKey task))
839862

840-
pure $ "💥 Removed due UTC of task" <+> prettyBody
841-
<+> "with id" <+> prettyId
863+
pure $ getResultMsg "💥 Removed due timestamp" task
864+
865+
pure $ vsep docs
866+
867+
868+
unwaitTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
869+
unwaitTasks conf connection ids = do
870+
docs <- forM ids $ \idSubstr -> do
871+
execWithTask conf connection idSubstr $ \task -> do
872+
runBeamSqlite connection $ runUpdate $
873+
update (_tldbTasks taskLiteDb)
874+
(\task_ -> mconcat
875+
[ (Task.waiting_utc task_) <-. (val_ Nothing)
876+
, (Task.review_utc task_) <-. (val_ Nothing)
877+
]
878+
)
879+
(\task_ -> primaryKey task_ ==. val_ (primaryKey task))
880+
881+
pure $ getResultMsg "💥 Removed waiting and review timestamps" task
882+
883+
pure $ vsep docs
884+
885+
886+
-- TODO:
887+
-- unwakeTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
888+
-- unwakeTasks conf connection ids = do
889+
-- docs <- forM ids $ \idSubstr -> do
890+
-- execWithTask conf connection idSubstr $ \task -> do
891+
-- runBeamSqlite connection $ runUpdate $
892+
-- update (_tldbTasks taskLiteDb)
893+
-- (\task_ -> mconcat [(Task.awake_utc task_) <-. (val_ Nothing)])
894+
-- (\task_ -> primaryKey task_ ==. val_ (primaryKey task))
895+
896+
-- pure $ getResultMsg "💥 Removed awake timestamp" task
897+
898+
-- pure $ vsep docs
899+
900+
901+
unrepeatTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
902+
unrepeatTasks conf connection ids = do
903+
docs <- forM ids $ \idSubstr -> do
904+
execWithTask conf connection idSubstr $ \task -> do
905+
runBeamSqlite connection $ runUpdate $
906+
update (_tldbTasks taskLiteDb)
907+
(\task_ -> mconcat
908+
[(Task.repetition_duration task_) <-. (val_ Nothing)])
909+
(\task_ -> primaryKey task_ ==. val_ (primaryKey task))
910+
911+
pure $ getResultMsg "💥 Removed repetition duration value" task
912+
913+
pure $ vsep docs
914+
915+
916+
untagTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
917+
untagTasks conf connection ids = do
918+
docs <- forM ids $ \idSubstr -> do
919+
execWithTask conf connection idSubstr $ \task -> do
920+
runBeamSqlite connection $ runDelete $ delete
921+
(_tldbTaskToTag taskLiteDb)
922+
(\tag -> TaskToTag.task_ulid tag ==. val_ (primaryKey task))
923+
924+
pure $ getResultMsg "💥 Removed all tags" task
925+
926+
pure $ vsep docs
927+
928+
929+
unnoteTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
930+
unnoteTasks conf connection ids = do
931+
docs <- forM ids $ \idSubstr -> do
932+
execWithTask conf connection idSubstr $ \task -> do
933+
runBeamSqlite connection $ runDelete $ delete
934+
(_tldbTaskToNote taskLiteDb)
935+
(\noteValue ->
936+
TaskToNote.task_ulid noteValue ==. val_ (primaryKey task)
937+
)
938+
939+
pure $ getResultMsg "💥 Removed all notes" task
940+
941+
pure $ vsep docs
942+
943+
944+
unprioTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
945+
unprioTasks conf connection ids = do
946+
docs <- forM ids $ \idSubstr -> do
947+
execWithTask conf connection idSubstr $ \task -> do
948+
runBeamSqlite connection $ runUpdate $
949+
update (_tldbTasks taskLiteDb)
950+
(\task_ -> mconcat
951+
[(Task.priority_adjustment task_) <-. (val_ Nothing)])
952+
(\task_ -> primaryKey task_ ==. val_ (primaryKey task))
953+
954+
pure $ getResultMsg "💥 Removed priority adjustment" task
955+
956+
pure $ vsep docs
957+
958+
959+
unmetaTasks :: Config -> Connection -> [IdText] -> IO (Doc AnsiStyle)
960+
unmetaTasks conf connection ids = do
961+
docs <- forM ids $ \idSubstr -> do
962+
execWithTask conf connection idSubstr $ \task -> do
963+
runBeamSqlite connection $ runUpdate $
964+
update (_tldbTasks taskLiteDb)
965+
(\task_ -> mconcat [(Task.metadata task_) <-. (val_ Nothing)])
966+
(\task_ -> primaryKey task_ ==. val_ (primaryKey task))
967+
968+
pure $ getResultMsg "💥 Removed metadata" task
842969

843970
pure $ vsep docs
844971

0 commit comments

Comments
 (0)