Skip to content

Commit

Permalink
[BUGFIX]: Implemented reactive joins for sticky publications.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasEckhart committed Oct 15, 2015
1 parent aec867c commit d9a260e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 61 deletions.
28 changes: 15 additions & 13 deletions client/hooks/stickies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ var stickyInsertHooks = {
},
onSuccess: function (formType, result) {
let sticky = Stickies.findOne({_id: result});
let story = UserStories.findOne({_id: sticky.storyId});
if (story && sticky) {
let product = Products.findOne({_id: story.productId});
if (product.advancedMode) {
let sprint = Sprints.findOne({_id: story.sprintId});
Meteor.call('updateBurndown', sprint._id, function (error) {
if (error) {
throwAlert('error', error.reason, error.details);
return;
}
Meteor.call('createActElStickyCreate', sticky.productId, Meteor.user()._id, sticky.title, story.title, sprint.goal, function (error) {
if (sticky) {
let story = UserStories.findOne({_id: sticky.storyId});
if (story) {
let product = Products.findOne({_id: story.productId});
if (product.advancedMode) {
let sprint = Sprints.findOne({_id: story.sprintId});
Meteor.call('updateBurndown', sprint._id, function (error) {
if (error) {
throwAlert('error', error.reason, error.details);
return;
}
throwAlert("success", "Success", "Sticky added.");
Meteor.call('createActElStickyCreate', sticky.productId, Meteor.user()._id, sticky.title, story.title, sprint.goal, function (error) {
if (error) {
throwAlert('error', error.reason, error.details);
return;
}
throwAlert("success", "Success", "Sticky added.");
});
});
});
}
}
}
}
Expand Down
39 changes: 21 additions & 18 deletions client/views/application/includes/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ Template.dialogs.events({
});
},
'click .delete-sticky-confirm': function () {
var product = Products.findOne({_id: this.data.productId}), stickyTitle = this.data.title;
Stickies.remove({_id: this.data._id});
if (product.advancedMode) {
Meteor.call('updateBurndown', product._id, function (err) {
if (err) {
throwAlert("error", "Error!", err);
}
});
Meteor.call('createActElStickyRemoved', product._id, Meteor.user()._id, stickyTitle, function (err) {
if (err) {
throwAlert("error", "Error!", err);
}
});
let story = UserStories.findOne({_id: this.data.storyId});
if (story) {
let product = Products.findOne({_id: story.productId}), stickyTitle = this.data.title;
Stickies.remove({_id: this.data._id});
if (product.advancedMode) {
Meteor.call('updateBurndown', product._id, function (err) {
if (err) {
throwAlert("error", "Error!", err);
}
});
Meteor.call('createActElStickyRemoved', product._id, Meteor.userId(), stickyTitle, function (err) {
if (err) {
throwAlert("error", "Error!", err);
}
});
}
Dialogs.remove(this._id);
throwAlert('success', 'Yeah!', 'Sticky removed.');
}
Dialogs.remove(this._id);
throwAlert('success', 'Yeah!', 'Sticky removed.');
},
'click .delete-user-story-confirm': function () {
var product = Products.findOne({_id: this.data.productId}), storyTitle = this.data.title;
Expand All @@ -72,7 +75,7 @@ Template.dialogs.events({
throwAlert("error", "Error!", err);
}
});
Meteor.call('createActElUserStoryRemoved', product._id, Meteor.user()._id, storyTitle, function (err) {
Meteor.call('createActElUserStoryRemoved', product._id, Meteor.userId(), storyTitle, function (err) {
if (err) {
throwAlert("error", "Error!", err);
}
Expand All @@ -95,15 +98,15 @@ Template.dialogs.events({
throwAlert("error", "Error!", err);
}
});
Meteor.call('createActElSprintRemoved', product._id, Meteor.user()._id, sprintGoal, function (err) {
Meteor.call('createActElSprintRemoved', product._id, Meteor.userId(), sprintGoal, function (err) {
if (err) {
throwAlert("error", "Error!", err);
}
});
Dialogs.remove(this._id);
throwAlert('success', 'Yeah!', 'Sprint removed.');
},
'click .delete-comment-confirm': function() {
'click .delete-comment-confirm': function () {
Comments.remove(this.data._id);
Dialogs.remove(this._id);
throwAlert('success', 'Yeah!', 'Comment removed.');
Expand Down
21 changes: 13 additions & 8 deletions collections/stickies.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ Stickies.attachSchema(new SimpleSchema({
/* Find corresponding product. */
let product = Products.findOne({slug: getRouteSlug()});
/* Get array with user IDs which have an invitation for the current product and accepted the invitation. */
let userIds = Invitations.find({productId: product._id, status: 1}).map((invitation) => invitation.userId);
/* We add the current user's id to the array, because users can assign stickies to themselves. */
userIds.push(Meteor.userId());
/* Return all users as options which accepted an invitation incl. our own user ID. */
return Users.find({_id: {$in: userIds}}).map((user) => ({
label: user.username,
value: user._id
}));
if (product) {
let userIds = Invitations.find({
productId: product._id,
status: 1
}).map((invitation) => invitation.userId);
/* We add the current user's id to the array, because users can assign stickies to themselves. */
userIds.push(Meteor.userId());
/* Return all users as options which accepted an invitation incl. our own user ID. */
return Users.find({_id: {$in: userIds}}).map((user) => ({
label: user.username,
value: user._id
}));
}
}
}
},
Expand Down
10 changes: 2 additions & 8 deletions lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,8 @@ Router.map(function () {
endDate: moment.utc(this.params.endDate).toDate()
});
/* If sprint is available, we want to subscribe to the corresponding stickies. */
if (sprintAvail && this.ready()) {
storyIds = [];
UserStories.find({sprintId: sprintAvail._id}).forEach(function (story) {
storyIds.push(story._id);
});
this.subscribe('stickiesAdvanced', storyIds);
} else this.render('loading');

if (sprintAvail && this.ready()) this.subscribe('stickiesAdvanced', sprintAvail._id);
else this.render('loading');
this.next();
} else this.render('loading');
} else {
Expand Down
67 changes: 53 additions & 14 deletions server/publications/stickies.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
"use strict";

Meteor.publish('stickiesByProductSlug', function (slug) {
let product = Products.findOne({slug: slug});
if (product) {
let storyIds = UserStories.find({productId: product._id}).map((story) => story._id);
return Stickies.find({storyId: {$in: storyIds}});
} else this.ready();
Meteor.publishComposite('stickiesByProductSlug', function (productSlug) {
return {
find: function () {
return Products.find({slug: productSlug});
},
children: [
{
find: function (product) {
return UserStories.find({productId: product._id});
},
children: [
{
find: function (userStory) {
return Stickies.find({storyId: userStory._id});
}
}
]
}
]
}
});

Meteor.publish('stickiesAdvanced', function (storyIds) {
return Stickies.find({storyId: {$in: storyIds}});
Meteor.publishComposite('stickiesAdvanced', function (sprintId) {
return {
find: function () {
return UserStories.find({sprintId: sprintId});
},
children: [
{
find: function (userStory) {
return Stickies.find({storyId: userStory._id});
}
}
]
}
});

Meteor.publish('productStat', function () {
let product = Products.findOne({}, {sort: {lastModified: -1}, limit: 1});
if (product) {
let storyIds = UserStories.find({productId: product._id}).map((story) => story._id);
return Stickies.find({storyId: {$in: storyIds}}, {fields: {productId: 1, status: 1, assigneeId: 1}});
} else this.ready();
Meteor.publishComposite('productStat', function () {
return {
find: function () {
return Products.find({}, {sort: {lastModified: -1}, limit: 1});
},
children: [
{
find: function (product) {
return UserStories.find({productId: product._id})
},
children: [
{
find: function (userStory) {
return Stickies.find({storyId: userStory._id}, {fields: {productId: 1, status: 1, assigneeId: 1}});
}
}
]
}
]
}
});

0 comments on commit d9a260e

Please sign in to comment.