1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 13:19: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

@ -0,0 +1,53 @@
/*!
* 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: {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
await sails.helpers.lists.deleteRelated(inputs.record);
sails.sockets.broadcast(
`board:${inputs.board.id}`,
'listClear',
{
item: inputs.record,
},
inputs.request,
);
sails.helpers.utils.sendWebhooks.with({
event: 'listClear',
buildData: () => ({
item: inputs.record,
included: {
projects: [inputs.project],
boards: [inputs.board],
},
}),
user: inputs.actorUser,
});
},
};

View file

@ -1,24 +1,12 @@
const valuesValidator = (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isFinite(value.position)) {
return false;
}
if (!_.isPlainObject(value.board)) {
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,
required: true,
},
project: {
@ -37,36 +25,43 @@ module.exports = {
async fn(inputs) {
const { values } = inputs;
const lists = await sails.helpers.boards.getLists(values.board.id);
const lists = await sails.helpers.boards.getFiniteListsById(values.board.id);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
values.position,
lists,
);
repositions.forEach(async ({ id, position: nextPosition }) => {
await List.update({
id,
boardId: values.board.id,
}).set({
position: nextPosition,
});
if (repositions.length > 0) {
// eslint-disable-next-line no-restricted-syntax
for (const reposition of repositions) {
// eslint-disable-next-line no-await-in-loop
await List.qm.updateOne(
{
id: reposition.record.id,
boardId: reposition.record.boardId,
},
{
position: reposition.position,
},
);
sails.sockets.broadcast(`board:${values.board.id}`, 'listUpdate', {
item: {
id,
position: nextPosition,
},
});
sails.sockets.broadcast(`board:${values.board.id}`, 'listUpdate', {
item: {
id: reposition.record.id,
position: reposition.position,
},
});
// TODO: send webhooks
});
// TODO: send webhooks
}
}
const list = await List.create({
const list = await List.qm.createOne({
...values,
position,
boardId: values.board.id,
}).fetch();
});
sails.sockets.broadcast(
`board:${list.boardId}`,
@ -79,13 +74,13 @@ module.exports = {
sails.helpers.utils.sendWebhooks.with({
event: 'listCreate',
data: {
buildData: () => ({
item: list,
included: {
projects: [inputs.project],
boards: [values.board],
},
},
}),
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: {
@ -22,7 +27,22 @@ module.exports = {
},
async fn(inputs) {
const list = await List.archiveOne(inputs.record.id);
const trashList = await List.qm.getOneTrashByBoardId(inputs.board.id);
const cards = await Card.qm.update(
{
listId: inputs.record.id,
},
{
listId: trashList.id,
position: null,
listChangedAt: new Date().toISOString(),
},
);
// TODO: create actions and notifications
const list = await List.qm.deleteOne(inputs.record.id);
if (list) {
sails.sockets.broadcast(
@ -30,23 +50,26 @@ module.exports = {
'listDelete',
{
item: list,
included: {
cards,
},
},
inputs.request,
);
sails.helpers.utils.sendWebhooks.with({
event: 'listDelete',
data: {
buildData: () => ({
item: list,
included: {
projects: [inputs.project],
boards: [inputs.board],
},
},
}),
user: inputs.actorUser,
});
}
return list;
return { list, cards };
},
};

View file

@ -0,0 +1,30 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
inputs: {
recordOrRecords: {
type: 'ref',
required: true,
},
},
async fn(inputs) {
let listIdOrIds;
if (_.isPlainObject(inputs.recordOrRecords)) {
({
recordOrRecords: { id: listIdOrIds },
} = inputs);
} else if (_.every(inputs.recordOrRecords, _.isPlainObject)) {
listIdOrIds = sails.helpers.utils.mapRecords(inputs.recordOrRecords);
}
const cards = await Card.qm.delete({
listId: listIdOrIds,
});
await sails.helpers.cards.deleteRelated(cards);
},
};

View file

@ -1,29 +0,0 @@
const idOrIdsValidator = (value) => _.isString(value) || _.every(value, _.isString);
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: idOrIdsValidator,
required: true,
},
exceptCardIdOrIds: {
type: 'json',
custom: idOrIdsValidator,
},
},
async fn(inputs) {
const criteria = {
listId: inputs.idOrIds,
};
if (!_.isUndefined(inputs.exceptCardIdOrIds)) {
criteria.id = {
'!=': inputs.exceptCardIdOrIds,
};
}
return sails.helpers.cards.getMany(criteria);
},
};

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 List.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 list = await List.qm.getOneById(inputs.id);
if (!list) {
throw 'pathNotFound';
}
const pathToProject = await sails.helpers.boards
.getPathToProjectById(list.boardId)
.intercept('pathNotFound', (nodes) => ({
pathNotFound: {
list,
...nodes,
},
}));
return {
list,
...pathToProject,
};
},
};

View file

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

View file

@ -0,0 +1,19 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
sync: true,
inputs: {
record: {
type: 'ref',
required: true,
},
},
fn(inputs) {
return [List.Types.ARCHIVE, List.Types.TRASH].includes(inputs.record.type);
},
};

View file

@ -0,0 +1,19 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
module.exports = {
sync: true,
inputs: {
record: {
type: 'ref',
required: true,
},
},
fn(inputs) {
return List.FINITE_TYPES.includes(inputs.record.type);
},
};

View file

@ -0,0 +1,20 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
// TODO: rename?
module.exports = {
sync: true,
inputs: {
record: {
type: 'ref',
required: true,
},
},
fn(inputs) {
return inputs.record.name || _.upperFirst(inputs.record.type);
},
};

View file

@ -0,0 +1,114 @@
/*!
* 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: {
type: 'ref',
required: true,
},
values: {
type: 'json',
required: true,
},
project: {
type: 'ref',
required: true,
},
board: {
type: 'ref',
required: true,
},
actorUser: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
exits: {
listInValuesMustBeEndless: {},
listInValuesMustBelongToBoard: {},
},
async fn(inputs) {
const { values } = inputs;
// TODO: allow for finite lists?
if (sails.helpers.lists.isFinite(values.list)) {
throw 'listInValuesMustBeEndless';
}
if (values.list.boardId !== inputs.board.id) {
throw 'listInValuesMustBelongToBoard';
}
if (inputs.record.type === List.Types.TRASH) {
values.prevListId = null;
} else if (sails.helpers.lists.isArchiveOrTrash(values.list)) {
values.prevListId = inputs.record.id;
} else if (inputs.record.type === List.Types.ARCHIVE) {
values.prevListId = null;
}
const cards = await Card.qm.update(
{
listId: inputs.record.id,
},
{
...values,
listId: values.list.id,
position: null,
listChangedAt: new Date().toISOString(),
},
);
const actions = await Action.qm.create(
cards.map((card) => ({
cardId: card.id,
userId: inputs.actorUser.id,
type: Action.Types.MOVE_CARD,
data: {
fromList: _.pick(inputs.record, ['id', 'type', 'name']),
toList: _.pick(values.list, ['id', 'type', 'name']),
},
})),
);
sails.sockets.broadcast(
`board:${inputs.board.id}`,
'cardsUpdate',
{
items: cards,
included: {
actions,
},
},
inputs.request,
);
cards.forEach((card) => {
// TODO: with prevData?
sails.helpers.utils.sendWebhooks.with({
event: 'cardUpdate',
buildData: () => ({
item: card,
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [values.list],
},
}),
user: inputs.actorUser,
});
});
// TODO: create notifications
return { cards, actions };
},
};

View file

@ -1,4 +1,9 @@
const List = require('../../models/List');
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
const { POSITION_GAP } = require('../../../constants');
module.exports = {
inputs: {
@ -6,10 +11,9 @@ module.exports = {
type: 'ref',
required: true,
},
type: {
type: 'string',
isIn: Object.values(List.SortTypes),
defaultsTo: List.SortTypes.NAME_ASC,
options: {
type: 'json',
required: true,
},
project: {
type: 'ref',
@ -28,66 +32,88 @@ module.exports = {
},
},
async fn(inputs) {
let cards = await sails.helpers.lists.getCards(inputs.record.id);
exits: {
cannotBeSortedAsEndlessList: {},
invalidFieldName: {},
},
switch (inputs.type) {
case List.SortTypes.NAME_ASC:
cards.sort((a, b) => a.name.localeCompare(b.name));
break;
case List.SortTypes.DUE_DATE_ASC:
cards.sort((a, b) => {
if (a.dueDate === null) return 1;
if (b.dueDate === null) return -1;
return new Date(a.dueDate) - new Date(b.dueDate);
});
break;
case List.SortTypes.CREATED_AT_ASC:
cards.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
break;
case List.SortTypes.CREATED_AT_DESC:
cards.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
break;
default:
throw new Error('Invalid sort type specified');
async fn(inputs) {
const { options } = inputs;
if (!sails.helpers.lists.isFinite(inputs.record)) {
throw 'cannotBeSortedAsEndlessList';
}
const positions = cards.map((c) => c.position).sort((a, b) => a - b);
let cards = await Card.qm.getByListId(inputs.record.id);
switch (options.fieldName) {
case List.SortFieldNames.NAME:
cards.sort((card1, card2) => card1.name.localeCompare(card2.name));
break;
case List.SortFieldNames.DUE_DATE:
cards.sort((card1, card2) => {
if (card1.dueDate === null) {
return 1;
}
if (card2.dueDate === null) {
return -1;
}
return new Date(card1.dueDate) - new Date(card2.dueDate);
});
break;
case List.SortFieldNames.CREATED_AT:
cards.sort((card1, card2) => new Date(card1.createdAt) - new Date(card2.createdAt));
break;
default:
throw 'invalidFieldName';
}
if (options.order === List.SortOrders.DESC) {
cards.reverse();
}
cards = await Promise.all(
cards.map(({ id }, index) =>
Card.updateOne({
id,
listId: inputs.record.id,
}).set({
position: positions[index],
}),
cards.map((card, index) =>
Card.qm.updateOne(
{
id: card.id,
listId: card.listId,
},
{
position: POSITION_GAP * (index + 1),
},
),
),
);
sails.sockets.broadcast(
`board:${inputs.record.boardId}`,
'listSort',
`board:${inputs.board.id}`,
'cardsUpdate',
{
item: inputs.record,
included: {
cards,
},
items: cards,
},
inputs.request,
);
sails.helpers.utils.sendWebhooks.with({
event: 'listSort',
data: {
item: inputs.record,
included: {
cards,
projects: [inputs.project],
boards: [inputs.board],
},
},
user: inputs.actorUser,
cards.forEach((card) => {
// TODO: with prevData?
sails.helpers.utils.sendWebhooks.with({
event: 'cardUpdate',
buildData: () => ({
item: card,
included: {
projects: [inputs.project],
boards: [inputs.board],
lists: [inputs.record],
},
}),
user: inputs.actorUser,
});
});
return cards;

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: {
@ -42,7 +34,10 @@ module.exports = {
const { values } = inputs;
if (!_.isUndefined(values.position)) {
const lists = await sails.helpers.boards.getLists(inputs.record.boardId, inputs.record.id);
const lists = await sails.helpers.boards.getFiniteListsById(
inputs.board.id,
inputs.record.id,
);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
values.position,
@ -51,26 +46,33 @@ module.exports = {
values.position = position;
repositions.forEach(async ({ id, position: nextPosition }) => {
await List.update({
id,
boardId: inputs.record.boardId,
}).set({
position: nextPosition,
});
if (repositions.length > 0) {
// eslint-disable-next-line no-restricted-syntax
for (const reposition of repositions) {
// eslint-disable-next-line no-await-in-loop
await List.qm.updateOne(
{
id: reposition.record.id,
boardId: reposition.record.boardId,
},
{
position: reposition.position,
},
);
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'listUpdate', {
item: {
id,
position: nextPosition,
},
});
sails.sockets.broadcast(`board:${inputs.board.id}`, 'listUpdate', {
item: {
id: reposition.record.id,
position: reposition.position,
},
});
// TODO: send webhooks
});
// TODO: send webhooks
}
}
}
const list = await List.updateOne(inputs.record.id).set({ ...values });
const list = await List.qm.updateOne(inputs.record.id, values);
if (list) {
sails.sockets.broadcast(
@ -84,16 +86,16 @@ module.exports = {
sails.helpers.utils.sendWebhooks.with({
event: 'listUpdate',
data: {
buildData: () => ({
item: list,
included: {
projects: [inputs.project],
boards: [inputs.board],
},
},
prevData: {
}),
buildPrevData: () => ({
item: inputs.record,
},
}),
user: inputs.actorUser,
});
}