feat: Add ability to copy/cut cards with shortcut support
This commit is contained in:
@@ -26,18 +26,25 @@
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - position
|
||||
* - name
|
||||
* properties:
|
||||
* boardId:
|
||||
* type: string
|
||||
* description: ID of the board to duplicate the card to
|
||||
* example: "1357158568008091265"
|
||||
* listId:
|
||||
* type: string
|
||||
* description: ID of the list to duplicate the card to
|
||||
* example: "1357158568008091266"
|
||||
* position:
|
||||
* type: number
|
||||
* minimum: 0
|
||||
* nullable: true
|
||||
* description: Position for the duplicated card within the list
|
||||
* example: 65536
|
||||
* name:
|
||||
* type: string
|
||||
* maxLength: 1024
|
||||
* nullable: true
|
||||
* description: Name/title for the duplicated card
|
||||
* example: Implement user authentication (copy)
|
||||
* responses:
|
||||
@@ -113,6 +120,8 @@
|
||||
* $ref: '#/components/responses/Forbidden'
|
||||
* 404:
|
||||
* $ref: '#/components/responses/NotFound'
|
||||
* 422:
|
||||
* $ref: '#/components/responses/UnprocessableEntity'
|
||||
*/
|
||||
|
||||
const { idInput } = require('../../../utils/inputs');
|
||||
@@ -124,6 +133,18 @@ const Errors = {
|
||||
CARD_NOT_FOUND: {
|
||||
cardNotFound: 'Card not found',
|
||||
},
|
||||
BOARD_NOT_FOUND: {
|
||||
boardNotFound: 'Board not found',
|
||||
},
|
||||
LIST_NOT_FOUND: {
|
||||
listNotFound: 'List not found',
|
||||
},
|
||||
LIST_MUST_BE_PRESENT: {
|
||||
listMustBePresent: 'List must be present',
|
||||
},
|
||||
POSITION_MUST_BE_PRESENT: {
|
||||
positionMustBePresent: 'Position must be present',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
@@ -132,15 +153,17 @@ module.exports = {
|
||||
...idInput,
|
||||
required: true,
|
||||
},
|
||||
boardId: idInput,
|
||||
listId: idInput,
|
||||
position: {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
required: true,
|
||||
allowNull: true,
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
maxLength: 1024,
|
||||
required: true,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -151,6 +174,18 @@ module.exports = {
|
||||
cardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
boardNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listNotFound: {
|
||||
responseType: 'notFound',
|
||||
},
|
||||
listMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
positionMustBePresent: {
|
||||
responseType: 'unprocessableEntity',
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
@@ -160,24 +195,60 @@ module.exports = {
|
||||
.getPathToProjectById(inputs.id)
|
||||
.intercept('pathNotFound', () => Errors.CARD_NOT_FOUND);
|
||||
|
||||
const boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
const isProjectManager = await sails.helpers.users.isProjectManager(currentUser.id, project.id);
|
||||
|
||||
let boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
board.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
if (!isProjectManager) {
|
||||
if (!boardMembership) {
|
||||
throw Errors.CARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: allow for endless lists?
|
||||
if (!sails.helpers.lists.isFinite(list)) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
let nextProject;
|
||||
let nextBoard;
|
||||
|
||||
if (!_.isUndefined(inputs.boardId)) {
|
||||
({ board: nextBoard, project: nextProject } = await sails.helpers.boards
|
||||
.getPathToProjectById(inputs.boardId)
|
||||
.intercept('pathNotFound', () => Errors.BOARD_NOT_FOUND));
|
||||
|
||||
boardMembership = await BoardMembership.qm.getOneByBoardIdAndUserId(
|
||||
nextBoard.id,
|
||||
currentUser.id,
|
||||
);
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.BOARD_NOT_FOUND; // Forbidden
|
||||
}
|
||||
}
|
||||
|
||||
if (!boardMembership) {
|
||||
throw Errors.LIST_NOT_FOUND; // Forbidden
|
||||
}
|
||||
|
||||
if (boardMembership.role !== BoardMembership.Roles.EDITOR) {
|
||||
throw Errors.NOT_ENOUGH_RIGHTS;
|
||||
}
|
||||
|
||||
let nextList;
|
||||
if (!_.isUndefined(inputs.listId)) {
|
||||
nextList = await List.qm.getOneById(inputs.listId, {
|
||||
boardId: (nextBoard || board).id,
|
||||
});
|
||||
|
||||
if (!nextList) {
|
||||
throw Errors.LIST_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
const values = _.pick(inputs, ['position', 'name']);
|
||||
|
||||
const {
|
||||
@@ -190,17 +261,23 @@ module.exports = {
|
||||
customFieldGroups,
|
||||
customFields,
|
||||
customFieldValues,
|
||||
} = await sails.helpers.cards.duplicateOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
values: {
|
||||
...values,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
});
|
||||
} = await sails.helpers.cards.duplicateOne
|
||||
.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
record: card,
|
||||
values: {
|
||||
...values,
|
||||
project: nextProject,
|
||||
board: nextBoard,
|
||||
list: nextList,
|
||||
creatorUser: currentUser,
|
||||
},
|
||||
request: this.req,
|
||||
})
|
||||
.intercept('positionMustBeInValues', () => Errors.POSITION_MUST_BE_PRESENT)
|
||||
.intercept('listMustBeInValues', () => Errors.LIST_MUST_BE_PRESENT);
|
||||
|
||||
return {
|
||||
item: nextCard,
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
/*!
|
||||
* 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: {
|
||||
fromRecord: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
toRecord: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
detachBoardCustomFieldGroups: {
|
||||
type: 'boolean',
|
||||
defaultsTo: true,
|
||||
},
|
||||
detachBaseCustomFieldGroups: {
|
||||
type: 'boolean',
|
||||
defaultsTo: true,
|
||||
},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const boardCustomFieldGroups = inputs.detachBoardCustomFieldGroups
|
||||
? await CustomFieldGroup.qm.getByBoardId(inputs.fromRecord.boardId)
|
||||
: [];
|
||||
|
||||
const cardCustomFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.fromRecord.id);
|
||||
|
||||
const customFieldGroups = [...boardCustomFieldGroups, ...cardCustomFieldGroups];
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
|
||||
let customFieldGroupsByBaseCustomFieldGroupId;
|
||||
let baseCustomFieldGroupById;
|
||||
let customFieldsByBaseCustomFieldGroupId;
|
||||
let nextCustomFieldsTotal = customFields.length;
|
||||
|
||||
if (inputs.detachBaseCustomFieldGroups) {
|
||||
customFieldGroupsByBaseCustomFieldGroupId = _.groupBy(
|
||||
customFieldGroups.filter(({ baseCustomFieldGroupId }) => baseCustomFieldGroupId),
|
||||
'baseCustomFieldGroupId',
|
||||
);
|
||||
|
||||
const baseCustomFieldGroupIds = Object.keys(customFieldGroupsByBaseCustomFieldGroupId);
|
||||
|
||||
if (baseCustomFieldGroupIds.length > 0) {
|
||||
const baseCustomFieldGroups =
|
||||
await BaseCustomFieldGroup.qm.getByIds(baseCustomFieldGroupIds);
|
||||
|
||||
baseCustomFieldGroupById = _.keyBy(baseCustomFieldGroups, 'id');
|
||||
|
||||
const baseCustomFields = await CustomField.qm.getByBaseCustomFieldGroupIds(
|
||||
Object.keys(baseCustomFieldGroupById),
|
||||
);
|
||||
|
||||
customFieldsByBaseCustomFieldGroupId = _.groupBy(
|
||||
baseCustomFields,
|
||||
'baseCustomFieldGroupId',
|
||||
);
|
||||
|
||||
nextCustomFieldsTotal += Object.entries(customFieldGroupsByBaseCustomFieldGroupId).reduce(
|
||||
(result, [baseCustomFieldGroupId, customFieldGroupsItem]) => {
|
||||
const customFieldsItem = customFieldsByBaseCustomFieldGroupId[baseCustomFieldGroupId];
|
||||
|
||||
if (!customFieldsItem) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result + customFieldsItem.length * customFieldGroupsItem.length;
|
||||
},
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(inputs.fromRecord.id);
|
||||
|
||||
const ids = await sails.helpers.utils.generateIds(
|
||||
customFieldGroups.length + nextCustomFieldsTotal,
|
||||
);
|
||||
|
||||
const nextCustomFieldGroupIdByCustomFieldGroupId = {};
|
||||
const nextCustomFieldGroupsValues = customFieldGroups.map((customFieldGroup, index) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] = id;
|
||||
|
||||
const values = {
|
||||
..._.pick(customFieldGroup, ['position']),
|
||||
id,
|
||||
cardId: inputs.toRecord.id,
|
||||
position: customFieldGroup.boardId
|
||||
? POSITION_GAP * (index + 1)
|
||||
: customFieldGroup.position + POSITION_GAP * boardCustomFieldGroups.length,
|
||||
};
|
||||
|
||||
if (inputs.detachBaseCustomFieldGroups) {
|
||||
values.name =
|
||||
customFieldGroup.name ||
|
||||
baseCustomFieldGroupById[customFieldGroup.baseCustomFieldGroupId].name;
|
||||
} else {
|
||||
Object.assign(values, {
|
||||
name: customFieldGroup.name,
|
||||
baseCustomFieldGroupId: customFieldGroup.baseCustomFieldGroupId,
|
||||
});
|
||||
}
|
||||
|
||||
return values;
|
||||
});
|
||||
|
||||
const nextCustomFieldGroups = await CustomFieldGroup.qm.create(nextCustomFieldGroupsValues);
|
||||
|
||||
const nextCustomFieldIdByCustomFieldId = {};
|
||||
const nextCustomFieldsValues = customFields.map((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[customField.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customField, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customField.customFieldGroupId],
|
||||
};
|
||||
});
|
||||
|
||||
if (inputs.detachBaseCustomFieldGroups) {
|
||||
Object.entries(customFieldGroupsByBaseCustomFieldGroupId).forEach(
|
||||
([baseCustomFieldGroupId, customFieldGroupsItem]) => {
|
||||
const customFieldsItem = customFieldsByBaseCustomFieldGroupId[baseCustomFieldGroupId];
|
||||
|
||||
if (!customFieldsItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
customFieldGroupsItem.forEach((customFieldGroup) => {
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const groupedId = `${customFieldGroup.id}:${customField.id}`;
|
||||
const id = ids.shift();
|
||||
|
||||
nextCustomFieldIdByCustomFieldId[groupedId] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
customFieldGroupId: nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id],
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const nextCustomFields = await CustomField.qm.create(nextCustomFieldsValues);
|
||||
|
||||
const nextCustomFieldValuesValues = customFieldValues.map((customFieldValue) => {
|
||||
const groupedId = `${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`;
|
||||
|
||||
return {
|
||||
..._.pick(customFieldValue, ['content']),
|
||||
cardId: inputs.toRecord.id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldValue.customFieldGroupId] ||
|
||||
customFieldValue.customFieldGroupId,
|
||||
customFieldId:
|
||||
nextCustomFieldIdByCustomFieldId[groupedId] ||
|
||||
nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId] ||
|
||||
customFieldValue.customFieldId,
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFieldValues = await CustomFieldValue.qm.create(nextCustomFieldValuesValues);
|
||||
|
||||
return {
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -198,11 +198,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const groupedId = `${customFieldGroup.id}:${customField.id}`;
|
||||
const id = ids.shift();
|
||||
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[cardId][
|
||||
`${customFieldGroup.id}:${customField.id}`
|
||||
] = id;
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[cardId][groupedId] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
@@ -223,11 +222,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
customFieldsItem.forEach((customField) => {
|
||||
const groupedId = `${customFieldGroup.id}:${customField.id}`;
|
||||
const id = ids.shift();
|
||||
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[customFieldGroup.cardId][
|
||||
`${customFieldGroup.id}:${customField.id}`
|
||||
] = id;
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[customFieldGroup.cardId][groupedId] = id;
|
||||
|
||||
nextCustomFieldsValues.push({
|
||||
..._.pick(customField, ['name', 'showOnFrontOfCard', 'position']),
|
||||
@@ -262,10 +260,11 @@ module.exports = {
|
||||
nextCustomFieldIdByCustomFieldIdByCardId[customFieldValue.cardId];
|
||||
|
||||
if (nextCustomFieldIdByCustomFieldId) {
|
||||
const groupedId = `${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`;
|
||||
|
||||
const nextCustomFieldId =
|
||||
nextCustomFieldIdByCustomFieldId[
|
||||
`${customFieldValue.customFieldGroupId}:${customFieldValue.customFieldId}`
|
||||
] || nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId];
|
||||
nextCustomFieldIdByCustomFieldId[groupedId] ||
|
||||
nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId];
|
||||
|
||||
if (nextCustomFieldId) {
|
||||
updateValues.customFieldId = nextCustomFieldId;
|
||||
|
||||
@@ -25,10 +25,6 @@ module.exports = {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
join: {
|
||||
type: 'boolean',
|
||||
defaultsTo: false,
|
||||
},
|
||||
request: {
|
||||
type: 'ref',
|
||||
},
|
||||
@@ -36,25 +32,58 @@ module.exports = {
|
||||
|
||||
exits: {
|
||||
positionMustBeInValues: {},
|
||||
boardInValuesMustBelongToProject: {},
|
||||
listMustBeInValues: {},
|
||||
listInValuesMustBelongToBoard: {},
|
||||
},
|
||||
|
||||
async fn(inputs) {
|
||||
const { values } = inputs;
|
||||
|
||||
if (values.list) {
|
||||
const typeState = List.TYPE_STATE_BY_TYPE[values.list.type];
|
||||
if (values.project && values.project.id === inputs.project.id) {
|
||||
delete values.project;
|
||||
}
|
||||
|
||||
if (inputs.record.isClosed) {
|
||||
if (typeState === List.TypeStates.OPENED) {
|
||||
values.isClosed = false;
|
||||
}
|
||||
} else if (typeState === List.TypeStates.CLOSED) {
|
||||
values.isClosed = true;
|
||||
const project = values.project || inputs.project;
|
||||
|
||||
if (values.board) {
|
||||
if (values.board.projectId !== project.id) {
|
||||
throw 'boardInValuesMustBelongToProject';
|
||||
}
|
||||
|
||||
if (values.board.id === inputs.board.id) {
|
||||
delete values.board;
|
||||
} else {
|
||||
values.boardId = values.board.id;
|
||||
}
|
||||
}
|
||||
|
||||
const board = values.board || inputs.board;
|
||||
|
||||
if (values.list) {
|
||||
if (values.list.boardId !== board.id) {
|
||||
throw 'listInValuesMustBelongToBoard';
|
||||
}
|
||||
|
||||
if (values.list.id === inputs.list.id) {
|
||||
delete values.list;
|
||||
} else {
|
||||
values.listId = values.list.id;
|
||||
}
|
||||
} else if (values.board) {
|
||||
throw 'listMustBeInValues';
|
||||
}
|
||||
|
||||
const list = values.list || inputs.list;
|
||||
|
||||
if (sails.helpers.lists.isFinite(list)) {
|
||||
if (values.list && _.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
}
|
||||
} else {
|
||||
values.position = null;
|
||||
}
|
||||
|
||||
if (sails.helpers.lists.isFinite(list)) {
|
||||
if (_.isUndefined(values.position)) {
|
||||
throw 'positionMustBeInValues';
|
||||
@@ -95,9 +124,54 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
let labelIds;
|
||||
if (values.board) {
|
||||
const prevLabels = await sails.helpers.cards.getLabels(inputs.record.id);
|
||||
|
||||
const labels = await Label.qm.getByBoardId(values.board.id);
|
||||
const labelByName = _.keyBy(labels, 'name');
|
||||
|
||||
labelIds = await Promise.all(
|
||||
prevLabels.map(async (label) => {
|
||||
if (labelByName[label.name]) {
|
||||
return labelByName[label.name].id;
|
||||
}
|
||||
|
||||
const { id } = await sails.helpers.labels.createOne.with({
|
||||
project,
|
||||
values: {
|
||||
..._.omit(label, ['id', 'boardId', 'createdAt', 'updatedAt']),
|
||||
board,
|
||||
},
|
||||
actorUser: values.creatorUser,
|
||||
});
|
||||
|
||||
return id;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (values.list) {
|
||||
const typeState = List.TYPE_STATE_BY_TYPE[values.list.type];
|
||||
|
||||
if (inputs.record.isClosed) {
|
||||
if (typeState === List.TypeStates.OPENED) {
|
||||
values.isClosed = false;
|
||||
}
|
||||
} else if (typeState === List.TypeStates.CLOSED) {
|
||||
values.isClosed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!values.name) {
|
||||
const t = sails.helpers.utils.makeTranslator(values.creatorUser.language);
|
||||
values.name = `${inputs.record.name} (${t('copy')})`;
|
||||
}
|
||||
|
||||
let card = await Card.qm.createOne({
|
||||
..._.pick(inputs.record, [
|
||||
'boardId',
|
||||
'listId',
|
||||
'prevListId',
|
||||
'type',
|
||||
'name',
|
||||
@@ -108,12 +182,16 @@ module.exports = {
|
||||
'isClosed',
|
||||
]),
|
||||
...values,
|
||||
listId: list.id,
|
||||
creatorUserId: values.creatorUser.id,
|
||||
listChangedAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
const cardMemberships = await CardMembership.qm.getByCardId(inputs.record.id);
|
||||
const boardMemberUserIds = await sails.helpers.boards.getMemberUserIds(card.boardId);
|
||||
const boardMemberUserIdsSet = new Set(boardMemberUserIds);
|
||||
|
||||
const cardMemberships = await CardMembership.qm.getByCardId(inputs.record.id, {
|
||||
userIdOrIds: boardMemberUserIds,
|
||||
});
|
||||
|
||||
const cardMembershipsValues = cardMemberships.map((cardMembership) => ({
|
||||
..._.pick(cardMembership, ['userId']),
|
||||
@@ -122,10 +200,13 @@ module.exports = {
|
||||
|
||||
const nextCardMemberships = await CardMembership.qm.create(cardMembershipsValues);
|
||||
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.record.id);
|
||||
if (!values.board) {
|
||||
const cardLabels = await CardLabel.qm.getByCardId(inputs.record.id);
|
||||
labelIds = sails.helpers.utils.mapRecords(cardLabels, 'labelId');
|
||||
}
|
||||
|
||||
const cardLabelsValues = cardLabels.map((cardLabel) => ({
|
||||
..._.pick(cardLabel, ['labelId']),
|
||||
const cardLabelsValues = labelIds.map((labelId) => ({
|
||||
labelId,
|
||||
cardId: card.id,
|
||||
}));
|
||||
|
||||
@@ -137,15 +218,7 @@ module.exports = {
|
||||
const tasks = await Task.qm.getByTaskListIds(taskListIds);
|
||||
const attachments = await Attachment.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const customFieldGroups = await CustomFieldGroup.qm.getByCardId(inputs.record.id);
|
||||
const customFieldGroupIds = sails.helpers.utils.mapRecords(customFieldGroups);
|
||||
|
||||
const customFields = await CustomField.qm.getByCustomFieldGroupIds(customFieldGroupIds);
|
||||
const customFieldValues = await CustomFieldValue.qm.getByCardId(inputs.record.id);
|
||||
|
||||
const ids = await sails.helpers.utils.generateIds(
|
||||
taskLists.length + attachments.length + customFieldGroups.length + customFields.length,
|
||||
);
|
||||
const ids = await sails.helpers.utils.generateIds(taskLists.length + attachments.length);
|
||||
|
||||
const nextTaskListIdByTaskListId = {};
|
||||
const nextTaskListsValues = await taskLists.map((taskList) => {
|
||||
@@ -162,8 +235,9 @@ module.exports = {
|
||||
const nextTaskLists = await TaskList.qm.create(nextTaskListsValues);
|
||||
|
||||
const nextTasksValues = tasks.map((task) => ({
|
||||
..._.pick(task, ['linkedCardId', 'assigneeUserId', 'position', 'name', 'isCompleted']),
|
||||
..._.pick(task, ['linkedCardId', 'position', 'name', 'isCompleted']),
|
||||
taskListId: nextTaskListIdByTaskListId[task.taskListId],
|
||||
assigneeUserId: boardMemberUserIdsSet.has(task.assigneeUserId) ? task.assigneeUserId : null,
|
||||
}));
|
||||
|
||||
const nextTasks = await Task.qm.create(nextTasksValues);
|
||||
@@ -193,47 +267,16 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
const nextCustomFieldGroupIdByCustomFieldGroupId = {};
|
||||
const nextCustomFieldGroupsValues = customFieldGroups.map((customFieldGroup) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldGroup.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customFieldGroup, ['baseCustomFieldGroupId', 'position', 'name']),
|
||||
id,
|
||||
cardId: card.id,
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFieldGroups = await CustomFieldGroup.qm.create(nextCustomFieldGroupsValues);
|
||||
|
||||
const nextCustomFieldIdByCustomFieldId = {};
|
||||
const nextCustomFieldsValues = customFields.map((customField) => {
|
||||
const id = ids.shift();
|
||||
nextCustomFieldIdByCustomFieldId[customField.id] = id;
|
||||
|
||||
return {
|
||||
..._.pick(customField, ['position', 'name', 'showOnFrontOfCard']),
|
||||
id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customField.customFieldGroupId],
|
||||
};
|
||||
});
|
||||
|
||||
const nextCustomFields = await CustomField.qm.create(nextCustomFieldsValues);
|
||||
|
||||
const nextCustomFieldValuesValues = customFieldValues.map((customFieldValue) => ({
|
||||
..._.pick(customFieldValue, ['content']),
|
||||
cardId: card.id,
|
||||
customFieldGroupId:
|
||||
nextCustomFieldGroupIdByCustomFieldGroupId[customFieldValue.customFieldGroupId] ||
|
||||
customFieldValue.customFieldGroupId,
|
||||
customFieldId:
|
||||
nextCustomFieldIdByCustomFieldId[customFieldValue.customFieldId] ||
|
||||
customFieldValue.customFieldId,
|
||||
}));
|
||||
|
||||
const nextCustomFieldValues = await CustomFieldValue.qm.create(nextCustomFieldValuesValues);
|
||||
const {
|
||||
customFieldGroups: nextCustomFieldGroups,
|
||||
customFields: nextCustomFields,
|
||||
customFieldValues: nextCustomFieldValues,
|
||||
} = await sails.helpers.cards.copyCustomFields(
|
||||
inputs.record,
|
||||
card,
|
||||
!!values.board,
|
||||
!!values.project,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
@@ -252,8 +295,8 @@ module.exports = {
|
||||
buildData: () => ({
|
||||
item: card,
|
||||
included: {
|
||||
projects: [inputs.project],
|
||||
boards: [inputs.board],
|
||||
projects: [project],
|
||||
boards: [board],
|
||||
lists: [list],
|
||||
cardMemberships: nextCardMemberships,
|
||||
cardLabels: nextCardLabels,
|
||||
@@ -291,6 +334,8 @@ module.exports = {
|
||||
}
|
||||
|
||||
await sails.helpers.actions.createOne.with({
|
||||
project,
|
||||
board,
|
||||
list,
|
||||
webhooks,
|
||||
values: {
|
||||
@@ -302,8 +347,6 @@ module.exports = {
|
||||
},
|
||||
user: values.creatorUser,
|
||||
},
|
||||
project: inputs.project,
|
||||
board: inputs.board,
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -98,7 +98,11 @@ module.exports = {
|
||||
throw 'coverAttachmentInValuesMustContainImage';
|
||||
}
|
||||
|
||||
values.coverAttachmentId = values.coverAttachment.id;
|
||||
if (values.coverAttachment.id === inputs.record.coverAttachmentId) {
|
||||
delete values.coverAttachment;
|
||||
} else {
|
||||
values.coverAttachmentId = values.coverAttachment.id;
|
||||
}
|
||||
}
|
||||
|
||||
const dueDate = _.isUndefined(values.dueDate) ? inputs.record.dueDate : values.dueDate;
|
||||
@@ -289,9 +293,14 @@ module.exports = {
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
sails.sockets.broadcast(`board:${card.boardId}`, 'cardUpdate', {
|
||||
item: card,
|
||||
});
|
||||
sails.sockets.broadcast(
|
||||
`board:${card.boardId}`,
|
||||
'cardUpdate',
|
||||
{
|
||||
item: card,
|
||||
},
|
||||
inputs.request,
|
||||
);
|
||||
|
||||
// TODO: add transfer action
|
||||
} else {
|
||||
|
||||
@@ -13,10 +13,16 @@ const createOne = (values) => CardMembership.create({ ...values }).fetch();
|
||||
|
||||
const getByIds = (ids) => defaultFind(ids);
|
||||
|
||||
const getByCardId = (cardId) =>
|
||||
defaultFind({
|
||||
const getByCardId = (cardId, { userIdOrIds } = {}) => {
|
||||
const criteria = {
|
||||
cardId,
|
||||
});
|
||||
};
|
||||
if (userIdOrIds) {
|
||||
criteria.userId = userIdOrIds;
|
||||
}
|
||||
|
||||
return defaultFind(criteria);
|
||||
};
|
||||
|
||||
const getByCardIds = (cardIds) =>
|
||||
defaultFind({
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "أرشيف",
|
||||
"Card Created": "تم إنشاء البطاقة",
|
||||
"Card Moved": "تم نقل البطاقة",
|
||||
"copy": "نسخة",
|
||||
"New Comment": "تعليق جديد",
|
||||
"Test Title": "عنوان تجريبي",
|
||||
"This is a test text message!": "هذه رسالة نصية تجريبية!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Архив",
|
||||
"Card Created": "Картата е създадена",
|
||||
"Card Moved": "Картата е преместена",
|
||||
"copy": "копие",
|
||||
"New Comment": "Нов коментар",
|
||||
"Test Title": "Тестово заглавие",
|
||||
"This is a test text message!": "Това е тестово текстово съобщение!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arxivar",
|
||||
"Card Created": "Targeta creada",
|
||||
"Card Moved": "Targeta moguda",
|
||||
"copy": "còpia",
|
||||
"New Comment": "Comentari nou",
|
||||
"Test Title": "Títol de prova",
|
||||
"This is a test text message!": "Aquest és un missatge de text de prova!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archiv",
|
||||
"Card Created": "Karta vytvořena",
|
||||
"Card Moved": "Karta přesunuta",
|
||||
"copy": "kopie",
|
||||
"New Comment": "Nový komentář",
|
||||
"Test Title": "Testovací název",
|
||||
"This is a test text message!": "Toto je testovací textová zpráva!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arkiv",
|
||||
"Card Created": "Kort oprettet",
|
||||
"Card Moved": "Kort flyttet",
|
||||
"copy": "kopi",
|
||||
"New Comment": "Ny kommentar",
|
||||
"Test Title": "Test titel",
|
||||
"This is a test text message!": "Dette er en test tekstbesked!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archiv",
|
||||
"Card Created": "Karte erstellt",
|
||||
"Card Moved": "Karte verschoben",
|
||||
"copy": "Kopie",
|
||||
"New Comment": "Neuer Kommentar",
|
||||
"Test Title": "Testtitel",
|
||||
"This is a test text message!": "Dies ist eine Test-Textnachricht!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Αρχείο",
|
||||
"Card Created": "Η κάρτα δημιουργήθηκε",
|
||||
"Card Moved": "Η κάρτα μετακινήθηκε",
|
||||
"copy": "αντίγραφο",
|
||||
"New Comment": "Νέο σχόλιο",
|
||||
"Test Title": "Τίτλος δοκιμής",
|
||||
"This is a test text message!": "Αυτό είναι ένα δοκιμαστικό μήνυμα!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archive",
|
||||
"Card Created": "Card Created",
|
||||
"Card Moved": "Card Moved",
|
||||
"copy": "copy",
|
||||
"New Comment": "New Comment",
|
||||
"Test Title": "Test Title",
|
||||
"This is a test text message!": "This is a test text message!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archive",
|
||||
"Card Created": "Card Created",
|
||||
"Card Moved": "Card Moved",
|
||||
"copy": "copy",
|
||||
"New Comment": "New Comment",
|
||||
"Test Title": "Test Title",
|
||||
"This is a test text message!": "This is a test text message!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archivo",
|
||||
"Card Created": "Tarjeta creada",
|
||||
"Card Moved": "Tarjeta movida",
|
||||
"copy": "copia",
|
||||
"New Comment": "Nuevo comentario",
|
||||
"Test Title": "Título de prueba",
|
||||
"This is a test text message!": "¡Este es un mensaje de texto de prueba!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arhiiv",
|
||||
"Card Created": "Kaart loodud",
|
||||
"Card Moved": "Kaart liigutatud",
|
||||
"copy": "koopia",
|
||||
"New Comment": "Uus kommentaar",
|
||||
"Test Title": "Testi pealkiri",
|
||||
"This is a test text message!": "See on testi tekstisõnum!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "بایگانی",
|
||||
"Card Created": "کارت ایجاد شد",
|
||||
"Card Moved": "کارت منتقل شد",
|
||||
"copy": "کپی",
|
||||
"New Comment": "نظر جدید",
|
||||
"Test Title": "عنوان آزمایشی",
|
||||
"This is a test text message!": "این یک پیام متنی آزمایشی است!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arkisto",
|
||||
"Card Created": "Kortti luotu",
|
||||
"Card Moved": "Kortti siirretty",
|
||||
"copy": "kopio",
|
||||
"New Comment": "Uusi kommentti",
|
||||
"Test Title": "Testin otsikko",
|
||||
"This is a test text message!": "Tämä on testiviesti!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archive",
|
||||
"Card Created": "Carte créée",
|
||||
"Card Moved": "Carte déplacée",
|
||||
"copy": "copie",
|
||||
"New Comment": "Nouveau commentaire",
|
||||
"Test Title": "Titre de test",
|
||||
"This is a test text message!": "Ceci est un message texte de test !",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archívum",
|
||||
"Card Created": "Kártya létrehozva",
|
||||
"Card Moved": "Kártya áthelyezve",
|
||||
"copy": "másolat",
|
||||
"New Comment": "Új hozzászólás",
|
||||
"Test Title": "Teszt cím",
|
||||
"This is a test text message!": "Ez itt egy szöveges teszt üzenet!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arsip",
|
||||
"Card Created": "Kartu dibuat",
|
||||
"Card Moved": "Kartu dipindahkan",
|
||||
"copy": "salinan",
|
||||
"New Comment": "Komentar baru",
|
||||
"Test Title": "Judul tes",
|
||||
"This is a test text message!": "Ini adalah pesan teks tes!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archivio",
|
||||
"Card Created": "Nuova task creata",
|
||||
"Card Moved": "Task spostata",
|
||||
"copy": "copia",
|
||||
"New Comment": "Nuovo commento",
|
||||
"Test Title": "Titolo di test",
|
||||
"This is a test text message!": "Questo è un messaggio di testo di test!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "アーカイブ",
|
||||
"Card Created": "カードが作成されました",
|
||||
"Card Moved": "カードが移動されました",
|
||||
"copy": "コピー",
|
||||
"New Comment": "新しいコメント",
|
||||
"Test Title": "テストタイトル",
|
||||
"This is a test text message!": "これはテストテキストメッセージです!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "보관함",
|
||||
"Card Created": "카드가 생성됨",
|
||||
"Card Moved": "카드가 이동됨",
|
||||
"copy": "복사본",
|
||||
"New Comment": "새 댓글",
|
||||
"Test Title": "테스트 제목",
|
||||
"This is a test text message!": "이것은 테스트 텍스트 메시지입니다!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archief",
|
||||
"Card Created": "Kaart aangemaakt",
|
||||
"Card Moved": "Kaart verplaatst",
|
||||
"copy": "kopie",
|
||||
"New Comment": "Nieuwe reactie",
|
||||
"Test Title": "Test titel",
|
||||
"This is a test text message!": "Dit is een test tekstbericht!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archiwum",
|
||||
"Card Created": "Karta utworzona",
|
||||
"Card Moved": "Karta przeniesiona",
|
||||
"copy": "kopia",
|
||||
"New Comment": "Nowy komentarz",
|
||||
"Test Title": "Tytuł testowy",
|
||||
"This is a test text message!": "To jest testowa wiadomość tekstowa!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arquivo",
|
||||
"Card Created": "Cartão criado",
|
||||
"Card Moved": "Cartão movido",
|
||||
"copy": "cópia",
|
||||
"New Comment": "Novo comentário",
|
||||
"Test Title": "Título de teste",
|
||||
"This is a test text message!": "Esta é uma mensagem de texto de teste!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arquivo",
|
||||
"Card Created": "Cartão criado",
|
||||
"Card Moved": "Cartão movido",
|
||||
"copy": "cópia",
|
||||
"New Comment": "Novo comentário",
|
||||
"Test Title": "Título de teste",
|
||||
"This is a test text message!": "Esta é uma mensagem de texto de teste!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arhivă",
|
||||
"Card Created": "Card creat",
|
||||
"Card Moved": "Card mutat",
|
||||
"copy": "copie",
|
||||
"New Comment": "Comentariu nou",
|
||||
"Test Title": "Titlu de test",
|
||||
"This is a test text message!": "Acesta este un mesaj text de test!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Архив",
|
||||
"Card Created": "Карточка создана",
|
||||
"Card Moved": "Карточка перемещена",
|
||||
"copy": "копия",
|
||||
"New Comment": "Новый комментарий",
|
||||
"Test Title": "Тестовый заголовок",
|
||||
"This is a test text message!": "Это тестовое сообщение!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Archív",
|
||||
"Card Created": "Karta vytvorená",
|
||||
"Card Moved": "Karta presunutá",
|
||||
"copy": "kópia",
|
||||
"New Comment": "Nový komentár",
|
||||
"Test Title": "Testovací názov",
|
||||
"This is a test text message!": "Toto je testovacia textová správa!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Архива",
|
||||
"Card Created": "Картица креирана",
|
||||
"Card Moved": "Картица премештена",
|
||||
"copy": "копија",
|
||||
"New Comment": "Нови коментар",
|
||||
"Test Title": "Тест наслов",
|
||||
"This is a test text message!": "Ово је тест текстуална порука!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arhiva",
|
||||
"Card Created": "Kartica kreirana",
|
||||
"Card Moved": "Kartica premeštena",
|
||||
"copy": "kopija",
|
||||
"New Comment": "Novi komentar",
|
||||
"Test Title": "Test naslov",
|
||||
"This is a test text message!": "Ovo je test tekstualna poruka!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arkiv",
|
||||
"Card Created": "Kort skapat",
|
||||
"Card Moved": "Kort flyttat",
|
||||
"copy": "kopia",
|
||||
"New Comment": "Ny kommentar",
|
||||
"Test Title": "Test titel",
|
||||
"This is a test text message!": "Detta är ett test textmeddelande!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arşiv",
|
||||
"Card Created": "Kart oluşturuldu",
|
||||
"Card Moved": "Kart taşındı",
|
||||
"copy": "kopya",
|
||||
"New Comment": "Yeni yorum",
|
||||
"Test Title": "Test başlığı",
|
||||
"This is a test text message!": "Bu bir test metin mesajıdır!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Архів",
|
||||
"Card Created": "Картку створено",
|
||||
"Card Moved": "Картку переміщено",
|
||||
"copy": "копія",
|
||||
"New Comment": "Новий коментар",
|
||||
"Test Title": "Тестовий заголовок",
|
||||
"This is a test text message!": "Це нове повідомлення!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "Arxiv",
|
||||
"Card Created": "Karta yaratildi",
|
||||
"Card Moved": "Karta ko'chirildi",
|
||||
"copy": "nusxa",
|
||||
"New Comment": "Yangi izoh",
|
||||
"Test Title": "Test sarlavha",
|
||||
"This is a test text message!": "Bu test matn xabari!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "归档",
|
||||
"Card Created": "卡片已创建",
|
||||
"Card Moved": "卡片已移动",
|
||||
"copy": "副本",
|
||||
"New Comment": "新评论",
|
||||
"Test Title": "测试标题",
|
||||
"This is a test text message!": "这是一条测试文本消息!",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Archive": "封存",
|
||||
"Card Created": "卡片已建立",
|
||||
"Card Moved": "卡片已移動",
|
||||
"copy": "副本",
|
||||
"New Comment": "新留言",
|
||||
"Test Title": "測試標題",
|
||||
"This is a test text message!": "這是一則測試文字訊息!",
|
||||
|
||||
Reference in New Issue
Block a user