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:
parent
7956503a46
commit
fe91b5241e
478 changed files with 21226 additions and 19495 deletions
78
server/api/helpers/boards/create-one.js
Normal file
78
server/api/helpers/boards/create-one.js
Normal 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,
|
||||
};
|
||||
},
|
||||
};
|
30
server/api/helpers/boards/delete-one.js
Normal file
30
server/api/helpers/boards/delete-one.js
Normal 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;
|
||||
},
|
||||
};
|
15
server/api/helpers/boards/get-board-memberships.js
Normal file
15
server/api/helpers/boards/get-board-memberships.js
Normal 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,
|
||||
});
|
||||
},
|
||||
};
|
15
server/api/helpers/boards/get-card-ids.js
Normal file
15
server/api/helpers/boards/get-card-ids.js
Normal 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);
|
||||
},
|
||||
};
|
41
server/api/helpers/boards/get-cards.js
Normal file
41
server/api/helpers/boards/get-cards.js
Normal 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);
|
||||
},
|
||||
};
|
15
server/api/helpers/boards/get-labels.js
Normal file
15
server/api/helpers/boards/get-labels.js
Normal 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,
|
||||
});
|
||||
},
|
||||
};
|
27
server/api/helpers/boards/get-lists.js
Normal file
27
server/api/helpers/boards/get-lists.js
Normal 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);
|
||||
},
|
||||
};
|
12
server/api/helpers/boards/get-many.js
Normal file
12
server/api/helpers/boards/get-many.js
Normal 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');
|
||||
},
|
||||
};
|
15
server/api/helpers/boards/get-member-user-ids.js
Normal file
15
server/api/helpers/boards/get-member-user-ids.js
Normal 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));
|
||||
},
|
||||
};
|
35
server/api/helpers/boards/get-project-path.js
Normal file
35
server/api/helpers/boards/get-project-path.js
Normal 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,
|
||||
};
|
||||
},
|
||||
};
|
81
server/api/helpers/boards/update-one.js
Normal file
81
server/api/helpers/boards/update-one.js
Normal 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;
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue