mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 15:49:46 +02:00
Project managers, board members, auto-update after reconnection, refactoring
This commit is contained in:
parent
d6cb1f6683
commit
b39119ace4
478 changed files with 21226 additions and 19495 deletions
58
server/api/helpers/lists/create-one.js
Normal file
58
server/api/helpers/lists/create-one.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
values: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isPlainObject(value) && _.isFinite(value.position),
|
||||
required: true,
|
||||
},
|
||||
board: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const lists = await sails.helpers.boards.getLists(inputs.board.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
lists,
|
||||
);
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await List.update({
|
||||
id,
|
||||
boardId: inputs.board.id,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.board.id}`, 'listUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const list = await List.create({
|
||||
...inputs.values,
|
||||
position,
|
||||
boardId: inputs.board.id,
|
||||
}).fetch();
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listCreate',
|
||||
{
|
||||
item: list,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
return list;
|
||||
},
|
||||
};
|
28
server/api/helpers/lists/delete-one.js
Normal file
28
server/api/helpers/lists/delete-one.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const list = await List.archiveOne(inputs.record.id);
|
||||
|
||||
if (list) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listDelete',
|
||||
{
|
||||
item: list,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
}
|
||||
|
||||
return list;
|
||||
},
|
||||
};
|
27
server/api/helpers/lists/get-cards.js
Normal file
27
server/api/helpers/lists/get-cards.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
module.exports = {
|
||||
inputs: {
|
||||
idOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
required: true,
|
||||
},
|
||||
exceptCardIdOrIds: {
|
||||
type: 'json',
|
||||
custom: (value) => _.isString(value) || _.every(value, _.isString),
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const criteria = {
|
||||
listId: inputs.idOrIds,
|
||||
};
|
||||
|
||||
if (!_.isUndefined(inputs.exceptCardIdOrIds)) {
|
||||
criteria.id = {
|
||||
'!=': inputs.exceptCardIdOrIds,
|
||||
};
|
||||
}
|
||||
|
||||
return sails.helpers.cards.getMany(criteria);
|
||||
},
|
||||
};
|
12
server/api/helpers/lists/get-many.js
Normal file
12
server/api/helpers/lists/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 List.find(inputs.criteria).sort('position');
|
||||
},
|
||||
};
|
34
server/api/helpers/lists/get-project-path.js
Normal file
34
server/api/helpers/lists/get-project-path.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
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,
|
||||
};
|
||||
},
|
||||
};
|
70
server/api/helpers/lists/update-one.js
Normal file
70
server/api/helpers/lists/update-one.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
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) {
|
||||
if (!_.isUndefined(inputs.values.position)) {
|
||||
const lists = await sails.helpers.boards.getLists(inputs.record.boardId, inputs.record.id);
|
||||
|
||||
const { position, repositions } = sails.helpers.utils.insertToPositionables(
|
||||
inputs.values.position,
|
||||
lists,
|
||||
);
|
||||
|
||||
inputs.values.position = position; // eslint-disable-line no-param-reassign
|
||||
|
||||
repositions.forEach(async ({ id, position: nextPosition }) => {
|
||||
await List.update({
|
||||
id,
|
||||
boardId: inputs.record.boardId,
|
||||
}).set({
|
||||
position: nextPosition,
|
||||
});
|
||||
|
||||
sails.sockets.broadcast(`board:${inputs.record.boardId}`, 'listUpdate', {
|
||||
item: {
|
||||
id,
|
||||
position: nextPosition,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const list = await List.updateOne(inputs.record.id).set(inputs.values);
|
||||
|
||||
if (list) {
|
||||
sails.sockets.broadcast(
|
||||
`board:${list.boardId}`,
|
||||
'listUpdate',
|
||||
{
|
||||
item: list,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
}
|
||||
|
||||
return list;
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue