mirror of
https://github.com/plankanban/planka.git
synced 2025-07-22 06:39:44 +02:00
Fix members and labels creation when transfer card to another board
This commit is contained in:
parent
35f9631326
commit
c5b44598f9
2 changed files with 31 additions and 60 deletions
|
@ -2,13 +2,7 @@ import { call, put, select } from 'redux-saga/effects';
|
||||||
|
|
||||||
import { goToBoardService } from './router';
|
import { goToBoardService } from './router';
|
||||||
import { createCardRequest, deleteCardRequest, updateCardRequest } from '../requests';
|
import { createCardRequest, deleteCardRequest, updateCardRequest } from '../requests';
|
||||||
import {
|
import { listByIdSelector, nextCardPositionSelector, pathSelector } from '../../../selectors';
|
||||||
boardByIdSelector,
|
|
||||||
cardByIdSelector,
|
|
||||||
listByIdSelector,
|
|
||||||
nextCardPositionSelector,
|
|
||||||
pathSelector,
|
|
||||||
} from '../../../selectors';
|
|
||||||
import { createCard, deleteCard, updateCard } from '../../../actions';
|
import { createCard, deleteCard, updateCard } from '../../../actions';
|
||||||
import { createLocalId } from '../../../utils/local-id';
|
import { createLocalId } from '../../../utils/local-id';
|
||||||
|
|
||||||
|
@ -62,35 +56,20 @@ export function* moveCurrentCardService(listId, index) {
|
||||||
|
|
||||||
export function* transferCardService(id, boardId, listId, index) {
|
export function* transferCardService(id, boardId, listId, index) {
|
||||||
const { cardId: currentCardId, boardId: currentBoardId } = yield select(pathSelector);
|
const { cardId: currentCardId, boardId: currentBoardId } = yield select(pathSelector);
|
||||||
|
const position = yield select(nextCardPositionSelector, listId, index, id);
|
||||||
|
|
||||||
if (id === currentCardId) {
|
if (id === currentCardId) {
|
||||||
yield call(goToBoardService, currentBoardId);
|
yield call(goToBoardService, currentBoardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const card = yield select(cardByIdSelector, id);
|
|
||||||
const board = yield select(boardByIdSelector, boardId);
|
|
||||||
|
|
||||||
yield put(deleteCard(id));
|
yield put(deleteCard(id));
|
||||||
|
|
||||||
if (board.isFetching === false) {
|
|
||||||
const position = yield select(nextCardPositionSelector, listId, index, id);
|
|
||||||
|
|
||||||
yield put(
|
|
||||||
createCard({
|
|
||||||
...card,
|
|
||||||
listId,
|
|
||||||
boardId,
|
|
||||||
position,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
yield call(updateCardRequest, id, {
|
yield call(updateCardRequest, id, {
|
||||||
listId,
|
listId,
|
||||||
boardId,
|
boardId,
|
||||||
position,
|
position,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
export function* transferCurrentCardService(boardId, listId, index) {
|
export function* transferCurrentCardService(boardId, listId, index) {
|
||||||
const { cardId } = yield select(pathSelector);
|
const { cardId } = yield select(pathSelector);
|
||||||
|
|
|
@ -143,7 +143,7 @@ module.exports = {
|
||||||
const labelByNameMap = _.keyBy(labels, 'name');
|
const labelByNameMap = _.keyBy(labels, 'name');
|
||||||
|
|
||||||
const labelIds = await Promise.all(
|
const labelIds = await Promise.all(
|
||||||
await prevLabels.map(async (prevLabel) => {
|
prevLabels.map(async (prevLabel) => {
|
||||||
if (labelByNameMap[prevLabel.name]) {
|
if (labelByNameMap[prevLabel.name]) {
|
||||||
return labelByNameMap[prevLabel.name].id;
|
return labelByNameMap[prevLabel.name].id;
|
||||||
}
|
}
|
||||||
|
@ -157,24 +157,23 @@ module.exports = {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
labelIds.forEach(async (labelId) => {
|
await Promise.all(
|
||||||
|
labelIds.map(async (labelId) => {
|
||||||
await CardLabel.create({
|
await CardLabel.create({
|
||||||
labelId,
|
labelId,
|
||||||
cardId: card.id,
|
cardId: card.id,
|
||||||
})
|
})
|
||||||
.tolerate('E_UNIQUE')
|
.tolerate('E_UNIQUE')
|
||||||
.fetch();
|
.fetch();
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const cardMemberships = await sails.helpers.getMembershipsForCard(card.id);
|
const cardMemberships = await sails.helpers.getMembershipsForCard(card.id);
|
||||||
const cardLabels = await sails.helpers.getCardLabelsForCard(card.id);
|
const cardLabels = await sails.helpers.getCardLabelsForCard(card.id);
|
||||||
const tasks = await sails.helpers.getTasksForCard(card.id);
|
const tasks = await sails.helpers.getTasksForCard(card.id);
|
||||||
const attachments = await sails.helpers.getAttachmentsForCard(card.id);
|
const attachments = await sails.helpers.getAttachmentsForCard(card.id);
|
||||||
|
|
||||||
sails.sockets.broadcast(
|
sails.sockets.broadcast(`board:${card.boardId}`, 'cardCreate', {
|
||||||
`board:${card.boardId}`,
|
|
||||||
'cardCreate',
|
|
||||||
{
|
|
||||||
item: card,
|
item: card,
|
||||||
included: {
|
included: {
|
||||||
cardMemberships,
|
cardMemberships,
|
||||||
|
@ -182,24 +181,17 @@ module.exports = {
|
||||||
tasks,
|
tasks,
|
||||||
attachments,
|
attachments,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
inputs.request,
|
|
||||||
);
|
|
||||||
|
|
||||||
const userIds = await sails.helpers.getSubscriptionUserIdsForCard(card.id);
|
const userIds = await sails.helpers.getSubscriptionUserIdsForCard(card.id);
|
||||||
|
|
||||||
userIds.forEach((userId) => {
|
userIds.forEach((userId) => {
|
||||||
sails.sockets.broadcast(
|
sails.sockets.broadcast(`user:${userId}`, 'cardUpdate', {
|
||||||
`user:${userId}`,
|
|
||||||
'cardUpdate',
|
|
||||||
{
|
|
||||||
item: {
|
item: {
|
||||||
id: card.id,
|
id: card.id,
|
||||||
isSubscribed: true,
|
isSubscribed: true,
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
inputs.request,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sails.sockets.broadcast(
|
sails.sockets.broadcast(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue