dialogWithBoardSwimlaneList.js 5.5 KB

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