dueCards.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { CardSearchPagedComponent } from '../../lib/cardSearch';
  2. import {
  3. OPERATOR_HAS,
  4. OPERATOR_SORT,
  5. OPERATOR_USER,
  6. ORDER_DESCENDING,
  7. PREDICATE_DUE_AT,
  8. } from '../../../config/search-const';
  9. import { QueryParams } from '../../../config/query-classes';
  10. // const subManager = new SubsManager();
  11. BlazeComponent.extendComponent({
  12. dueCardsView() {
  13. // eslint-disable-next-line no-console
  14. // console.log('sort:', Utils.dueCardsView());
  15. return Utils.dueCardsView();
  16. },
  17. events() {
  18. return [
  19. {
  20. 'click .js-due-cards-view-change': Popup.open('dueCardsViewChange'),
  21. },
  22. ];
  23. },
  24. }).register('dueCardsHeaderBar');
  25. Template.dueCards.helpers({
  26. userId() {
  27. return Meteor.userId();
  28. },
  29. });
  30. BlazeComponent.extendComponent({
  31. events() {
  32. return [
  33. {
  34. 'click .js-due-cards-view-me'() {
  35. Utils.setDueCardsView('me');
  36. Popup.close();
  37. },
  38. 'click .js-due-cards-view-all'() {
  39. Utils.setDueCardsView('all');
  40. Popup.close();
  41. },
  42. },
  43. ];
  44. },
  45. }).register('dueCardsViewChangePopup');
  46. class DueCardsComponent extends CardSearchPagedComponent {
  47. onCreated() {
  48. super.onCreated();
  49. const queryParams = new QueryParams();
  50. queryParams.addPredicate(OPERATOR_HAS, {
  51. field: PREDICATE_DUE_AT,
  52. exists: true,
  53. });
  54. // queryParams[OPERATOR_LIMIT] = 5;
  55. queryParams.addPredicate(OPERATOR_SORT, {
  56. name: PREDICATE_DUE_AT,
  57. order: ORDER_DESCENDING,
  58. });
  59. if (Utils.dueCardsView() !== 'all') {
  60. queryParams.addPredicate(OPERATOR_USER, Meteor.user().username);
  61. }
  62. this.runGlobalSearch(queryParams.getQueryParams());
  63. }
  64. dueCardsView() {
  65. // eslint-disable-next-line no-console
  66. //console.log('sort:', Utils.dueCardsView());
  67. return Utils.dueCardsView();
  68. }
  69. sortByBoard() {
  70. return this.dueCardsView() === 'board';
  71. }
  72. dueCardsList() {
  73. const results = this.getResults();
  74. console.log('results:', results);
  75. const cards = [];
  76. if (results) {
  77. results.forEach(card => {
  78. cards.push(card);
  79. });
  80. }
  81. cards.sort((a, b) => {
  82. const x = a.dueAt === null ? new Date('2100-12-31') : a.dueAt;
  83. const y = b.dueAt === null ? new Date('2100-12-31') : b.dueAt;
  84. if (x > y) return 1;
  85. else if (x < y) return -1;
  86. return 0;
  87. });
  88. // eslint-disable-next-line no-console
  89. console.log('cards:', cards);
  90. return cards;
  91. }
  92. }
  93. DueCardsComponent.register('dueCards');