diff options
author | Andrés Manelli <andresmanelli@gmail.com> | 2019-02-23 16:36:29 +0100 |
---|---|---|
committer | Andrés Manelli <andresmanelli@gmail.com> | 2019-02-24 00:05:00 +0100 |
commit | 0fec7115451ba3b49442965c8160df4911157601 (patch) | |
tree | 12364d6c96f0900aea318b16863a246b6c6dd9ee | |
parent | 7a6afb8aea2c3398ec0fe34d664398bd94cac90a (diff) | |
download | wekan-0fec7115451ba3b49442965c8160df4911157601.tar.gz wekan-0fec7115451ba3b49442965c8160df4911157601.tar.bz2 wekan-0fec7115451ba3b49442965c8160df4911157601.zip |
Prepare to create card from template
-rw-r--r-- | client/components/cards/cardDetails.js | 58 | ||||
-rw-r--r-- | client/components/lists/listBody.jade | 6 | ||||
-rw-r--r-- | client/components/lists/listBody.js | 7 | ||||
-rw-r--r-- | models/boards.js | 2 | ||||
-rw-r--r-- | models/cardComments.js | 6 | ||||
-rw-r--r-- | models/cards.js | 25 | ||||
-rw-r--r-- | models/checklists.js | 13 |
7 files changed, 57 insertions, 60 deletions
diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index 489f28ae..1281356d 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -459,26 +459,9 @@ BlazeComponent.extendComponent({ }, }).register('boardsAndLists'); - -function cloneCheckList(_id, checklist) { - 'use strict'; - const checklistId = checklist._id; - checklist.cardId = _id; - checklist._id = null; - const newChecklistId = Checklists.insert(checklist); - ChecklistItems.find({checklistId}).forEach(function(item) { - item._id = null; - item.checklistId = newChecklistId; - item.cardId = _id; - ChecklistItems.insert(item); - }); -} - Template.copyCardPopup.events({ 'click .js-done'() { const card = Cards.findOne(Session.get('currentCard')); - const oldId = card._id; - card._id = null; const lSelect = $('.js-select-lists')[0]; card.listId = lSelect.options[lSelect.selectedIndex].value; const slSelect = $('.js-select-swimlanes')[0]; @@ -493,38 +476,13 @@ Template.copyCardPopup.events({ if (title) { card.title = title; card.coverId = ''; - const _id = Cards.insert(card); + const _id = card.copy(); // In case the filter is active we need to add the newly inserted card in // the list of exceptions -- cards that are not filtered. Otherwise the // card will disappear instantly. // See https://github.com/wekan/wekan/issues/80 Filter.addException(_id); - // copy checklists - let cursor = Checklists.find({cardId: oldId}); - cursor.forEach(function() { - cloneCheckList(_id, arguments[0]); - }); - - // copy subtasks - cursor = Cards.find({parentId: oldId}); - cursor.forEach(function() { - 'use strict'; - const subtask = arguments[0]; - subtask.parentId = _id; - subtask._id = null; - /* const newSubtaskId = */ Cards.insert(subtask); - }); - - // copy card comments - cursor = CardComments.find({cardId: oldId}); - cursor.forEach(function () { - 'use strict'; - const comment = arguments[0]; - comment.cardId = _id; - comment._id = null; - CardComments.insert(comment); - }); Popup.close(); } }, @@ -561,9 +519,8 @@ Template.copyChecklistToManyCardsPopup.events({ Filter.addException(_id); // copy checklists - let cursor = Checklists.find({cardId: oldId}); - cursor.forEach(function() { - cloneCheckList(_id, arguments[0]); + Checklists.find({cardId: oldId}).forEach((ch) => { + ch.copy(_id); }); // copy subtasks @@ -577,13 +534,8 @@ Template.copyChecklistToManyCardsPopup.events({ }); // copy card comments - cursor = CardComments.find({cardId: oldId}); - cursor.forEach(function () { - 'use strict'; - const comment = arguments[0]; - comment.cardId = _id; - comment._id = null; - CardComments.insert(comment); + CardComments.find({cardId: oldId}).forEach((cmt) => { + cmt.copy(_id); }); } Popup.close(); diff --git a/client/components/lists/listBody.jade b/client/components/lists/listBody.jade index 4d7ec158..80ce70c0 100644 --- a/client/components/lists/listBody.jade +++ b/client/components/lists/listBody.jade @@ -96,11 +96,9 @@ template(name="searchCardPopup") label {{_ 'boards'}}: .link-board-wrapper select.js-select-boards + option(value="") each boards - if $eq _id currentBoard._id - option(value="{{_id}}" selected) {{_ 'current'}} - else - option(value="{{_id}}") {{title}} + option(value="{{_id}}") {{title}} form.js-search-term-form input(type="text" name="searchTerm" placeholder="{{_ 'search-example'}}" autofocus) .list-body.js-perfect-scrollbar.search-card-results diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 66d056c4..e6849eb2 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -456,6 +456,7 @@ BlazeComponent.extendComponent({ archived: false, linkedId: {$nin: ownCardsIds}, _id: {$nin: ownCardsIds}, + type: {$nin: ['template-card']}, }); }, @@ -523,16 +524,16 @@ BlazeComponent.extendComponent({ }, onCreated() { - const isTemplateSearch = $(Popup._getTopStack().openerElement).hasClass('js-search-template'); + this.isTemplateSearch = $(Popup._getTopStack().openerElement).hasClass('js-search-template'); let board = {}; - if (isTemplateSearch) { + if (this.isTemplateSearch) { board = Boards.findOne(Meteor.user().profile.templatesBoardId); } else { // Prefetch first non-current board id board = Boards.findOne({ archived: false, 'members.userId': Meteor.userId(), - _id: {$ne: Session.get('currentBoard')}, + _id: {$nin: [Session.get('currentBoard'), Meteor.user().profile.templatesBoardId]}, }); } if (!board) { diff --git a/models/boards.js b/models/boards.js index c17c7351..25cf5e37 100644 --- a/models/boards.js +++ b/models/boards.js @@ -473,6 +473,8 @@ Boards.helpers({ if (this.isTemplatesBoard()) { query.type = 'template-card'; query.archived = false; + } else { + query.type = {$nin: ['template-card']}; } const projection = { limit: 10, sort: { createdAt: -1 } }; diff --git a/models/cardComments.js b/models/cardComments.js index 974c5ec9..f29366a5 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -67,6 +67,12 @@ CardComments.allow({ }); CardComments.helpers({ + copy(newCardId) { + this.cardId = newCardId; + this._id = null; + CardComments.insert(this); + }, + user() { return Users.findOne(this.userId); }, diff --git a/models/cards.js b/models/cards.js index e9fc453e..c7b4a366 100644 --- a/models/cards.js +++ b/models/cards.js @@ -272,6 +272,31 @@ Cards.allow({ }); Cards.helpers({ + copy() { + const oldId = this._id; + this._id = null; + const _id = Cards.insert(this); + + // copy checklists + Checklists.find({cardId: oldId}).forEach((ch) => { + ch.copy(_id); + }); + + // copy subtasks + Cards.find({parentId: oldId}).forEach((subtask) => { + subtask.parentId = _id; + subtask._id = null; + Cards.insert(subtask); + }); + + // copy card comments + CardComments.find({cardId: oldId}).forEach((cmt) => { + cmt.copy(_id); + }); + + return _id; + }, + list() { return Lists.findOne(this.listId); }, diff --git a/models/checklists.js b/models/checklists.js index a372fafa..99e9f25e 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -48,6 +48,19 @@ Checklists.attachSchema(new SimpleSchema({ })); Checklists.helpers({ + copy(newCardId) { + const oldChecklistId = this._id; + this._id = null; + this.cardId = newCardId; + const newChecklistId = Checklists.insert(this); + ChecklistItems.find({checklistId: oldChecklistId}).forEach((item) => { + item._id = null; + item.checklistId = newChecklistId; + item.cardId = newCardId; + ChecklistItems.insert(item); + }); + }, + itemCount() { return ChecklistItems.find({ checklistId: this._id }).count(); }, |