diff --git a/CHANGELOG.md b/CHANGELOG.md index 1740f8c..c7e73c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Add: Option to disable automatic update of a note overview #57 - Add: Option to configure the `status` field per note overview #66 @aiosk - Add: Option to configure the date and timeformat per note overview #68 @aiosk +- Add: The option `limit` to set how many results should be displayed per note overview #69 ## v1.6.0 (2022-12-26) diff --git a/README.md b/README.md index 2c6cd0e..edb19a2 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,14 @@ By which field the output should be sorted. It can be only sorted by one field a sort: todo_due ASC ``` +### limit + +Displayes only the first x hits of the search. Without the limit option all results are displayed. + +```yml +limit: 5 +``` + ### alias This allows renaming the fields in the output. diff --git a/src/noteoverview.ts b/src/noteoverview.ts index 9ce6f60..347c798 100644 --- a/src/noteoverview.ts +++ b/src/noteoverview.ts @@ -961,6 +961,19 @@ export namespace noteoverview { ]; let noteCount = 0; + let queryLimit = 50; + let noteLimit = overviewSettings["limit"] + ? overviewSettings["limit"] + : -1; + + if (noteLimit != -1) { + logging.verbose("Note limit: " + noteLimit); + if (overviewSettings.limit < queryLimit) { + queryLimit = overviewSettings.limit; + logging.verbose("Query limit: " + queryLimit); + } + } + let queryNotes = null; let pageQueryNotes = 1; const entrys: string[] = []; @@ -971,7 +984,7 @@ export namespace noteoverview { fields: "id, parent_id, " + dbFieldsArray.join(","), order_by: options.orderBy, order_dir: options.orderDir.toUpperCase(), - limit: 50, + limit: queryLimit, page: pageQueryNotes++, }); } catch (error) { @@ -988,6 +1001,9 @@ export namespace noteoverview { } for (let queryNotesKey in queryNotes.items) { + if (noteLimit != -1 && noteCount >= noteLimit) { + break; + } if (queryNotes.items[queryNotesKey].id != noteId) { noteCount++; @@ -1009,7 +1025,10 @@ export namespace noteoverview { } } } - } while (queryNotes.has_more); + } while ( + queryNotes.has_more && + (noteCount <= noteLimit || noteLimit == -1) + ); if (options.listview) { if (options.listview.separator) {