summaryrefslogtreecommitdiffstats
path: root/client/components/cards/labels.js
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-09-08 20:19:42 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-09-08 20:19:42 +0200
commit45b662a1ddb46a0f17fab7b2383c82aa1e1620ef (patch)
treecc7be215c7e7ebffd2597df70cf271b3dd435e1a /client/components/cards/labels.js
parentc04341f1ea5efe082bf7318cf9eb0e99b9b8374a (diff)
downloadwekan-45b662a1ddb46a0f17fab7b2383c82aa1e1620ef.tar.gz
wekan-45b662a1ddb46a0f17fab7b2383c82aa1e1620ef.tar.bz2
wekan-45b662a1ddb46a0f17fab7b2383c82aa1e1620ef.zip
Centralize all mutations at the model level
This commit uses a new package that I need to document. It tries to solve the long-standing debate in the Meteor community about allow/deny rules versus methods (RPC). This approach gives us both the centralized security rules of allow/deny and the white-list of allowed mutations similarly to Meteor methods. The idea to have static mutation descriptions is also inspired by Facebook's Relay/GraphQL. This will allow the development of a REST API using the high-level methods instead of the MongoDB queries to do the mapping between the HTTP requests and our collections.
Diffstat (limited to 'client/components/cards/labels.js')
-rw-r--r--client/components/cards/labels.js51
1 files changed, 8 insertions, 43 deletions
diff --git a/client/components/cards/labels.js b/client/components/cards/labels.js
index 2da3b80b..d2ee0140 100644
--- a/client/components/cards/labels.js
+++ b/client/components/cards/labels.js
@@ -45,19 +45,9 @@ Template.createLabelPopup.helpers({
Template.cardLabelsPopup.events({
'click .js-select-label'(evt) {
- const cardId = Template.parentData(2).data._id;
+ const card = Cards.findOne(Session.get('currentCard'));
const labelId = this._id;
- let operation;
- if (Cards.find({ _id: cardId, labelIds: labelId}).count() === 0)
- operation = '$addToSet';
- else
- operation = '$pull';
-
- Cards.update(cardId, {
- [operation]: {
- labelIds: labelId,
- },
- });
+ card.toggleLabel(labelId);
evt.preventDefault();
},
'click .js-edit-label': Popup.open('editLabel'),
@@ -79,20 +69,10 @@ Template.formLabel.events({
Template.createLabelPopup.events({
// Create the new label
'submit .create-label'(evt, tpl) {
+ const board = Boards.findOne(Session.get('currentBoard'));
const name = tpl.$('#labelName').val().trim();
- const boardId = Session.get('currentBoard');
const color = Blaze.getData(tpl.find('.fa-check')).color;
-
- Boards.update(boardId, {
- $push: {
- labels: {
- name,
- color,
- _id: Random.id(6),
- },
- },
- });
-
+ board.addLabel(name, color);
Popup.back();
evt.preventDefault();
},
@@ -100,31 +80,16 @@ Template.createLabelPopup.events({
Template.editLabelPopup.events({
'click .js-delete-label': Popup.afterConfirm('deleteLabel', function() {
- const boardId = Session.get('currentBoard');
- Boards.update(boardId, {
- $pull: {
- labels: {
- _id: this._id,
- },
- },
- });
-
+ const board = Boards.findOne(Session.get('currentBoard'));
+ board.removeLabel(this._id);
Popup.back(2);
}),
'submit .edit-label'(evt, tpl) {
evt.preventDefault();
+ const board = Boards.findOne(Session.get('currentBoard'));
const name = tpl.$('#labelName').val().trim();
- const boardId = Session.get('currentBoard');
- const getLabel = Utils.getLabelIndex(boardId, this._id);
const color = Blaze.getData(tpl.find('.fa-check')).color;
-
- Boards.update(boardId, {
- $set: {
- [getLabel.key('name')]: name,
- [getLabel.key('color')]: color,
- },
- });
-
+ board.editLabel(this._id, name, color);
Popup.back();
},
});