Helpers for dealing with trees of cards

This commit is contained in:
Nicu Tofan 2018-06-19 01:00:14 +03:00
parent 879a84184f
commit fd465fbb60
No known key found for this signature in database
GPG key ID: 7EE66E95E64FD0B7
2 changed files with 19 additions and 1 deletions

View file

@ -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}};
},

View file

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