Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
86fe330
test: Add test data for TQ-short-mode value
claremacrae Feb 2, 2025
a8ecb49
refactor: - Start creating QueryFileDefaults class, via TDD
claremacrae Feb 2, 2025
bd8da90
test: . Extract variable data
claremacrae Feb 2, 2025
1285e41
test: . Extract generateQueryFileDefaultsSource()
claremacrae Feb 2, 2025
7abb961
test: . Inline local variables
claremacrae Feb 2, 2025
0e6daf9
feat: - Teach QueryFileDefaults to generate short/full mode
claremacrae Feb 2, 2025
086d8fe
feat: - Teach getQueryForQueryRenderer() to use QueryFileDefaults
claremacrae Feb 2, 2025
01049e8
vault: TQ-short-mode is now automatically recognised by Tasks
claremacrae Feb 2, 2025
ae53d88
refactor: - Allow QueryFileDefaults.source() to take OptionalTasksFile
claremacrae Feb 2, 2025
5cc0032
refactor: . inline queryFileDefaultsSource
claremacrae Feb 2, 2025
eea4aa8
refactor: . extract query()
claremacrae Feb 2, 2025
31cd940
refactor: . move query() to QueryFileDefaults.ts
claremacrae Feb 2, 2025
cfbd214
refactor: - introduce QueryFileDefaults.query()
claremacrae Feb 2, 2025
e38e7dc
refactor: - inline query()
claremacrae Feb 2, 2025
50a594b
refactor: - Replace cryptic TQ- property refix with tasks-query-
claremacrae Feb 2, 2025
b22c156
refactor: - Replace hyphens with underscores in QueryFileDefaults pro…
claremacrae Feb 2, 2025
dcc03d2
test: - Add more tasks_query_* properties to test data
claremacrae Feb 3, 2025
cba229f
refactor: . Extract QueryFileDefaults.instruction()
claremacrae Feb 3, 2025
7120a73
refactor: . Inline local variables
claremacrae Feb 3, 2025
082861c
test: - Prepare to support more properties in QueryFileDefaults.test.ts
claremacrae Feb 3, 2025
e63617f
test: - Switch to inline snapshots in QueryFileDefaults.test.ts
claremacrae Feb 3, 2025
2f23955
refactor: - "Many of one" - prepare to support more instructions
claremacrae Feb 3, 2025
690c42c
feat: - Set 'tasks_query_explain' prop to true, to enable 'explain'
claremacrae Feb 3, 2025
adc7d7d
feat: - Set 'tasks_query_show_tree' prop to true, to show tree
claremacrae Feb 3, 2025
e01aaa4
refactor: . extract variable field
claremacrae Feb 3, 2025
99f69d9
refactor: . Extract QueryFileDefaults.showOrHide()
claremacrae Feb 3, 2025
6424256
refactor: . Inline local field
claremacrae Feb 3, 2025
fdfce45
feat: - Set 'tasks_query_show_tags' prop to false, to hide tags
claremacrae Feb 3, 2025
7d7d746
refactor: . Rename method to showAndHide(), to align with instruction()
claremacrae Feb 3, 2025
f340133
feat: - Set 'tasks_query_show_id' prop to false, to hide ids
claremacrae Feb 3, 2025
7aa4e65
feat: - Set 'tasks_query_show_depends_on' prop to false, to hide depe…
claremacrae Feb 3, 2025
2b59795
comment: Explain order of instructions
claremacrae Feb 3, 2025
31e4303
feat: - Set 'tasks_query_show_priority' prop to false, to hide priority
claremacrae Feb 3, 2025
f8c4e74
feat: - Set 'tasks_query_show_recurrence_rule' prop to false, to hide…
claremacrae Feb 3, 2025
5700fa1
feat: - Set 'tasks_query_show_on_completion' prop to false, to hide o…
claremacrae Feb 3, 2025
0f81c70
feat: - Set 'tasks_query_show_created_date' prop to false, to hide cr…
claremacrae Feb 3, 2025
0880bfc
feat: - Set 'tasks_query_show_start_date' prop to false, to hide star…
claremacrae Feb 3, 2025
c7e4157
feat: - Set 'tasks_query_show_scheduled_date' prop to false, to hide …
claremacrae Feb 3, 2025
51d9864
feat: - Set 'tasks_query_show_due_date' prop to false, to hide due date
claremacrae Feb 3, 2025
eeea1cb
feat: - Set 'tasks_query_show_cancelled_date' prop to false, to hide …
claremacrae Feb 3, 2025
4e56ff8
feat: - Set 'tasks_query_show_done_date' prop to false, to hide done …
claremacrae Feb 3, 2025
cd8ab92
feat: - Set 'tasks_query_show_urgency' prop to true, to show urgency
claremacrae Feb 3, 2025
32a8322
feat: - Set 'tasks_query_show_backlink' prop to false, to hide backlinks
claremacrae Feb 3, 2025
44db9ed
feat: - Set 'tasks_query_show_edit_button' prop to false, to hide edi…
claremacrae Feb 3, 2025
55f24bc
feat: - Set 'tasks_query_show_postpone_button' prop to false, to hide…
claremacrae Feb 3, 2025
332e62c
feat: - Set 'tasks_query_show_task_count' prop to false, to hide task…
claremacrae Feb 3, 2025
b128cf6
vault: Remove placeholder code for properties now built-in to Tasks
claremacrae Feb 3, 2025
48e7b47
vault: Add widen-property-labels.css
claremacrae Feb 3, 2025
29274c5
feat: - Set 'tasks_query_extra_instructions' prop, to add arbitrary e…
claremacrae Feb 3, 2025
5306c70
refactor: . Extract extraInstructions
claremacrae Feb 3, 2025
029d415
refactor: . Extract addValue()
claremacrae Feb 3, 2025
e1ea015
refactor: - Simplify use of 'tasks_query_extra_instructions'
claremacrae Feb 3, 2025
7779e4c
vault: Remove placeholder code for properties now built-in to Tasks
claremacrae Feb 3, 2025
56c7a03
feat: Teach 'explain' to show instructions from Query File Defaults
claremacrae Feb 3, 2025
fb141e3
vault: Update notes in 'Placeholder examples to capture in tests and …
claremacrae Feb 3, 2025
ef1cb80
vault: Make all queries honour 'tasks_query_explain' property
claremacrae Feb 3, 2025
fac4ed8
refactor: . Rename parameter to queryFile, for clarity
claremacrae Feb 3, 2025
6dd369a
refactor: . Extract explainQuery()
claremacrae Feb 3, 2025
543b0ee
refactor: . Extract variable intro
claremacrae Feb 3, 2025
f889408
refactor: . Reuse explainQuery()
claremacrae Feb 3, 2025
7089a9c
refactor: - Better explanation of source of query file defaults
claremacrae Feb 3, 2025
d0f01d0
test: - Fix confusing test names
claremacrae Feb 3, 2025
e06cc22
refactor: . Extract variable ignoreGlobalQuery
claremacrae Feb 3, 2025
d071892
refactor: . Slide line up
claremacrae Feb 3, 2025
2ba8105
refactor: - Make code reflect name of variable correctly
claremacrae Feb 3, 2025
7324d79
fix: Make 'ignore global query' work in Query File Defaults
claremacrae Feb 3, 2025
1bbd2f6
vault: Enable manual easy testing of 'ignore global query'
claremacrae Feb 3, 2025
eb4cf4b
test: - Show all supported QueryFileDefaults in frontmatter
claremacrae Feb 3, 2025
fc33517
refactor: - Better explanation of source of query file defaults
claremacrae Feb 3, 2025
f8044d9
test: - Save YAML files of supported query properties
claremacrae Feb 3, 2025
d048a7b
vault: Install and enable the "Meta Bind" plugin
claremacrae Feb 3, 2025
4df042c
vault: Add "Meta Bind" widgets for editing Query File Defaults
claremacrae Feb 3, 2025
6db1ad4
vault: Group together related "Meta Bind" widgets
claremacrae Feb 3, 2025
b26b68c
docs: Add Query File Defaults.md - and link to it in the Changelog
claremacrae Feb 3, 2025
80176b2
refactor: Add QueryFileDefaults.metaBindPluginWidgets() - for docs
claremacrae Feb 3, 2025
34beaf4
docs: Whitespace changes made by lint:markdown
claremacrae Feb 3, 2025
2539964
vault: Machine-generate the MetaBind widgets text
claremacrae Feb 3, 2025
f21ac51
test: - Rename approved file
claremacrae Feb 3, 2025
9eede32
test: - Generate a snippet to embed MetaBind widgets in docs
claremacrae Feb 3, 2025
a906176
docs: Show how to use Meta Bind plugin to control Tasks searches
claremacrae Feb 3, 2025
26dae6b
refactor: - Move 'explain' toggle to end of Meta Bind widgets
claremacrae Feb 3, 2025
5ebfa5c
vault: - Move 'explain' toggle to end of Meta Bind widgets
claremacrae Feb 3, 2025
724a4f3
docs: - Move 'explain' toggle to end of Meta Bind widgets
claremacrae Feb 3, 2025
f3a2e67
docs: Improve 'Creating a User Interface for the defaults' instructions
claremacrae Feb 3, 2025
d266baa
docs: Add screenshot of using Meta Bind widgets to control searches
claremacrae Feb 3, 2025
57225d1
docs: Using Obsidian 'File properties' view to customise Tasks searches
claremacrae Feb 3, 2025
b6c4b30
docs: Move list of supported property values to end
claremacrae Feb 3, 2025
2962795
docs: Move 'Types of Query File Defaults property values' to end
claremacrae Feb 3, 2025
7ddcd85
docs: Improve wording of a heading
claremacrae Feb 3, 2025
9ba11c7
docs: Move and improve the CSS to widen property names
claremacrae Feb 3, 2025
36e210c
docs: Improve headings at start of Query File Defaults.md
claremacrae Feb 3, 2025
692f69c
docs: Move the Meta Bind widgets snippet to separate file
claremacrae Feb 3, 2025
e6b19a0
docs: Hide the Meta Bind widgets setup in a callout
claremacrae Feb 3, 2025
0b064a7
docs: Improve 'Obsidian-native User Interface' instructions
claremacrae Feb 4, 2025
8ea25fd
docs: Improve 'Using Query Properties in Placeholders'
claremacrae Feb 4, 2025
1aca903
docs: Better heading name for section that covers more than Placeholders
claremacrae Feb 4, 2025
1aabf7e
vault: Save some experiments with query properties in searches - for …
claremacrae Feb 4, 2025
a6842e3
docs: add link to 'Query File Defaults'
claremacrae Feb 4, 2025
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
29 changes: 13 additions & 16 deletions docs/Getting Started/Obsidian Properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ group by function \
return value ? window.moment(value).format('YYYY MMMM') : 'no date'
```

## Using Query Properties in Placeholders
## Using Query Properties in Searches

> [!released]
> Use of Obsidian properties in placeholders was introduced in Tasks X.Y.Z.
Expand All @@ -192,31 +192,32 @@ group by function \
- `query.file.hasProperty()` works.
- `query.file.property()` works.

Imagine this text at the top of the note containing the query:
Imagine this text at the top of **the note containing the query**:

```yaml
---
search-text: exercise
workdate: 2024-04-01
groupby: group by happens
---
```

It can be used in your query in two ways:
It can be used in queries in several ways:

1. A search term from front-matter embedded via placeholder:
1. A search term from frontmatter embedded via placeholder:

```javascript
description includes {{query.file.property('search-text')}}
due on or before {{query.file.property('workdate')}}
```

1. An entire instruction controlled by front-matter value:
2. An entire instruction controlled by front-matter value:

```javascript
{{const prop = 'TQ-explain'; return query.file.hasProperty(prop) ? ( query.file.property(prop) ? 'explain' : '') : '';}}

