2022-08-14 12:15:09 +02:00
|
|
|
import AbstractModel, { type IAbstract } from '@/models/abstractModel'
|
2022-07-21 00:42:36 +02:00
|
|
|
import TaskModel, { type ITask } from '@/models/task'
|
|
|
|
import UserModel, { type IUser } from '@/models/user'
|
|
|
|
import SubscriptionModel, { type ISubscription } from '@/models/subscription'
|
|
|
|
import type { INamespace } from '@/models/namespace'
|
|
|
|
|
2020-09-26 23:02:37 +02:00
|
|
|
import {getSavedFilterIdFromListId} from '@/helpers/savedFilter'
|
2019-03-02 11:25:10 +01:00
|
|
|
|
2022-08-14 12:15:09 +02:00
|
|
|
export interface IList extends IAbstract {
|
2022-06-23 03:22:21 +02:00
|
|
|
id: number
|
|
|
|
title: string
|
|
|
|
description: string
|
2022-07-21 00:42:36 +02:00
|
|
|
owner: IUser
|
|
|
|
tasks: ITask[]
|
|
|
|
namespaceId: INamespace['id']
|
2022-06-23 03:22:21 +02:00
|
|
|
isArchived: boolean
|
|
|
|
hexColor: string
|
|
|
|
identifier: string
|
2022-08-14 12:15:45 +02:00
|
|
|
backgroundInformation: any // FIXME: improve type
|
2022-06-23 03:22:21 +02:00
|
|
|
isFavorite: boolean
|
2022-07-21 00:42:36 +02:00
|
|
|
subscription: ISubscription
|
2022-06-23 03:22:21 +02:00
|
|
|
position: number
|
|
|
|
backgroundBlurHash: string
|
|
|
|
|
|
|
|
created: Date
|
|
|
|
updated: Date
|
2022-07-21 00:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class ListModel extends AbstractModel implements IList {
|
2022-08-14 12:15:45 +02:00
|
|
|
id = 0
|
|
|
|
title = ''
|
|
|
|
description = ''
|
|
|
|
owner: IUser = UserModel
|
|
|
|
tasks: ITask[] = []
|
|
|
|
namespaceId: INamespace['id'] = 0
|
|
|
|
isArchived = false
|
|
|
|
hexColor = ''
|
|
|
|
identifier = ''
|
|
|
|
backgroundInformation: any = null
|
|
|
|
isFavorite = false
|
|
|
|
subscription: ISubscription = null
|
|
|
|
position = 0
|
|
|
|
backgroundBlurHash = ''
|
2022-07-21 00:42:36 +02:00
|
|
|
|
2022-08-14 12:15:45 +02:00
|
|
|
created: Date = null
|
|
|
|
updated: Date = null
|
2020-09-05 22:35:52 +02:00
|
|
|
|
2022-08-14 12:15:45 +02:00
|
|
|
constructor(data: Partial<IList>) {
|
|
|
|
super()
|
|
|
|
this.assignData(data)
|
2020-03-25 22:27:29 +01:00
|
|
|
|
2022-02-13 19:57:12 +01:00
|
|
|
this.owner = new UserModel(this.owner)
|
|
|
|
|
2019-03-02 11:25:10 +01:00
|
|
|
// Make all tasks to task models
|
|
|
|
this.tasks = this.tasks.map(t => {
|
|
|
|
return new TaskModel(t)
|
|
|
|
})
|
2022-02-13 19:57:12 +01:00
|
|
|
|
|
|
|
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
|
|
|
|
this.hexColor = '#' + this.hexColor
|
2021-02-14 20:18:51 +01:00
|
|
|
}
|
|
|
|
|
2022-02-13 19:57:12 +01:00
|
|
|
if (typeof this.subscription !== 'undefined' && this.subscription !== null) {
|
|
|
|
this.subscription = new SubscriptionModel(this.subscription)
|
|
|
|
}
|
2022-02-13 18:11:26 +01:00
|
|
|
|
2020-02-08 14:16:06 +01:00
|
|
|
this.created = new Date(this.created)
|
|
|
|
this.updated = new Date(this.updated)
|
2019-03-02 11:25:10 +01:00
|
|
|
}
|
2020-02-08 14:16:06 +01:00
|
|
|
|
2020-09-26 23:02:37 +02:00
|
|
|
isSavedFilter() {
|
|
|
|
return this.getSavedFilterId() > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
getSavedFilterId() {
|
|
|
|
return getSavedFilterIdFromListId(this.id)
|
|
|
|
}
|
2019-03-02 11:25:10 +01:00
|
|
|
}
|