Skip to content

Commit bad8939

Browse files
authored
Merge pull request #3320 from obsidian-tasks-group/docs-query-file-defaults
docs: Major enhancements to Query File Defaults docs
2 parents e305196 + f6d6a99 commit bad8939

27 files changed

+517
-59
lines changed

docs/.obsidian/graph.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"collapse-filter": false,
3-
"search": "-path:_meta -file:README",
3+
"search": "-path:_meta -file:README -file:CHANGELOG -file:About -file:\"Quick Reference\" -file:\"Known Limitations\"",
44
"showTags": false,
55
"showAttachments": false,
66
"hideUnresolved": false,
@@ -50,16 +50,16 @@
5050
}
5151
}
5252
],
53-
"collapse-display": true,
54-
"showArrow": false,
55-
"textFadeMultiplier": 0,
56-
"nodeSizeMultiplier": 1,
53+
"collapse-display": false,
54+
"showArrow": true,
55+
"textFadeMultiplier": -3,
56+
"nodeSizeMultiplier": 1.54097073518915,
5757
"lineSizeMultiplier": 1,
5858
"collapse-forces": false,
5959
"centerStrength": 0.518713248970312,
6060
"repelStrength": 16.8733723958333,
6161
"linkStrength": 1,
6262
"linkDistance": 319,
63-
"scale": 1.3626171834729273,
63+
"scale": 0.27373780164375944,
6464
"close": false
6565
}

docs/How To/About How Tos.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ These How-to guides take you through the steps required to solve real-world prob
2626
- [[How to style backlinks]]
2727
- [[How to style buttons]]
2828
- [[Show tasks in a calendar]]
29+
30+
## Advanced Techniques
31+
32+
- [[Make a query user interface]]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
publish: true
3+
---
4+
5+
# How to make a query user interface
6+
7+
<span class="related-pages">#plugin/meta-bind</span>
8+
9+
## Meta Bind Tasks User Interface to Query File Defaults
10+
11+
> [!released]
12+
> Query File Defaults were introduced in Tasks X.Y.Z.
13+
14+
The [[Meta Bind Plugin]] allows Obsidian users to make their notes interactive with inline input fields, metadata displays, and buttons.
15+
16+
We can combine:
17+
18+
1. The Tasks plugin's [[Query File Defaults]] facility, based on specific properties named `TQ_*`,
19+
2. The Meta Bind plugin's ability to create widgets to modify note properties.
20+
21+
... to create a User Interface to easily adjust your Tasks searches, that can:
22+
23+
- show and hide each of the task properties,
24+
- enable or disable other search features, such as nested tasks, short mode, backlink and buttons,
25+
- and allow arbitrary extra instructions to be added:
26+
27+
![Meta Bind widgets to edit Query File Defaults](../images/query-file-defaults-meta-bind-controls.png)
28+
<span class="caption">Meta Bind widgets to edit Query File Defaults</span>
29+
30+
## How to set it up
31+
32+
Follow these steps, which assume you have already [turned off Obsidian's Restricted mode](https://help.obsidian.md/Extending+Obsidian/Plugin+security):
33+
34+
1. Install and enable the [Meta Bind](https://obsidian.md/plugins?search=Meta%20Bind) plugin.
35+
2. Copy the Markdown code-block below.
36+
3. Paste the Markdown in to a note in Obsidian that has one or more Tasks searches.
37+
4. Switch to Live Preview or Reading modes, to see the widgets.
38+
5. After experimenting, delete any labels and widgets that you do not need.
39+
40+
<!-- snippet: DocsSamplesForDefaults.test.DocsSamplesForDefaults_meta-bind-widgets-snippet.approved.md -->
41+
```md
42+
short mode: `INPUT[toggle:TQ_short_mode]`
43+
tree: `INPUT[toggle:TQ_show_tree]`
44+
tags: `INPUT[toggle:TQ_show_tags]`
45+
id: `INPUT[toggle:TQ_show_id]` depends on: `INPUT[toggle:TQ_show_depends_on]`
46+
priority: `INPUT[toggle:TQ_show_priority]`
47+
recurrence rule: `INPUT[toggle:TQ_show_recurrence_rule]` on completion: `INPUT[toggle:TQ_show_on_completion]`
48+
start date: `INPUT[toggle:TQ_show_start_date]` scheduled date: `INPUT[toggle:TQ_show_scheduled_date]` due date: `INPUT[toggle:TQ_show_due_date]`
49+
created date: `INPUT[toggle:TQ_show_created_date]` cancelled date: `INPUT[toggle:TQ_show_cancelled_date]` done date: `INPUT[toggle:TQ_show_done_date]`
50+
urgency: `INPUT[toggle:TQ_show_urgency]`
51+
backlink: `INPUT[toggle:TQ_show_backlink]`
52+
edit button: `INPUT[toggle:TQ_show_edit_button]` postpone button: `INPUT[toggle:TQ_show_postpone_button]`
53+
task count: `INPUT[toggle:TQ_show_task_count]`
54+
extra instructions: `INPUT[textArea:TQ_extra_instructions]`
55+
explain: `INPUT[toggle:TQ_explain]`
56+
```
57+
<!-- endSnippet -->
58+
59+
## Why provide this?
60+
61+
Some might say that this mechanism is perhaps a little awkward, and wouldn't it be good for Tasks to provide its own user interface?
62+
63+
We agree, and we are tracking this in [issue #2579](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2579).
64+
65+
However, the development process went something like this:
66+
67+
1. Teach Tasks to use [[Obsidian Properties#Using Query Properties in Searches|query properties in searches]].
68+
2. Discover that generating Tasks instructions from simple `true`/`false` properties required some really rather complex JavaScript code inside user queries, which was:
69+
- horrible for us to document,
70+
- horrible for users to have to copy and understand, cluttering up their searches.
71+
3. Implement the [[Query File Defaults]] mechanism.
72+
4. Discover that using Obsidian's [Properties view](https://help.obsidian.md/Plugins/Properties+view) core plugin was *sort-of-OK*, but:
73+
- it was a little tedious opening and closing that side-panel,
74+
- it does not do a very good job editing multi-line strings, which are useful with `TQ_extra_instructions`.
75+
5. Experiment with [[Meta Bind Plugin]] and decide this use of it is a relatively easy and big step forward, until such time as Obsidian has its own user interface!

docs/Other Plugins/About Other Plugins.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ aliases:
1212

1313
- [[Dataview]]
1414
- [[Kanban Plugin]]
15+
- [[Meta Bind Plugin]]
16+
- Easily modify the [[layout]] of your Tasks searches, without having to edit instructions.
1517
- [[QuickAdd]]
1618
- Using the Quickadd plugin to help create tasks
1719

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
publish: true
3+
---
4+
5+
# Meta Bind Plugin
6+
7+
<span class="related-pages">#plugin/meta-bind</span>
8+
9+
## Introduction
10+
11+
The [Meta Bind](https://github.com/mProjectsCode/obsidian-meta-bind-plugin) allows Obsidian users to make their notes interactive with inline input fields, metadata displays, and buttons.
12+
13+
It can even be used to create [[Make a query user interface|simple user interface to customise Tasks queries]].

docs/Queries/About Queries.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,55 @@ In the following sections we will explain all the various options that are avail
4646
### Searching tasks - Basics
4747

4848
- [[Filters]]
49+
- Control which tasks are shown in Tasks Queries.
4950
- [[Explaining Queries]]
51+
- Get Tasks to show how your query is interpreted, so you can check your instructions.
5052
- [[Comments]]
53+
- Write notes to your future self, explaining your Queries.
5154
- [[Examples]]
55+
- A selection of some of the more commonly used search instructions.
5256

53-
### Searching tasks - Advanced
57+
### Searching tasks - Re-using instructions
5458

5559
- [[Global Query]]
60+
- Set a global query in the settings that Tasks will add to the start of all the Queries in your vault.
61+
- [[Query File Defaults]]
62+
- Set properties in note frontmatter, to instruct tasks to add instructions to all the Queries in that file.
63+
64+
> [!tip] The Query is assembled like this:
65+
>
66+
> 1. Get the **Global Query**, from settings.
67+
> - This will be discarded if `ignore global query` is present in any of the following locations.
68+
> 2. Append the **Query File Defaults**, based on the Query file's properties.
69+
> 3. Append the **Query Source**, from the `tasks` block.
70+
>
71+
> Later [[Layout]] instructions will override earlier ones.
72+
73+
### Searching tasks - Advanced
74+
5675
- [[Combining Filters]]
76+
- How to use `AND`, `OR` and `NOT`.
77+
- Warning: Make sure you understand where to place brackets in these instructions!
5778
- [[Regular Expressions]]
79+
- A complex but powerful alternative to simple text searches.
5880
- [[Line Continuations]]
81+
- Break long instructions up across multiple lines for readability.
5982

6083
### Viewing the results
6184

6285
- [[Backlinks]]
86+
- Navigate from tasks in Queries back to the source Markdown line.
6387

6488
### Controlling the display
6589

6690
- [[Limiting]]
91+
- Control the maximum number of tasks displayed in a Query's results, and in each group of tasks.
6792
- [[Sorting]]
93+
- Define the sort order.
6894
- [[Grouping]]
95+
- Define headings to group tasks.
6996
- [[Layout]]
97+
- Hide and show individual elements of the Query results.
7098

7199
## Query Tips
72100

docs/Queries/Explaining Queries.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ Explanation of this Tasks code block query:
163163
```
164164
<!-- endSnippet -->
165165

166+
## Advanced Examples
167+
166168
### Global Query is displayed
167169

168170
> [!released]
@@ -208,6 +210,67 @@ Explanation of this Tasks code block query:
208210
```
209211
<!-- endSnippet -->
210212

213+
### Query File Defaults are displayed
214+
215+
> [!released]
216+
> The [[Query File Defaults]] facility was introduced in Tasks X.Y.Z.
217+
218+
> [!info]- What are Query File Defaults?
219+
> You can use [[Query File Defaults]] facility to modify Tasks searches, by adding certain pre-defined property value's the query file's frontmatter.
220+
>
221+
> For example, setting `TQ_short_mode` to `true` makes Tasks insert the following line at the start of the query:
222+
>
223+
> ```text
224+
> short mode
225+
> ```
226+
227+
Consider this Markdown note:
228+
229+
<!-- placeholder to force blank line before included text --><!-- include: DocsSamplesForExplain.test.explain_query_file_defaults_file_content.approved.md -->
230+
231+
````text
232+
---
233+
TQ_extra_instructions: |-
234+
folder includes {{query.file.folder}}
235+
not done
236+
TQ_short_mode: true
237+
TQ_show_tree: true
238+
---
239+
240+
```tasks
241+
explain
242+
```
243+
````
244+
245+
<!-- placeholder to force blank line after included text --><!-- endInclude -->
246+
247+
The Tasks results begin would the following:
248+
249+
<!-- snippet: DocsSamplesForExplain.test.explain_query_file_defaults_explanation.approved.explanation.text -->
250+
```text
251+
Explanation of the Query File Defaults (from properties/frontmatter in the query's file):
252+
253+
folder includes {{query.file.folder}} =>
254+
folder includes Test Data/
255+
256+
not done
257+
258+
Explanation of this Tasks code block query:
259+
260+
No filters supplied. All tasks will match the query.
261+
```
262+
<!-- endSnippet -->
263+
264+
> [!info]- Why are the generated layout instructions not visible?
265+
> The Query File Defaults will have generated these instructions:
266+
>
267+
> ```text
268+
> short mode
269+
> show tree
270+
> ```
271+
>
272+
> Currently, the `explain` output does not display [[layout]] instructions. We are tracking this in [issue #2093](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2093).
273+
211274
### Placeholder values are expanded
212275
213276
> [!released]

docs/Queries/Layout.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ For example:
151151
```tasks
152152
no due date
153153
path includes GitHub
154-
154+
155155
hide recurrence rule
156156
hide task count
157157
hide backlink
@@ -190,3 +190,38 @@ Example:
190190
```
191191

192192
This can be reversed with [[#Full Mode]].
193+
194+
## Alternative to typing layout instructions
195+
196+
> [!released]
197+
> [[Query File Defaults]] were introduced in Tasks X.Y.Z.
198+
199+
All the layout instructions in this page can be generated for you automatically, by putting certain file properties (called 'Query File Defaults') in the file containing the query.
200+
201+
For example, suppose the file containing our query begins with the following:
202+
203+
<!-- snippet: DocsSamplesForDefaults.test.DocsSamplesForDefaults_demo-short-mode_yaml.approved.yaml -->
204+
```yaml
205+
---
206+
TQ_short_mode: true
207+
---
208+
```
209+
<!-- endSnippet -->
210+
211+
All Tasks code blocks in that file will then have this content automatically inserted at their start:
212+
213+
<!-- snippet: DocsSamplesForDefaults.test.DocsSamplesForDefaults_demo-short-mode_instructions.approved.txt -->
214+
```txt
215+
short mode
216+
```
217+
<!-- endSnippet -->
218+
219+
And of course, if `TQ_short_mode` were `false`, the following would be inserted:
220+
221+
```txt
222+
full mode
223+
```
224+
225+
For more information, see [[Query File Defaults]].
226+
227+
And for even more power, see [[Make a query user interface]].

0 commit comments

Comments
 (0)