Skip to content

Commit

Permalink
feat: Add new priorities: highest and lowest (#1943)
Browse files Browse the repository at this point in the history
* feat: added new priorities: highest and lowest

* fixed suggestor unit tests

* review changes: fixed priority numbers, changed highest icon

* fixed highest priority emoji to a star in a box

* fixed edit task modal styling

* fixed highest priority emoji to final one

* added documentation

* review changes: fixed css snippet

* review changes: fixed | symbol disappearing in quick reference docs

* review changes: fixed edit task view
  • Loading branch information
chrabia authored May 29, 2023
1 parent 3156647 commit 93ab4dd
Show file tree
Hide file tree
Showing 28 changed files with 226 additions and 44 deletions.
2 changes: 1 addition & 1 deletion docs/Advanced/Quickadd.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Task with due date only:

Task with priority and reminder date and due date:

`#task {{VALUE:task name}} ⏰ {{VDATE:reminder date and time,YYYY-MM-DD HH:mm}} {{VALUE:⏫,🔼,🔽, }} 📅 {{VDATE:due date,YYYY-MM-DD}}`
`#task {{VALUE:task name}} ⏰ {{VDATE:reminder date and time,YYYY-MM-DD HH:mm}} {{VALUE:🔺,⏫,🔼,🔽,⏬️, }} 📅 {{VDATE:due date,YYYY-MM-DD}}`

<video controls width="100%">
<source src="https://user-images.githubusercontent.com/38974541/143468599-ae598f7d-cc84-4fc9-8293-eae72cf81f8a.mov" />
Expand Down
22 changes: 21 additions & 1 deletion docs/Advanced/Styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The generic classes are:

In addition to the generic classes, there are [**data attributes**](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes) that represent the content of the various task components.

A **priority data attributes** named `data-task-priority` represents the specific priority of a class. It can be `high`, `medium`, `low` or `normal`.
A **priority data attributes** named `data-task-priority` represents the specific priority of a class. It can be `highest`, `high`, `medium`, `low`, `lowest` or `normal`.
The `normal` value is special: it is added as a default to a task's upper `task-list-item` even if there is no priority field set for that task.

A **date attribute** represents a due, created, start, scheduled or done date in a format relative to the current date.
Expand Down Expand Up @@ -200,6 +200,11 @@ The following rules remove the Tasks priority emoticon and render the tasks' che

<!-- snippet: resources/sample_vaults/Tasks-Demo/.obsidian/snippets/tasks-plugin-priority-as-checkbox-color.css -->
```css
.task-list-item[data-task-priority="highest"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-purple);
border-color: var(--color-purple);
}

.task-list-item[data-task-priority="high"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-red);
border-color: var(--color-red);
Expand All @@ -220,6 +225,11 @@ The following rules remove the Tasks priority emoticon and render the tasks' che
border-color: var(--color-cyan);
}

.task-list-item[data-task-priority="lowest"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-green);
border-color: var(--color-green);
}

/* This part removes the regular priority emoticon */
span.task-priority {
display: none;
Expand Down Expand Up @@ -457,6 +467,11 @@ span.tasks-list-text {
}

/* Represent tasks' priority with colorful round checkboxes instead of the priority emoticons */
.task-list-item[data-task-priority="highest"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-purple);
border-color: var(--color-purple);
}

.task-list-item[data-task-priority="high"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-red);
border-color: var(--color-red);
Expand All @@ -477,6 +492,11 @@ span.tasks-list-text {
border-color: var(--color-cyan);
}

.task-list-item[data-task-priority="lowest"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-green);
border-color: var(--color-green);
}

/* This part removes the regular priority emoticon */
span.task-priority {
display: none;
Expand Down
10 changes: 9 additions & 1 deletion docs/Advanced/Urgency.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ The scores are as follows:
<td><code>0.0</code></td>
</tr>
<tr>
<td rowspan="4">Priority</td>
<td rowspan="6">Priority</td>
<td>Highest</td>
<td><code>9.0</code></td>
</tr>
<tr>
<td>High</td>
<td><code>6.0</code></td>
</tr>
Expand All @@ -73,6 +77,10 @@ The scores are as follows:
<tr>
<td>Low</td>
<td><code>0.0</code></td>
</tr>
<tr>
<td>Lowest</td>
<td><code>-0.6</code></td>
</tr>
<tr>
<td rowspan="3">Scheduled</td>
Expand Down
2 changes: 2 additions & 0 deletions docs/Getting Started/Auto-Suggest.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ Similarly, you can type some fraction of the word `start` (of whatever length is
| Searchable Text | Text that is added |
| ----------------------------- | -------------------------- |
|| \<new line> |
| 🔺 highest priority | 🔺 |
| ⏫ high priority ||
| 🔼 medium priority | 🔼 |
| 🔽 low priority | 🔽 |
| ⏬️ lowest priority | ⏬️ |
| 🔁 recurring (repeat) | 🔁 |
| every | 🔁 every |
| every day | 🔁 every day |
Expand Down
12 changes: 7 additions & 5 deletions docs/Getting Started/Priority.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ publish: true
Tasks can have a priority.
In order to specify the priority of a task, you can append one of the "priority signifiers", shown here in decreasing order of priority:

1. ⏫ for high priority
2. 🔼 for medium priority
3. use no signifier to indicate no priority
4. 🔽 for low priority
1. 🔺 for highest priority
2. ⏫ for high priority
3. 🔼 for medium priority
4. use no signifier to indicate no priority
5. 🔽 for low priority
6. ⏬️ for lowest priority

If a task has no priority at all, it is considered between low and medium priority.
This means that the priority of 🔽 low tasks is considered lower than the priority of tasks without any specific priority.
Expand All @@ -35,7 +37,7 @@ Instead of adding the emoji manually, you can:

The following instructions use the priority signifiers in tasks.

- `priority is (above, below)? (low, none, medium, high)`
- `priority is (above, below)? (lowest, low, none, medium, high, highest)`
- [[Filters#Priority|Documentation]]
- `sort by priority`
- [[Sorting#Basics|Documentation]]
Expand Down
12 changes: 7 additions & 5 deletions docs/Queries/Filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,16 @@ For example:

### Priority

- `priority is (above|below|not)? (low|none|medium|high)`
- `priority is (above|below|not)? (lowest|low|none|medium|high|highest)`

The available priorities are (from high to low):

1. ⏫ for high priority
2. 🔼 for medium priority
3. use no signifier to indicate no priority (searched for with 'none')
4. 🔽 for low priority
1. 🔺 for highest priority
2. ⏫ for high priority
3. 🔼 for medium priority
4. use no signifier to indicate no priority (searched for with 'none')
5. 🔽 for low priority
6. ⏬️ for lowest priority

For more information, see [[Priority|Priorities]].

Expand Down
2 changes: 2 additions & 0 deletions docs/Queries/Grouping.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ For more information, including adding your own customised statuses, see [[Statu

1. `priority`
- The priority of the task, namely one of:
- `Priority 0: Highest`
- `Priority 1: High`
- `Priority 2: Medium`
- `Priority 3: None`
- `Priority 4: Low`
- `Priority 5: Lowest`
1. `urgency` ([[Urgency|urgency]])
- Currently, the groups run from the lowest urgency to highest.
- You can reverse this with `group by urgency reverse`.
Expand Down
2 changes: 1 addition & 1 deletion docs/Quick Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This table summarizes the filters and other options available inside a `tasks` b
| `is recurring`<br>`is not recurring` | `sort by recurring` | `group by recurring` | |
| `recurrence (includes, does not include) <string>`<br>`recurrence (regex matches, regex does not match) /regex/i` | | `group by recurrence` | `hide recurrence rule` |
| **[[Filters#Priority\|Priority]]** and **[[Urgency\|urgency]]** | | | |
| `priority is (above, below, not)? (low, none, medium, high)` | `sort by priority` | `group by priority` | `hide priority` |
| `priority is (above, below, not)? (lowest, low, none, medium, high, highest)` | `sort by priority` | `group by priority` | `hide priority` |
| | `sort by urgency` | `group by urgency` | `show urgency` |
| **[[Filters#Filters for File Properties\|File properties]]** | | | |
| `path (includes, does not include) <path>`<br>`path (regex matches, regex does not match) /regex/i` | `sort by path` | `group by path` | |
Expand Down
2 changes: 2 additions & 0 deletions docs/Reference/Task Formats/Dataview Format.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ For more information, see [[Dates]].
> These names were chosen for use in Tasks, and are not known to dataview. They can of course be searched in dataview.
```markdown
- [ ] #task Lowest priority [priority:: lowest]
- [ ] #task Low priority [priority:: low]
- [ ] #task Normal priority
- [ ] #task Medium priority [priority:: medium]
- [ ] #task High priority [priority:: high]
- [ ] #task Highest priority [priority:: highest]
```

For more information, see [[Priority]].
Expand Down
2 changes: 2 additions & 0 deletions docs/Reference/Task Formats/Tasks Emoji Format.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ For more information, see [[Dates]].
## Tasks Emoji Format for Priorities

```markdown
- [ ] #task Lowest priority ⏬️
- [ ] #task Low priority 🔽
- [ ] #task Normal priority
- [ ] #task Medium priority 🔼
- [ ] #task High priority ⏫
- [ ] #task Highest priority 🔺
```

For more information, see [[Priority]].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.task-list-item[data-task-priority="highest"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-purple);
border-color: var(--color-purple);
}

.task-list-item[data-task-priority="high"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-red);
border-color: var(--color-red);
Expand All @@ -18,8 +23,12 @@
border-color: var(--color-cyan);
}

.task-list-item[data-task-priority="lowest"] input[type=checkbox] {
box-shadow: 0px 0px 2px 2px var(--color-green);
border-color: var(--color-green);
}

/* This part removes the regular priority emoticon */
span.task-priority {
display: none;
}

15 changes: 14 additions & 1 deletion src/Query/Filter/PriorityField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class PriorityField extends Field {
// is to capture them in Nested Capture Groups, like this:
// (leading-white-space-in-outer-capture-group(values-to-use-are-in-inner-capture-group))
// The capture groups are numbered in the order of their opening brackets, from left to right.
private static readonly priorityRegexp = /^priority(\s+is)?(\s+(above|below|not))?(\s+(low|none|medium|high))$/;
private static readonly priorityRegexp =
/^priority(\s+is)?(\s+(above|below|not))?(\s+(lowest|low|none|medium|high|highest))$/;

createFilterOrErrorMessage(line: string): FilterOrErrorMessage {
const result = new FilterOrErrorMessage(line);
Expand All @@ -20,6 +21,9 @@ export class PriorityField extends Field {
let filterPriority: Priority | null = null;

switch (filterPriorityString) {
case 'lowest':
filterPriority = Priority.Lowest;
break;
case 'low':
filterPriority = Priority.Low;
break;
Expand All @@ -32,6 +36,9 @@ export class PriorityField extends Field {
case 'high':
filterPriority = Priority.High;
break;
case 'highest':
filterPriority = Priority.Highest;
break;
}

if (filterPriority === null) {
Expand Down Expand Up @@ -92,6 +99,9 @@ export class PriorityField extends Field {
case Priority.High:
priorityName = 'High';
break;
case Priority.Highest:
priorityName = 'Highest';
break;
case Priority.Medium:
priorityName = 'Medium';
break;
Expand All @@ -101,6 +111,9 @@ export class PriorityField extends Field {
case Priority.Low:
priorityName = 'Low';
break;
case Priority.Lowest:
priorityName = 'Lowest';
break;
}
return [`Priority ${task.priority}: ${priorityName}`];
};
Expand Down
8 changes: 8 additions & 0 deletions src/Suggestor/Suggestor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function addTaskPropertySuggestions(
appendText: `${symbols.scheduledDateSymbol} `,
});
if (!hasPriority(line)) {
genericSuggestions.push({
displayText: `${symbols.prioritySymbols.Highest} highest priority`,
appendText: `${symbols.prioritySymbols.Highest} `,
});
genericSuggestions.push({
displayText: `${symbols.prioritySymbols.High} high priority`,
appendText: `${symbols.prioritySymbols.High} `,
Expand All @@ -95,6 +99,10 @@ function addTaskPropertySuggestions(
displayText: `${symbols.prioritySymbols.Low} low priority`,
appendText: `${symbols.prioritySymbols.Low} `,
});
genericSuggestions.push({
displayText: `${symbols.prioritySymbols.Lowest} lowest priority`,
appendText: `${symbols.prioritySymbols.Lowest} `,
});
}
if (!line.includes(symbols.recurrenceSymbol))
genericSuggestions.push({
Expand Down
2 changes: 2 additions & 0 deletions src/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import { compareByDate } from './lib/DateTools';
* @enum {number}
*/
export enum Priority {
Highest = '0',
High = '1',
Medium = '2',
None = '3',
Low = '4',
Lowest = '5',
}

export class TaskRegularExpressions {
Expand Down
4 changes: 3 additions & 1 deletion src/TaskLineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ function getComponentClassesAndData(component: TaskLayoutComponent, task: Task):
break;
case 'priority': {
let priorityValue = null;
if (task.priority === taskModule.Priority.High) priorityValue = 'high';
if (task.priority === taskModule.Priority.Highest) priorityValue = 'highest';
else if (task.priority === taskModule.Priority.High) priorityValue = 'high';
else if (task.priority === taskModule.Priority.Medium) priorityValue = 'medium';
else if (task.priority === taskModule.Priority.Low) priorityValue = 'low';
else if (task.priority === taskModule.Priority.Lowest) priorityValue = 'lowest';
else priorityValue = 'normal';
dataAttributes['taskPriority'] = priorityValue;
genericClasses.push(LayoutClasses.priority);
Expand Down
8 changes: 7 additions & 1 deletion src/TaskSerializer/DataviewTaskSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ function toInlineFieldRegex(innerFieldRegex: RegExp): RegExp {
*/
export const DATAVIEW_SYMBOLS = {
prioritySymbols: {
Highest: 'priority:: highest',
High: 'priority:: high',
Medium: 'priority:: medium',
Low: 'priority:: low',
Lowest: 'priority:: lowest',
None: '',
},
startDateSymbol: 'start::',
Expand All @@ -72,7 +74,7 @@ export const DATAVIEW_SYMBOLS = {
doneDateSymbol: 'completion::',
recurrenceSymbol: 'repeat::',
TaskFormatRegularExpressions: {
priorityRegex: toInlineFieldRegex(/priority:: *(high|medium|low)/),
priorityRegex: toInlineFieldRegex(/priority:: *(highest|high|medium|low|lowest)/),
startDateRegex: toInlineFieldRegex(/start:: *(\d{4}-\d{2}-\d{2})/),
createdDateRegex: toInlineFieldRegex(/created:: *(\d{4}-\d{2}-\d{2})/),
scheduledDateRegex: toInlineFieldRegex(/scheduled:: *(\d{4}-\d{2}-\d{2})/),
Expand All @@ -93,12 +95,16 @@ export class DataviewTaskSerializer extends DefaultTaskSerializer {

protected parsePriority(p: string): Priority {
switch (p) {
case 'highest':
return Priority.Highest;
case 'high':
return Priority.High;
case 'medium':
return Priority.Medium;
case 'low':
return Priority.Low;
case 'lowest':
return Priority.Lowest;
default:
return Priority.None;
}
Expand Down
Loading

0 comments on commit 93ab4dd

Please sign in to comment.