mirror of
https://github.com/wekan/wekan.git
synced 2026-02-02 06:31:47 +01:00
Propagate async/await to List.copy(), Swimlane.copy() and callers
Since Card.copy() is now async, all callers in the copy chain need to be updated to properly await the async operations: - Make List.copy() async and await card.copy() in loop - Make Swimlane.copy() async and await list.copy() in loop - Fix mutateSelectedCards() to support async callbacks and method calls - Make template copy event handler async in listBody.js This also fixes the copySelection feature which was passing a callback to mutateSelectedCards() but the function only supported method names.
This commit is contained in:
parent
14de981ac3
commit
35715ef2a3
4 changed files with 49 additions and 35 deletions
|
|
@ -817,7 +817,7 @@ BlazeComponent.extendComponent({
|
|||
evt.preventDefault();
|
||||
this.term.set(evt.target.searchTerm.value);
|
||||
},
|
||||
'click .js-minicard'(evt) {
|
||||
async 'click .js-minicard'(evt) {
|
||||
// 0. Common
|
||||
const title = $('.js-element-title')
|
||||
.val()
|
||||
|
|
@ -835,7 +835,7 @@ BlazeComponent.extendComponent({
|
|||
if (this.isTemplateSearch) {
|
||||
element.type = 'cardType-card';
|
||||
element.linkedId = '';
|
||||
_id = element.copy(this.boardId, this.swimlaneId, this.listId);
|
||||
_id = await element.copy(this.boardId, this.swimlaneId, this.listId);
|
||||
// 1.B Linked card
|
||||
} else {
|
||||
_id = element.link(this.boardId, this.swimlaneId, this.listId);
|
||||
|
|
@ -847,13 +847,13 @@ BlazeComponent.extendComponent({
|
|||
.lists()
|
||||
.length;
|
||||
element.type = 'list';
|
||||
_id = element.copy(this.boardId, this.swimlaneId);
|
||||
_id = await element.copy(this.boardId, this.swimlaneId);
|
||||
} else if (this.isSwimlaneTemplateSearch) {
|
||||
element.sort = ReactiveCache.getBoard(this.boardId)
|
||||
.swimlanes()
|
||||
.length;
|
||||
element.type = 'swimlane';
|
||||
_id = element.copy(this.boardId);
|
||||
_id = await element.copy(this.boardId);
|
||||
} else if (this.isBoardTemplateSearch) {
|
||||
Meteor.call(
|
||||
'copyBoard',
|
||||
|
|
|
|||
|
|
@ -105,10 +105,15 @@ BlazeComponent.extendComponent({
|
|||
},
|
||||
}).register('filterSidebar');
|
||||
|
||||
function mutateSelectedCards(mutationName, ...args) {
|
||||
ReactiveCache.getCards(MultiSelection.getMongoSelector(), {sort: ['sort']}).forEach(card => {
|
||||
card[mutationName](...args);
|
||||
});
|
||||
async function mutateSelectedCards(mutationNameOrCallback, ...args) {
|
||||
const cards = ReactiveCache.getCards(MultiSelection.getMongoSelector(), {sort: ['sort']});
|
||||
for (const card of cards) {
|
||||
if (typeof mutationNameOrCallback === 'function') {
|
||||
await mutationNameOrCallback(card);
|
||||
} else {
|
||||
await card[mutationNameOrCallback](...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BlazeComponent.extendComponent({
|
||||
|
|
@ -441,28 +446,31 @@ Template.copySelectionPopup.events({
|
|||
const cardId = instance.selectedCardId.get();
|
||||
const position = instance.position.get();
|
||||
|
||||
mutateSelectedCards((card) => {
|
||||
const newCard = card.copy(boardId, swimlaneId, listId);
|
||||
if (newCard) {
|
||||
let sortIndex = 0;
|
||||
if (cardId) {
|
||||
const targetCard = ReactiveCache.getCard(cardId);
|
||||
if (targetCard) {
|
||||
if (position === 'above') {
|
||||
sortIndex = targetCard.sort - 0.5;
|
||||
} else {
|
||||
sortIndex = targetCard.sort + 0.5;
|
||||
mutateSelectedCards(async (card) => {
|
||||
const newCardId = await card.copy(boardId, swimlaneId, listId);
|
||||
if (newCardId) {
|
||||
const newCard = ReactiveCache.getCard(newCardId);
|
||||
if (newCard) {
|
||||
let sortIndex = 0;
|
||||
if (cardId) {
|
||||
const targetCard = ReactiveCache.getCard(cardId);
|
||||
if (targetCard) {
|
||||
if (position === 'above') {
|
||||
sortIndex = targetCard.sort - 0.5;
|
||||
} else {
|
||||
sortIndex = targetCard.sort + 0.5;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// To end
|
||||
const board = ReactiveCache.getBoard(boardId);
|
||||
const cards = board.cards({ swimlaneId, listId }).sort('sort');
|
||||
if (cards.length > 0) {
|
||||
sortIndex = cards[cards.length - 1].sort + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// To end
|
||||
const board = ReactiveCache.getBoard(boardId);
|
||||
const cards = board.cards({ swimlaneId, listId }).sort('sort');
|
||||
if (cards.length > 0) {
|
||||
sortIndex = cards[cards.length - 1].sort + 1;
|
||||
}
|
||||
newCard.setSort(sortIndex);
|
||||
}
|
||||
newCard.setSort(sortIndex);
|
||||
}
|
||||
});
|
||||
EscapeActions.executeUpTo('multiselection');
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ Lists.allow({
|
|||
});
|
||||
|
||||
Lists.helpers({
|
||||
copy(boardId, swimlaneId) {
|
||||
async copy(boardId, swimlaneId) {
|
||||
const oldId = this._id;
|
||||
const oldSwimlaneId = this.swimlaneId || null;
|
||||
this.boardId = boardId;
|
||||
|
|
@ -217,13 +217,16 @@ Lists.helpers({
|
|||
}
|
||||
|
||||
// Copy all cards in list
|
||||
ReactiveCache.getCards({
|
||||
const cards = ReactiveCache.getCards({
|
||||
swimlaneId: oldSwimlaneId,
|
||||
listId: oldId,
|
||||
archived: false,
|
||||
}).forEach(card => {
|
||||
card.copy(boardId, swimlaneId, _id);
|
||||
});
|
||||
for (const card of cards) {
|
||||
await card.copy(boardId, swimlaneId, _id);
|
||||
}
|
||||
|
||||
return _id;
|
||||
},
|
||||
|
||||
async move(boardId, swimlaneId) {
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ Swimlanes.allow({
|
|||
});
|
||||
|
||||
Swimlanes.helpers({
|
||||
copy(boardId) {
|
||||
async copy(boardId) {
|
||||
const oldId = this._id;
|
||||
const oldBoardId = this.boardId;
|
||||
this.boardId = boardId;
|
||||
|
|
@ -163,12 +163,15 @@ Swimlanes.helpers({
|
|||
}
|
||||
|
||||
// Copy all lists in swimlane
|
||||
ReactiveCache.getLists(query).forEach(list => {
|
||||
const lists = ReactiveCache.getLists(query);
|
||||
for (const list of lists) {
|
||||
list.type = 'list';
|
||||
list.swimlaneId = oldId;
|
||||
list.boardId = boardId;
|
||||
list.copy(boardId, _id);
|
||||
});
|
||||
await list.copy(boardId, _id);
|
||||
}
|
||||
|
||||
return _id;
|
||||
},
|
||||
|
||||
async move(toBoardId) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue