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,38 @@
module.exports = {
inputs: {
values: {
type: 'json',
required: true,
},
user: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const project = await Project.create(inputs.values).fetch();
const projectManager = await ProjectManager.create({
projectId: project.id,
userId: inputs.user.id,
}).fetch();
sails.sockets.broadcast(
`user:${projectManager.userId}`,
'projectCreate',
{
item: project,
},
inputs.request,
);
return {
project,
projectManager,
};
},
};

View file

@ -0,0 +1,44 @@
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
request: {
type: 'ref',
},
},
async fn(inputs) {
const projectManagers = await ProjectManager.destroy({
projectId: inputs.record.id,
}).fetch();
const project = await Project.archiveOne(inputs.record.id);
if (project) {
const managerUserIds = sails.helpers.utils.mapRecords(projectManagers, 'userId');
const boardIds = await sails.helpers.projects.getBoardIds(project.id);
const boardRooms = boardIds.map((boardId) => `board:${boardId}`);
const memberUserIds = await sails.helpers.boards.getMemberUserIds(boardIds);
const userIds = _.union(managerUserIds, memberUserIds);
userIds.forEach((userId) => {
sails.sockets.removeRoomMembersFromRooms(`user:${userId}`, boardRooms);
sails.sockets.broadcast(
`user:${userId}`,
'projectDelete',
{
item: project,
},
inputs.request,
);
});
}
return project;
},
};

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 boards = await sails.helpers.projects.getBoards(inputs.idOrIds);
return sails.helpers.utils.mapRecords(boards);
},
};

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 boardIds = await sails.helpers.projects.getBoardIds(inputs.idOrIds);
return sails.helpers.boards.getMemberUserIds(boardIds);
},
};

View file

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

View file

@ -0,0 +1,16 @@
module.exports = {
inputs: {
idOrIds: {
type: 'json',
custom: (value) => _.isString(value) || _.every(value, _.isString),
required: true,
},
},
async fn(inputs) {
const managerUserIds = await sails.helpers.projects.getManagerUserIds(inputs.idOrIds);
const memberUserIds = await sails.helpers.projects.getBoardMemberUserIds(inputs.idOrIds);
return _.union(managerUserIds, memberUserIds);
},
};

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 projectManagers = await sails.helpers.projects.getProjectManagers(inputs.idOrIds);
return sails.helpers.utils.mapRecords(projectManagers, 'userId', _.isArray(inputs.idOrIds));
},
};

View file

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

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.projectManagers.getMany({
projectId: inputs.idOrIds,
});
},
};

View file

@ -0,0 +1,120 @@
const path = require('path');
const rimraf = require('rimraf');
module.exports = {
inputs: {
record: {
type: 'ref',
required: true,
},
values: {
type: 'json',
custom: (value) => {
if (!_.isPlainObject(value)) {
return false;
}
if (
!_.isUndefined(value.background) &&
!_.isNull(value.background) &&
!_.isPlainObject(value.background)
) {
return false;
}
if (!_.isUndefined(value.backgroundImage) && !_.isNull(value.backgroundImage)) {
return false;
}
return true;
},
required: true,
},
request: {
type: 'ref',
},
},
exits: {
backgroundImageDirnameMustBeNotNullInValues: {},
},
async fn(inputs) {
if (!_.isUndefined(inputs.values.backgroundImage)) {
/* eslint-disable no-param-reassign */
inputs.values.backgroundImageDirname = null;
delete inputs.values.backgroundImage;
/* eslint-enable no-param-reassign */
}
if (inputs.values.backgroundImageDirname) {
// eslint-disable-next-line no-param-reassign
inputs.values.background = {
type: 'image',
};
} else if (
_.isNull(inputs.values.backgroundImageDirname) &&
inputs.record.background &&
inputs.record.background.type === 'image'
) {
inputs.values.background = null; // eslint-disable-line no-param-reassign
}
let project;
if (inputs.values.background && inputs.values.background.type === 'image') {
if (_.isNull(inputs.values.backgroundImageDirname)) {
throw 'backgroundImageDirnameMustBeNotNullInValues';
}
if (_.isUndefined(inputs.values.backgroundImageDirname)) {
project = await Project.updateOne({
id: inputs.record.id,
backgroundImageDirname: {
'!=': null,
},
}).set(inputs.values);
if (!project) {
delete inputs.values.background; // eslint-disable-line no-param-reassign
}
}
}
if (!project) {
project = await Project.updateOne(inputs.record.id).set(inputs.values);
}
if (project) {
if (
inputs.record.backgroundImageDirname &&
project.backgroundImageDirname !== inputs.record.backgroundImageDirname
) {
try {
rimraf.sync(
path.join(
sails.config.custom.projectBackgroundImagesPath,
inputs.record.backgroundImageDirname,
),
);
} catch (error) {
console.warn(error.stack); // eslint-disable-line no-console
}
}
const userIds = await sails.helpers.projects.getManagerAndBoardMemberUserIds(project.id);
userIds.forEach((userId) => {
sails.sockets.broadcast(
`user:${userId}`,
'projectUpdate',
{
item: project,
},
inputs.request,
);
});
}
return project;
},
};