2
0

myCards.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. events() {
  9. return [
  10. {
  11. 'click .js-toggle-my-cards-choose-sort': Popup.open(
  12. 'myCardsSortChange',
  13. ),
  14. },
  15. ];
  16. },
  17. }).register('myCardsHeaderBar');
  18. Template.myCards.helpers({
  19. userId() {
  20. return Meteor.userId();
  21. },
  22. });
  23. class MyCardsComponent extends CardSearchPagedComponent {
  24. onCreated() {
  25. super.onCreated();
  26. this.runGlobalSearch(null);
  27. Meteor.subscribe('setting');
  28. }
  29. // eslint-disable-next-line no-unused-vars
  30. getSubscription(queryParams) {
  31. return Meteor.subscribe(
  32. 'myCards',
  33. this.sessionId,
  34. this.subscriptionCallbacks,
  35. );
  36. }
  37. myCardsList() {
  38. const boards = [];
  39. let board = null;
  40. let swimlane = null;
  41. let list = null;
  42. const cursor = this.getResults();
  43. if (cursor) {
  44. cursor.forEach(card => {
  45. // eslint-disable-next-line no-console
  46. // console.log('card:', card.title);
  47. if (board === null || card.boardId !== board._id) {
  48. // eslint-disable-next-line no-console
  49. // console.log('new board');
  50. board = card.getBoard();
  51. if (board.archived) {
  52. board = null;
  53. return;
  54. }
  55. // eslint-disable-next-line no-console
  56. // console.log('board:', b, b._id, b.title);
  57. boards.push(board);
  58. board.mySwimlanes = [];
  59. swimlane = null;
  60. list = null;
  61. }
  62. if (swimlane === null || card.swimlaneId !== swimlane._id) {
  63. // eslint-disable-next-line no-console
  64. // console.log('new swimlane');
  65. swimlane = card.getSwimlane();
  66. if (swimlane.archived) {
  67. swimlane = null;
  68. return;
  69. }
  70. board.mySwimlanes.push(swimlane);
  71. swimlane.myLists = [];
  72. list = null;
  73. }
  74. if (list === null || card.listId !== list._id) {
  75. // eslint-disable-next-line no-console
  76. // console.log('new list');
  77. list = card.getList();
  78. if (list.archived) {
  79. list = null;
  80. return;
  81. }
  82. swimlane.myLists.push(list);
  83. list.myCards = [];
  84. }
  85. list.myCards.push(card);
  86. });
  87. // sort the data structure
  88. boards.forEach(board => {
  89. board.mySwimlanes.forEach(swimlane => {
  90. swimlane.myLists.forEach(list => {
  91. list.myCards.sort((a, b) => {
  92. return a.sort - b.sort;
  93. });
  94. });
  95. swimlane.myLists.sort((a, b) => {
  96. return a.sort - b.sort;
  97. });
  98. });
  99. board.mySwimlanes.sort((a, b) => {
  100. return a.sort - b.sort;
  101. });
  102. });
  103. boards.sort((a, b) => {
  104. let x = a.sort;
  105. let y = b.sort;
  106. // show the template board last
  107. if (a.type === 'template-container') {
  108. x = 99999999;
  109. } else if (b.type === 'template-container') {
  110. y = 99999999;
  111. }
  112. return x - y;
  113. });
  114. // eslint-disable-next-line no-console
  115. // console.log('boards:', boards);
  116. return boards;
  117. }
  118. return [];
  119. }
  120. }
  121. MyCardsComponent.register('myCards');