Browse Source

Add move() methods to Swimlanes and Lists collections

John Supplee 4 years ago
parent
commit
59a3ac1f37
3 changed files with 58 additions and 2 deletions
  1. 5 2
      models/cards.js
  2. 30 0
      models/lists.js
  3. 23 0
      models/swimlanes.js

+ 5 - 2
models/cards.js

@@ -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) {

+ 30 - 0
models/lists.js

@@ -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 => {

+ 23 - 0
models/swimlanes.js

@@ -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 => {