Fix the board component data loading

This commit is contained in:
Maxime Quandalle 2015-08-23 01:05:59 +02:00
parent d5eec54c72
commit 2248671b7c
3 changed files with 98 additions and 88 deletions

View file

@ -55,7 +55,7 @@ BlazeComponent.extendComponent({
cardLink: function() {
var card = this.currentData().card();
return Blaze.toHTML(HTML.A({
return card && Blaze.toHTML(HTML.A({
href: card.absoluteUrl(),
'class': 'action-card'
}, card.title));
@ -69,7 +69,7 @@ BlazeComponent.extendComponent({
attachmentLink: function() {
var attachment = this.currentData().attachment();
return Blaze.toHTML(HTML.A({
return attachment && Blaze.toHTML(HTML.A({
href: attachment.url(),
'class': 'js-open-attachment-viewer'
}, attachment.name()));

View file

@ -1,6 +1,13 @@
template(name="board")
if Template.subscriptionsReady
if isBoardReady.get
if currentBoard
+boardBody
else
+message(label="board-no-found")
else
+spinner
template(name="boardBody")
.board-wrapper(class=currentBoard.colorClass)
.board-canvas(
class=currentBoard.sidebarSize
@ -16,10 +23,6 @@ template(name="board")
if currentUser.isBoardMember
+addListForm
+sidebar
else
+message(label="board-no-found")
else
+spinner
template(name="addListForm")
.list.js-list.list-composer.js-list-composer

View file

@ -1,4 +1,4 @@
var boardSubsManager = new SubsManager();
var subManager = new SubsManager();
BlazeComponent.extendComponent({
template: function() {
@ -6,12 +6,19 @@ BlazeComponent.extendComponent({
},
onCreated: function() {
this.draggingActive = new ReactiveVar(false);
this.showOverlay = new ReactiveVar(false);
var self = this;
self.draggingActive = new ReactiveVar(false);
self.showOverlay = new ReactiveVar(false);
self.isBoardReady = new ReactiveVar(false);
// The pattern we use to manually handle data loading is described here:
// https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
// XXX The boardId should be readed from some sort the component "props",
// unfortunatly, Blaze doesn't have this notion.
boardSubsManager.subscribe('board', Session.get('currentBoard'));
self.autorun(function() {
var handle = subManager.subscribe('board', Session.get('currentBoard'));
self.isBoardReady.set(handle.ready());
});
},
openNewListForm: function() {
@ -47,8 +54,25 @@ BlazeComponent.extendComponent({
return currentCard && currentCard.listId === listId;
},
onRendered: function() {
var self = this;
sidebarSize: function() {
var sidebar = this.componentChildren('sidebar')[0];
if (sidebar && sidebar.isOpen())
return 'next-sidebar';
},
events: function() {
return [{
// XXX The board-overlay div should probably be moved to the parent
// component.
'mouseenter .board-overlay': function() {
this.showOverlay.set(false);
}
}];
}
}).register('board');
Template.boardBody.onRendered(function() {
var self = BlazeComponent.getComponentForElement(this.firstNode);
self.scrollLeft();
@ -109,26 +133,9 @@ BlazeComponent.extendComponent({
// creation form by clicking on the corresponding element.
var currentBoard = Boards.findOne(Session.get('currentBoard'));
if (currentBoard.lists().count() === 0) {
this.openNewListForm();
self.openNewListForm();
}
},
sidebarSize: function() {
var sidebar = this.componentChildren('sidebar')[0];
if (sidebar && sidebar.isOpen())
return 'next-sidebar';
},
events: function() {
return [{
// XXX The board-overlay div should probably be moved to the parent
// component.
'mouseenter .board-overlay': function() {
this.showOverlay.set(false);
}
}];
}
}).register('board');
});
BlazeComponent.extendComponent({
template: function() {