myCards.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import { CardSearchPagedComponent } from '../../lib/cardSearch';
  2. BlazeComponent.extendComponent({
  3. myCardsSort() {
  4. // eslint-disable-next-line no-console
  5. // console.log('sort:', Utils.myCardsSort());
  6. return Utils.myCardsSort();
  7. },
  8. myCardsView() {
  9. // eslint-disable-next-line no-console
  10. // console.log('sort:', Utils.myCardsView());
  11. return Utils.myCardsView();
  12. },
  13. events() {
  14. return [
  15. {
  16. 'click .js-toggle-my-cards-choose-sort': Popup.open(
  17. 'myCardsSortChange',
  18. ),
  19. 'click .js-my-cards-view-change': Popup.open(
  20. 'myCardsViewChange'),
  21. },
  22. ];
  23. },
  24. }).register('myCardsHeaderBar');
  25. Template.myCards.helpers({
  26. userId() {
  27. return Meteor.userId();
  28. },
  29. });
  30. BlazeComponent.extendComponent({
  31. events() {
  32. return [
  33. {
  34. 'click .js-my-cards-view-boards'() {
  35. Utils.setMyCardsView('boards');
  36. Popup.back();
  37. },
  38. 'click .js-my-cards-view-table'() {
  39. Utils.setMyCardsView('table');
  40. Popup.back();
  41. },
  42. },
  43. ];
  44. },
  45. }).register('myCardsViewChangePopup');
  46. class MyCardsComponent extends CardSearchPagedComponent {
  47. onCreated() {
  48. super.onCreated();
  49. this.runGlobalSearch(null);
  50. Meteor.subscribe('setting');
  51. }
  52. // eslint-disable-next-line no-unused-vars
  53. getSubscription(queryParams) {
  54. return Meteor.subscribe(
  55. 'myCards',
  56. this.sessionId,
  57. this.subscriptionCallbacks,
  58. );
  59. }
  60. myCardsView() {
  61. // eslint-disable-next-line no-console
  62. //console.log('sort:', Utils.myCardsView());
  63. return Utils.myCardsView();
  64. }
  65. labelName(board, labelId) {
  66. const label = board.getLabelById(labelId)
  67. const name = label.name
  68. return name
  69. }
  70. labelColor(board, labelId) {
  71. const label = board.getLabelById(labelId)
  72. const color = label.color
  73. return color
  74. }
  75. myCardsList() {
  76. const boards = [];
  77. let board = null;
  78. let swimlane = null;
  79. let list = null;
  80. const cursor = this.getResults();
  81. if (cursor) {
  82. cursor.forEach(card => {
  83. // eslint-disable-next-line no-console
  84. // console.log('card:', card.title);
  85. if (board === null || card.boardId !== board._id) {
  86. // eslint-disable-next-line no-console
  87. // console.log('new board');
  88. board = card.getBoard();
  89. if (board.archived) {
  90. board = null;
  91. return;
  92. }
  93. // eslint-disable-next-line no-console
  94. // console.log('board:', b, b._id, b.title);
  95. boards.push(board);
  96. board.mySwimlanes = [];
  97. swimlane = null;
  98. list = null;
  99. }
  100. if (swimlane === null || card.swimlaneId !== swimlane._id) {
  101. // eslint-disable-next-line no-console
  102. // console.log('new swimlane');
  103. swimlane = card.getSwimlane();
  104. if (swimlane.archived) {
  105. swimlane = null;
  106. return;
  107. }
  108. board.mySwimlanes.push(swimlane);
  109. swimlane.myLists = [];
  110. list = null;
  111. }
  112. if (list === null || card.listId !== list._id) {
  113. // eslint-disable-next-line no-console
  114. // console.log('new list');
  115. list = card.getList();
  116. if (list.archived) {
  117. list = null;
  118. return;
  119. }
  120. swimlane.myLists.push(list);
  121. list.myCards = [];
  122. }
  123. list.myCards.push(card);
  124. });
  125. // sort the data structure
  126. boards.forEach(board => {
  127. board.mySwimlanes.forEach(swimlane => {
  128. swimlane.myLists.forEach(list => {
  129. list.myCards.sort((a, b) => {
  130. return a.sort - b.sort;
  131. });
  132. });
  133. swimlane.myLists.sort((a, b) => {
  134. return a.sort - b.sort;
  135. });
  136. });
  137. board.mySwimlanes.sort((a, b) => {
  138. return a.sort - b.sort;
  139. });
  140. });
  141. boards.sort((a, b) => {
  142. let x = a.sort;
  143. let y = b.sort;
  144. // show the template board last
  145. if (a.type === 'template-container') {
  146. x = 99999999;
  147. } else if (b.type === 'template-container') {
  148. y = 99999999;
  149. }
  150. return x - y;
  151. });
  152. // eslint-disable-next-line no-console
  153. // console.log('boards:', boards);
  154. return boards;
  155. }
  156. return [];
  157. }
  158. }
  159. MyCardsComponent.register('myCards');