mirror of
https://github.com/wekan/wekan.git
synced 2025-04-23 05:27:14 -04:00
My Cards page development
* rename `findCards()` to `myBoards()` * return model objects for Boards, Swimlanes, Lists, and Cards. Previously created a data structure with limited properties. * Sort the myBoards data structure according to the `sort` property * add a `swimlane()` method in the cards model
This commit is contained in:
parent
0497d38c1d
commit
5e68362352
4 changed files with 67 additions and 56 deletions
|
@ -11,20 +11,23 @@ template(name="myCardsModalTitle")
|
|||
|
||||
template(name="myCards")
|
||||
.wrapper
|
||||
each board in cardsFind
|
||||
each board in myBoards
|
||||
.my-cards-board-wrapper
|
||||
.board-title
|
||||
+viewer
|
||||
= board.title
|
||||
each swimlane in board.swimlanes
|
||||
| {{#if board.archived}} ({{_ 'archived' }}){{/if}}
|
||||
each swimlane in board.mySwimlanes
|
||||
.swimlane-title(class=swimlane.colorClass)
|
||||
+viewer
|
||||
= swimlane.title
|
||||
each list in swimlane.lists
|
||||
| {{#if swimlane.archived}} ({{_ 'archived' }}){{/if}}
|
||||
each list in swimlane.myLists
|
||||
.my-cards-list-wrapper
|
||||
.list-title(class=list.colorClass)
|
||||
+viewer
|
||||
= list.title
|
||||
each card in list.cards
|
||||
| {{#if list.archived}} ({{_ 'archived' }}){{/if}}
|
||||
each card in list.myCards
|
||||
a.minicard-wrapper.card-title(href=card.absoluteUrl)
|
||||
+minicard(card)
|
||||
|
|
|
@ -30,7 +30,7 @@ BlazeComponent.extendComponent({
|
|||
// subManager.subscribe('myCards');
|
||||
},
|
||||
|
||||
cardsFind() {
|
||||
myBoards() {
|
||||
const userId = Meteor.userId();
|
||||
const boards = [];
|
||||
let board = null;
|
||||
|
@ -39,8 +39,8 @@ BlazeComponent.extendComponent({
|
|||
|
||||
const cursor = Cards.find(
|
||||
{
|
||||
archived: false,
|
||||
$or: [{ members: userId }, { assignees: userId }],
|
||||
archived: false,
|
||||
},
|
||||
{
|
||||
sort: {
|
||||
|
@ -51,8 +51,6 @@ BlazeComponent.extendComponent({
|
|||
},
|
||||
},
|
||||
);
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('cursor:', cursor);
|
||||
|
||||
let newBoard = false;
|
||||
let newSwimlane = false;
|
||||
|
@ -61,74 +59,50 @@ BlazeComponent.extendComponent({
|
|||
cursor.forEach(card => {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('card:', card.title);
|
||||
if (list === null || list.id !== card.listId) {
|
||||
if (list === null || card.listId !== list._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new list');
|
||||
let l = Lists.findOne(card.listId);
|
||||
if (!l) {
|
||||
l = {
|
||||
_id: card.listId,
|
||||
title: 'undefined list',
|
||||
colorClass: '',
|
||||
};
|
||||
list = card.list();
|
||||
if (list.archived) {
|
||||
list = null;
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('list:', l);
|
||||
list = {
|
||||
id: l._id,
|
||||
title: l.title,
|
||||
colorClass: l.colorClass(),
|
||||
cards: [card],
|
||||
};
|
||||
list.myCards = [card];
|
||||
newList = true;
|
||||
}
|
||||
if (swimlane === null || card.swimlaneId !== swimlane.id) {
|
||||
if (swimlane === null || card.swimlaneId !== swimlane._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new swimlane');
|
||||
let s = Swimlanes.findOne(card.swimlaneId);
|
||||
if (!s) {
|
||||
s = {
|
||||
_id: card.swimlaneId,
|
||||
colorClass: '',
|
||||
title: 'undefined swimlane',
|
||||
};
|
||||
swimlane = card.swimlane();
|
||||
if (swimlane.archived) {
|
||||
swimlane = null;
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('swimlane:', s);
|
||||
swimlane = {
|
||||
id: s._id,
|
||||
colorClass: s.colorClass()
|
||||
? s.colorClass()
|
||||
: 'swimlane-default-color',
|
||||
title: s.title,
|
||||
lists: [list],
|
||||
};
|
||||
swimlane.myLists = [list];
|
||||
newSwimlane = true;
|
||||
}
|
||||
if (board === null || card.boardId !== board.id) {
|
||||
if (board === null || card.boardId !== board._id) {
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('new board');
|
||||
const b = Boards.findOne(card.boardId);
|
||||
board = card.board();
|
||||
if (board.archived) {
|
||||
board = null;
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
// console.log('board:', b, b._id, b.title);
|
||||
board = {
|
||||
id: b._id,
|
||||
colorClass: b.colorClass(),
|
||||
title: b.title,
|
||||
slug: b.slug,
|
||||
swimlanes: [swimlane],
|
||||
};
|
||||
board.mySwimlanes = [swimlane];
|
||||
newBoard = true;
|
||||
}
|
||||
|
||||
if (newBoard) {
|
||||
boards.push(board);
|
||||
} else if (newSwimlane) {
|
||||
board.swimlanes.push(swimlane);
|
||||
board.mySwimlanes.push(swimlane);
|
||||
} else if (newList) {
|
||||
swimlane.lists.push(list);
|
||||
swimlane.myLists.push(list);
|
||||
} else {
|
||||
list.cards.push(card);
|
||||
list.myCards.push(card);
|
||||
}
|
||||
|
||||
newBoard = false;
|
||||
|
@ -136,6 +110,36 @@ BlazeComponent.extendComponent({
|
|||
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;
|
||||
|
|
|
@ -461,6 +461,10 @@ Cards.helpers({
|
|||
return Lists.findOne(this.listId);
|
||||
},
|
||||
|
||||
swimlane() {
|
||||
return Swimlanes.findOne(this.swimlaneId);
|
||||
},
|
||||
|
||||
board() {
|
||||
return Boards.findOne(this.boardId);
|
||||
},
|
||||
|
|
|
@ -56,7 +56,7 @@ Meteor.publish('mySwimlanes', function() {
|
|||
|
||||
return Swimlanes.find(
|
||||
{
|
||||
archived: false,
|
||||
// archived: false,
|
||||
_id: { $in: swimlanes },
|
||||
},
|
||||
{
|
||||
|
@ -88,7 +88,7 @@ Meteor.publish('myLists', function() {
|
|||
|
||||
return Lists.find(
|
||||
{
|
||||
archived: false,
|
||||
// archived: false,
|
||||
_id: { $in: lists },
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue