My Cards: fix bug when null board, swimlane, or list

* Add new functions to model card for retrieving associated board,
swimlane, or list with default values
* Use new card model methods
This commit is contained in:
John R. Supplee 2021-01-08 21:51:28 +02:00
parent b79ee281ec
commit 0e1c510948
6 changed files with 54 additions and 33 deletions

View file

@ -30,21 +30,21 @@ template(name="dueCards")
ul.due-cards-context-list
li.due-cards-context(title="{{_ 'board'}}")
+viewer
= card.board.title
= card.getBoard.title
li.due-cards-context.due-cards-context-separator
= ' '
| {{_ 'context-separator'}}
= ' '
li.due-cards-context(title="{{_ 'swimlane'}}")
+viewer
= card.swimlane.title
= card.getSwimlane.title
li.due-cards-context
= ' '
| {{_ 'context-separator'}}
= ' '
li.due-cards-context(title="{{_ 'list'}}")
+viewer
= card.list.title
= card.getList.title
template(name="dueCardsViewChangePopup")

View file

@ -142,22 +142,4 @@ BlazeComponent.extendComponent({
// console.log('cards:', cards);
return cards;
},
events() {
return [
{
// 'click .js-my-card'(evt) {
// const card = this.currentData().card;
// // eslint-disable-next-line no-console
// console.log('currentData():', this.currentData());
// // eslint-disable-next-line no-console
// console.log('card:', card);
// if (card) {
// Utils.goCardId(card._id);
// }
// evt.preventDefault();
// },
},
];
},
}).register('dueCards');

View file

@ -50,21 +50,21 @@ template(name="myCards")
ul.my-cards-context-list
li.my-cards-context(title="{{_ 'board'}}")
+viewer
= card.board.title
= card.getBoard.title
li.my-cards-context.my-cards-context-separator
= ' '
| {{_ 'context-separator'}}
= ' '
li.my-cards-context(title="{{_ 'swimlane'}}")
+viewer
= card.swimlane.title
= card.getSwimlane.title
li.my-cards-context
= ' '
| {{_ 'context-separator'}}
= ' '
li.my-cards-context(title="{{_ 'list'}}")
+viewer
= card.list.title
= card.getList.title
template(name="myCardsSortChangePopup")

View file

@ -93,7 +93,7 @@ BlazeComponent.extendComponent({
if (list === null || card.listId !== list._id) {
// eslint-disable-next-line no-console
// console.log('new list');
list = card.list();
list = card.getList();
if (list.archived) {
list = null;
return;
@ -104,7 +104,7 @@ BlazeComponent.extendComponent({
if (swimlane === null || card.swimlaneId !== swimlane._id) {
// eslint-disable-next-line no-console
// console.log('new swimlane');
swimlane = card.swimlane();
swimlane = card.getSwimlane();
if (swimlane.archived) {
swimlane = null;
return;
@ -115,7 +115,7 @@ BlazeComponent.extendComponent({
if (board === null || card.boardId !== board._id) {
// eslint-disable-next-line no-console
// console.log('new board');
board = card.board();
board = card.getBoard();
if (board.archived) {
board = null;
return;
@ -201,9 +201,9 @@ BlazeComponent.extendComponent({
const cards = [];
cursor.forEach(card => {
if (
!card.board().archived &&
!card.swimlane().archived &&
!card.list().archived
!card.getBoard().archived &&
!card.getSwimlane().archived &&
!card.getList().archived
) {
cards.push(card);
}

View file

@ -469,6 +469,45 @@ Cards.helpers({
return Boards.findOne(this.boardId);
},
getList() {
const list = this.list();
if (!list) {
return {
_id: this.listId,
title: 'Undefined List',
archived: false,
colorClass: '',
};
}
return list;
},
getSwimlane() {
const swimlane = this.swimlane();
if (!swimlane) {
return {
_id: this.swimlaneId,
title: 'Undefined Swimlane',
archived: false,
colorClass: '',
};
}
return swimlane;
},
getBoard() {
const board = this.board();
if (!board) {
return {
_id: this.boardId,
title: 'Undefined Board',
archived: false,
colorClass: '',
};
}
return board;
},
labels() {
const boardLabels = this.board().labels;
const cardLabels = _.filter(boardLabels, label => {

View file

@ -104,9 +104,9 @@ Meteor.publish('dueCards', function(allUsers = false) {
const lists = [];
cards.forEach(card => {
boards.push(card.boardId);
swimlanes.push(card.swimlaneId);
lists.push(card.listId);
if (card.boardId) boards.push(card.boardId);
if (card.swimlaneId) swimlanes.push(card.swimlaneId);
if (card.listId) lists.push(card.listId);
});
return [