dialogWithBoardSwimlaneList.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. export class DialogWithBoardSwimlaneList extends BlazeComponent {
  2. /** returns the card dialog options
  3. * @return Object with properties { boardId, swimlaneId, listId }
  4. */
  5. getDialogOptions() {
  6. }
  7. /** list is done
  8. * @param listId the selected list id
  9. * @param options the selected options (Object with properties { boardId, swimlaneId, listId })
  10. */
  11. setDone(listId, options) {
  12. }
  13. /** get the default options
  14. * @return the options
  15. */
  16. getDefaultOption(boardId) {
  17. const ret = {
  18. 'boardId' : "",
  19. 'swimlaneId' : "",
  20. 'listId' : "",
  21. }
  22. return ret;
  23. }
  24. onCreated() {
  25. this.currentBoardId = Utils.getCurrentBoardId();
  26. this.selectedBoardId = new ReactiveVar(this.currentBoardId);
  27. this.selectedSwimlaneId = new ReactiveVar('');
  28. this.selectedListId = new ReactiveVar('');
  29. this.setOption(this.currentBoardId);
  30. }
  31. /** set the last confirmed dialog field values
  32. * @param boardId the current board id
  33. */
  34. setOption(boardId) {
  35. this.cardOption = this.getDefaultOption();
  36. let currentOptions = this.getDialogOptions();
  37. if (currentOptions && boardId && currentOptions[boardId]) {
  38. this.cardOption = currentOptions[boardId];
  39. if (this.cardOption.boardId &&
  40. this.cardOption.swimlaneId &&
  41. this.cardOption.listId
  42. )
  43. {
  44. this.selectedBoardId.set(this.cardOption.boardId)
  45. this.selectedSwimlaneId.set(this.cardOption.swimlaneId);
  46. this.selectedListId.set(this.cardOption.listId);
  47. }
  48. }
  49. this.getBoardData(this.selectedBoardId.get());
  50. if (!this.selectedSwimlaneId.get() || !Swimlanes.findOne({_id: this.selectedSwimlaneId.get(), boardId: this.selectedBoardId.get()})) {
  51. this.setFirstSwimlaneId();
  52. }
  53. if (!this.selectedListId.get() || !Lists.findOne({_id: this.selectedListId.get(), boardId: this.selectedBoardId.get()})) {
  54. this.setFirstListId();
  55. }
  56. }
  57. /** sets the first swimlane id */
  58. setFirstSwimlaneId() {
  59. try {
  60. const board = Boards.findOne(this.selectedBoardId.get());
  61. const swimlaneId = board.swimlanes().fetch()[0]._id;
  62. this.selectedSwimlaneId.set(swimlaneId);
  63. } catch (e) {}
  64. }
  65. /** sets the first list id */
  66. setFirstListId() {
  67. try {
  68. const board = Boards.findOne(this.selectedBoardId.get());
  69. const listId = board.lists().fetch()[0]._id;
  70. this.selectedListId.set(listId);
  71. } catch (e) {}
  72. }
  73. /** returns if the board id was the last confirmed one
  74. * @param boardId check this board id
  75. * @return if the board id was the last confirmed one
  76. */
  77. isDialogOptionBoardId(boardId) {
  78. let ret = this.cardOption.boardId == boardId;
  79. return ret;
  80. }
  81. /** returns if the swimlane id was the last confirmed one
  82. * @param swimlaneId check this swimlane id
  83. * @return if the swimlane id was the last confirmed one
  84. */
  85. isDialogOptionSwimlaneId(swimlaneId) {
  86. let ret = this.cardOption.swimlaneId == swimlaneId;
  87. return ret;
  88. }
  89. /** returns if the list id was the last confirmed one
  90. * @param listId check this list id
  91. * @return if the list id was the last confirmed one
  92. */
  93. isDialogOptionListId(listId) {
  94. let ret = this.cardOption.listId == listId;
  95. return ret;
  96. }
  97. /** returns all available board */
  98. boards() {
  99. const ret = Boards.find(
  100. {
  101. archived: false,
  102. 'members.userId': Meteor.userId(),
  103. _id: { $ne: Meteor.user().getTemplatesBoardId() },
  104. },
  105. {
  106. sort: { sort: 1 },
  107. },
  108. );
  109. return ret;
  110. }
  111. /** returns all available swimlanes of the current board */
  112. swimlanes() {
  113. const board = Boards.findOne(this.selectedBoardId.get());
  114. const ret = board.swimlanes();
  115. return ret;
  116. }
  117. /** returns all available lists of the current board */
  118. lists() {
  119. const board = Boards.findOne(this.selectedBoardId.get());
  120. const ret = board.lists();
  121. return ret;
  122. }
  123. /** get the board data from the server
  124. * @param boardId get the board data of this board id
  125. */
  126. getBoardData(boardId) {
  127. const self = this;
  128. Meteor.subscribe('board', boardId, false, {
  129. onReady() {
  130. const sameBoardId = self.selectedBoardId.get() == boardId;
  131. self.selectedBoardId.set(boardId);
  132. if (!sameBoardId) {
  133. // reset swimlane id (for selection in cards())
  134. self.setFirstSwimlaneId();
  135. // reset list id (for selection in cards())
  136. self.setFirstListId();
  137. }
  138. },
  139. });
  140. }
  141. events() {
  142. return [
  143. {
  144. 'click .js-done'() {
  145. const boardSelect = this.$('.js-select-boards')[0];
  146. const boardId = boardSelect.options[boardSelect.selectedIndex].value;
  147. const listSelect = this.$('.js-select-lists')[0];
  148. const listId = listSelect.options[listSelect.selectedIndex].value;
  149. const swimlaneSelect = this.$('.js-select-swimlanes')[0];
  150. const swimlaneId = swimlaneSelect.options[swimlaneSelect.selectedIndex].value;
  151. const options = {
  152. 'boardId' : boardId,
  153. 'swimlaneId' : swimlaneId,
  154. 'listId' : listId,
  155. }
  156. this.setDone(boardId, swimlaneId, listId, options);
  157. Popup.back(2);
  158. },
  159. 'change .js-select-boards'(event) {
  160. const boardId = $(event.currentTarget).val();
  161. this.getBoardData(boardId);
  162. },
  163. 'change .js-select-swimlanes'(event) {
  164. this.selectedSwimlaneId.set($(event.currentTarget).val());
  165. },
  166. },
  167. ];
  168. }
  169. }