Sfoglia il codice sorgente

Helpers for dealing with trees of cards

Nicu Tofan 7 anni fa
parent
commit
fd465fbb60
2 ha cambiato i file con 19 aggiunte e 1 eliminazioni
  1. 19 0
      models/cards.js
  2. 0 1
      server/migrations.js

+ 19 - 0
models/cards.js

@@ -297,14 +297,33 @@ Cards.helpers({
     }
     return true;
   },
+
+  parentCard() {
+    if (this.parentId === '') {
+      return null;
+    }
+    return Cards.findOne(this.parentId);
+  },
+
+  isTopLevel() {
+    return this.parentId === '';
+  },
 });
 
 Cards.mutations({
+  applyToKids(funct) {
+    Cards.find({ parentId: this._id }).forEach((card) => {
+      funct(card);
+    });
+  },
+
   archive() {
+    this.applyToKids((card) => { return card.archive(); });
     return {$set: {archived: true}};
   },
 
   restore() {
+    this.applyToKids((card) => { return card.restore(); });
     return {$set: {archived: false}};
   },
 

+ 0 - 1
server/migrations.js

@@ -258,7 +258,6 @@ Migrations.add('add-assigner-field', () => {
   }, noValidateMulti);
 });
 
-
 Migrations.add('add-parent-field-to-cards', () => {
   Cards.update({
     parentId: {