dueCards.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.dueCardsView();
  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. Utils.setDueCardsView('me');
  37. Popup.back();
  38. },
  39. 'click .js-due-cards-view-all'() {
  40. Utils.setDueCardsView('all');
  41. Popup.back();
  42. },
  43. },
  44. ];
  45. },
  46. }).register('dueCardsViewChangePopup');
  47. class DueCardsComponent extends CardSearchPagedComponent {
  48. onCreated() {
  49. super.onCreated();
  50. const queryParams = new QueryParams();
  51. queryParams.addPredicate(OPERATOR_HAS, {
  52. field: PREDICATE_DUE_AT,
  53. exists: true,
  54. });
  55. // queryParams[OPERATOR_LIMIT] = 5;
  56. queryParams.addPredicate(OPERATOR_SORT, {
  57. name: PREDICATE_DUE_AT,
  58. order: ORDER_ASCENDING,
  59. });
  60. if (Utils.dueCardsView() !== 'all') {
  61. queryParams.addPredicate(OPERATOR_USER, ReactiveCache.getCurrentUser().username);
  62. }
  63. this.runGlobalSearch(queryParams);
  64. }
  65. dueCardsView() {
  66. // eslint-disable-next-line no-console
  67. //console.log('sort:', Utils.dueCardsView());
  68. return Utils.dueCardsView();
  69. }
  70. sortByBoard() {
  71. return this.dueCardsView() === 'board';
  72. }
  73. dueCardsList() {
  74. const results = this.getResults();
  75. console.log('results:', results);
  76. const cards = [];
  77. if (results) {
  78. results.forEach(card => {
  79. cards.push(card);
  80. });
  81. }
  82. cards.sort((a, b) => {
  83. const x = a.dueAt === null ? new Date('2100-12-31') : a.dueAt;
  84. const y = b.dueAt === null ? new Date('2100-12-31') : b.dueAt;
  85. if (x > y) return 1;
  86. else if (x < y) return -1;
  87. return 0;
  88. });
  89. // eslint-disable-next-line no-console
  90. console.log('cards:', cards);
  91. return cards;
  92. }
  93. }
  94. DueCardsComponent.register('dueCards');