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

Feature Request: Tasks should be filterable on the completed state #46

Closed
strich opened this issue Mar 19, 2021 · 25 comments
Closed

Feature Request: Tasks should be filterable on the completed state #46

strich opened this issue Mar 19, 2021 · 25 comments
Assignees
Labels
feature-request New feature or request.
Projects
Milestone

Comments

@strich
Copy link

strich commented Mar 19, 2021

A common scenario (if not the most common) when gathering tasks using dataview is likely to be able to pull all tasks that remain incomplete. It would be ideal to be able to do something like the following to filter out tasks that aren't complete:

task from ""
where !task.complete
sort file.day desc
@blacksmithgu blacksmithgu added the feature-request New feature or request. label Mar 20, 2021
@blacksmithgu blacksmithgu self-assigned this Mar 20, 2021
@blacksmithgu
Copy link
Owner

This has been on my TODO list forever since it's conceptually simple, my task query implementation is just a hack. Will improve.

@channingwalton
Copy link

This would be awesome. Is there a workaround in the meantime?

@Zyrohex
Copy link

Zyrohex commented Apr 28, 2021

This would be a great addition! Hope to see it implemented soon.

@blacksmithgu
Copy link
Owner

I have good news and bad news. The good news is this is now possible; the bad news is you need to write a tiny bit of javascript for it:

```dataviewjs
dv.taskList(dv.pages("#projects").file.tasks.where(t => !t.completed));
```

@channingwalton
Copy link

cool, how can I search in every note in my vault?

@clotodex
Copy link

clotodex commented May 8, 2021

cool, how can I search in every note in my vault?

With "". dv.pages works like sources in dataview. You need to quote it though - so '""' (single-tick, quote, quote, single-tick)

dv.taskList(dv.pages('""').file.tasks.where(t => !t.completed));

@breach78
Copy link

breach78 commented Jun 1, 2021

I have good news and bad news. The good news is this is now possible; the bad news is you need to write a tiny bit of javascript for it:

```dataviewjs
dv.taskList(dv.pages("#projects").file.tasks.where(t => !t.completed));

Thank you!
Is it possible to list it in modified order?

@wenlzhang
Copy link

Is it possible to sort the tasks based on file name?

@danielhauck
Copy link

danielhauck commented Aug 11, 2021

You mean for tasks that are appearing in a file? Like give me all from "Project X"?

```dataviewjs
const targetPage = "Project X"

 

