Kaynağa Gözat

Merge pull request #4142 from mfilser/global_search_load_card_details

Global search load card details
Lauri Ojansivu 3 yıl önce
ebeveyn
işleme
25024fbe6b

+ 2 - 1
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() {

+ 10 - 2
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) {

+ 1 - 1
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();

+ 1 - 1
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);
     }
   },

+ 2 - 6
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', () => {

+ 21 - 1
client/lib/utils.js

@@ -1,4 +1,16 @@
 Utils = {
+  /** returns the current board id
+   * <li> 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
+   * <li> 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) {

+ 18 - 9
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', '');

+ 14 - 9
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);
     },
   });

+ 17 - 1
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,