2023-01-16 23:00:10 +01:00
|
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
2025-10-21 15:08:50 +03:00
|
|
|
import { BlazeComponent } from 'meteor/peerlibrary:blaze-components';
|
2021-03-01 01:49:56 +02:00
|
|
|
|
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());
|
2025-10-19 20:05:36 +03:00
|
|
|
return Utils && Utils.dueCardsView ? Utils.dueCardsView() : 'me';
|
2021-01-07 22:36:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
},
|
2025-10-21 14:57:57 +03:00
|
|
|
dueCardsList() {
|
|
|
|
|
const component = BlazeComponent.getComponentForElement(this);
|
|
|
|
|
if (component && component.dueCardsList) {
|
|
|
|
|
return component.dueCardsList();
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
},
|
2025-10-21 15:08:50 +03:00
|
|
|
hasResults() {
|
|
|
|
|
const component = BlazeComponent.getComponentForElement(this);
|
|
|
|
|
if (component && component.dueCardsList) {
|
|
|
|
|
const cards = component.dueCardsList();
|
|
|
|
|
return cards && cards.length > 0;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
searching() {
|
|
|
|
|
return false; // No longer using search, so always false
|
|
|
|
|
},
|
|
|
|
|
hasQueryErrors() {
|
|
|
|
|
return false; // No longer using search, so always false
|
|
|
|
|
},
|
|
|
|
|
errorMessages() {
|
|
|
|
|
return []; // No longer using search, so always empty
|
|
|
|
|
},
|
2021-01-07 22:36:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
BlazeComponent.extendComponent({
|
|
|
|
|
events() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
2021-01-09 18:36:27 +02:00
|
|
|
'click .js-due-cards-view-me'() {
|
2025-10-19 20:05:36 +03:00
|
|
|
if (Utils && Utils.setDueCardsView) {
|
|
|
|
|
Utils.setDueCardsView('me');
|
|
|
|
|
}
|
2021-10-21 10:35:16 +02:00
|
|
|
Popup.back();
|
2021-01-07 22:36:10 +02:00
|
|
|
},
|
|
|
|
|
|
2021-01-09 18:36:27 +02:00
|
|
|
'click .js-due-cards-view-all'() {
|
2025-10-19 20:05:36 +03:00
|
|
|
if (Utils && Utils.setDueCardsView) {
|
|
|
|
|
Utils.setDueCardsView('all');
|
|
|
|
|
}
|
2021-10-21 10:35:16 +02:00
|
|
|
Popup.back();
|
2021-01-07 22:36:10 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
}).register('dueCardsViewChangePopup');
|
|
|
|
|
|
2025-10-21 15:08:50 +03:00
|
|
|
class DueCardsComponent extends BlazeComponent {
|
2021-01-07 22:36:10 +02:00
|
|
|
onCreated() {
|
2021-03-01 01:49:56 +02:00
|
|
|
super.onCreated();
|
2025-10-19 20:05:36 +03:00
|
|
|
|
2025-10-21 15:08:50 +03:00
|
|
|
this._cachedCards = null;
|
|
|
|
|
this._cachedTimestamp = null;
|
|
|
|
|
this.subscriptionHandle = null;
|
2025-10-19 20:05:36 +03:00
|
|
|
|
2025-10-21 15:08:50 +03:00
|
|
|
// Subscribe to the optimized due cards publication
|
|
|
|
|
this.autorun(() => {
|
|
|
|
|
const allUsers = this.dueCardsView() === 'all';
|
|
|
|
|
if (this.subscriptionHandle) {
|
|
|
|
|
this.subscriptionHandle.stop();
|
2025-10-19 20:05:36 +03:00
|
|
|
}
|
2025-10-21 15:08:50 +03:00
|
|
|
this.subscriptionHandle = Meteor.subscribe('dueCards', allUsers);
|
2021-03-11 02:05:46 +02:00
|
|
|
});
|
2025-10-21 15:08:50 +03:00
|
|
|
}
|
2021-03-01 01:49:56 +02:00
|
|
|
|
2025-10-21 15:08:50 +03:00
|
|
|
onDestroyed() {
|
|
|
|
|
super.onDestroyed();
|
|
|
|
|
if (this.subscriptionHandle) {
|
|
|
|
|
this.subscriptionHandle.stop();
|
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());
|
2025-10-19 20:05:36 +03:00
|
|
|
return Utils && Utils.dueCardsView ? Utils.dueCardsView() : 'me';
|
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() {
|
2025-10-21 15:08:50 +03:00
|
|
|
// Use cached results if available to avoid expensive re-sorting
|
|
|
|
|
if (this._cachedCards && this._cachedTimestamp && (Date.now() - this._cachedTimestamp < 5000)) {
|
|
|
|
|
return this._cachedCards;
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-07 22:36:10 +02:00
|
|
|
|
2025-10-21 15:08:50 +03:00
|
|
|
// Get cards directly from the subscription (already sorted by the publication)
|
|
|
|
|
const cards = ReactiveCache.getCards({
|
|
|
|
|
type: 'cardType-card',
|
|
|
|
|
archived: false,
|
|
|
|
|
dueAt: { $exists: true, $nin: [null, ''] }
|
2021-01-07 22:36:10 +02:00
|
|
|
});
|
|
|
|
|
|
2025-10-21 15:08:50 +03:00
|
|
|
// Filter cards based on user view preference
|
|
|
|
|
const allUsers = this.dueCardsView() === 'all';
|
|
|
|
|
const currentUser = ReactiveCache.getCurrentUser();
|
|
|
|
|
let filteredCards = cards;
|
|
|
|
|
|
|
|
|
|
if (!allUsers && currentUser) {
|
|
|
|
|
filteredCards = cards.filter(card => {
|
|
|
|
|
return card.members && card.members.includes(currentUser._id) ||
|
|
|
|
|
card.assignees && card.assignees.includes(currentUser._id) ||
|
|
|
|
|
card.userId === currentUser._id;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cache the results for 5 seconds to avoid re-filtering on every render
|
|
|
|
|
this._cachedCards = filteredCards;
|
|
|
|
|
this._cachedTimestamp = Date.now();
|
|
|
|
|
|
|
|
|
|
return filteredCards;
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DueCardsComponent.register('dueCards');
|