dv.taskList(
    dv.array(
        dv.page(targetPage).file.tasks
    ).where(t => !t.completed)
)
```

You just need to 'cast' it as a dataview array.

@wenlzhang
Copy link

Thanks for the prompt reply! @danielhauck Sorry for not being clear about what I am trying to achieve. Now I will elaborate it as follows.

First, I may query all tasks from files within a folder with something like:

dv.taskList(dv.pages('"Daily note"')
	.file.tasks
	.where(t => !t.completed)
	)

This lists all uncompleted tasks from files within the folder Daily note. However, I am not sure how are the task files sorted. Therefore, I would like the tasks to be sorted based on the file name where they come from, e.g. Note A, Note B, Note C, etc. Each of such a note/file consists of a series of uncompleted tasks.

I tried the following options (without knowing if the syntax is correct or not :-(, however), but neither of them worked for me.

dv.taskList(dv.pages('"120-Daily note"')
	.file.tasks
	.where(t => !t.completed)
	.sort(p => p.file.name, 'asc')
	)
dv.taskList(dv.pages('"120-Daily note"')
	.file.tasks
	.where(t => !t.completed)
	.sort(t => t.file.name, 'asc')
	)

Of course, it would be great if the tasks from individual files/notes can also be somehow sorted, e.g., based on task description.

I also tried your code, and it gives the following error message:

const targetPage = "Daily note"

dv.taskList(
    dv.array(
        dv.page(targetPage).file.tasks
    ).where(t => !t.completed)
)
Evaluation Error: TypeError: Cannot read property 'file' of undefined
    at eval (eval at <anonymous> (eval at <anonymous> (app://obsidian.md/app.js:1:1212458)), <anonymous>:5:28)
    at DataviewInlineApi.eval (eval at <anonymous> (app://obsidian.md/app.js:1:1212458), <anonymous>:12129:33)
    at evalInContext (eval at <anonymous> (app://obsidian.md/app.js:1:1212458), <anonymous>:12129:49)
    at DataviewJSRenderer.eval (eval at <anonymous> (app://obsidian.md/app.js:1:1212458), <anonymous>:12591:17)
    at Generator.next (<anonymous>)
    at eval (eval at <anonymous> (app://obsidian.md/app.js:1:1212458), <anonymous>:26:71)
    at new Promise (<anonymous>)
    at __awaiter (eval at <anonymous> (app://obsidian.md/app.js:1:1212458), <anonymous>:22:12)
    at DataviewJSRenderer.render (eval at <anonymous> (app://obsidian.md/app.js:1:1212458), <anonymous>:12583:16)
    at DataviewJSRenderer.eval (eval at <anonymous> (app://obsidian.md/app.js:1:1212458), <anonymous>:12578:28)

@blacksmithgu
Copy link
Owner

Ah, this is a short-coming of the dv.taskList() implementation; I need to add some configuration to be able to decide how you sort tasks and files. @wenlzhang Would you mind filing an issue with the contents of your comment for tracking?

@wenlzhang
Copy link

That's great news! Looking forward to that! @blacksmithgu This feature request can be found in the following issue:
#407

@rickybright
Copy link

Is there a way that instead of telling it to look at a file with dv.pages I can have it look at all the files in a folder?

@blacksmithgu
Copy link
Owner

You still use dv.pages, just providing the path to the folder: dv.pages('"path/to/folder/"').

@rickybright
Copy link

Ah, I was just using dv.pages("x/y/z") instead of dv.pages('"x/y/z"').

@sheeley sheeley added this to To do in Tasks Aug 25, 2021
@sheeley sheeley moved this from To do to In progress in Tasks Aug 25, 2021
@blacksmithgu blacksmithgu added this to the 0.4.6 milestone Aug 25, 2021
@blacksmithgu blacksmithgu moved this from In progress to Done in Tasks Aug 25, 2021
@blacksmithgu
Copy link
Owner

Yay, tasks can now be filtered on completed!

TASK WHERE !completed

You can also do a fair bit other stuff with them, like using the text property (which contains their text), or subtasks (which contains a list of subtasks), and so on!

@blacksmithgu
Copy link
Owner

Thanks for @sheeley for implementing this functionality.

@uwidev
Copy link

uwidev commented Sep 19, 2021

Does this functionality extend to DataView Table queries? I'm trying to count all completed tasks onto a table as a proof of concept. I later want to count completed completed tasks per folder. For some reason I can't get any tasks to query.

Here's my query

TABLE length(rows) as "Count Completed Tasks"
FROM "Test"
WHERE completed
Flatten file.tasks
GROUP BY file.folder

Running it barebones and just trying to query completed tasks without fancy groupings doesn't yield any results either. Running the query as a Task rather than a Table works, however.

This is how my notes are set up, in their own folders as follows.
image

@sheeley
Copy link
Contributor

sheeley commented Sep 19, 2021

The task list and table depend upon different implementations internally. I could see this being interesting.

@blacksmithgu think there should be a task table?

@blacksmithgu
Copy link
Owner

@blongty @sheeley The correct move here is to (1) allow FROM statements to select tasks instead of files, and (2) implement task renderering support so that they work automatically in both list views and table views.

This is something @sheeley can look into in the short-medium term if he has time / interest.

@sheeley
Copy link
Contributor

sheeley commented Sep 21, 2021

@blacksmithgu happy to. Thoughts on the syntax?

  • task table foo, bar from ...
  • table foo, bar as task from
  • table foo, bar from tasks

And for the functionality, would you expect a single task per row? Or would it be possible to render a task per cell? I could see value in the latter.

@blacksmithgu
Copy link
Owner

For the syntax, I'm thinking TABLE foo, bar FROM TASKS <source query>; this particular syntax is mainly because we can extend it easily to support sections and other metadata (FROM SECTIONS ...).

I think the default would be one task per row, allowing "task lists" via a GROUP BY.

@acetuk
Copy link

acetuk commented Jan 11, 2022

Does this functionality extend to DataView Table queries? I'm trying to count all completed tasks onto a table as a proof of concept. I later want to count completed completed tasks per folder. For some reason I can't get any tasks to query.

Here's my query

TABLE length(rows) as "Count Completed Tasks"
FROM "Test"
WHERE completed
Flatten file.tasks
GROUP BY file.folder

Running it barebones and just trying to query completed tasks without fancy groupings doesn't yield any results either. Running the query as a Task rather than a Table works, however.

This is how my notes are set up, in their own folders as follows. image

Did you find a way to count the tasks? I am trying to do the same thing in a standard dataview query where I want to report the number of open tasks and potentially exclude results returned from pages that have no tasks.

@KaynaL-MT
Copy link

this also worked for me:

TASK
WHERE task != completed

@martijnvangils
Copy link

task where !completed works as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request.
Projects
Tasks
Done
Development

No branches or pull requests