dueCards.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { CardSearchPagedComponent } from '../../lib/cardSearch';
  3. import {
  4. OPERATOR_HAS,
  5. OPERATOR_SORT,
  6. OPERATOR_USER,
  7. ORDER_ASCENDING,
  8. PREDICATE_DUE_AT,
  9. } from '../../../config/search-const';
  10. import { QueryParams } from '../../../config/query-classes';
  11. // const subManager = new SubsManager();
  12. BlazeComponent.extendComponent({
  13. dueCardsView() {
  14. // eslint-disable-next-line no-console
  15. // console.log('sort:', Utils.dueCardsView());
  16. return Utils && Utils.dueCardsView ? Utils.dueCardsView() : 'me';
  17. },
  18. events() {
  19. return [
  20. {
  21. 'click .js-due-cards-view-change': Popup.open('dueCardsViewChange'),
  22. },
  23. ];
  24. },
  25. }).register('dueCardsHeaderBar');
  26. Template.dueCards.helpers({
  27. userId() {
  28. return Meteor.userId();
  29. },
  30. });
  31. BlazeComponent.extendComponent({
  32. events() {
  33. return [
  34. {
  35. 'click .js-due-cards-view-me'() {
  36. if (Utils && Utils.setDueCardsView) {
  37. Utils.setDueCardsView('me');
  38. }
  39. Popup.back();
  40. },
  41. 'click .js-due-cards-view-all'() {
  42. if (Utils && Utils.setDueCardsView) {
  43. Utils.setDueCardsView('all');
  44. }
  45. Popup.back();
  46. },
  47. },
  48. ];
  49. },
  50. }).register('dueCardsViewChangePopup');
  51. class DueCardsComponent extends CardSearchPagedComponent {
  52. onCreated() {
  53. super.onCreated();
  54. // Add a small delay to ensure ReactiveCache is ready
  55. this.searchRetryCount = 0;
  56. this.maxRetries = 3;
  57. // Use a timeout to ensure the search runs after the component is fully initialized
  58. Meteor.setTimeout(() => {
  59. this.performSearch();
  60. }, 100);
  61. }
  62. performSearch() {
  63. if (process.env.DEBUG === 'true') {
  64. console.log('Performing due cards search, attempt:', this.searchRetryCount + 1);
  65. }
  66. // Check if user is authenticated
  67. const currentUser = ReactiveCache.getCurrentUser();
  68. if (!currentUser) {
  69. if (process.env.DEBUG === 'true') {
  70. console.log('User not authenticated, waiting...');
  71. }
  72. Meteor.setTimeout(() => {
  73. this.performSearch();
  74. }, 1000);
  75. return;
  76. }
  77. if (process.env.DEBUG === 'true') {
  78. console.log('User authenticated:', currentUser.username);
  79. }
  80. const queryParams = new QueryParams();
  81. queryParams.addPredicate(OPERATOR_HAS, {
  82. field: PREDICATE_DUE_AT,
  83. exists: true,
  84. });
  85. // queryParams[OPERATOR_LIMIT] = 5;
  86. queryParams.addPredicate(OPERATOR_SORT, {
  87. name: PREDICATE_DUE_AT,
  88. order: ORDER_ASCENDING,
  89. });
  90. // Note: User filtering is handled server-side based on board membership
  91. // The OPERATOR_USER filter is too restrictive as it only shows cards where
  92. // the user is assigned or a member of the card, not the board
  93. // if (Utils && Utils.dueCardsView && Utils.dueCardsView() !== 'all') {
  94. // const currentUser = ReactiveCache.getCurrentUser();
  95. // if (currentUser && currentUser.username) {
  96. // queryParams.addPredicate(OPERATOR_USER, currentUser.username);
  97. // }
  98. // }
  99. // Debug: Log the query parameters
  100. if (process.env.DEBUG === 'true') {
  101. console.log('Due cards query params:', queryParams.params);
  102. console.log('Due cards query text:', queryParams.text);
  103. console.log('Due cards has predicates:', queryParams.getPredicates('has'));
  104. console.log('Due cards sort predicates:', queryParams.getPredicates('sort'));
  105. }
  106. this.runGlobalSearch(queryParams);
  107. }
  108. dueCardsView() {
  109. // eslint-disable-next-line no-console
  110. //console.log('sort:', Utils.dueCardsView());
  111. return Utils && Utils.dueCardsView ? Utils.dueCardsView() : 'me';
  112. }
  113. sortByBoard() {
  114. return this.dueCardsView() === 'board';
  115. }
  116. dueCardsList() {
  117. const results = this.getResults();
  118. console.log('results:', results);
  119. const cards = [];
  120. if (results) {
  121. results.forEach(card => {
  122. cards.push(card);
  123. });
  124. }
  125. cards.sort((a, b) => {
  126. const x = a.dueAt === null ? new Date('2100-12-31') : a.dueAt;
  127. const y = b.dueAt === null ? new Date('2100-12-31') : b.dueAt;
  128. if (x > y) return 1;
  129. else if (x < y) return -1;
  130. return 0;
  131. });
  132. // eslint-disable-next-line no-console
  133. console.log('cards:', cards);
  134. return cards;
  135. }
  136. }
  137. DueCardsComponent.register('dueCards');