mirror of
https://github.com/wekan/wekan.git
synced 2025-04-20 12:07:11 -04:00
Bug fix for issue #3698
* Rewrite routine for building the My Cards hierarchical list * Use a separate publication for retrieving My Cards * Fix bug with limit and skip projectsion
This commit is contained in:
parent
769bb7a55d
commit
07a3301414
5 changed files with 104 additions and 176 deletions
|
@ -6,16 +6,6 @@ template(name="myCardsHeaderBar")
|
|||
i.fa.fa-list
|
||||
| {{_ 'my-cards'}}
|
||||
|
||||
.board-header-btns.left
|
||||
a.board-header-btn.js-toggle-my-cards-choose-sort(title="{{_ 'myCardsSortChange-title'}}")
|
||||
i.fa.fa-caret-down
|
||||
if $eq myCardsSort 'board'
|
||||
i.fa.fa-th-large
|
||||
| {{_ 'myCardsSortChange-choice-board'}}
|
||||
if $eq myCardsSort 'dueAt'
|
||||
i.fa.fa-calendar
|
||||
| {{_ 'myCardsSortChange-choice-dueat'}}
|
||||
|
||||
template(name="myCardsModalTitle")
|
||||
if currentUser
|
||||
h2
|
||||
|
@ -28,46 +18,22 @@ template(name="myCards")
|
|||
+spinner
|
||||
else
|
||||
.wrapper
|
||||
if $eq myCardsSort 'board'
|
||||
each board in myCardsList
|
||||
.my-cards-board-wrapper
|
||||
.my-cards-board-title(class=board.colorClass, id="header")
|
||||
a(href=board.originRelativeUrl)
|
||||
+viewer
|
||||
= board.title
|
||||
each swimlane in board.mySwimlanes
|
||||
.my-cards-swimlane-title(class="{{#if swimlane.colorClass}}{{ swimlane.colorClass }}{{else}}swimlane-default-color{{/if}}")
|
||||
+viewer
|
||||
= swimlane.title
|
||||
each list in swimlane.myLists
|
||||
.my-cards-list-wrapper
|
||||
.my-cards-list-title(class=list.colorClass)
|
||||
+viewer
|
||||
= list.title
|
||||
each card in list.myCards
|
||||
.my-cards-card-wrapper
|
||||
a.minicard-wrapper(href=card.originRelativeUrl)
|
||||
+minicard(card)
|
||||
else
|
||||
.my-cards-dueat-list-wrapper
|
||||
each card in myDueCardsList
|
||||
+resultCard(card)
|
||||
|
||||
template(name="myCardsSortChangePopup")
|
||||
if currentUser
|
||||
ul.pop-over-list
|
||||
li
|
||||
with "my-cards-sort-board"
|
||||
a.js-my-cards-sort-board
|
||||
i.fa.fa-th-large.colorful
|
||||
| {{_ 'myCardsSortChange-choice-board'}}
|
||||
if $eq Utils.myCardsSort "board"
|
||||
i.fa.fa-check
|
||||
hr
|
||||
li
|
||||
with "my-cards-sort-dueat"
|
||||
a.js-my-cards-sort-dueat
|
||||
i.fa.fa-calendar.colorful
|
||||
| {{_ 'myCardsSortChange-choice-dueat'}}
|
||||
if $eq Utils.myCardsSort "dueAt"
|
||||
i.fa.fa-check
|
||||
each board in myCardsList
|
||||
.my-cards-board-wrapper
|
||||
.my-cards-board-title(class=board.colorClass, id="header")
|
||||
a(href=board.originRelativeUrl)
|
||||
+viewer
|
||||
= board.title
|
||||
each swimlane in board.mySwimlanes
|
||||
.my-cards-swimlane-title(class="{{#if swimlane.colorClass}}{{ swimlane.colorClass }}{{else}}swimlane-default-color{{/if}}")
|
||||
+viewer
|
||||
= swimlane.title
|
||||
each list in swimlane.myLists
|
||||
.my-cards-list-wrapper
|
||||
.my-cards-list-title(class=list.colorClass)
|
||||
+viewer
|
||||
= list.title
|
||||
each card in list.myCards
|
||||
.my-cards-card-wrapper
|
||||
a.minicard-wrapper(href=card.originRelativeUrl)
|
||||
+minicard(card)
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
import { CardSearchPagedComponent } from '../../lib/cardSearch';
|
||||
import { QueryParams } from '../../../config/query-classes';
|
||||
import {
|
||||
OPERATOR_LIMIT,
|
||||
OPERATOR_SORT,
|
||||
OPERATOR_USER,
|
||||
ORDER_DESCENDING,
|
||||
PREDICATE_DUE_AT,
|
||||
} from '../../../config/search-const';
|
||||
|
||||
// const subManager = new SubsManager();
|
||||
|
||||
BlazeComponent.extendComponent({
|
||||
myCardsSort() {
|
||||
|
@ -34,48 +24,21 @@ Template.myCards.helpers({
|
|||
},
|
||||
});
|
||||
|
||||
BlazeComponent.extendComponent({
|
||||
events() {
|
||||
return [
|
||||
{
|
||||
'click .js-my-cards-sort-board'() {
|
||||
Utils.setMyCardsSort('board');
|
||||
Popup.close();
|
||||
},
|
||||
|
||||
'click .js-my-cards-sort-dueat'() {
|
||||
Utils.setMyCardsSort('dueAt');
|
||||
Popup.close();
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
}).register('myCardsSortChangePopup');
|
||||
|
||||
class MyCardsComponent extends CardSearchPagedComponent {
|
||||
onCreated() {
|
||||
super.onCreated();
|
||||
|
||||
const queryParams = new QueryParams();
|
||||
queryParams.addPredicate(OPERATOR_USER, Meteor.user().username);
|
||||
queryParams.addPredicate(OPERATOR_SORT, {
|
||||
name: PREDICATE_DUE_AT,
|
||||
order: ORDER_DESCENDING,
|
||||
});
|
||||
queryParams.addPredicate(OPERATOR_LIMIT, 100);
|
||||
|
||||
this.runGlobalSearch(queryParams);
|
||||
this.runGlobalSearch(null);
|
||||
Meteor.subscribe('setting');
|
||||
}
|
||||
|
||||
myCardsSort() {
|
||||
// eslint-disable-next-line no-console
|
||||
//console.log('sort:', Utils.myCardsSort());
|
||||
return Utils.myCardsSort();
|
||||
}
|
||||
|
||||
sortByBoard() {
|
||||
return this.myCardsSort() === 'board';
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
getSubscription(queryParams) {
|
||||
return Meteor.subscribe(
|
||||
'myCards',
|
||||
this.sessionId,
|
||||
this.subscriptionCallbacks,
|
||||
);
|
||||
}
|
||||
|
||||
myCardsList() {
|
||||
|
@ -87,35 +50,9 @@ class MyCardsComponent extends CardSearchPagedComponent {
|
|||
const cursor = this.getResults();
|
||||
|
||||
if (cursor) {
|
||||
let newBoard = false;
|
||||
let newSwimlane = false;
|
||||
let newList = false;
|
||||
|
||||
cursor.forEach(card => {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('card:', card.title);
|
||||
if (list === null || card.listId !== list._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new list');
|
||||
list = card.getList();
|
||||
if (list.archived) {
|
||||
list = null;
|
||||
return;
|
||||
}
|
||||
list.myCards = [card];
|
||||
newList = true;
|
||||
}
|
||||
if (swimlane === null || card.swimlaneId !== swimlane._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new swimlane');
|
||||
swimlane = card.getSwimlane();
|
||||
if (swimlane.archived) {
|
||||
swimlane = null;
|
||||
return;
|
||||
}
|
||||
swimlane.myLists = [list];
|
||||
newSwimlane = true;
|
||||
}
|
||||
if (board === null || card.boardId !== board._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new board');
|
||||
|
@ -126,23 +63,38 @@ class MyCardsComponent extends CardSearchPagedComponent {
|
|||
}
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('board:', b, b._id, b.title);
|
||||
board.mySwimlanes = [swimlane];
|
||||
newBoard = true;
|
||||
}
|
||||
|
||||
if (newBoard) {
|
||||
boards.push(board);
|
||||
} else if (newSwimlane) {
|
||||
board.mySwimlanes.push(swimlane);
|
||||
} else if (newList) {
|
||||
swimlane.myLists.push(list);
|
||||
} else {
|
||||
list.myCards.push(card);
|
||||
board.mySwimlanes = [];
|
||||
swimlane = null;
|
||||
list = null;
|
||||
}
|
||||
|
||||
newBoard = false;
|
||||
newSwimlane = false;
|
||||
newList = false;
|
||||
if (swimlane === null || card.swimlaneId !== swimlane._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new swimlane');
|
||||
swimlane = card.getSwimlane();
|
||||
if (swimlane.archived) {
|
||||
swimlane = null;
|
||||
return;
|
||||
}
|
||||
board.mySwimlanes.push(swimlane);
|
||||
swimlane.myLists = [];
|
||||
list = null;
|
||||
}
|
||||
|
||||
if (list === null || card.listId !== list._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new list');
|
||||
list = card.getList();
|
||||
if (list.archived) {
|
||||
list = null;
|
||||
return;
|
||||
}
|
||||
swimlane.myLists.push(list);
|
||||
list.myCards = [];
|
||||
}
|
||||
|
||||
list.myCards.push(card);
|
||||
});
|
||||
|
||||
// sort the data structure
|
||||
|
@ -182,27 +134,5 @@ class MyCardsComponent extends CardSearchPagedComponent {
|
|||
|
||||
return [];
|
||||
}
|
||||
|
||||
myDueCardsList() {
|
||||
const cursor = this.getResults();
|
||||
const cards = [];
|
||||
cursor.forEach(card => {
|
||||
cards.push(card);
|
||||
});
|
||||
|
||||
cards.sort((a, b) => {
|
||||
const x = a.dueAt === null ? new Date('2100-12-31') : a.dueAt;
|
||||
const y = b.dueAt === null ? new Date('2100-12-31') : b.dueAt;
|
||||
|
||||
if (x > y) return 1;
|
||||
else if (x < y) return -1;
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('cursor:', cards);
|
||||
return cards;
|
||||
}
|
||||
}
|
||||
MyCardsComponent.register('myCards');
|
||||
|
|
|
@ -62,7 +62,6 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
// console.log('getting results');
|
||||
const sessionData = this.getSessionData();
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('selector:', sessionData.getSelector());
|
||||
console.log('session data:', sessionData);
|
||||
const cards = [];
|
||||
sessionData.cards.forEach(cardId => {
|
||||
|
@ -99,10 +98,8 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
}
|
||||
}
|
||||
|
||||
runGlobalSearch(queryParams) {
|
||||
this.searching.set(true);
|
||||
this.stopSubscription();
|
||||
this.subscriptionHandle = Meteor.subscribe(
|
||||
getSubscription(queryParams) {
|
||||
return Meteor.subscribe(
|
||||
'globalSearch',
|
||||
this.sessionId,
|
||||
queryParams.params,
|
||||
|
@ -111,6 +108,12 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
);
|
||||
}
|
||||
|
||||
runGlobalSearch(queryParams) {
|
||||
this.searching.set(true);
|
||||
this.stopSubscription();
|
||||
this.subscriptionHandle = this.getSubscription(queryParams);
|
||||
}
|
||||
|
||||
queryErrorMessages() {
|
||||
const messages = [];
|
||||
|
||||
|
|
|
@ -52,7 +52,9 @@ export class QueryParams {
|
|||
|
||||
hasOperator(operator) {
|
||||
return (
|
||||
this.params[operator] !== undefined && this.params[operator].length > 0
|
||||
this.params[operator] !== undefined &&
|
||||
(this.params[operator].length === undefined ||
|
||||
this.params[operator].length > 0)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -68,7 +70,11 @@ export class QueryParams {
|
|||
}
|
||||
|
||||
getPredicate(operator) {
|
||||
return this.params[operator][0];
|
||||
if (typeof this.params[operator] === 'object') {
|
||||
return this.params[operator][0];
|
||||
} else {
|
||||
return this.params[operator];
|
||||
}
|
||||
}
|
||||
|
||||
getPredicates(operator) {
|
||||
|
@ -196,6 +202,10 @@ export class Query {
|
|||
return this.queryParams;
|
||||
}
|
||||
|
||||
setQueryParams(queryParams) {
|
||||
this.queryParams = queryParams;
|
||||
}
|
||||
|
||||
addPredicate(operator, predicate) {
|
||||
this.queryParams.addPredicate(operator, predicate);
|
||||
}
|
||||
|
|
|
@ -53,10 +53,20 @@ Meteor.publish('card', cardId => {
|
|||
});
|
||||
|
||||
Meteor.publish('myCards', function(sessionId) {
|
||||
check(sessionId, String);
|
||||
|
||||
const queryParams = new QueryParams();
|
||||
queryParams.addPredicate(OPERATOR_USER, Meteor.user().username);
|
||||
queryParams.setPredicate(OPERATOR_LIMIT, 200);
|
||||
|
||||
return findCards(sessionId, buildQuery(queryParams));
|
||||
const query = buildQuery(queryParams);
|
||||
query.projection.sort = {
|
||||
boardId: 1,
|
||||
swimlaneId: 1,
|
||||
listId: 1,
|
||||
};
|
||||
|
||||
return findCards(sessionId, query);
|
||||
});
|
||||
|
||||
// Meteor.publish('dueCards', function(sessionId, allUsers = false) {
|
||||
|
@ -449,16 +459,18 @@ function buildSelector(queryParams) {
|
|||
|
||||
const query = new Query();
|
||||
query.selector = selector;
|
||||
query.params = queryParams;
|
||||
query.setQueryParams(queryParams);
|
||||
query._errors = errors;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
function buildProjection(query) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('query:', query);
|
||||
let skip = 0;
|
||||
if (query.params.skip) {
|
||||
skip = query.params.skip;
|
||||
if (query.getQueryParams().skip) {
|
||||
skip = query.getQueryParams().skip;
|
||||
}
|
||||
let limit = DEFAULT_LIMIT;
|
||||
const configLimit = parseInt(process.env.RESULTS_PER_PAGE, 10);
|
||||
|
@ -466,8 +478,8 @@ function buildProjection(query) {
|
|||
limit = configLimit;
|
||||
}
|
||||
|
||||
if (query.params.hasOperator(OPERATOR_LIMIT)) {
|
||||
limit = query.params.getPredicate(OPERATOR_LIMIT);
|
||||
if (query.getQueryParams().hasOperator(OPERATOR_LIMIT)) {
|
||||
limit = query.getQueryParams().getPredicate(OPERATOR_LIMIT);
|
||||
}
|
||||
|
||||
const projection = {
|
||||
|
@ -499,12 +511,13 @@ function buildProjection(query) {
|
|||
limit,
|
||||
};
|
||||
|
||||
if (query.params.hasOperator(OPERATOR_SORT)) {
|
||||
if (query.getQueryParams().hasOperator(OPERATOR_SORT)) {
|
||||
const order =
|
||||
query.params.getPredicate(OPERATOR_SORT).order === ORDER_ASCENDING
|
||||
query.getQueryParams().getPredicate(OPERATOR_SORT).order ===
|
||||
ORDER_ASCENDING
|
||||
? 1
|
||||
: -1;
|
||||
switch (query.params.getPredicate(OPERATOR_SORT).name) {
|
||||
switch (query.getQueryParams().getPredicate(OPERATOR_SORT).name) {
|
||||
case PREDICATE_DUE_AT:
|
||||
projection.sort = {
|
||||
dueAt: order,
|
||||
|
@ -633,6 +646,12 @@ function findCards(sessionId, query) {
|
|||
update.$set.resultsCount = update.$set.cards.length;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('sessionId:', sessionId);
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('userId:', userId);
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('update:', update);
|
||||
SessionData.upsert({ userId, sessionId }, update);
|
||||
|
||||
// remove old session data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue