فهرست منبع

Added ability to change card's parent.

Nicu Tofan 7 سال پیش
والد
کامیت
b7d508e8c4
5فایلهای تغییر یافته به همراه156 افزوده شده و 30 حذف شده
  1. 27 0
      client/components/cards/cardDetails.jade
  2. 110 27
      client/components/cards/cardDetails.js
  3. 3 0
      i18n/en.i18n.json
  4. 4 0
      models/boards.js
  5. 12 3
      models/cards.js

+ 27 - 0
client/components/cards/cardDetails.jade

@@ -283,10 +283,37 @@ template(name="cardMorePopup")
       button.js-copy-card-link-to-clipboard(class="btn") {{_ 'copy-card-link-to-clipboard'}}
     span.clearfix
     br
+    h2 {{_ 'change-card-parent'}}
+    label {{_ 'source-board'}}:
+      select.js-field-parent-board
+        each boards
+          if isParentBoard
+            option(value="{{_id}}" selected) {{title}}
+          else
+            option(value="{{_id}}") {{title}}
+        if isTopLevel
+          option(value="none" selected) {{_ 'custom-field-dropdown-none'}}
+        else
+          option(value="none") {{_ 'custom-field-dropdown-none'}}
+
+    label {{_ 'parent-card'}}:
+      select.js-field-parent-card
+        if isTopLevel
+          option(value="none" selected) {{_ 'custom-field-dropdown-none'}}
+        else
+          each cards
+            if isParentCard
+              option(value="{{_id}}" selected) {{title}}
+            else
+              option(value="{{_id}}") {{title}}
+          option(value="none") {{_ 'custom-field-dropdown-none'}}
+    br
     | {{_ 'added'}}
     span.date(title=card.createdAt) {{ moment createdAt 'LLL' }}
     a.js-delete(title="{{_ 'card-delete-notice'}}") {{_ 'delete'}}
 
+
+
 template(name="cardDeletePopup")
   p {{_ "card-delete-pop"}}
   unless archived

+ 110 - 27
client/components/cards/cardDetails.js

@@ -390,7 +390,6 @@ Template.moveCardPopup.events({
     Popup.close();
   },
 });
