diff options
author | Andrés Manelli <andresmanelli@gmail.com> | 2018-03-19 15:31:38 -0300 |
---|---|---|
committer | Andrés Manelli <andresmanelli@gmail.com> | 2018-03-19 15:31:38 -0300 |
commit | ca89442f3a62a7a97044a6e572eea70158edadbd (patch) | |
tree | 56210c8388c30a86da62c6b9a00653e5ade9c1ab | |
parent | 153960742cac53c52f176f1bc645d850f25ac966 (diff) | |
download | wekan-ca89442f3a62a7a97044a6e572eea70158edadbd.tar.gz wekan-ca89442f3a62a7a97044a6e572eea70158edadbd.tar.bz2 wekan-ca89442f3a62a7a97044a6e572eea70158edadbd.zip |
Clean checklists model
-rw-r--r-- | models/checklists.js | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/models/checklists.js b/models/checklists.js index d9b15140..637e280c 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -46,23 +46,10 @@ Checklists.helpers({ isFinished() { return 0 !== this.itemCount() && this.itemCount() === this.finishedCount(); }, - getItem(_id) { - return _.findWhere(this.items, { _id }); - }, itemIndex(itemId) { const items = self.findOne({_id : this._id}).items; return _.pluck(items, '_id').indexOf(itemId); }, - getNewItemId() { - const itemCount = this.itemCount(); - let idx = 0; - if (itemCount > 0) { - const lastId = this.items[itemCount - 1]._id; - const lastIdSuffix = lastId.substr(this._id.length); - idx = parseInt(lastIdSuffix, 10) + 1; - } - return `${this._id}${idx}`; - }, }); Checklists.allow({ @@ -86,108 +73,9 @@ Checklists.before.insert((userId, doc) => { }); Checklists.mutations({ - //for checklist itself setTitle(title) { return { $set: { title } }; }, - //for items in checklist - addItem(title) { - const _id = this.getNewItemId(); - return { - $addToSet: { - items: { - _id, title, - isFinished: false, - sort: this.itemCount(), - }, - }, - }; - }, - addFullItem(item) { - const itemsUpdate = {}; - this.items.forEach(function(iterItem, index) { - if (iterItem.sort >= item.sort) { - itemsUpdate[`items.${index}.sort`] = iterItem.sort + 1; - } - }); - if (!_.isEmpty(itemsUpdate)) { - self.direct.update({ _id: this._id }, { $set: itemsUpdate }); - } - return { $addToSet: { items: item } }; - }, - removeItem(itemId) { - const item = this.getItem(itemId); - const itemsUpdate = {}; - this.items.forEach(function(iterItem, index) { - if (iterItem.sort > item.sort) { - itemsUpdate[`items.${index}.sort`] = iterItem.sort - 1; - } - }); - if (!_.isEmpty(itemsUpdate)) { - self.direct.update({ _id: this._id }, { $set: itemsUpdate }); - } - return { $pull: { items: { _id: itemId } } }; - }, - editItem(itemId, title) { - if (this.getItem(itemId)) { - const itemIndex = this.itemIndex(itemId); - return { - $set: { - [`items.${itemIndex}.title`]: title, - }, - }; - } - return {}; - }, - finishItem(itemId) { - if (this.getItem(itemId)) { - const itemIndex = this.itemIndex(itemId); - return { - $set: { - [`items.${itemIndex}.isFinished`]: true, - }, - }; - } - return {}; - }, - resumeItem(itemId) { - if (this.getItem(itemId)) { - const itemIndex = this.itemIndex(itemId); - return { - $set: { - [`items.${itemIndex}.isFinished`]: false, - }, - }; - } - return {}; - }, - toggleItem(itemId) { - const item = this.getItem(itemId); - if (item) { - const itemIndex = this.itemIndex(itemId); - return { - $set: { - [`items.${itemIndex}.isFinished`]: !item.isFinished, - }, - }; - } - return {}; - }, - sortItems(itemIDs) { - const validItems = []; - itemIDs.forEach((itemID) => { - if (this.getItem(itemID)) { - validItems.push(this.itemIndex(itemID)); - } - }); - const modifiedValues = {}; - for (let i = 0; i < validItems.length; i++) { - modifiedValues[`items.${validItems[i]}.sort`] = i; - } - return { - $set: modifiedValues, - }; - }, }); if (Meteor.isServer) { @@ -205,30 +93,6 @@ if (Meteor.isServer) { }); }); - //TODO: so there will be no activity for adding item into checklist, maybe will be implemented in the future. - // The future is now - Checklists.after.update((userId, doc, fieldNames, modifier) => { - if (fieldNames.includes('items')) { - if (modifier.$addToSet) { - Activities.insert({ - userId, - activityType: 'addChecklistItem', - cardId: doc.cardId, - boardId: Cards.findOne(doc.cardId).boardId, - checklistId: doc._id, - checklistItemId: modifier.$addToSet.items._id, - }); - } else if (modifier.$pull) { - const activity = Activities.findOne({ - checklistItemId: modifier.$pull.items._id, - }); - if (activity) { - Activities.remove(activity._id); - } - } - } - }); - Checklists.before.remove((userId, doc) => { const activities = Activities.find({ checklistId: doc._id }); if (activities) { @@ -239,7 +103,6 @@ if (Meteor.isServer) { }); } -//CARD COMMENT REST API if (Meteor.isServer) { JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/checklists', function (req, res) { try { |