Fix Datetime Handling (#168)

Fix task filters

Fix null dates

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/168
This commit is contained in:
konrad 2020-06-27 17:04:30 +00:00
parent d586e15c56
commit cd588caa02
5 changed files with 32 additions and 31 deletions

View file

@ -78,8 +78,8 @@
this.wunderlistCode = this.$route.query.code this.wunderlistCode = this.$route.query.code
this.migrationService.getStatus() this.migrationService.getStatus()
.then(r => { .then(r => {
if(r.time_unix) { if(r.time) {
this.lastMigrationDate = new Date(r.time_unix) this.lastMigrationDate = new Date(r.time)
return return
} }
this.migrate() this.migrate()

View file

@ -14,9 +14,9 @@ export default class TaskModel extends AbstractModel {
this.listId = Number(this.listId) this.listId = Number(this.listId)
// Make date objects from timestamps // Make date objects from timestamps
this.dueDate = this.dueDate ? new Date(this.dueDate) : null this.dueDate = this.dueDate && !this.dueDate.startsWith('0001') ? new Date(this.dueDate) : null
this.startDate = this.startDate ? new Date(this.startDate) : null this.startDate = this.startDate && !this.startDate.startsWith('0001') ? new Date(this.startDate) : null
this.endDate = this.endDate ? new Date(this.endDate) : null this.endDate = this.endDate && !this.endDate.startsWith('0001') ? new Date(this.endDate) : null
// Cancel all scheduled notifications for this task to be sure to only have available notifications // Cancel all scheduled notifications for this task to be sure to only have available notifications
this.cancelScheduledNotifications() this.cancelScheduledNotifications()
@ -32,13 +32,13 @@ export default class TaskModel extends AbstractModel {
// Parse the repeat after into something usable // Parse the repeat after into something usable
this.parseRepeatAfter() this.parseRepeatAfter()
// Parse the assignees into user models // Parse the assignees into user models
this.assignees = this.assignees.map(a => { this.assignees = this.assignees.map(a => {
return new UserModel(a) return new UserModel(a)
}) })
this.createdBy = new UserModel(this.createdBy) this.createdBy = new UserModel(this.createdBy)
this.labels = this.labels.map(l => { this.labels = this.labels.map(l => {
return new LabelModel(l) return new LabelModel(l)
}) })
@ -52,7 +52,7 @@ export default class TaskModel extends AbstractModel {
} }
// Make all subtasks to task models // Make all subtasks to task models
Object.keys(this.relatedTasks).forEach(relationKind => { Object.keys(this.relatedTasks).forEach(relationKind => {
this.relatedTasks[relationKind] = this.relatedTasks[relationKind].map(t => { this.relatedTasks[relationKind] = this.relatedTasks[relationKind].map(t => {
return new TaskModel(t) return new TaskModel(t)
}) })
@ -64,14 +64,14 @@ export default class TaskModel extends AbstractModel {
}) })
// Set the task identifier to empty if the list does not have one // Set the task identifier to empty if the list does not have one
if(this.identifier === `-${this.index}`) { if (this.identifier === `-${this.index}`) {
this.identifier = '' this.identifier = ''
} }
this.created = new Date(this.created) this.created = new Date(this.created)
this.updated = new Date(this.updated) this.updated = new Date(this.updated)
} }
defaults() { defaults() {
return { return {
id: 0, id: 0,
@ -81,7 +81,7 @@ export default class TaskModel extends AbstractModel {
priority: 0, priority: 0,
labels: [], labels: [],
assignees: [], assignees: [],
dueDate: 0, dueDate: 0,
startDate: 0, startDate: 0,
endDate: 0, endDate: 0,
@ -99,15 +99,15 @@ export default class TaskModel extends AbstractModel {
createdBy: UserModel, createdBy: UserModel,
created: null, created: null,
updated: null, updated: null,
listId: 0, // Meta, only used when creating a new task listId: 0, // Meta, only used when creating a new task
} }
} }
///////////////// /////////////////
// Helper functions // Helper functions
/////////////// ///////////////
/** /**
* Parses the "repeat after x seconds" from the task into a usable js object inside the task. * Parses the "repeat after x seconds" from the task into a usable js object inside the task.
* This function should only be called from the constructor. * This function should only be called from the constructor.
@ -157,7 +157,7 @@ export default class TaskModel extends AbstractModel {
async scheduleNotification(date) { async scheduleNotification(date) {
if(date < new Date()) { if (date < new Date()) {
console.debug('Date is in the past, not scheduling a notification. Date is ', date) console.debug('Date is in the past, not scheduling a notification. Date is ', date)
return return
} }
@ -199,12 +199,12 @@ export default class TaskModel extends AbstractModel {
}, },
], ],
}) })
.then(() => { .then(() => {
console.debug('Notification scheduled for ' + date) console.debug('Notification scheduled for ' + date)
}) })
.catch(e => { .catch(e => {
console.debug('Error scheduling notification', e) console.debug('Error scheduling notification', e)
}) })
} }
} }

View file

@ -68,15 +68,15 @@
</th> </th>
<th v-if="activeColumns.dueDate"> <th v-if="activeColumns.dueDate">
Due&nbsp;Date Due&nbsp;Date
<sort :order="sortBy.due_date_unix" @click="sort('due_date_unix')"/> <sort :order="sortBy.due_date" @click="sort('due_date')"/>
</th> </th>
<th v-if="activeColumns.startDate"> <th v-if="activeColumns.startDate">
Start&nbsp;Date Start&nbsp;Date
<sort :order="sortBy.start_date_unix" @click="sort('start_date_unix')"/> <sort :order="sortBy.start_date" @click="sort('start_date')"/>
</th> </th>
<th v-if="activeColumns.endDate"> <th v-if="activeColumns.endDate">
End&nbsp;Date End&nbsp;Date
<sort :order="sortBy.end_date_unix" @click="sort('end_date_unix')"/> <sort :order="sortBy.end_date" @click="sort('end_date')"/>
</th> </th>
<th v-if="activeColumns.percentDone"> <th v-if="activeColumns.percentDone">
%&nbsp;Done %&nbsp;Done

View file

@ -57,24 +57,25 @@
} }
const params = { const params = {
sort_by: ['due_date_unix', 'id'], sort_by: ['due_date', 'id'],
order_by: ['desc', 'desc'], order_by: ['desc', 'desc'],
filter_by: ['done'], filter_by: ['done'],
filter_value: [false], filter_value: [false],
filter_comparator: ['equals'], filter_comparator: ['equals'],
filter_concat: 'and', filter_concat: 'and',
filter_include_nulls: true,
} }
if (!this.showAll) { if (!this.showAll) {
params.filter_by.push('start_date') params.filter_by.push('start_date')
params.filter_value.push(Math.round(+this.startDate / 1000)) params.filter_value.push(this.startDate)
params.filter_comparator.push('greater') params.filter_comparator.push('greater')
params.filter_by.push('end_date') params.filter_by.push('end_date')
params.filter_value.push(Math.round(+this.endDate / 1000)) params.filter_value.push(this.endDate)
params.filter_comparator.push('less') params.filter_comparator.push('less')
params.filter_by.push('due_date') params.filter_by.push('due_date')
params.filter_value.push(Math.round(+this.endDate / 1000)) params.filter_value.push(this.endDate)
params.filter_comparator.push('less') params.filter_comparator.push('less')
} }

View file

@ -460,9 +460,9 @@
}, },
setActiveFields() { setActiveFields() {
this.dueDate = +new Date(this.task.dueDate) === 0 ? null : this.task.dueDate this.dueDate = this.task.dueDate ? this.task.dueDate : null
this.task.startDate = +new Date(this.task.startDate) === 0 ? null : this.task.startDate this.task.startDate = this.task.startDate ? this.task.startDate : null
this.task.endDate = +new Date(this.task.endDate) === 0 ? null : this.task.endDate this.task.endDate = this.task.endDate ? this.task.endDate : null
// Set all active fields based on values in the model // Set all active fields based on values in the model
this.activeFields.assignees = this.task.assignees.length > 0 this.activeFields.assignees = this.task.assignees.length > 0