1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 07:39:44 +02:00

feat: Version 2

Closes #627, closes #1047
This commit is contained in:
Maksim Eltyshev 2025-05-10 02:09:06 +02:00
parent ad7fb51cfa
commit 2ee1166747
1557 changed files with 76832 additions and 47042 deletions

View file

@ -1,24 +1,12 @@
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isFinite(value.position)) {
return false;
}
if (!_.isPlainObject(value.card)) {
return false;
}
return true;
};
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
inputs: {
values: {
type: 'ref',
custom: valuesValidator,
type: 'json',
required: true,
},
project: {
@ -33,6 +21,10 @@ module.exports = {
type: 'ref',
required: true,
},
card: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
@ -45,39 +37,44 @@ module.exports = {
async fn(inputs) {
const { values } = inputs;
const tasks = await sails.helpers.cards.getTasks(values.card.id);
const tasks = await Task.qm.getByTaskListId(values.taskList.id);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
values.position,
tasks,
);
repositions.forEach(async ({ id, position: nextPosition }) => {
await Task.update({
id,
cardId: values.card.id,
}).set({
position: nextPosition,
});
// eslint-disable-next-line no-restricted-syntax
for (const reposition of repositions) {
// eslint-disable-next-line no-await-in-loop
await Task.qm.updateOne(
{
id: reposition.record.id,
taskListId: reposition.record.taskListId,
},
{
position: reposition.position,
},
);
sails.sockets.broadcast(`board:${values.card.boardId}`, 'taskUpdate', {
sails.sockets.broadcast(`board:${inputs.board.id}`, 'taskUpdate', {
item: {
id,
position: nextPosition,
id: reposition.record.id,
position: reposition.position,
},
});
// TODO: send webhooks
});
}
const task = await Task.create({
const task = await Task.qm.createOne({
...values,
position,
cardId: values.card.id,
}).fetch();
taskListId: values.taskList.id,
});
sails.sockets.broadcast(
`board:${values.card.boardId}`,
`board:${inputs.board.id}`,
'taskCreate',
{
item: task,
@ -87,15 +84,16 @@ module.exports = {
sails.helpers.utils.sendWebhooks.with({
event: 'taskCreate',
data: {
buildData: () => ({
item: task,
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.list],
cards: [values.card],
cards: [inputs.card],
taskLists: [values.taskList],
},
},
}),
user: inputs.actorUser,
});

View file

@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
inputs: {
record: {
@ -20,6 +25,10 @@ module.exports = {
type: 'ref',
required: true,
},
taskList: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
@ -30,7 +39,7 @@ module.exports = {
},
async fn(inputs) {
const task = await Task.archiveOne(inputs.record.id);
const task = await Task.qm.deleteOne(inputs.record.id);
if (task) {
sails.sockets.broadcast(
@ -44,15 +53,16 @@ module.exports = {
sails.helpers.utils.sendWebhooks.with({
event: 'taskDelete',
data: {
buildData: () => ({
item: task,
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.list],
cards: [inputs.card],
taskLists: [inputs.taskList],
},
},
}),
user: inputs.actorUser,
});
}

View file

@ -1,14 +0,0 @@
const criteriaValidator = (value) => _.isArray(value) || _.isPlainObject(value);
module.exports = {
inputs: {
criteria: {
type: 'json',
custom: criteriaValidator,
},
},
async fn(inputs) {
return Task.find(inputs.criteria).sort('position');
},
};

View file

@ -0,0 +1,39 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
inputs: {
id: {
type: 'string',
required: true,
},
},
exits: {
pathNotFound: {},
},
async fn(inputs) {
const task = await Task.qm.getOneById(inputs.id);
if (!task) {
throw 'pathNotFound';
}
const pathToProject = await sails.helpers.taskLists
.getPathToProjectById(task.taskListId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
task,
...nodes,
},
}));
return {
task,
...pathToProject,
};
},
};

View file

@ -1,34 +0,0 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
required: true,
},
},
exits: {
pathNotFound: {},
},
async fn(inputs) {
const task = await Task.findOne(inputs.criteria);
if (!task) {
throw 'pathNotFound';
}
const path = await sails.helpers.cards
.getProjectPath(task.cardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
task,
...nodes,
},
}));
return {
task,
...path,
};
},
};

View file

@ -1,14 +1,7 @@
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
return false;
}
return true;
};
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
inputs: {
@ -18,7 +11,6 @@ module.exports = {
},
values: {
type: 'json',
custom: valuesValidator,
required: true,
},
project: {
@ -37,6 +29,10 @@ module.exports = {
type: 'ref',
required: true,
},
taskList: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
@ -46,11 +42,32 @@ module.exports = {
},
},
exits: {
taskListInValuesMustBelongToCard: {},
},
// TODO: use normalizeValues
async fn(inputs) {
const { values } = inputs;
if (values.taskList) {
if (values.taskList.cardId !== inputs.card.id) {
throw 'taskListInValuesMustBelongToCard';
}
if (values.taskList.id === inputs.taskList.id) {
delete values.taskList;
} else {
values.taskListId = values.taskList.id;
}
}
const taskList = values.taskList || inputs.taskList;
if (!_.isUndefined(values.position)) {
const tasks = await sails.helpers.cards.getTasks(inputs.record.cardId, inputs.record.id);
const tasks = await Task.qm.getByTaskListId(taskList.id, {
exceptIdOrIds: inputs.record.id,
});
const { position, repositions } = sails.helpers.utils.insertToPositionables(
values.position,
@ -59,26 +76,31 @@ module.exports = {
values.position = position;
repositions.forEach(async ({ id, position: nextPosition }) => {
await Task.update({
id,
cardId: inputs.record.cardId,
}).set({
position: nextPosition,
});
// eslint-disable-next-line no-restricted-syntax
for (const reposition of repositions) {
// eslint-disable-next-line no-await-in-loop
await Task.qm.updateOne(
{
id: reposition.record.id,
taskListId: reposition.record.taskListId,
},
{
position: reposition.position,
},
);
sails.sockets.broadcast(`board:${inputs.board.id}`, 'taskUpdate', {
item: {
id,
position: nextPosition,
id: reposition.record.id,
position: reposition.position,
},
});
// TODO: send webhooks
});
}
}
const task = await Task.updateOne(inputs.record.id).set({ ...values });
const task = await Task.qm.updateOne(inputs.record.id, values);
if (task) {
sails.sockets.broadcast(
@ -92,18 +114,22 @@ module.exports = {
sails.helpers.utils.sendWebhooks.with({
event: 'taskUpdate',
data: {
buildData: () => ({
item: task,
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.list],
cards: [inputs.card],
taskLists: [taskList],
},
},
prevData: {
}),
buildPrevData: () => ({
item: inputs.record,
},
included: {
taskLists: [inputs.taskList],
},
}),
user: inputs.actorUser,
});
}