Skip to content

Commit

Permalink
Fix #1885
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmanelli committed Sep 12, 2018
1 parent 6aa7a2a commit 31f7305
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions client/components/lists/listBody.js
Expand Up @@ -319,20 +319,29 @@ BlazeComponent.extendComponent({
},

swimlanes() {
if (!this.selectedBoardId) {
return [];
}
const swimlanes = Swimlanes.find({boardId: this.selectedBoardId.get()});
if (swimlanes.count())
this.selectedSwimlaneId.set(swimlanes.fetch()[0]._id);
return swimlanes;
},

lists() {
if (!this.selectedBoardId) {
return [];
}
const lists = Lists.find({boardId: this.selectedBoardId.get()});
if (lists.count())
this.selectedListId.set(lists.fetch()[0]._id);
return lists;
},

cards() {
if (!this.board) {
return [];
}
const ownCardsIds = this.board.cards().map((card) => { return card.linkedId || card._id; });
return Cards.find({
boardId: this.selectedBoardId.get(),
Expand Down Expand Up @@ -360,14 +369,19 @@ BlazeComponent.extendComponent({
// LINK CARD
evt.stopPropagation();
evt.preventDefault();
const linkedId = $('.js-select-cards option:selected').val();
if (!linkedId) {
Popup.close();
return;
}
const _id = Cards.insert({
title: $('.js-select-cards option:selected').text(), //dummy
listId: this.listId,
swimlaneId: this.swimlaneId,
boardId: this.boardId,
sort: Lists.findOne(this.listId).cards().count(),
type: 'cardType-linkedCard',
linkedId: $('.js-select-cards option:selected').val(),
linkedId,
});
Filter.addException(_id);
Popup.close();
Expand All @@ -377,6 +391,10 @@ BlazeComponent.extendComponent({
evt.stopPropagation();
evt.preventDefault();
const impBoardId = $('.js-select-boards option:selected').val();
if (!impBoardId || Cards.findOne({linkedId: impBoardId, archived: false})) {
Popup.close();
return;
}
const _id = Cards.insert({
title: $('.js-select-boards option:selected').text(), //dummy
listId: this.listId,
Expand All @@ -400,19 +418,24 @@ BlazeComponent.extendComponent({

onCreated() {
// Prefetch first non-current board id
const boardId = Boards.findOne({
let board = Boards.findOne({
archived: false,
'members.userId': Meteor.userId(),
_id: {$ne: Session.get('currentBoard')},
})._id;
});
if (!board) {
Popup.close();
return;
}
const boardId = board._id;
// Subscribe to this board
subManager.subscribe('board', boardId);
this.selectedBoardId = new ReactiveVar(boardId);

this.boardId = Session.get('currentBoard');
// In order to get current board info
subManager.subscribe('board', this.boardId);
const board = Boards.findOne(this.boardId);
board = Boards.findOne(this.boardId);
// List where to insert card
const list = $(Popup._getTopStack().openerElement).closest('.js-list');
this.listId = Blaze.getData(list[0])._id;
Expand All @@ -438,6 +461,9 @@ BlazeComponent.extendComponent({
},

results() {
if (!this.selectedBoardId) {
return [];
}
const board = Boards.findOne(this.selectedBoardId.get());
return board.searchCards(this.term.get(), false);
},
Expand Down

0 comments on commit 31f7305

Please sign in to comment.