mirror of
https://github.com/wekan/wekan.git
synced 2025-04-24 22:17:16 -04:00
Prevent dublicated empty labels of the same color
This commit is contained in:
parent
ab761f1186
commit
43de3b8a01
2 changed files with 15 additions and 6 deletions
|
@ -69,12 +69,12 @@ Template.formLabel.events({
|
||||||
Template.createLabelPopup.events({
|
Template.createLabelPopup.events({
|
||||||
// Create the new label
|
// Create the new label
|
||||||
'submit .create-label'(evt, tpl) {
|
'submit .create-label'(evt, tpl) {
|
||||||
|
evt.preventDefault();
|
||||||
const board = Boards.findOne(Session.get('currentBoard'));
|
const board = Boards.findOne(Session.get('currentBoard'));
|
||||||
const name = tpl.$('#labelName').val().trim();
|
const name = tpl.$('#labelName').val().trim();
|
||||||
const color = Blaze.getData(tpl.find('.fa-check')).color;
|
const color = Blaze.getData(tpl.find('.fa-check')).color;
|
||||||
board.addLabel(name, color);
|
board.addLabel(name, color);
|
||||||
Popup.back();
|
Popup.back();
|
||||||
evt.preventDefault();
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,7 @@ Boards.helpers({
|
||||||
},
|
},
|
||||||
|
|
||||||
getLabel(name, color) {
|
getLabel(name, color) {
|
||||||
return this.labels.find((current) => {
|
return _.findWhere(this.labels, { name, color });
|
||||||
return ((current.name === name) && (current.color === color));
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
labelIndex(labelId) {
|
labelIndex(labelId) {
|
||||||
|
@ -138,11 +136,22 @@ Boards.mutations({
|
||||||
|
|
||||||
addLabel(name, color) {
|
addLabel(name, color) {
|
||||||
const _id = Random.id(6);
|
const _id = Random.id(6);
|
||||||
|
|
||||||
|
// If an empty label of a given color already exists we don't want to create
|
||||||
|
// an other one because they would be indistinguishable in the UI (they
|
||||||
|
// would still have different `_id` but that is not exposed to the user).
|
||||||
|
if (name === '' && this.getLabel(name, color)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
return { $push: {labels: { _id, name, color }}};
|
return { $push: {labels: { _id, name, color }}};
|
||||||
},
|
},
|
||||||
|
|
||||||
editLabel(labelId, name, color) {
|
editLabel(labelId, name, color) {
|
||||||
const labelIndex = this.labelIndex(labelId);
|
const labelIndex = this.labelIndex(labelId);
|
||||||
|
|
||||||
|
if (name === '' && this.getLabel(name, color)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
$set: {
|
$set: {
|
||||||
[`labels.${labelIndex}.name`]: name,
|
[`labels.${labelIndex}.name`]: name,
|
||||||
|
@ -299,8 +308,8 @@ if (Meteor.isServer) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// If the user removes a label from a board, we have to remove references to
|
// If the user remove one label from a board, we cant to remove reference of
|
||||||
// this label in all cards of the board.
|
// this label in any card of this board.
|
||||||
Boards.after.update((userId, doc, fieldNames, modifier) => {
|
Boards.after.update((userId, doc, fieldNames, modifier) => {
|
||||||
if (!_.contains(fieldNames, 'labels') ||
|
if (!_.contains(fieldNames, 'labels') ||
|
||||||
!modifier.$pull ||
|
!modifier.$pull ||
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue