Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/tasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaimund Schlüßler <raimund.schluessler@mailbox.org>2019-01-27 09:24:23 +0300
committerRaimund Schlüßler <raimund.schluessler@mailbox.org>2020-05-09 21:37:15 +0300
commit64fc9b27af2f794ec89ca4d789b6d712447a1b81 (patch)
tree877ded2215a1814f154fb78f3a250728f0c51cc7 /src/models/task.js
parent0b75a29dcf83b56d48189d99e9aa189b1306e6d4 (diff)
Implement manual sorting
Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
Diffstat (limited to 'src/models/task.js')
-rw-r--r--src/models/task.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/models/task.js b/src/models/task.js
index d43e6766..85e89ef6 100644
--- a/src/models/task.js
+++ b/src/models/task.js
@@ -112,6 +112,12 @@ export default class Task {
this._class = this.vtodo.getFirstPropertyValue('class') || 'PUBLIC'
this._pinned = this.vtodo.getFirstPropertyValue('x-pinned') === 'true'
+ let sortOrder = this.vtodo.getFirstPropertyValue('x-apple-sort-order')
+ if (sortOrder === null) {
+ sortOrder = this.getSortOrder()
+ }
+ this._sortOrder = +sortOrder
+
this._searchQuery = ''
this._matchesSearchQuery = true
}
@@ -555,6 +561,10 @@ export default class Task {
this.updateLastModified()
this._created = this.vtodo.getFirstPropertyValue('created')
this._createdMoment = moment(this._created, 'YYYYMMDDTHHmmss')
+ // Update the sortorder if necessary
+ if (this.vtodo.getFirstPropertyValue('x-apple-sort-order') === null) {
+ this._sortOrder = this.getSortOrder()
+ }
}
get class() {
@@ -571,6 +581,48 @@ export default class Task {
this._class = this.vtodo.getFirstPropertyValue('class') || 'PUBLIC'
}
+ get sortOrder() {
+ return this._sortOrder
+ }
+
+ set sortOrder(sortOrder) {
+ // We expect an integer for the sort order.
+ sortOrder = parseInt(sortOrder)
+ if (isNaN(sortOrder)) {
+ this.vtodo.removeProperty('x-apple-sort-order')
+ // Get the default sort order.
+ sortOrder = this.getSortOrder()
+ } else {
+ this.vtodo.updatePropertyWithValue('x-apple-sort-order', sortOrder)
+ }
+ this.updateLastModified()
+ this._sortOrder = sortOrder
+ }
+
+ /**
+ * Construct the default value for the sort order
+ * from the created date.
+ *
+ * @returns {Integer} The sort order
+ */
+ getSortOrder() {
+ // If there is no created date we return 0.
+ if (this._created === null) {
+ return 0
+ }
+ return this._created.subtractDate(
+ new ICAL.Time({
+ year: 2001,
+ month: 1,
+ day: 1,
+ hour: 0,
+ minute: 0,
+ second: 0,
+ isDate: false,
+ })
+ ).toSeconds()
+ }
+
/**
* Checks if the task matches the search query
*