1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00

feat: Labels reordering

Closes #289
This commit is contained in:
Maksim Eltyshev 2023-01-09 12:17:06 +01:00
parent d260d2dac0
commit a741e26ccb
33 changed files with 370 additions and 104 deletions

View file

@ -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();

View file

@ -9,6 +9,6 @@ module.exports = {
},
async fn(inputs) {
return Label.find(inputs.criteria).sort('id');
return Label.find(inputs.criteria).sort('position');
},
};

View file

@ -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) {