wekan/client/components/main/myCards.js

198 lines
4.7 KiB
JavaScript
Raw Normal View History

import {CardSearchPagedComponent} from "../../lib/cardSearch";
const subManager = new SubsManager();
BlazeComponent.extendComponent({
myCardsSort() {
// eslint-disable-next-line no-console
// console.log('sort:', Utils.myCardsSort());
return Utils.myCardsSort();
2020-12-31 19:14:55 +02:00
},
events() {
return [
{
'click .js-toggle-my-cards-choose-sort': Popup.open(
'myCardsSortChange',
),
},
];
2020-12-31 19:14:55 +02:00
},
}).register('myCardsHeaderBar');
2020-12-31 19:14:55 +02:00
Template.myCards.helpers({
userId() {
return Meteor.userId();
},
});
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 {
2020-12-31 19:14:55 +02:00
onCreated() {
super.onCreated();
const queryParams = {
users: [Meteor.user().username],
sort: { name: 'dueAt', order: 'des' },
};
this.autorunGlobalSearch(queryParams);
2020-12-31 19:14:55 +02:00
Meteor.subscribe('setting');
}
myCardsSort() {
// eslint-disable-next-line no-console
//console.log('sort:', Utils.myCardsSort());
return Utils.myCardsSort();
}
sortByBoard() {
return this.myCardsSort() === 'board';
}
2020-12-31 19:14:55 +02:00
myCardsList() {
2020-12-31 19:14:55 +02:00
const boards = [];
let board = null;
let swimlane = null;
let list = null;
const cursor = this.getResults();
2020-12-31 19:14:55 +02:00
if (cursor) {
let newBoard = false;
let newSwimlane = false;
let newList = false;
2020-12-31 19:14:55 +02:00
cursor.forEach(card => {
2020-12-31 19:14:55 +02:00
// 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;
2020-12-31 19:14:55 +02:00
}
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;
2020-12-31 19:14:55 +02:00
}
if (board === null || card.boardId !== board._id) {
// eslint-disable-next-line no-console
// console.log('new board');
board = card.getBoard();
if (board.archived) {
board = null;
return;
}
// 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);
}
2020-12-31 19:14:55 +02:00
newBoard = false;
newSwimlane = false;
newList = false;
});
// sort the data structure
boards.forEach(board => {
board.mySwimlanes.forEach(swimlane => {
swimlane.myLists.forEach(list => {
list.myCards.sort((a, b) => {
return a.sort - b.sort;
});
});
swimlane.myLists.sort((a, b) => {
return a.sort - b.sort;
});
});
board.mySwimlanes.sort((a, b) => {
return a.sort - b.sort;
});
});
boards.sort((a, b) => {
let x = a.sort;
let y = b.sort;
// show the template board last
if (a.type === 'template-container') {
x = 99999999;
} else if (b.type === 'template-container') {
y = 99999999;
}
return x - y;
});
// eslint-disable-next-line no-console
// console.log('boards:', boards);
return boards;
}
return [];
}
myDueCardsList() {
const cursor = this.getResults();
const cards = [];
cursor.forEach(card => {
cards.push(card);
});
cards.sort((a, b) => {
const x = a.dueAt === null ? Date('2100-12-31') : a.dueAt;
const y = b.dueAt === null ? 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');