diff --git a/CHANGELOG.md b/CHANGELOG.md index c31fc1a..6fdb2eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add: Translation - Fix: #67 HTML image tags are not recognized for `image` option - Add: Option to disable automatic update of a note overview #57 +- Add: Option to configure the `status` field per note overview #66 @aiosk ## v1.6.0 (2022-12-26) diff --git a/README.md b/README.md index b0060ce..d620184 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ A note overview is created based on the defined search and the specified fields. - [count](#count) - [listview](#listview) - [link](#link) + - [status](#status) - [Examples](#examples) - [ToDo Overview](#todo-overview) - [Show all ToDos with status](#show-all-todos-with-status) @@ -113,7 +114,7 @@ Options that can be specified in the in the code block using YAML syntax. ### search The search filter which will be used to create the overview. -[Documentation of search filters](https://joplinapp.org/help/#search-filters). +[Documentation of search filters](https://joplinapp.org/help/apps/search#search-filters). ```yml search: type:todo @@ -273,6 +274,19 @@ link: html: true ``` +### status + +Customize note status field for a single overview. + +```yml +status: + note: "" + todo: + open: ☐ + done: 🗹 + overdue: ⚠ +``` + ## Examples ### ToDo Overview diff --git a/__test__/data/options/note_status.yml b/__test__/data/options/note_status.yml new file mode 100644 index 0000000..99258d0 --- /dev/null +++ b/__test__/data/options/note_status.yml @@ -0,0 +1,6 @@ +status: + note: "n" + todo: + open: "o" + done: "d" + overdue: "od" diff --git a/__test__/fields.test.ts b/__test__/fields.test.ts index 881a794..45f7441 100644 --- a/__test__/fields.test.ts +++ b/__test__/fields.test.ts @@ -42,3 +42,35 @@ describe("Field function", function () { expect(result).toBe("[Link](" + fields["source_url"] + ")"); }); }); + +describe("note status text", function () { + it(`Status `, async () => { + const options = getOptionsFromFile("note_status"); + const optionsObject = await noteoverview.getOptions(options); + + const now = new Date().getTime(); + const testCases = [ + [0, 0, 0, "n"], + [1, 0, 0, "o"], + [1, 0, now, "d"], + [1, now - 86400, 0, "od"], + [1, now + 86400, now - 86400, "d"], + [1, now - 86400, now + 86400, "d"], + ]; + + for (const t of testCases) { + const fields: Object = { + is_todo: Number(t[0]), + todo_due: Number(t[1]), + todo_completed: Number(t[2]), + }; + const expected = t[3]; + const actual = await noteoverview.getFieldValue( + "status", + fields, + optionsObject + ); + expect(actual).toBe(expected); + } + }); +}); diff --git a/src/locales/de_DE.json b/src/locales/de_DE.json index e85ef60..4388f2a 100644 --- a/src/locales/de_DE.json +++ b/src/locales/de_DE.json @@ -66,6 +66,10 @@ "label": "Farbe: %s", "description": "HTML Farbe für das Abschlussdatum (%s), wenn die Aufgabe abgeschlossen wurde, aber kein Fälligkeitsdatum gesetzt wurde" }, + "noteStatus": { + "label": "Feld status: %s", + "description": "Text für das Statusfeld wenn es sich um eine Notiz und keine Aufgabe handelt" + }, "fileLogLevel": { "label": "Loglevel", "description": "Einstellung für das Loglevel", diff --git a/src/locales/en_US.json b/src/locales/en_US.json index 19ab491..b932094 100644 --- a/src/locales/en_US.json +++ b/src/locales/en_US.json @@ -65,6 +65,10 @@ "label": "Color: %s", "description": "HTML color for the %s, when the todo was completed but no due date was set" }, + "noteStatus": { + "label": "Field status: %s", + "description": "Text for the status field if it is a note and not a todo" + }, "fileLogLevel": { "label": "Loglevel", "description": "Setting for the Loglevel", diff --git a/src/noteoverview.ts b/src/noteoverview.ts index e283295..e0605bd 100644 --- a/src/noteoverview.ts +++ b/src/noteoverview.ts @@ -313,6 +313,7 @@ export namespace noteoverview { export async function getDefaultStatusText(): Promise { let status = { + note: await joplin.settings.value("noteStatus"), todo: { overdue: await joplin.settings.value("todoStatusOverdue"), open: await joplin.settings.value("todoStatusOpen"), @@ -865,6 +866,7 @@ export namespace noteoverview { if (fields.includes("status")) { additionalFields.push("todo_due"); additionalFields.push("todo_completed"); + additionalFields.push("is_todo"); } // include body @@ -1201,11 +1203,15 @@ export namespace noteoverview { } break; case "status": - const status: string = await noteoverview.getToDoStatus( - fields["todo_due"], - fields["todo_completed"] - ); - value = options.statusText["todo"][status]; + if (!!fields["is_todo"]) { + const status: string = await noteoverview.getToDoStatus( + fields["todo_due"], + fields["todo_completed"] + ); + value = options.statusText["todo"][status]; + } else { + value = options.statusText["note"]; + } break; case "excerpt": value = await noteoverview.getMarkdownExcerpt( diff --git a/src/settings.ts b/src/settings.ts index 07bb09e..2db83af 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -60,6 +60,15 @@ export namespace settings { ), }, + noteStatus: { + value: "", + advanced: true, + type: SettingItemType.String, + section: "noteOverviewSection", + public: true, + label: i18n.__("settings.noteStatus.label", "note"), + description: i18n.__("settings.noteStatus.description"), + }, todoStatusOpen: { value: "", advanced: true,