2022-08-04 18:57:43 +00:00
|
|
|
import AbstractModel from './abstractModel'
|
|
|
|
import UserModel from './user'
|
2019-03-07 19:48:40 +00:00
|
|
|
|
2022-08-04 18:57:43 +00:00
|
|
|
import type {ILabel} from '@/modelTypes/ILabel'
|
|
|
|
import type {IUser} from '@/modelTypes/IUser'
|
2022-07-20 22:42:36 +00:00
|
|
|
|
2022-08-04 18:57:43 +00:00
|
|
|
import {colorIsDark} from '@/helpers/color/colorIsDark'
|
2022-07-20 22:42:36 +00:00
|
|
|
|
2022-09-06 09:36:01 +00:00
|
|
|
export default class LabelModel extends AbstractModel<ILabel> implements ILabel {
|
2022-08-14 10:15:45 +00:00
|
|
|
id = 0
|
|
|
|
title = ''
|
|
|
|
// FIXME: this should be empty and be definied in the client.
|
|
|
|
// that way it get's never send to the server db and is easier to change in future versions.
|
2023-09-06 15:10:36 +00:00
|
|
|
hexColor = ''
|
2022-08-14 10:15:45 +00:00
|
|
|
description = ''
|
|
|
|
createdBy: IUser
|
2022-11-13 21:04:57 +00:00
|
|
|
projectId = 0
|
2022-08-14 10:15:45 +00:00
|
|
|
textColor = ''
|
2022-07-20 22:42:36 +00:00
|
|
|
|
2022-08-14 10:15:45 +00:00
|
|
|
created: Date = null
|
|
|
|
updated: Date = null
|
|
|
|
|
2022-09-26 16:09:24 +00:00
|
|
|
constructor(data: Partial<ILabel> = {}) {
|
2022-08-14 10:15:45 +00:00
|
|
|
super()
|
|
|
|
this.assignData(data)
|
2022-06-23 01:22:21 +00:00
|
|
|
|
2024-01-21 19:25:19 +00:00
|
|
|
if (this.hexColor !== '' && !this.hexColor.startsWith('#') && !this.hexColor.startsWith('var(')) {
|
2020-04-12 21:54:46 +00:00
|
|
|
this.hexColor = '#' + this.hexColor
|
2019-03-07 19:48:40 +00:00
|
|
|
}
|
2024-01-21 19:20:00 +00:00
|
|
|
|
|
|
|
if (this.hexColor === '') {
|
|
|
|
this.hexColor = 'var(--grey-200)'
|
|
|
|
this.textColor = 'var(--grey-800)'
|
|
|
|
} else {
|
|
|
|
this.textColor = colorIsDark(this.hexColor)
|
|
|
|
// Fixed colors to avoid flipping in dark mode
|
|
|
|
? 'hsl(215, 27.9%, 16.9%)' // grey-800
|
|
|
|
: 'hsl(220, 13%, 91%)' // grey-200
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:54:46 +00:00
|
|
|
this.createdBy = new UserModel(this.createdBy)
|
2020-02-08 13:16:06 +00:00
|
|
|
|
|
|
|
this.created = new Date(this.created)
|
|
|
|
this.updated = new Date(this.updated)
|
2019-03-07 19:48:40 +00:00
|
|
|
}
|
|
|
|
}
|