2021-03-01 01:49:56 +02:00
|
|
|
import { CardSearchPagedComponent } from '../../lib/cardSearch';
|
|
|
|
|
2021-03-07 02:12:31 +02:00
|
|
|
// const subManager = new SubsManager();
|
2021-01-10 18:08:03 +02:00
|
|
|
|
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 [
|
|
|
|
{
|
2021-01-09 18:36:27 +02:00
|
|
|
'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 [
|
|
|
|
{
|
2021-01-09 18:36:27 +02:00
|
|
|
'click .js-due-cards-view-me'() {
|
|
|
|
Utils.setDueCardsView('me');
|
2021-01-07 22:36:10 +02:00
|
|
|
Popup.close();
|
|
|
|
},
|
|
|
|
|
2021-01-09 18:36:27 +02:00
|
|
|
'click .js-due-cards-view-all'() {
|
|
|
|
Utils.setDueCardsView('all');
|
2021-01-07 22:36:10 +02:00
|
|
|
Popup.close();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
|
|
|
}).register('dueCardsViewChangePopup');
|
|
|
|
|
2021-03-01 01:49:56 +02:00
|
|
|
class DueCardsComponent extends CardSearchPagedComponent {
|
2021-01-07 22:36:10 +02:00
|
|
|
onCreated() {
|
2021-03-01 01:49:56 +02:00
|
|
|
super.onCreated();
|
|
|
|
|
|
|
|
const queryParams = {
|
|
|
|
has: [{ field: 'dueAt', exists: true }],
|
|
|
|
limit: 5,
|
|
|
|
skip: 0,
|
|
|
|
sort: { name: 'dueAt', order: 'des' },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Utils.dueCardsView() !== 'all') {
|
|
|
|
queryParams.users = [Meteor.user().username];
|
|
|
|
}
|
|
|
|
|
2021-03-05 21:20:55 +02:00
|
|
|
this.runGlobalSearch(queryParams);
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-07 22:36:10 +02:00
|
|
|
|
|
|
|
dueCardsView() {
|
|
|
|
// eslint-disable-next-line no-console
|
2021-02-02 18:31:13 +02:00
|
|
|
//console.log('sort:', Utils.dueCardsView());
|
2021-01-07 22:36:10 +02:00
|
|
|
return Utils.dueCardsView();
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-07 22:36:10 +02:00
|
|
|
|
|
|
|
sortByBoard() {
|
|
|
|
return this.dueCardsView() === 'board';
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-07 22:36:10 +02:00
|
|
|
|
|
|
|
dueCardsList() {
|
2021-03-01 01:49:56 +02:00
|
|
|
const results = this.getResults();
|
|
|
|
console.log('results:', results);
|
2021-01-07 22:36:10 +02:00
|
|
|
const cards = [];
|
2021-03-01 01:49:56 +02:00
|
|
|
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
|
2021-03-01 01:49:56 +02:00
|
|
|
console.log('cards:', cards);
|
2021-01-07 22:36:10 +02:00
|
|
|
return cards;
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DueCardsComponent.register('dueCards');
|