Update Global Search, Due Cards, and My Cards to use the same

code for searching and display
This commit is contained in:
John R. Supplee 2021-03-01 01:49:56 +02:00
parent 8181074238
commit a1bda1169e
7 changed files with 266 additions and 637 deletions

View file

@ -1,3 +1,5 @@
import { CardSearchPagedComponent } from '../../lib/cardSearch';
const subManager = new SubsManager();
BlazeComponent.extendComponent({
@ -40,102 +42,43 @@ BlazeComponent.extendComponent({
},
}).register('dueCardsViewChangePopup');
BlazeComponent.extendComponent({
class DueCardsComponent extends CardSearchPagedComponent {
onCreated() {
this.isPageReady = new ReactiveVar(false);
super.onCreated();
this.autorun(() => {
const handle = subManager.subscribe(
'dueCards',
Utils.dueCardsView() === 'all',
);
Tracker.nonreactive(() => {
Tracker.autorun(() => {
this.isPageReady.set(handle.ready());
});
});
});
Meteor.subscribe('setting');
},
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];
}
this.autorunGlobalSearch(queryParams);
}
dueCardsView() {
// eslint-disable-next-line no-console
//console.log('sort:', Utils.dueCardsView());
return Utils.dueCardsView();
},
}
sortByBoard() {
return this.dueCardsView() === 'board';
},
}
dueCardsList() {
const allUsers = Utils.dueCardsView() === 'all';
const user = Meteor.user();
const archivedBoards = [];
Boards.find({ archived: true }).forEach(board => {
archivedBoards.push(board._id);
});
const permiitedBoards = [];
let selector = {
archived: false,
};
// for every user including admin allow her to see cards only from public boards
// or those where she is a member
//if (!user.isAdmin) {
selector.$or = [
{ permission: 'public' },
{ members: { $elemMatch: { userId: user._id, isActive: true } } },
];
//}
Boards.find(selector).forEach(board => {
permiitedBoards.push(board._id);
});
const archivedSwimlanes = [];
Swimlanes.find({ archived: true }).forEach(swimlane => {
archivedSwimlanes.push(swimlane._id);
});
const archivedLists = [];
Lists.find({ archived: true }).forEach(list => {
archivedLists.push(list._id);
});
selector = {
archived: false,
boardId: {
$nin: archivedBoards,
$in: permiitedBoards,
},
swimlaneId: { $nin: archivedSwimlanes },
listId: { $nin: archivedLists },
dueAt: { $ne: null },
endAt: null,
};
if (!allUsers) {
selector.$or = [{ members: user._id }, { assignees: user._id }];
}
const results = this.getResults();
console.log('results:', results);
const cards = [];
// eslint-disable-next-line no-console
// console.log('cards selector:', selector);
Cards.find(selector).forEach(card => {
cards.push(card);
// eslint-disable-next-line no-console
// console.log(
// 'board:',
// card.board(),
// 'swimlane:',
// card.swimlane(),
// 'list:',
// card.list(),
// );
});
if (results) {
results.forEach(card => {
cards.push(card);
});
}
cards.sort((a, b) => {
const x = a.dueAt === null ? Date('2100-12-31') : a.dueAt;
@ -148,7 +91,9 @@ BlazeComponent.extendComponent({
});
// eslint-disable-next-line no-console
// console.log('cards:', cards);
console.log('cards:', cards);
return cards;
},
}).register('dueCards');
}
}
DueCardsComponent.register('dueCards');