-
 BlazeComponent.extendComponent({
   onCreated() {
     subManager.subscribe('board', Session.get('currentBoard'));
@@ -427,6 +426,7 @@ BlazeComponent.extendComponent({
   },
 }).register('boardsAndLists');
 
+
 function cloneCheckList(_id, checklist) {
   'use strict';
   const checklistId = checklist._id;
@@ -558,36 +558,119 @@ Template.copyChecklistToManyCardsPopup.events({
   },
 });
 
+BlazeComponent.extendComponent({
+  onCreated() {
+    this.currentCard = this.currentData();
+    this.parentCard = this.currentCard.parentCard();
+    if (this.parentCard) {
+      this.parentBoard = this.parentCard.board();
+    } else {
+      this.parentBoard = null;
+    }
+  },
+
+  boards() {
+    const boards = Boards.find({
+      archived: false,
+      'members.userId': Meteor.userId(),
+    }, {
+      sort: ['title'],
+    });
+    return boards;
+  },
 
-Template.cardMorePopup.events({
-  'click .js-copy-card-link-to-clipboard' () {
-    // Clipboard code from:
-    // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
-    const StringToCopyElement = document.getElementById('cardURL');
-    StringToCopyElement.select();
-    if (document.execCommand('copy')) {
-      StringToCopyElement.blur();
+  cards() {
+    if (this.parentBoard) {
+      return this.parentBoard.cards();
     } else {
-      document.getElementById('cardURL').selectionStart = 0;
-      document.getElementById('cardURL').selectionEnd = 999;
-      document.execCommand('copy');
-      if (window.getSelection) {
-        if (window.getSelection().empty) { // Chrome
-          window.getSelection().empty();
-        } else if (window.getSelection().removeAllRanges) { // Firefox
-          window.getSelection().removeAllRanges();
-        }
-      } else if (document.selection) { // IE?
-        document.selection.empty();
-      }
+      return [];
     }
   },
-  'click .js-delete': Popup.afterConfirm('cardDelete', function () {
-    Popup.close();
-    Cards.remove(this._id);
-    Utils.goBoardId(this.boardId);
-  }),
-});
+
+  isParentBoard() {
+    const board = this.currentData();
+    if (this.parentBoard) {
+      return board._id === this.parentBoard;
+    }
+    return false;
+  },
+
+  isParentCard() {
+    const card = this.currentData();
+    if (this.parentCard) {
+      return card._id === this.parentCard;
+    }
+    return false;
+  },
+
+  setParentCardId(cardId) {
+    if (cardId === 'null') {
+      cardId = null;
+      this.parentCard = null;
+    } else {
+      this.parentCard = Cards.findOne(cardId);
+    }
+    this.currentCard.setParentId(cardId);
+  },
+
+  events() {
+    return [{
+      'click .js-copy-card-link-to-clipboard' () {
+        // Clipboard code from:
+        // https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
+        const StringToCopyElement = document.getElementById('cardURL');
+        StringToCopyElement.select();
+        if (document.execCommand('copy')) {
+          StringToCopyElement.blur();
+        } else {
+          document.getElementById('cardURL').selectionStart = 0;
+          document.getElementById('cardURL').selectionEnd = 999;
+          document.execCommand('copy');
+          if (window.getSelection) {
+            if (window.getSelection().empty) { // Chrome
+              window.getSelection().empty();
+            } else if (window.getSelection().removeAllRanges) { // Firefox
+              window.getSelection().removeAllRanges();
+            }
+          } else if (document.selection) { // IE?
+            document.selection.empty();
+          }
+        }
+      },
+      'click .js-delete': Popup.afterConfirm('cardDelete', function () {
+        Popup.close();
+        Cards.remove(this._id);
+        Utils.goBoardId(this.boardId);
+      }),
+      'change .js-field-parent-board'(evt) {
+        const selection = $(evt.currentTarget).val();
+        const list = $('.js-field-parent-card');
+        list.empty();
+        if (selection === 'none') {
+          this.parentBoard = null;
+          list.prop('disabled', true);
+        } else {
+          this.parentBoard = Boards.findOne(selection);
+          this.parentBoard.cards().forEach(function(card) {
+            list.append(
+              $('<option></option>').val(card._id).html(card.title)
+            );
+          });
+          list.prop('disabled', false);
+        }
+        list.append(
+          `<option value='none' selected='selected'>${TAPi18n.__('custom-field-dropdown-none')}</option>`
+        );
+        this.setParentCardId('null');
+      },
+      'change .js-field-parent-card'(evt) {
+        const selection = $(evt.currentTarget).val();
+        this.setParentCardId(selection);
+      },
+    }];
+  },
+}).register('cardMorePopup');
+
 
 // Close the card details pane by pressing escape
 EscapeActions.register('detailsPane',

+ 3 - 0
i18n/en.i18n.json

@@ -493,6 +493,9 @@
     "prefix-with-parent": "Prefix with parent",
     "subtext-with-full-path": "Subtext with full path",
     "subtext-with-parent": "Subtext with parent",
+    "change-card-parent": "Change card's parent",
+    "parent-card": "Parent card",
+    "source-board": "Source board",
     "no-parent": "Don't show parent"
 
 }

+ 4 - 0
models/boards.js

@@ -220,6 +220,10 @@ Boards.helpers({
     return Swimlanes.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } });
   },
 
+  cards() {
+    return Cards.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } });
+  },
+
   hasOvertimeCards(){
     const card = Cards.findOne({isOvertime: true, boardId: this._id, archived: false} );
     return card !== undefined;

+ 12 - 3
models/cards.js

@@ -327,10 +327,14 @@ Cards.helpers({
   },
 
   parentCardName() {
-    if (this.parentId === '') {
-      return '';
+    let result = '';
+    if (this.parentId !== '') {
+      const card = Cards.findOne(this.parentId);
+      if (card) {
+        result = card.title;
+      }
     }
-    return Cards.findOne(this.parentId).title;
+    return result;
   },
 
   parentListId() {
@@ -541,6 +545,11 @@ Cards.mutations({
   unsetSpentTime() {
     return {$unset: {spentTime: '', isOvertime: false}};
   },
+
+  setParentId(parentId) {
+    return {$set: {parentId}};
+  },
+
 });