marcusolsson / obsidian-projects

Plain text project planning in Obsidian
Apache License 2.0
1.43k stars 58 forks source link

Support loading Dataview queries from notes within notes #98

Open wenlzhang opened 1 year ago

wenlzhang commented 1 year ago

What would you like to be added?

Currently, one can only define Dataview queries in the project setup window. It would be great if one can load Dataview queries from any note within the vault. For instance, one note that contains such Dataview query can be as follows:

---
title: Dataview query for Obsidian Projects
---

```dataview
table file.ctime as "Created", file.mtime as "Modified"
from ""
where contains(file.name, "Note")


### Why is this needed?

Being able to load Dataview queries from notes makes the Dataview queries reusable for other purposes. For instance, one can view the query results in the corresponding notes. Moreover, it can be easier to edit the Dataview queries if they are loaded from notes, as one can view and edit the corresponding Dataview query results in real time in those notes. Furthermore, if one decide not to use the Projects plugin, those Dataview queries can still be used as long as Dataview is used. 
marcusolsson commented 1 year ago

I'm not sure I understand how you'd use the result of a query in a note. Right now, there's no way of displaying the note content in Projects.

Or are you saying that you'd like to use a dataview query in a note to configure the project?

wenlzhang commented 1 year ago

Or are you saying that you'd like to use a dataview query in a note to configure the project?

Yes, I meant this. Obsidian Projects can load the Dataview query in a note to configure the project.

Right now, there's no way of displaying the note content in Projects.

Regarding this, I meant to say that one can tune the Dataview query in a note and see the query result within that note. This point is not related to displaying note content within Obsidian Projects.

marcusolsson commented 1 year ago

one can tune the Dataview query in a note and see the query result

Out of curiosity, is the reason you'd want this feature so that you could preview the result while building the query? For example, if Projects had a way to preview the results while writing the query, would that also work for you?

wenlzhang commented 1 year ago

Out of curiosity, is the reason you'd want this feature so that you could preview the result while building the query?

Yes, this is one of the reasons for requesting this feature. The second reason is that I can also see the Dataview query results directly within the note, independent of Obsidian Projects. The third reason is that the Dataview query would still work even if I do not use Obsidian Projects in the future.

marcusolsson commented 1 year ago

Thank you for clarifying 🙏

I can see the need, though I'm not sure what the solution is yet. Another alternative could be to add a block reference to a dataview code block for example.

wenlzhang commented 1 year ago

Another alternative could be to add a block reference to a dataview code block for example.

Or, could the following work? In the note that has the Dataview query for Obsidian Projects, there is only one Dataview code block. In this note, there can also be front matter, but there can be no other content. Would this make the implementation easier?

marcusolsson commented 1 year ago

Implementation-wise, I don't think it would be complicated. I'm more concerned with the usability. Selecting a note to use as a dataview query would likely require docs to explain the format, what's allowed and what's not. Before taking this on, I'd like to explore solutions that minimize configuration and user error.

I've put a low priority on this for now, but if more people are interested in this, I'll bump it up!

wenlzhang commented 1 year ago

Thanks for the clarifications!

For example, if Projects had a way to preview the results while writing the query, would that also work for you?

Considering this, maybe another solution would be to consider this feature. In addition, one can allow the user to select whether to store/update the configured Dataview query (in the project configuration window) in a chosen note. This way, the user would not need to configure the Dataview query in the corresponding note, but the note just serves as a backup for the query in the configuration pane.

keerah commented 11 months ago

Very interested in dataview queries as well. Great Idea!