1
0

Add notifications overview (#414)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/414
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2021-02-21 15:13:58 +00:00
parent 971d3cc358
commit c076298cf0
11 changed files with 385 additions and 17 deletions

View File

@ -0,0 +1,84 @@
import AbstractModel from '@/models/abstractModel'
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
import UserModel from '@/models/user'
import TaskModel from '@/models/task'
import TaskCommentModel from '@/models/taskComment'
import ListModel from '@/models/list'
import TeamModel from '@/models/team'
import names from './notificationNames.json'
export default class NotificationModel extends AbstractModel {
constructor(data) {
super(data)
switch (this.name) {
case names.TASK_COMMENT:
this.notification.doer = new UserModel(this.notification.doer)
this.notification.task = new TaskModel(this.notification.task)
this.notification.comment = new TaskCommentModel(this.notification.comment)
break
case names.TASK_ASSIGNED:
this.notification.doer = new UserModel(this.notification.doer)
this.notification.task = new TaskModel(this.notification.task)
this.notification.assignee = new UserModel(this.notification.assignee)
break
case names.TASK_DELETED:
this.notification.doer = new UserModel(this.notification.doer)
this.notification.task = new TaskModel(this.notification.task)
break
case names.LIST_CREATED:
this.notification.doer = new UserModel(this.notification.doer)
this.notification.list = new ListModel(this.notification.list)
break
case names.TEAM_MEMBER_ADDED:
this.notification.doer = new UserModel(this.notification.doer)
this.notification.member = new UserModel(this.notification.member)
this.notification.team = new TeamModel(this.notification.team)
break
}
this.created = new Date(this.created)
this.readAt = parseDateOrNull(this.readAt)
}
defaults() {
return {
id: 0,
name: '',
notification: null,
read: false,
readAt: null,
}
}
toText(user = null) {
let who = ''
switch (this.name) {
case names.TASK_COMMENT:
return `commented on ${this.notification.task.getTextIdentifier()}`
case names.TASK_ASSIGNED:
who = `${this.notification.assignee.getDisplayName()}`
if (user !== null && user.id === this.notification.assignee.id) {
who = 'you'
}
return `assigned ${who} to ${this.notification.task.getTextIdentifier()}`
case names.TASK_DELETED:
return `deleted ${this.notification.task.getTextIdentifier()}`
case names.LIST_CREATED:
return `created ${this.notification.list.title}`
case names.TEAM_MEMBER_ADDED:
who = `${this.notification.member.getDisplayName()}`
if (user !== null && user.id === this.notification.memeber.id) {
who = 'you'
}
return `added ${who} to the ${this.notification.team.title} team`
}
return ''
}
}

View File

@ -0,0 +1,7 @@
{
"TASK_COMMENT": "task.comment",
"TASK_ASSIGNED": "task.assigned",
"TASK_DELETED": "task.deleted",
"LIST_CREATED": "list.created",
"TEAM_MEMBER_ADDED": "team.member.added"
}

View File

@ -3,13 +3,7 @@ import UserModel from './user'
import LabelModel from './label'
import AttachmentModel from './attachment'
import SubscriptionModel from '@/models/subscription'
const parseDate = date => {
if (date && !date.startsWith('0001')) {
return new Date(date)
}
return null
}
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
export default class TaskModel extends AbstractModel {
@ -22,10 +16,10 @@ export default class TaskModel extends AbstractModel {
this.listId = Number(this.listId)
// Make date objects from timestamps
this.dueDate = parseDate(this.dueDate)
this.startDate = parseDate(this.startDate)
this.endDate = parseDate(this.endDate)
this.doneAt = parseDate(this.doneAt)
this.dueDate = parseDateOrNull(this.dueDate)
this.startDate = parseDateOrNull(this.startDate)
this.endDate = parseDateOrNull(this.endDate)
this.doneAt = parseDateOrNull(this.doneAt)
// Cancel all scheduled notifications for this task to be sure to only have available notifications
this.cancelScheduledNotifications()
@ -76,7 +70,7 @@ export default class TaskModel extends AbstractModel {
this.identifier = ''
}
if(typeof this.subscription !== 'undefined' && this.subscription !== null) {
if (typeof this.subscription !== 'undefined' && this.subscription !== null) {
this.subscription = new SubscriptionModel(this.subscription)
}
@ -119,6 +113,14 @@ export default class TaskModel extends AbstractModel {
}
}
getTextIdentifier() {
if(this.identifier === '') {
return `#${this.index}`
}
return this.identifier
}
/////////////////
// Helper functions
///////////////