Skip to content

Commit

Permalink
Add: #69 limit of displayed notes
Browse files Browse the repository at this point in the history
  • Loading branch information
JackGruber committed Dec 24, 2023
1 parent 62cc8b7 commit 0a81a62
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 21 additions & 2 deletions src/noteoverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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) {
Expand All @@ -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++;

Expand All @@ -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) {
Expand Down

0 comments on commit 0a81a62

Please sign in to comment.