fix(labels): make color reset work
This commit is contained in:
parent
e94b71d577
commit
28050d9cd5
@ -51,6 +51,7 @@ import Multiselect from '@/components/input/multiselect.vue'
|
|||||||
import type {ILabel} from '@/modelTypes/ILabel'
|
import type {ILabel} from '@/modelTypes/ILabel'
|
||||||
import {useLabelStore} from '@/stores/labels'
|
import {useLabelStore} from '@/stores/labels'
|
||||||
import {useTaskStore} from '@/stores/tasks'
|
import {useTaskStore} from '@/stores/tasks'
|
||||||
|
import {getRandomColorHex} from '@/helpers/color/randomColor'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
@ -132,7 +133,10 @@ async function createAndAddLabel(title: string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLabel = await labelStore.createLabel(new LabelModel({title}))
|
const newLabel = await labelStore.createLabel(new LabelModel({
|
||||||
|
title,
|
||||||
|
hexColor: getRandomColorHex(),
|
||||||
|
}))
|
||||||
addLabel(newLabel, false)
|
addLabel(newLabel, false)
|
||||||
labels.value.push(newLabel)
|
labels.value.push(newLabel)
|
||||||
success({message: t('task.label.addCreateSuccess')})
|
success({message: t('task.label.addCreateSuccess')})
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
* @param color
|
* @param color
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function colorFromHex(color: string) {
|
export function colorFromHex(color: string): string {
|
||||||
if (color.substring(0, 1) === '#') {
|
if (color !== '' && color.substring(0, 1) === '#') {
|
||||||
color = color.substring(1, 7)
|
color = color.substring(1, 7)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,12 +24,8 @@ export default class LabelModel extends AbstractModel<ILabel> implements ILabel
|
|||||||
constructor(data: Partial<ILabel> = {}) {
|
constructor(data: Partial<ILabel> = {}) {
|
||||||
super()
|
super()
|
||||||
this.assignData(data)
|
this.assignData(data)
|
||||||
|
|
||||||
if (this.hexColor === '') {
|
|
||||||
this.hexColor = getRandomColorHex()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.hexColor.substring(0, 1) !== '#') {
|
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
|
||||||
this.hexColor = '#' + this.hexColor
|
this.hexColor = '#' + this.hexColor
|
||||||
}
|
}
|
||||||
this.textColor = colorIsDark(this.hexColor) ? '#4a4a4a' : '#fff'
|
this.textColor = colorIsDark(this.hexColor) ? '#4a4a4a' : '#fff'
|
||||||
|
@ -67,7 +67,7 @@ export const useLabelStore = defineStore('label', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setLabel(label: ILabel) {
|
function setLabel(label: ILabel) {
|
||||||
labels.value[label.id] = label
|
labels.value[label.id] = {...label}
|
||||||
update(label)
|
update(label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import {useBaseStore} from '@/stores/base'
|
|||||||
import ProjectUserService from '@/services/projectUsers'
|
import ProjectUserService from '@/services/projectUsers'
|
||||||
import {useAuthStore} from '@/stores/auth'
|
import {useAuthStore} from '@/stores/auth'
|
||||||
import TaskCollectionService from '@/services/taskCollection'
|
import TaskCollectionService from '@/services/taskCollection'
|
||||||
|
import {getRandomColorHex} from '@/helpers/color/randomColor'
|
||||||
|
|
||||||
interface MatchedAssignee extends IUser {
|
interface MatchedAssignee extends IUser {
|
||||||
match: string,
|
match: string,
|
||||||
@ -337,7 +338,10 @@ export const useTaskStore = defineStore('task', () => {
|
|||||||
let label = validateLabel(Object.values(labelStore.labels), labelTitle)
|
let label = validateLabel(Object.values(labelStore.labels), labelTitle)
|
||||||
if (typeof label === 'undefined') {
|
if (typeof label === 'undefined') {
|
||||||
// label not found, create it
|
// label not found, create it
|
||||||
const labelModel = new LabelModel({title: labelTitle})
|
const labelModel = new LabelModel({
|
||||||
|
title: labelTitle,
|
||||||
|
hexColor: getRandomColorHex(),
|
||||||
|
})
|
||||||
label = await labelStore.createLabel(labelModel)
|
label = await labelStore.createLabel(labelModel)
|
||||||
}
|
}
|
||||||
return label
|
return label
|
||||||
|
@ -150,8 +150,8 @@ function deleteLabel(label: ILabel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function editLabelSubmit() {
|
function editLabelSubmit() {
|
||||||
return labelStore.updateLabel(labelEditLabel.value)
|
return labelStore.updateLabel(labelEditLabel.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function editLabel(label: ILabel) {
|
function editLabel(label: ILabel) {
|
||||||
if (label.createdBy.id !== userInfo.value.id) {
|
if (label.createdBy.id !== userInfo.value.id) {
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {computed, ref} from 'vue'
|
import {computed, onBeforeMount, ref} from 'vue'
|
||||||
import {useI18n} from 'vue-i18n'
|
import {useI18n} from 'vue-i18n'
|
||||||
import {useRouter} from 'vue-router'
|
import {useRouter} from 'vue-router'
|
||||||
|
|
||||||
@ -46,6 +46,7 @@ import LabelModel from '@/models/label'
|
|||||||
import {useLabelStore} from '@/stores/labels'
|
import {useLabelStore} from '@/stores/labels'
|
||||||
import {useTitle} from '@/composables/useTitle'
|
import {useTitle} from '@/composables/useTitle'
|
||||||
import {success} from '@/message'
|
import {success} from '@/message'
|
||||||
|
import {getRandomColorHex} from '@/helpers/color/randomColor'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@ -55,6 +56,8 @@ useTitle(() => t('label.create.title'))
|
|||||||
const labelStore = useLabelStore()
|
const labelStore = useLabelStore()
|
||||||
const label = ref(new LabelModel())
|
const label = ref(new LabelModel())
|
||||||
|
|
||||||
|
onBeforeMount(() => label.value.hexColor = getRandomColorHex())
|
||||||
|
|
||||||
const showError = ref(false)
|
const showError = ref(false)
|
||||||
const loading = computed(() => labelStore.isLoading)
|
const loading = computed(() => labelStore.isLoading)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user