1
0

feat(labels): assign random color when creating labels

Resolves F-591
Related discussion: https://community.vikunja.io/t/assign-a-random-color-to-a-new-label/348/7
This commit is contained in:
kolaente
2023-09-06 17:10:36 +02:00
parent 9c46d064ac
commit 3f3d4b1682
2 changed files with 26 additions and 3 deletions

View File

@ -5,15 +5,14 @@ import type {ILabel} from '@/modelTypes/ILabel'
import type {IUser} from '@/modelTypes/IUser'
import {colorIsDark} from '@/helpers/color/colorIsDark'
const DEFAULT_LABEL_BACKGROUND_COLOR = 'e8e8e8'
import {getRandomColorHex} from '@/helpers/color/randomColor'
export default class LabelModel extends AbstractModel<ILabel> implements ILabel {
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.
hexColor = DEFAULT_LABEL_BACKGROUND_COLOR
hexColor = ''
description = ''
createdBy: IUser
projectId = 0
@ -25,6 +24,10 @@ export default class LabelModel extends AbstractModel<ILabel> implements ILabel
constructor(data: Partial<ILabel> = {}) {
super()
this.assignData(data)
if (this.hexColor === '') {
this.hexColor = getRandomColorHex()
}
if (this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor