wekan/client/components/main/dueCards.js

113 lines
2.5 KiB
JavaScript
Raw Normal View History

import { ReactiveCache } from '/imports/reactiveCache';
import { CardSearchPagedComponent } from '../../lib/cardSearch';
2021-03-11 02:05:46 +02:00
import {
OPERATOR_HAS,
OPERATOR_SORT,
OPERATOR_USER,
2021-04-20 16:23:56 +02:00
ORDER_ASCENDING,
2021-03-11 02:05:46 +02:00
PREDICATE_DUE_AT,
} from '../../../config/search-const';
import { QueryParams } from '../../../config/query-classes';
2021-03-07 02:12:31 +02:00
// const subManager = new SubsManager();
2021-01-07 22:36:10 +02:00
BlazeComponent.extendComponent({
dueCardsView() {
// eslint-disable-next-line no-console
// console.log('sort:', Utils.dueCardsView());
return Utils.dueCardsView();
},
events() {
return [
{
'click .js-due-cards-view-change': Popup.open('dueCardsViewChange'),
2021-01-07 22:36:10 +02:00
},
];
},
}).register('dueCardsHeaderBar');
Template.dueCards.helpers({
userId() {
return Meteor.userId();
},
});
BlazeComponent.extendComponent({
events() {
return [
{
'click .js-due-cards-view-me'() {
Utils.setDueCardsView('me');
Popup.back();
2021-01-07 22:36:10 +02:00
},
'click .js-due-cards-view-all'() {
Utils.setDueCardsView('all');
Popup.back();
2021-01-07 22:36:10 +02:00
},
},
];
},
}).register('dueCardsViewChangePopup');
class DueCardsComponent extends CardSearchPagedComponent {
2021-01-07 22:36:10 +02:00
onCreated() {
super.onCreated();
2021-03-11 02:05:46 +02:00
const queryParams = new QueryParams();
queryParams.addPredicate(OPERATOR_HAS, {
field: PREDICATE_DUE_AT,
exists: true,
});
// queryParams[OPERATOR_LIMIT] = 5;
queryParams.addPredicate(OPERATOR_SORT, {
name: PREDICATE_DUE_AT,
2021-04-20 16:23:56 +02:00
order: ORDER_ASCENDING,
2021-03-11 02:05:46 +02:00
});
if (Utils.dueCardsView() !== 'all') {
queryParams.addPredicate(OPERATOR_USER, ReactiveCache.getCurrentUser().username);
}
2021-04-20 16:23:56 +02:00
this.runGlobalSearch(queryParams);
}
2021-01-07 22:36:10 +02:00
dueCardsView() {
// eslint-disable-next-line no-console
//console.log('sort:', Utils.dueCardsView());
2021-01-07 22:36:10 +02:00
return Utils.dueCardsView();
}
2021-01-07 22:36:10 +02:00
sortByBoard() {
return this.dueCardsView() === 'board';
}
2021-01-07 22:36:10 +02:00
dueCardsList() {
const results = this.getResults();
console.log('results:', results);
2021-01-07 22:36:10 +02:00
const cards = [];
if (results) {
results.forEach(card => {
cards.push(card);
});
}
2021-01-07 22:36:10 +02:00
cards.sort((a, b) => {
2021-03-07 02:12:31 +02:00
const x = a.dueAt === null ? new Date('2100-12-31') : a.dueAt;
const y = b.dueAt === null ? new Date('2100-12-31') : b.dueAt;
2021-01-07 22:36:10 +02:00
if (x > y) return 1;
else if (x < y) return -1;
return 0;
});
// eslint-disable-next-line no-console
console.log('cards:', cards);
2021-01-07 22:36:10 +02:00
return cards;
}
}
DueCardsComponent.register('dueCards');