Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jgclark committed Jan 20, 2025
2 parents f54db9b + 340be2f commit 4a11ed1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 11 additions & 0 deletions dwertheimer.TaskSorting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ Set the primary and secondary sort order for this default search in plugin prefe

This command brings all the tasks inside of the currently open note to the top of the note. You can choose whether you want headings (e.g. "Open Tasks", "Sheduled Tasks" etc.) or whether you want just the sorted tasks brought to the top. Note: brings only task lines (not indented underneath)

### /tsh - Tasks Sort under Heading (choose)

This command will sort the tasks under a heading that you choose.
You can pass the heading as a parameter, or you can choose it interactively.
You can also pass the sort order as a parameter, e.g. (["-priority", "content"]), or you can choose it interactively.
For example, this command will sort all the tasks under the heading "Open Tasks" by priority and then alphabetically by content.

```
noteplan://x-callback-url/runPlugin?pluginID=dwertheimer.TaskSorting&command=Sort%20tasks%20under%20heading%20%28choose%29&arg0=Open%20Tasks&arg1=%5B%22-priority%22%2C%22content%22%5D
```

## Task Sorting Notes

- At this time, the plugin will ignore headings that are attached to the tasks (e.g. tasks indented under root-level #headings). I need to understand/think more about this use case and how to deal with it in sorting.
Expand Down
8 changes: 6 additions & 2 deletions dwertheimer.TaskSorting/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"noteplan.minAppVersion": "3.4.0",
"plugin.id": "dwertheimer.TaskSorting",
"plugin.name": "🥷 Task Sorting & Tools",
"plugin.version": "1.1.0",
"plugin.lastUpdateInfo": "Added \\cnt copy noteTags command.\nInitial release of commands moved from the Task Automations plugin to the TaskSorter plugin.",
"plugin.version": "1.2.0",
"plugin.lastUpdateInfo": "1.2.0: Added heading and sortOrder as params that can be passed. Added \\cnt copy noteTags command.\nInitial release of commands moved from the Task Automations plugin to the TaskSorter plugin.",
"plugin.description": "Commands for sorting tasks in a note",
"plugin.author": "dwertheimer",
"plugin.requiredFiles-EDIT_ME": [
Expand Down Expand Up @@ -39,6 +39,10 @@
"jsFunction": "sortTasksUnderHeading",
"alias": [
"tsh"
],
"arguments": [
"heading (string)",
"sortOrder (array of strings) -- see README for details"
]
},
{
Expand Down
8 changes: 5 additions & 3 deletions dwertheimer.TaskSorting/src/sortTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,16 @@ export async function sortTasks(
* sortTasksUnderHeading
* Plugin entrypoint for "/sth"
*/
export async function sortTasksUnderHeading() {
export async function sortTasksUnderHeading(_heading: string, _sortOrder: string): Promise<void> {
try {
if (Editor.note) {
const heading = await chooseHeading(Editor?.note, false, false, false)
const heading = _heading || (await chooseHeading(Editor?.note, false, false, false))
if (heading && Editor.note) {
const block = getBlockUnderHeading(Editor.note, heading)
clo(block, `sortTasksUnderHeading block`)
if (block?.length) {
const sortOrder = await getUserSort()
const sortOrder: Array<string> = _sortOrder ? JSON.parse(_sortOrder) : await getUserSort()
clo(sortOrder, `sortTasksUnderHeading sortOrder`)
if (sortOrder) {
const sortedTasks = sortParagraphsByType(block, sortOrder)
clo(sortedTasks, `sortTasksUnderHeading sortedTasks`)
Expand Down

0 comments on commit 4a11ed1

Please sign in to comment.