feat(labels): assign random color when creating labels
continuous-integration/drone/push Build is failing Details

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
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 26 additions and 3 deletions

View File

@ -0,0 +1,20 @@
const COLORS = [
'#ffbe0b',
'#fd8a09',
'#fb5607',
'#ff006e',
'#efbdeb',
'#8338ec',
'#5f5ff6',
'#3a86ff',
'#4c91ff',
'#0ead69',
'#25be8b',
'#073b4c',
'#373f47',
]
export function getRandomColorHex(): string {
return COLORS[Math.floor(Math.random() * COLORS.length)]
}

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