Skip to content

Commit

Permalink
Add: #66 Option to configure the status field per note overview @aiosk
Browse files Browse the repository at this point in the history
  • Loading branch information
JackGruber committed Dec 18, 2023
2 parents d17d825 + 4864fc2 commit 793c7e5
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions __test__/data/options/note_status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
status:
note: "n"
todo:
open: "o"
done: "d"
overdue: "od"
32 changes: 32 additions & 0 deletions __test__/fields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
4 changes: 4 additions & 0 deletions src/locales/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 11 additions & 5 deletions src/noteoverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export namespace noteoverview {

export async function getDefaultStatusText(): Promise<Object> {
let status = {
note: await joplin.settings.value("noteStatus"),
todo: {
overdue: await joplin.settings.value("todoStatusOverdue"),
open: await joplin.settings.value("todoStatusOpen"),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 793c7e5

Please sign in to comment.