mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
parent
d260d2dac0
commit
a741e26ccb
33 changed files with 370 additions and 104 deletions
|
@ -14,6 +14,10 @@ module.exports = {
|
|||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
|
@ -55,7 +59,7 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'color']);
|
||||
const values = _.pick(inputs, ['position', 'name', 'color']);
|
||||
|
||||
const label = await sails.helpers.labels.createOne.with({
|
||||
values: {
|
||||
|
|
|
@ -14,6 +14,9 @@ module.exports = {
|
|||
regex: /^[0-9]+$/,
|
||||
required: true,
|
||||
},
|
||||
position: {
|
||||
type: 'number',
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
|
@ -22,7 +25,6 @@ module.exports = {
|
|||
color: {
|
||||
type: 'string',
|
||||
isIn: Label.COLORS,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -55,7 +57,7 @@ module.exports = {
|
|||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['name', 'color']);
|
||||
const values = _.pick(inputs, ['position', 'name', 'color']);
|
||||
|
||||
label = await sails.helpers.labels.updateOne.with({
|
||||
values,
|
||||
|
|
|
@ -7,11 +7,23 @@ module.exports = {
|
|||
custom: idOrIdsValidator,
|
||||
required: true,
|
||||
},
|
||||
exceptLabelIdOrIds: {
|
||||
type: 'json',
|
||||
custom: idOrIdsValidator,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return sails.helpers.labels.getMany({
|
||||
const criteria = {
|
||||
boardId: inputs.idOrIds,
|
||||
});
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptLabelIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptLabelIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.labels.getMany(criteria);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3,6 +3,10 @@ const valuesValidator = (value) => {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isPlainObject(value.board)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -25,8 +29,32 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
const labels = await sails.helpers.boards.getLabels(values.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
labels,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Label.update({
|
||||
id,
|
||||
boardId: values.board.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${values.board.id}`, 'labelUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const label = await Label.create({
|
||||
...values,
|
||||
position,
|
||||
boardId: values.board.id,
|
||||
}).fetch();
|
||||
|
||||
|
|
|
@ -9,6 +9,6 @@ module.exports = {
|
|||
},
|
||||
|
||||
async fn(inputs) {
|
||||
return Label.find(inputs.criteria).sort('id');
|
||||
return Label.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
const valuesValidator = (value) => {
|
||||
if (!_.isPlainObject(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
|
@ -6,6 +18,7 @@ module.exports = {
|
|||
},
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: valuesValidator,
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
|
@ -16,6 +29,33 @@ module.exports = {
|
|||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (!_.isUndefined(values.position)) {
|
||||
const labels = await sails.helpers.boards.getLabels(inputs.record.boardId, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
values.position,
|
||||
labels,
|
||||
);
|
||||
|
||||
values.position = position;
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await Label.update({
|
||||
id,
|
||||
boardId: inputs.record.boardId,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'labelUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const label = await Label.updateOne(inputs.record.id).set({ ...values });
|
||||
|
||||
if (label) {
|
||||
|
|
|
@ -41,6 +41,10 @@ module.exports = {
|
|||
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
|
||||
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
|
||||
|
||||
position: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
isNotEmptyString: true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue