diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index f3693cb5d..ab6deb4a4 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -546,7 +546,8 @@ Template.cardDetails.helpers({ } }); Template.cardDetailsPopup.onDestroyed(() => { - Session.delete('popupCard'); + Session.delete('popupCardId'); + Session.delete('popupCardBoardId'); }); Template.cardDetailsPopup.helpers({ popupCard() { diff --git a/client/components/cards/resultCard.js b/client/components/cards/resultCard.js index 89632b97a..8e04f1654 100644 --- a/client/components/cards/resultCard.js +++ b/client/components/cards/resultCard.js @@ -7,8 +7,16 @@ Template.resultCard.helpers({ BlazeComponent.extendComponent({ clickOnMiniCard(evt) { evt.preventDefault(); - Session.set('popupCard', this.currentData()._id); - this.cardDetailsPopup(evt); + const this_ = this; + const cardId = this.currentData()._id; + const boardId = this.currentData().boardId; + Meteor.subscribe('popupCardData', cardId, { + onReady() { + Session.set('popupCardId', cardId); + Session.set('popupCardBoardId', boardId); + this_.cardDetailsPopup(evt); + }, + }); }, cardDetailsPopup(event) { diff --git a/client/components/lists/listBody.js b/client/components/lists/listBody.js index 3ec189a21..bb03d72cd 100644 --- a/client/components/lists/listBody.js +++ b/client/components/lists/listBody.js @@ -150,7 +150,7 @@ BlazeComponent.extendComponent({ // overwriting the event in case the card is already selected. } else if (Utils.isMiniScreen()) { evt.preventDefault(); - Session.set('popupCard', this.currentData()._id); + Session.set('popupCardId', this.currentData()._id); this.cardDetailsPopup(evt); } else if (Session.equals('currentCard', this.currentData()._id)) { evt.stopImmediatePropagation(); diff --git a/client/components/sidebar/sidebarSearches.js b/client/components/sidebar/sidebarSearches.js index 643fcb59c..f5e8a5c82 100644 --- a/client/components/sidebar/sidebarSearches.js +++ b/client/components/sidebar/sidebarSearches.js @@ -16,7 +16,7 @@ BlazeComponent.extendComponent({ clickOnMiniCard(evt) { if (Utils.isMiniScreen()) { evt.preventDefault(); - Session.set('popupCard', this.currentData()._id); + Session.set('popupCardId', this.currentData()._id); this.cardDetailsPopup(evt); } }, diff --git a/client/config/blazeHelpers.js b/client/config/blazeHelpers.js index 741b2fc58..22194f3bd 100644 --- a/client/config/blazeHelpers.js +++ b/client/config/blazeHelpers.js @@ -1,10 +1,6 @@ Blaze.registerHelper('currentBoard', () => { - const boardId = Session.get('currentBoard'); - if (boardId) { - return Boards.findOne(boardId); - } else { - return null; - } + const ret = Utils.getCurrentBoard(); + return ret; }); Blaze.registerHelper('currentCard', () => { diff --git a/client/lib/utils.js b/client/lib/utils.js index 3e2cad868..6395fe741 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -1,4 +1,16 @@ Utils = { + /** returns the current board id + *
  • returns the current board id or the board id of the popup card if set + */ + getCurrentBoardId() { + let popupCardBoardId = Session.get('popupCardBoardId'); + let currentBoard = Session.get('currentBoard'); + let ret = currentBoard; + if (popupCardBoardId) { + ret = popupCardBoardId; + } + return ret; + }, getCurrentCardId(ignorePopupCard) { let ret = Session.get('currentCard'); if (!ret && !ignorePopupCard) { @@ -7,7 +19,15 @@ Utils = { return ret; }, getPopupCardId() { - const ret = Session.get('popupCard'); + const ret = Session.get('popupCardId'); + return ret; + }, + /** returns the current board + *
  • returns the current board or the board of the popup card if set + */ + getCurrentBoard() { + const boardId = Utils.getCurrentBoardId(); + const ret = Boards.findOne(boardId); return ret; }, getCurrentCard(ignorePopupCard) { diff --git a/config/router.js b/config/router.js index dec27ba21..a35883ee3 100644 --- a/config/router.js +++ b/config/router.js @@ -12,7 +12,8 @@ FlowRouter.route('/', { Session.set('currentBoard', null); Session.set('currentList', null); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Filter.reset(); Session.set('sortBy', ''); @@ -35,7 +36,8 @@ FlowRouter.route('/public', { Session.set('currentBoard', null); Session.set('currentList', null); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Filter.reset(); Session.set('sortBy', ''); @@ -58,7 +60,8 @@ FlowRouter.route('/b/:id/:slug', { const previousBoard = Session.get('currentBoard'); Session.set('currentBoard', currentBoard); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); // If we close a card, we'll execute again this route action but we don't // want to excape every current actions (filters, etc.) @@ -87,7 +90,8 @@ FlowRouter.route('/b/:boardId/:slug/:cardId', { Session.set('currentBoard', params.boardId); Session.set('currentCard', params.cardId); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Utils.manageCustomUI(); Utils.manageMatomo(); @@ -216,7 +220,8 @@ FlowRouter.route('/import/:source', { Session.set('currentBoard', null); Session.set('currentList', null); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Session.set('importSource', params.source); Filter.reset(); @@ -237,7 +242,8 @@ FlowRouter.route('/setting', { Session.set('currentBoard', null); Session.set('currentList', null); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Filter.reset(); Session.set('sortBy', ''); @@ -261,7 +267,8 @@ FlowRouter.route('/information', { Session.set('currentBoard', null); Session.set('currentList', null); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Filter.reset(); Session.set('sortBy', ''); @@ -284,7 +291,8 @@ FlowRouter.route('/people', { Session.set('currentBoard', null); Session.set('currentList', null); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Filter.reset(); Session.set('sortBy', ''); @@ -307,7 +315,8 @@ FlowRouter.route('/admin-reports', { Session.set('currentBoard', null); Session.set('currentList', null); Session.set('currentCard', null); - Session.set('popupCard', null); + Session.set('popupCardId', null); + Session.set('popupCardBoardId', null); Filter.reset(); Session.set('sortBy', ''); diff --git a/models/users.js b/models/users.js index 69c6d5e0e..2cefac993 100644 --- a/models/users.js +++ b/models/users.js @@ -458,46 +458,51 @@ Users.safeFields = { if (Meteor.isClient) { Users.helpers({ isBoardMember() { - const board = Boards.findOne(Session.get('currentBoard')); + const board = Utils.getCurrentBoard(); return board && board.hasMember(this._id); }, isNotNoComments() { - const board = Boards.findOne(Session.get('currentBoard')); + const board = Utils.getCurrentBoard(); return ( board && board.hasMember(this._id) && !board.hasNoComments(this._id) ); }, isNoComments() { - const board = Boards.findOne(Session.get('currentBoard')); + const board = Utils.getCurrentBoard(); return board && board.hasNoComments(this._id); }, isNotCommentOnly() { - const board = Boards.findOne(Session.get('currentBoard')); + const board = Utils.getCurrentBoard(); return ( board && board.hasMember(this._id) && !board.hasCommentOnly(this._id) ); }, isCommentOnly() { - const board = Boards.findOne(Session.get('currentBoard')); + const board = Utils.getCurrentBoard(); return board && board.hasCommentOnly(this._id); }, isNotWorker() { - const board = Boards.findOne(Session.get('currentBoard')); + const board = Utils.getCurrentBoard(); return board && board.hasMember(this._id) && !board.hasWorker(this._id); }, isWorker() { - const board = Boards.findOne(Session.get('currentBoard')); + const board = Utils.getCurrentBoard(); return board && board.hasWorker(this._id); }, - isBoardAdmin(boardId = Session.get('currentBoard')) { - const board = Boards.findOne(boardId); + isBoardAdmin(boardId) { + let board; + if (boardId) { + board = Boards.findOne(boardId); + } else { + board = Utils.getCurrentBoard(); + } return board && board.hasAdmin(this._id); }, }); diff --git a/server/publications/cards.js b/server/publications/cards.js index caa9190a5..8322de09d 100644 --- a/server/publications/cards.js +++ b/server/publications/cards.js @@ -52,7 +52,22 @@ const escapeForRegex = require('escape-string-regexp'); Meteor.publish('card', cardId => { check(cardId, String); - return Cards.find({ _id: cardId }); + const ret = Cards.find({ _id: cardId }); + return ret; +}); + +/** publish all data which is necessary to display card details as popup + * @returns array of cursors + */ +Meteor.publishRelations('popupCardData', function(cardId) { + check(cardId, String); + this.cursor( + Cards.find({_id: cardId}), + function(cardId, card) { + this.cursor(Boards.find({_id: card.boardId})); + }, + ); + return this.ready() }); Meteor.publish('myCards', function(sessionId) { @@ -489,6 +504,7 @@ function buildProjection(query) { labelIds: 1, customFields: 1, userId: 1, + description: 1, }, sort: { boardId: 1,