Allow description and member two way binding

This commit is contained in:
Andrés Manelli 2018-04-17 01:55:57 -03:00
parent a93de07fb9
commit 0a62089df0
6 changed files with 82 additions and 14 deletions

View file

@ -406,6 +406,18 @@ Cards.helpers({
return this.isImportedCard() || this.isImportedBoard();
},
setDescription(description) {
if (this.isImportedCard()) {
const card = Cards.findOne({_id: this.importedId});
return Cards.update({_id: this.importedId}, {$set: {description}});
} else if (this.isImportedBoard()) {
const board = Boards.findOne({_id: this.importedId});
return Boards.update({_id: this.importedId}, {$set: {description}});
} else {
return {$set: {description}};
}
},
getDescription() {
if (this.isImportedCard()) {
const card = Cards.findOne({_id: this.importedId});
@ -426,6 +438,62 @@ Cards.helpers({
return null;
}
},
getMembers() {
if (this.isImportedCard()) {
const card = Cards.findOne({_id: this.importedId});
return card.members;
} else if (this.isImportedBoard()) {
const board = Boards.findOne({_id: this.importedId});
return board.activeMembers().map((member) => {
return member.userId;
});
} else {
return this.members;
}
},
assignMember(memberId) {
if (this.isImportedCard()) {
return Cards.update(
{ _id: this.importedId },
{ $addToSet: { members: memberId }}
);
} else if (this.isImportedBoard()) {
const board = Boards.findOne({_id: this.importedId});
return board.addMember(memberId);
} else {
return Cards.update(
{ _id: this._id },
{ $addToSet: { members: memberId}}
);
}
},
unassignMember(memberId) {
if (this.isImportedCard()) {
return Cards.update(
{ _id: this.importedId },
{ $pull: { members: memberId }}
);
} else if (this.isImportedBoard()) {
const board = Boards.findOne({_id: this.importedId});
return board.removeMember(memberId);
} else {
return Cards.update(
{ _id: this._id },
{ $pull: { members: memberId}}
);
}
},
toggleMember(memberId) {
if (this.getMembers() && this.getMembers().indexOf(memberId) > -1) {
return this.unassignMember(memberId);
} else {
return this.assignMember(memberId);
}
},
});
Cards.mutations({