Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modified command #21

Merged
merged 8 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tasklite-core/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ data Command
| ListNew
| ListOld
| ListOpen
| ListModified
| ListModifiedOnly
| ListDone
| ListObsolete
| ListDeletable
Expand Down Expand Up @@ -462,6 +464,12 @@ commandParser conf =

<> command "open" (toParserInfo (pure ListOpen)
"List all open tasks by priority desc")

<> command "modified" (toParserInfo (pure ListModified)
"List all tasks by modified UTC desc")

<> command "modifiedonly" (toParserInfo (pure ListModifiedOnly)
"List tasks where modified UTC != creation UTC by modified UTC desc")

-- All tasks due to no later than
-- <> command "yesterday"
Expand Down Expand Up @@ -853,6 +861,8 @@ executeCLiCommand conf now connection cmd =
ListNew -> newTasks conf now connection
ListOld -> listOldTasks conf now connection
ListOpen -> openTasks conf now connection
ListModified -> modifiedTasks conf now connection AllItems
ListModifiedOnly -> modifiedTasks conf now connection ModifiedItemsOnly
ListOverdue -> overdueTasks conf now connection
ListRepeating -> listRepeating conf now connection
ListRecurring -> listRecurring conf now connection
Expand Down
30 changes: 30 additions & 0 deletions tasklite-core/source/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,36 @@ openTasks conf now connection = do
pure $ formatTasks conf now tasks


modifiedTasks
:: Config
-> DateTime
-> Connection
-> ListModifiedFlag
-> IO (Doc AnsiStyle)
modifiedTasks conf now connection listModifiedFlag = do
tasks <- query_ connection $ Query
"select * from `tasks_view` \
\order by `modified_utc` desc"
let
filterModified =
P.filter (\task ->
(removeNSec $ ulidTextToDateTime $ FullTask.ulid task)
/= (parseUtc $ FullTask.modified_utc task))

removeNSec :: Maybe DateTime -> Maybe DateTime
removeNSec mDateTime =
case mDateTime of
Just dateTime -> Just $ dateTime { dtTime = (dtTime dateTime) { todNSec = 0 } }
Nothing -> Nothing

filteredTasks =
case listModifiedFlag of
AllItems -> tasks
ModifiedItemsOnly -> filterModified tasks

pure $ formatTasks conf now filteredTasks


overdueTasks :: Config -> DateTime -> Connection -> IO (Doc AnsiStyle)
overdueTasks conf now connection = do
tasks <- query_ connection $ Query
Expand Down
3 changes: 3 additions & 0 deletions tasklite-core/source/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type TagText = Text
data Filter a = NoFilter | Only a
deriving (Eq, Ord, Show)

data ListModifiedFlag = AllItems | ModifiedItemsOnly
deriving (Eq, Show)


(<++>) :: Doc ann -> Doc ann -> Doc ann
x <++> y =
Expand Down