Add move() methods to Swimlanes and Lists collections

This commit is contained in:
John Supplee 2021-03-26 16:51:01 +02:00
parent 3ce3612047
commit 59a3ac1f37
3 changed files with 58 additions and 2 deletions

View file

@ -1527,14 +1527,17 @@ Cards.mutations({
return this.move(boardId, swimlaneId, listId, sort);
},
move(boardId, swimlaneId, listId, sort) {
move(boardId, swimlaneId, listId, sort=null) {
const mutatedFields = {
boardId,
swimlaneId,
listId,
sort,
};
if (sort !== null) {
mutatedFields.sort = sort;
}
// we must only copy the labels and custom fields if the target board
// differs from the source board
if (this.boardId !== boardId) {

View file

@ -297,6 +297,36 @@ Lists.mutations({
return { $set: { starred: !!enable } };
},
move(boardId, swimlaneId, sort=null) {
const mutatedFields = {
boardId,
swimlaneId,
sort,
};
if (this.boardId !== boardId) {
mutatedFields.boardId = boardId;
}
if (this.swimlaneId !== swimlaneId) {
mutatedFields.swimlaneId = swimlaneId;
}
if (sort !== null && sort !== this.sort) {
mutatedFields.sort = sort;
}
if (Object.keys(mutatedFields).length) {
this.cards().forEach(card => {
card.move(boardId, swimlaneId, this._id);
});
Lists.update(this._id, {
$set: mutatedFields,
});
}
},
archive() {
if (this.isTemplateList()) {
this.cards().forEach(card => {

View file

@ -269,6 +269,29 @@ Swimlanes.mutations({
return { $set: { archived: true, archivedAt: new Date() } };
},
move(boardId, sort=null) {
const mutatedFields = {};
if (this.boardId !== boardId) {
mutatedFields.boardId = boardId;
}
if (sort !== null && sort !== this.sort) {
mutatedFields.sort = sort;
}
if (Object.keys(mutatedFields).length) {
this.lists().forEach(list => {
list.move(boardId, this._id);
});
Swimlanes.update(this._id, {
$set: mutatedFields,
});
}
},
restore() {
if (this.isTemplateSwimlane()) {
this.myLists().forEach(list => {