{{const prop = 'TQ-show-tree'; return query.file.hasProperty(prop) && ( query.file.property(prop) ? 'show' : 'hide') + ' tree' || ''}}
{{query.file.property('groupby')}}
```

1. Scripting, which allows creation of a custom filter, which works when the search term is empty
3. Scripting, which allows creation of a custom filter, which works when the search term is empty

```javascript
filter by function \
Expand All @@ -226,6 +227,9 @@ It can be used in your query in two ways:
return task.description.toLowerCase().includes(propertyLower);
```

> [!tip]
> See also [[Query File Defaults]] for built-in properties automatically supported by Tasks searches.

> [!warning] Using properties with no value
> Currently when a property in a placeholder is not set:
>
Expand All @@ -235,13 +239,6 @@ It can be used in your query in two ways:
> [!Info]
> In a future release, we will likely allow Tasks to silently ignore built filters created from properties that have no value.

> [!Info]
> In a future release, we will likely introduce standard property names for instructions that will automatically be included inside Tasks queries.
> Perhaps:
>
> - tasks-search-explain: true/false
> - tasks-search-limit: number

## How does Tasks interpret Obsidian Properties?

Consider a file with the following example properties (or "Frontmatter"):
Expand Down
151 changes: 151 additions & 0 deletions docs/Queries/Query File Defaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
publish: true
---

# Query File Defaults

## Summary

Scenarios:

- You have multiple Tasks queries in a Markdown file, and they have a lot of
text in common. You would like to avoid repeating those common instructions in
each one.
- Usually you like to see your Tasks search results with certain [[Layout]]
options, but sometimes it is nice to see more detail, perhaps turning
`show tree` on and off, depending on your mood.

## Applying instructions to every Tasks search in a file

### Obsidian-native User Interface

You can use the Obsidian **File properties** view to customise Tasks searches:

![Obsidian's 'File properties' widget, with checkboxes and a text box to modify query file defaults for a file containing Tasks searches.](../images/query-file-defaults-file-properties-controls.png)
<span class="caption">Obsidian's **File properties** widget, with checkboxes and a text box to modify query file defaults for a file containing Tasks searches. See [[#Widening property names in Obsidian]] for the CSS snippet used to widen property names.</span>

To try this out:

1. Show the `File properties` panel:
- Enable the Obsidian core Properties view plugin: `Settings` > `Core plugins` > turn on `Properties view`
- Switch to Reading or Live Preview modes.
- Run the `Properties view: Show file properties` command.
2. Add one or more `tasks_query_*` properties to the file
- Click on `Add property`.
- Start typing `tasks_query_`.
- Or you can paste in property names from the [[#Supported Query File Defaults property values]] section below.
- Press `<Return>` or `<Enter>` to add the property.
3. Now you can modify these `tasks_query_*` properties to change the behaviour of Tasks searches in this file.

> [!info]
> We plan to streamline the addition of these properties to notes.

#### Widening property names in Obsidian

By default, the property names are very narrow in Obsidian.

You can make them wider with the following CSS Snippet.

<!-- snippet: resources/sample_vaults/Tasks-Demo/.obsidian/snippets/widen-property-labels.css -->
```css
/* Make property labels wider, to fit the names of Tasks-specific properties */
.metadata-content {
--metadata-label-width: 18em;
}
```
<!-- endSnippet -->

The Obsidian user guide shows how to [use CSS snippets in Obsidian](https://help.obsidian.md/How+to/Add+custom+styles#Use+Themes+and+or+CSS+snippets).

### Meta Bind User Interface

You can use the [Meta Bind](https://obsidian.md/plugins?search=Meta%20Bind) plugin to create a User Interface to easily change your Tasks searches:

![Meta Bind widgets to edit Query File Defaults](../images/query-file-defaults-meta-bind-controls.png)
<span class="caption">Meta Bind widgets to edit Query File Defaults</span>

> [!info]- Set up Meta Bind widgets to edit Query File Defaults
> Steps to do this, which assume you have already [turned off Obsidian's Restricted mode](https://help.obsidian.md/Extending+Obsidian/Plugin+security):
>
> 1. Install and enable [Meta Bind](https://obsidian.md/plugins?search=Meta%20Bind)
> 2. Click the Copy button to copy the Markdown below.
> 3. Paste the markdown in to a note in Obsidian that has one or more Tasks searches.
> 4. Switch to Live Preview or Reading modes, to see the widgets.
> 5. After experimenting, delete any labels and widgets that you do not need.
>
> ![[Meta Bind Query Widgets]]

## Technical details

### Supported Query File Defaults property values

These are all the properties currently supported by Tasks, as Query File Defaults.

<!-- snippet: DocsSamplesForDefaults.test.DocsSamplesForDefaults_supported-properties-empty.approved.yaml -->
```yaml
---
tasks_query_explain:
tasks_query_short_mode:
tasks_query_show_tree:
tasks_query_show_tags:
tasks_query_show_id:
tasks_query_show_depends_on:
tasks_query_show_priority:
tasks_query_show_recurrence_rule:
tasks_query_show_on_completion:
tasks_query_show_created_date:
tasks_query_show_start_date:
tasks_query_show_scheduled_date:
tasks_query_show_due_date:
tasks_query_show_cancelled_date:
tasks_query_show_done_date:
tasks_query_show_urgency:
tasks_query_show_backlink:
tasks_query_show_edit_button:
tasks_query_show_postpone_button:
tasks_query_show_task_count:
tasks_query_extra_instructions:
---
```
<!-- endSnippet -->

> [!tip]
> We hope in the future to add an Obsidian Command to add all supported Query
> File Defaults properties to the current file automatically.

### Types of Query File Defaults property values

These are all the types of properties currently supported by Tasks, as Query
File Defaults.

> [!tip]
> We plan to make Tasks add these types to the Obsidian vault automatically in
> future.

```json
{
"types": {
"tasks_query_explain": "checkbox",
"tasks_query_short_mode": "checkbox",
"tasks_query_show_tree": "checkbox",
"tasks_query_show_tags": "checkbox",
"tasks_query_show_id": "checkbox",
"tasks_query_show_depends_on": "checkbox",
"tasks_query_show_priority": "checkbox",
"tasks_query_show_recurrence_rule": "checkbox",
"tasks_query_show_on_completion": "checkbox",
"tasks_query_show_created_date": "checkbox",
"tasks_query_show_start_date": "checkbox",
"tasks_query_show_scheduled_date": "checkbox",
"tasks_query_show_due_date": "checkbox",
"tasks_query_show_cancelled_date": "checkbox",
"tasks_query_show_done_date": "checkbox",
"tasks_query_show_urgency": "checkbox",
"tasks_query_show_backlink": "checkbox",
"tasks_query_show_edit_button": "checkbox",
"tasks_query_show_postpone_button": "checkbox",
"tasks_query_show_task_count": "checkbox",
"tasks_query_extra_instructions": "text"
}
}
```
2 changes: 1 addition & 1 deletion docs/Scripting/Placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Explanation of this Tasks code block query:
> [!released]
> Use of Obsidian properties in placeholders was introduced in Tasks X.Y.Z.

It is now possible to use properties in the query file. See [[Obsidian Properties#Using Query Properties in Placeholders]]
It is now possible to use properties in the query file. See [[Obsidian Properties#Using Query Properties in Searches]]

## Error checking: invalid variables

Expand Down
4 changes: 3 additions & 1 deletion docs/What is New/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ _In recent [Tasks releases](https://github.com/obsidian-tasks-group/obsidian-tas

- X.Y.Z:
- Add `query.file.hasProperty()` and `query.file.property()` in custom filters
- Add `{{query.file.hasProperty()}}` and `{{query.file.property()}}` in placeholders - see [[Obsidian Properties#Using Query Properties in Placeholders|Using Query Properties in Placeholders]].
- Add `{{query.file.hasProperty()}}` and `{{query.file.property()}}` in placeholders - see [[Obsidian Properties#Using Query Properties in Searches|Using Query Properties in Placeholders]].
- Placeholders can now call functions and contain expressions.
- New [[Query File Defaults]] facility allows easy customising of all the
Tasks searches in a file, by editing properties
- Add Chinese translation of [[Settings]], [[Editing a Status]] and [[Check your Statuses]]
- 7.14.0:
- Add [[Editing Dates#Date-picker on task dates|date picker]] to Reading mode and Tasks query search results.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- snippet: DocsSamplesForDefaults.test.DocsSamplesForDefaults_meta-bind-widgets-snippet.approved.md -->
```md
short mode: `INPUT[toggle:tasks_query_short_mode]`
tree: `INPUT[toggle:tasks_query_show_tree]`
tags: `INPUT[toggle:tasks_query_show_tags]`
id: `INPUT[toggle:tasks_query_show_id]` depends on: `INPUT[toggle:tasks_query_show_depends_on]`
priority: `INPUT[toggle:tasks_query_show_priority]`
recurrence rule: `INPUT[toggle:tasks_query_show_recurrence_rule]` on completion: `INPUT[toggle:tasks_query_show_on_completion]`
start date: `INPUT[toggle:tasks_query_show_start_date]` scheduled date: `INPUT[toggle:tasks_query_show_scheduled_date]` due date: `INPUT[toggle:tasks_query_show_due_date]`
created date: `INPUT[toggle:tasks_query_show_created_date]` cancelled date: `INPUT[toggle:tasks_query_show_cancelled_date]` done date: `INPUT[toggle:tasks_query_show_done_date]`
urgency: `INPUT[toggle:tasks_query_show_urgency]`
backlink: `INPUT[toggle:tasks_query_show_backlink]`
edit button: `INPUT[toggle:tasks_query_show_edit_button]` postpone button: `INPUT[toggle:tasks_query_show_postpone_button]`
task count: `INPUT[toggle:tasks_query_show_task_count]`
extra instructions: `INPUT[textArea:tasks_query_extra_instructions]`
explain: `INPUT[toggle:tasks_query_explain]`
```
<!-- endSnippet -->
3 changes: 2 additions & 1 deletion resources/sample_vaults/Tasks-Demo/.obsidian/appearance.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"js-engine-code-block-border",
"dataview-block",
"dataview-clare",
"dataview-blocks"
"dataview-blocks",
"widen-property-labels"
],
"accentColor": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"obsidian-kanban",
"js-engine",
"table-editor-obsidian",
"reveal-active-file-button"
"reveal-active-file-button",
"obsidian-meta-bind-plugin"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"devMode": false,
"ignoreCodeBlockRestrictions": false,
"preferredDateFormat": "YYYY-MM-DD",
"firstWeekday": {
"index": 1,
"name": "Monday",
"shortName": "Mo"
},
"syncInterval": 200,
"minSyncInterval": 50,
"maxSyncInterval": 1000,
"enableJs": false,
"viewFieldDisplayNullAsEmpty": false,
"enableSyntaxHighlighting": true,
"enableEditorRightClickMenu": true,
"inputFieldTemplates": [],
"buttonTemplates": [],
"excludedFolders": [
"templates"
]
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "obsidian-meta-bind-plugin",
"name": "Meta Bind",
"version": "1.3.3",
"minAppVersion": "1.4.0",
"description": "Make your notes interactive with inline input fields, metadata displays, and buttons.",
"author": "Moritz Jung",
"authorUrl": "https://www.moritzjung.dev/",
"fundingUrl": "https://github.com/sponsors/mProjectsCode",
"helpUrl": "https://www.moritzjung.dev/obsidian-meta-bind-plugin-docs/",
"isDesktopOnly": false
}
Loading