mProjectsCode / obsidian-meta-bind-plugin

A plugin for Obsidian to make your notes interactive with inline input fields, metadata displays, and buttons.
https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/
GNU General Public License v3.0
488 stars 40 forks source link

The ability to limit optionQuery results based on frontmatter data #200

Open Davve37 opened 8 months ago

Davve37 commented 8 months ago

Is your Feature Request Related to a Problem?

No response

Describe the Feature you'd Like

Currently optionQuery() only takes data sources input to limit the alternatives, but I need/want to specify notes more specifically, and would like to be able to restrict the options on frontmatter/property data as well.

Additional Context

No response

mProjectsCode commented 6 months ago

The current results are generated with dataview, so this would be a breaking change.

LynetteCullens commented 2 months ago

The current results are generated with dataview, so this would be a breaking change.

Can you just extend the dataview input/return to include the .where attribute?

mProjectsCode commented 2 months ago

I am not sure I get what you mean. Could you elaborate?

LynetteCullens commented 2 months ago

I am not sure I get what you mean. Could you elaborate?

optionQuery("Glossary") is equivalent to dv.pages('"Glossary"').

I am asking if the .where can be used in addition to the dv.pages argument. Like this: dv.pages('"Glossary"').where(p => p.fileClass == 'Dimensions');

mProjectsCode commented 2 months ago

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/4dc698adac1563765bb429d4454e12f13e87c4d2/packages/obsidian/src/modals/SuggesterModalHelper.ts#L46C55-L46C108

That could actually work, the only downside is that this would require users to write JS expressions.

LynetteCullens commented 2 months ago

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/4dc698adac1563765bb429d4454e12f13e87c4d2/packages/obsidian/src/modals/SuggesterModalHelper.ts#L46C55-L46C108

That could actually work, the only downside is that this would require users to write JS expressions.

The where works the same in datviewjs as it does in normal DQL, but DQL does have less words. The query would be: FROM "Glossary" Where contains(fileClass, "Dimensions")

mProjectsCode commented 2 months ago

The where works the same in datviewjs as it does in normal DQL, but DQL does have less words.

https://github.com/blacksmithgu/obsidian-dataview/blob/3c29f7cb5bb76f62b5342b88050e054a7272667f/src/api/data-array.ts#L27

Are you sure about that?

LynetteCullens commented 2 months ago

The where works the same in datviewjs as it does in normal DQL, but DQL does have less words.

https://github.com/blacksmithgu/obsidian-dataview/blob/3c29f7cb5bb76f62b5342b88050e054a7272667f/src/api/data-array.ts#L27

Are you sure about that?

If you need an example....

Query One

Dataview

Table without ID
file.link, file.frontmatter.mathLink
From "Glossary"
Where contains(fileClass, "Dimensions")

image

Dataviewjs

const rows = dv.pages('"Glossary"').where(p => p.fileClass == 'Dimensions').map(p => [
        p.file.link, 
        p.file.frontmatter.mathLink]);
dv.table(["Link", "mathLink"], rows);

image

Query Two

Dataview

Table without ID
file.link, file.frontmatter.mathLink
From "Glossary"
Where !contains(fileClass, "Dimensions")
Limit 10

image

Dataviewjs

const rows = dv.pages('"Glossary"').where(p => p.fileClass !== 'Dimensions').map(p => [
        p.file.link, 
        p.file.frontmatter.mathLink]).limit(10);
dv.table(["Link", "mathLink"], rows);

image