Prechádzať zdrojové kódy

Move checklist popup restores now the last selected board value in dropdown menu

Martin Filser 3 rokov pred
rodič
commit
70558d00a7
1 zmenil súbory, kde vykonal 54 pridanie a 21 odobranie
  1. 54 21
      client/components/cards/checklists.js

+ 54 - 21
client/components/cards/checklists.js

@@ -379,16 +379,11 @@ BlazeComponent.extendComponent({
 
 
 BlazeComponent.extendComponent({
 BlazeComponent.extendComponent({
   onCreated() {
   onCreated() {
-    const boardId = Utils.getCurrentBoardId();
-    subManager.subscribe('board', boardId, false);
-    // subManager.subscribe('swimlane', swimlaneId, false);
-    // subManager.subscribe('list', listId, false);
-    // subManager.subscribe('card', cardId, false);
-    this.selectedBoardId = new ReactiveVar(boardId);
+    this.currentBoardId = Utils.getCurrentBoardId();
+    this.selectedBoardId = new ReactiveVar(this.currentBoardId);
     this.selectedSwimlaneId = new ReactiveVar('');
     this.selectedSwimlaneId = new ReactiveVar('');
     this.selectedListId = new ReactiveVar('');
     this.selectedListId = new ReactiveVar('');
-    this.selectedCardId = new ReactiveVar('');
-    this.setMoveChecklistDialogOption(boardId);
+    this.setMoveChecklistDialogOption(this.currentBoardId);
   },
   },
 
 
   /** set the last confirmed dialog field values
   /** set the last confirmed dialog field values
@@ -405,20 +400,39 @@ BlazeComponent.extendComponent({
     let currentOptions = Meteor.user().getMoveChecklistDialogOptions();
     let currentOptions = Meteor.user().getMoveChecklistDialogOptions();
     if (currentOptions && boardId && currentOptions[boardId]) {
     if (currentOptions && boardId && currentOptions[boardId]) {
       this.moveChecklistDialogOption = currentOptions[boardId];
       this.moveChecklistDialogOption = currentOptions[boardId];
+      if (this.moveChecklistDialogOption.boardId &&
+          this.moveChecklistDialogOption.swimlaneId &&
+          this.moveChecklistDialogOption.listId
+      )
+      {
+        this.selectedBoardId.set(this.moveChecklistDialogOption.boardId)
+        this.selectedSwimlaneId.set(this.moveChecklistDialogOption.swimlaneId);
+        this.selectedListId.set(this.moveChecklistDialogOption.listId);
+      }
+    }
+    this.getBoardData(boardId);
+    if (!this.selectedSwimlaneId.get() || !Swimlanes.findOne({_id: this.selectedSwimlaneId.get(), boardId: this.selectedBoardId.get()})) {
+      this.setFirstSwimlaneId();
     }
     }
-    const board = Boards.findOne(boardId);
+    if (!this.selectedListId.get() || !Lists.findOne({_id: this.selectedListId.get(), boardId: this.selectedBoardId.get()})) {
+      this.setFirstListId();
+    }
+  },
+  /** sets the first swimlane id */
+  setFirstSwimlaneId() {
     try {
     try {
+      const board = Boards.findOne(this.selectedBoardId.get());
       const swimlaneId = board.swimlanes().fetch()[0]._id;
       const swimlaneId = board.swimlanes().fetch()[0]._id;
       this.selectedSwimlaneId.set(swimlaneId);
       this.selectedSwimlaneId.set(swimlaneId);
     } catch (e) {}
     } catch (e) {}
-
+  },
+  /** sets the first list id */
+  setFirstListId() {
     try {
     try {
-      const listId = board.lists().fetch()[0];
+      const board = Boards.findOne(this.selectedBoardId.get());
+      const listId = board.lists().fetch()[0]._id;
       this.selectedListId.set(listId);
       this.selectedListId.set(listId);
     } catch (e) {}
     } catch (e) {}
-
-    const cardId = Utils.getCurrentCardId();
-    this.selectedCardId.set(cardId);
   },
   },
 
 
   /** returns if the board id was the last confirmed one
   /** returns if the board id was the last confirmed one
@@ -458,7 +472,7 @@ BlazeComponent.extendComponent({
   },
   },
 
 
   boards() {
   boards() {
-    return Boards.find(
+    const ret = Boards.find(
       {
       {
         archived: false,
         archived: false,
         'members.userId': Meteor.userId(),
         'members.userId': Meteor.userId(),
@@ -468,16 +482,19 @@ BlazeComponent.extendComponent({
         sort: { sort: 1 },
         sort: { sort: 1 },
       },
       },
     );
     );
+    return ret;
   },
   },
 
 
   swimlanes() {
   swimlanes() {
     const board = Boards.findOne(this.selectedBoardId.get());
     const board = Boards.findOne(this.selectedBoardId.get());
-    return board.swimlanes();
+    const ret = board.swimlanes();
+    return ret;
   },
   },
 
 
   lists() {
   lists() {
     const board = Boards.findOne(this.selectedBoardId.get());
     const board = Boards.findOne(this.selectedBoardId.get());
-    return board.lists();
+    const ret = board.lists();
+    return ret;
   },
   },
 
 
   cards() {
   cards() {
@@ -486,6 +503,24 @@ BlazeComponent.extendComponent({
     return ret;
     return ret;
   },
   },
 
 
+  /** get the board data from the server
+   * @param boardId get the board data of this board id
+   */
+  getBoardData(boardId) {
+    const self = this;
+    Meteor.subscribe('board', boardId, false, {
+      onReady() {
+        self.selectedBoardId.set(boardId);
+
+        // reset swimlane id (for selection in cards())
+        self.setFirstSwimlaneId();
+
+        // reset list id (for selection in cards())
+        self.setFirstListId();
+      },
+    });
+  },
+
   events() {
   events() {
     return [
     return [
       {
       {
@@ -508,15 +543,13 @@ BlazeComponent.extendComponent({
             'listId' : listId,
             'listId' : listId,
             'cardId': cardId,
             'cardId': cardId,
           }
           }
-          Meteor.user().setMoveChecklistDialogOption(boardId, options);
+          Meteor.user().setMoveChecklistDialogOption(this.currentBoardId, options);
           this.data().checklist.move(cardId);
           this.data().checklist.move(cardId);
           Popup.back(2);
           Popup.back(2);
         },
         },
         'change .js-select-boards'(event) {
         'change .js-select-boards'(event) {
           const boardId = $(event.currentTarget).val();
           const boardId = $(event.currentTarget).val();
-          subManager.subscribe('board', boardId, false);
-          this.setMoveChecklistDialogOption(boardId);
-          this.selectedBoardId.set(boardId);
+          this.getBoardData(boardId);
         },
         },
         'change .js-select-swimlanes'(event) {
         'change .js-select-swimlanes'(event) {
           this.selectedSwimlaneId.set($(event.currentTarget).val());
           this.selectedSwimlaneId.set($(event.currentTarget).val());