myCards.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. const subManager = new SubsManager();
  2. Meteor.subscribe('myCards');
  3. Meteor.subscribe('mySwimlanes');
  4. Meteor.subscribe('myLists');
  5. Template.myCardsHeaderBar.events({
  6. 'click .js-open-archived-board'() {
  7. Modal.open('archivedBoards');
  8. },
  9. });
  10. Template.myCardsHeaderBar.helpers({
  11. title() {
  12. return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
  13. },
  14. templatesUser() {
  15. return Meteor.user();
  16. },
  17. });
  18. Template.myCards.helpers({
  19. userId() {
  20. return Meteor.userId();
  21. },
  22. });
  23. BlazeComponent.extendComponent({
  24. onCreated() {
  25. Meteor.subscribe('setting');
  26. // subManager.subscribe('myCards');
  27. },
  28. myBoards() {
  29. const userId = Meteor.userId();
  30. const boards = [];
  31. let board = null;
  32. let swimlane = null;
  33. let list = null;
  34. const cursor = Cards.find(
  35. {
  36. $or: [{ members: userId }, { assignees: userId }],
  37. archived: false,
  38. },
  39. {
  40. sort: {
  41. boardId: 1,
  42. swimlaneId: 1,
  43. listId: 1,
  44. sort: 1,
  45. },
  46. },
  47. );
  48. let newBoard = false;
  49. let newSwimlane = false;
  50. let newList = false;
  51. cursor.forEach(card => {
  52. // eslint-disable-next-line no-console
  53. // console.log('card:', card.title);
  54. if (list === null || card.listId !== list._id) {
  55. // eslint-disable-next-line no-console
  56. // console.log('new list');
  57. list = card.list();
  58. if (list.archived) {
  59. list = null;
  60. return;
  61. }
  62. list.myCards = [card];
  63. newList = true;
  64. }
  65. if (swimlane === null || card.swimlaneId !== swimlane._id) {
  66. // eslint-disable-next-line no-console
  67. // console.log('new swimlane');
  68. swimlane = card.swimlane();
  69. if (swimlane.archived) {
  70. swimlane = null;
  71. return;
  72. }
  73. swimlane.myLists = [list];
  74. newSwimlane = true;
  75. }
  76. if (board === null || card.boardId !== board._id) {
  77. // eslint-disable-next-line no-console
  78. // console.log('new board');
  79. board = card.board();
  80. if (board.archived) {
  81. board = null;
  82. return;
  83. }
  84. // eslint-disable-next-line no-console
  85. // console.log('board:', b, b._id, b.title);
  86. board.mySwimlanes = [swimlane];
  87. newBoard = true;
  88. }
  89. if (newBoard) {
  90. boards.push(board);
  91. } else if (newSwimlane) {
  92. board.mySwimlanes.push(swimlane);
  93. } else if (newList) {
  94. swimlane.myLists.push(list);
  95. } else {
  96. list.myCards.push(card);
  97. }
  98. newBoard = false;
  99. newSwimlane = false;
  100. newList = false;
  101. });
  102. // sort the data structure
  103. boards.forEach(board => {
  104. board.mySwimlanes.forEach(swimlane => {
  105. swimlane.myLists.forEach(list => {
  106. list.myCards.sort((a, b) => {
  107. return a.sort - b.sort;
  108. });
  109. });
  110. swimlane.myLists.sort((a, b) => {
  111. return a.sort - b.sort;
  112. });
  113. });
  114. board.mySwimlanes.sort((a, b) => {
  115. return a.sort - b.sort;
  116. });
  117. });
  118. boards.sort((a, b) => {
  119. let x = a.sort;
  120. let y = b.sort;
  121. // show the template board last
  122. if (a.type === 'template-container') {
  123. x = 99999999;
  124. } else if (b.type === 'template-container') {
  125. y = 99999999;
  126. }
  127. return x - y;
  128. });
  129. // eslint-disable-next-line no-console
  130. // console.log('boards:', boards);
  131. return boards;
  132. },
  133. events() {
  134. return [
  135. {
  136. 'click .js-my-card'(evt) {
  137. const card = this.currentData().card;
  138. // eslint-disable-next-line no-console
  139. console.log('currentData():', this.currentData());
  140. // eslint-disable-next-line no-console
  141. console.log('card:', card);
  142. if (card) {
  143. Utils.goCardId(card._id);
  144. }
  145. evt.preventDefault();
  146. },
  147. },
  148. ];
  149. },
  150. }).register('myCards');