dueCards.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const subManager = new SubsManager();
  2. BlazeComponent.extendComponent({
  3. dueCardsView() {
  4. // eslint-disable-next-line no-console
  5. // console.log('sort:', Utils.dueCardsView());
  6. return Utils.dueCardsView();
  7. },
  8. events() {
  9. return [
  10. {
  11. 'click .js-due-cards-view-change': Popup.open('dueCardsViewChange'),
  12. },
  13. ];
  14. },
  15. }).register('dueCardsHeaderBar');
  16. Template.dueCards.helpers({
  17. userId() {
  18. return Meteor.userId();
  19. },
  20. });
  21. BlazeComponent.extendComponent({
  22. events() {
  23. return [
  24. {
  25. 'click .js-due-cards-view-me'() {
  26. Utils.setDueCardsView('me');
  27. Popup.close();
  28. },
  29. 'click .js-due-cards-view-all'() {
  30. Utils.setDueCardsView('all');
  31. Popup.close();
  32. },
  33. },
  34. ];
  35. },
  36. }).register('dueCardsViewChangePopup');
  37. BlazeComponent.extendComponent({
  38. onCreated() {
  39. this.isPageReady = new ReactiveVar(false);
  40. this.autorun(() => {
  41. const handle = subManager.subscribe(
  42. 'dueCards',
  43. Utils.dueCardsView() === 'all',
  44. );
  45. Tracker.nonreactive(() => {
  46. Tracker.autorun(() => {
  47. this.isPageReady.set(handle.ready());
  48. });
  49. });
  50. });
  51. Meteor.subscribe('setting');
  52. },
  53. dueCardsView() {
  54. // eslint-disable-next-line no-console
  55. console.log('sort:', Utils.dueCardsView());
  56. return Utils.dueCardsView();
  57. },
  58. sortByBoard() {
  59. return this.dueCardsView() === 'board';
  60. },
  61. dueCardsList() {
  62. const allUsers = Utils.dueCardsView() === 'all';
  63. const user = Meteor.user();
  64. const archivedBoards = [];
  65. Boards.find({ archived: true }).forEach(board => {
  66. archivedBoards.push(board._id);
  67. });
  68. const permiitedBoards = [];
  69. let selector = {
  70. archived: false,
  71. };
  72. // for every user including admin allow her to see cards only from public boards
  73. // or those where she is a member
  74. //if (!user.isAdmin) {
  75. selector.$or = [
  76. { permission: 'public' },
  77. { members: { $elemMatch: { userId: user._id, isActive: true } } },
  78. ];
  79. //}
  80. Boards.find(selector).forEach(board => {
  81. permiitedBoards.push(board._id);
  82. });
  83. const archivedSwimlanes = [];
  84. Swimlanes.find({ archived: true }).forEach(swimlane => {
  85. archivedSwimlanes.push(swimlane._id);
  86. });
  87. const archivedLists = [];
  88. Lists.find({ archived: true }).forEach(list => {
  89. archivedLists.push(list._id);
  90. });
  91. selector = {
  92. archived: false,
  93. boardId: {
  94. $nin: archivedBoards,
  95. $in: permiitedBoards,
  96. },
  97. swimlaneId: { $nin: archivedSwimlanes },
  98. listId: { $nin: archivedLists },
  99. dueAt: { $ne: null },
  100. endAt: null,
  101. };
  102. if (!allUsers) {
  103. selector.$or = [{ members: user._id }, { assignees: user._id }];
  104. }
  105. const cards = [];
  106. // eslint-disable-next-line no-console
  107. // console.log('cards selector:', selector);
  108. Cards.find(selector).forEach(card => {
  109. cards.push(card);
  110. // eslint-disable-next-line no-console
  111. // console.log(
  112. // 'board:',
  113. // card.board(),
  114. // 'swimlane:',
  115. // card.swimlane(),
  116. // 'list:',
  117. // card.list(),
  118. // );
  119. });
  120. cards.sort((a, b) => {
  121. const x = a.dueAt === null ? Date('2100-12-31') : a.dueAt;
  122. const y = b.dueAt === null ? Date('2100-12-31') : b.dueAt;
  123. if (x > y) return 1;
  124. else if (x < y) return -1;
  125. return 0;
  126. });
  127. // eslint-disable-next-line no-console
  128. // console.log('cards:', cards);
  129. return cards;
  130. },
  131. }).register('dueCards');