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,
|
||||
|
|
|
@ -1,44 +1,5 @@
|
|||
const POSITION_GAP = 65535;
|
||||
const { addPosition, removePosition } = require('../../utils/migrations');
|
||||
|
||||
module.exports.up = async (knex) => {
|
||||
await knex.schema.table('task', (table) => {
|
||||
/* Columns */
|
||||
module.exports.up = (knex) => addPosition(knex, 'task', 'card_id');
|
||||
|
||||
table.specificType('position', 'double precision');
|
||||
|
||||
/* Indexes */
|
||||
|
||||
table.index('position');
|
||||
});
|
||||
|
||||
const tasks = await knex('task').orderBy(['card_id', 'id']);
|
||||
|
||||
let prevCardId;
|
||||
let position;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (task of tasks) {
|
||||
if (task.card_id === prevCardId) {
|
||||
position += POSITION_GAP;
|
||||
} else {
|
||||
prevCardId = task.card_id;
|
||||
position = POSITION_GAP;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await knex('task')
|
||||
.update({
|
||||
position,
|
||||
})
|
||||
.where('id', task.id);
|
||||
}
|
||||
|
||||
return knex.schema.table('task', (table) => {
|
||||
table.dropNullable('position');
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.down = async (knex) =>
|
||||
knex.schema.table('task', (table) => {
|
||||
table.dropColumn('position');
|
||||
});
|
||||
module.exports.down = (knex) => removePosition(knex, 'task');
|
||||
|
|
5
server/db/migrations/20230108213138_labels_reordering.js
Normal file
5
server/db/migrations/20230108213138_labels_reordering.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const { addPosition, removePosition } = require('../../utils/migrations');
|
||||
|
||||
module.exports.up = (knex) => addPosition(knex, 'label', 'board_id');
|
||||
|
||||
module.exports.down = (knex) => removePosition(knex, 'label');
|
49
server/utils/migrations.js
Normal file
49
server/utils/migrations.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
const POSITION_GAP = 65535;
|
||||
|
||||
const addPosition = async (knex, tableName, parentFieldName) => {
|
||||
await knex.schema.table(tableName, (table) => {
|
||||
/* Columns */
|
||||
|
||||
table.specificType('position', 'double precision');
|
||||
|
||||
/* Indexes */
|
||||
|
||||
table.index('position');
|
||||
});
|
||||
|
||||
const records = await knex(tableName).orderBy([parentFieldName, 'id']);
|
||||
|
||||
let prevParentId;
|
||||
let position;
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (record of records) {
|
||||
if (record[parentFieldName] === prevParentId) {
|
||||
position += POSITION_GAP;
|
||||
} else {
|
||||
prevParentId = record[parentFieldName];
|
||||
position = POSITION_GAP;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await knex(tableName)
|
||||
.update({
|
||||
position,
|
||||
})
|
||||
.where('id', record.id);
|
||||
}
|
||||
|
||||
return knex.schema.table(tableName, (table) => {
|
||||
table.dropNullable('position');
|
||||
});
|
||||
};
|
||||
|
||||
const removePosition = (knex, tableName) =>
|
||||
knex.schema.table(tableName, (table) => {
|
||||
table.dropColumn('position');
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
addPosition,
|
||||
removePosition,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue