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

Project managers, board members, auto-update after reconnection, refactoring

This commit is contained in:
Maksim Eltyshev 2021-06-24 01:05:22 +05:00
parent 7956503a46
commit fe91b5241e
478 changed files with 21226 additions and 19495 deletions

View file

@ -0,0 +1,78 @@
module.exports = {
inputs: {
values: {
type: 'json',
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
required: true,
},
user: {
type: 'ref',
required: true,
},
project: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const managerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.project.id);
const boards = await sails.helpers.projects.getBoards(inputs.project.id);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
boards,
);
repositions.forEach(async ({ id, position: nextPosition }) => {
await Board.update({
id,
projectId: inputs.project.id,
}).set({
position: nextPosition,
});
const memberUserIds = await sails.helpers.boards.getMemberUserIds(id);
const userIds = _.union(managerUserIds, memberUserIds);
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
position: nextPosition,
},
});
});
});
const board = await Board.create({
...inputs.values,
position,
projectId: inputs.project.id,
}).fetch();
const boardMembership = await BoardMembership.create({
boardId: board.id,
userId: inputs.user.id,
}).fetch();
managerUserIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardCreate',
{
item: board,
},
inputs.request,
);
});
return {
board,
boardMembership,
};
},
};

View file

@ -0,0 +1,30 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const board = await Board.archiveOne(inputs.record.id);
if (board) {
sails.sockets.leaveAll(`board:${board.id}`);
sails.sockets.broadcast(
`project:${board.projectId}`,
'boardDelete',
{
item: board,
},
inputs.request,
);
}
return board;
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.boardMemberships.getMany({
boardId: inputs.idOrIds,
});
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const cards = await sails.helpers.boards.getCards(inputs.idOrIds);
return sails.helpers.utils.mapRecords(cards);
},
};

View file

@ -0,0 +1,41 @@
const LIMIT = 10;
module.exports = {
inputs: {
recordOrIdOrIds: {
type: 'ref',
custom: (value) => _.isObjectLike(value) || _.isString(value) || _.every(value, _.isString),
required: true,
},
beforeId: {
type: 'string',
},
},
async fn(inputs) {
const criteria = {};
let sort;
let limit;
if (_.isObjectLike(inputs.recordOrIdOrIds)) {
criteria.boardId = inputs.recordOrIdOrIds.id;
if (inputs.recordOrIdOrIds.type === Board.Types.KANBAN) {
sort = 'position';
} else if (inputs.recordOrIdOrIds.type === Board.Types.COLLECTION) {
if (inputs.beforeId) {
criteria.id = {
'<': inputs.beforeId,
};
}
limit = LIMIT;
}
} else {
criteria.boardId = inputs.recordOrIdOrIds;
}
return sails.helpers.cards.getMany(criteria, sort, limit);
},
};

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
return sails.helpers.labels.getMany({
boardId: inputs.idOrIds,
});
},
};

View file

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

View file

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

View file

@ -0,0 +1,15 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const boardMemberships = await sails.helpers.boards.getBoardMemberships(inputs.idOrIds);
return sails.helpers.utils.mapRecords(boardMemberships, 'userId', _.isArray(inputs.idOrIds));
},
};

View file

@ -0,0 +1,35 @@
module.exports = {
inputs: {
criteria: {
type: 'json',
required: true,
},
},
exits: {
pathNotFound: {},
},
async fn(inputs) {
const board = await Board.findOne(inputs.criteria);
if (!board) {
throw 'pathNotFound';
}
const project = await Project.findOne(board.projectId);
if (!project) {
throw {
pathNotFound: {
board,
},
};
}
return {
board,
project,
};
},
};

View file

@ -0,0 +1,81 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
values: {
type: 'json',
custom: (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (!_.isUndefined(value.position) && !_.isFinite(value.position)) {
return false;
}
return true;
},
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(
inputs.record.projectId,
);
if (!_.isUndefined(inputs.values.position)) {
const boards = await sails.helpers.projects.getBoards(
inputs.record.projectId,
inputs.record.id,
);
const { position, repositions } = sails.helpers.utils.insertToPositionables(
inputs.values.position,
boards,
);
inputs.values.position = position; // eslint-disable-line no-param-reassign
repositions.forEach(async ({ id, position: nextPosition }) => {
await Board.update({
id,
projectId: inputs.record.projectId,
}).set({
position: nextPosition,
});
userIds.forEach((userId) => {
sails.sockets.broadcast(`user:${userId}`, 'boardUpdate', {
item: {
id,
position: nextPosition,
},
});
});
});
}
const board = await Board.updateOne(inputs.record.id).set(inputs.values);
if (board) {
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'boardUpdate',
{
item: board,
},
inputs.request,
);
});
}
return board;
},
};