fetch missing milestones on project page

This commit is contained in:
Radek Stepan 2014-10-13 20:13:31 -07:00
parent 956e8cc846
commit 3101287e87

View File

@ -28,27 +28,34 @@ module.exports = Ractive.extend
# Should not happen... # Should not happen...
throw 500 unless project throw 500 unless project
# Does it have milestones already? # We don't know if we have all milestones, so fetch them.
return @set('ready', yes) if project.milestones
# We are loading the milestones then.
done = do system.async done = do system.async
findMilestone = (number) ->
_.find project.milestones or [], { number }
fetchMilestones = (cb) -> fetchMilestones = (cb) ->
milestones.fetchAll project, cb milestones.fetchAll project, cb
fetchIssues = (allMilestones, cb) -> fetchIssues = (allMilestones, cb) ->
async.map allMilestones, (milestone, cb) -> async.each allMilestones, (milestone, cb) ->
# Maybe we have this milestone already?
return cb null if findMilestone milestone.number
# Need to fetch the issues then.
issues.fetchAll { owner, name, 'milestone': milestone.number }, (err, obj) -> issues.fetchAll { owner, name, 'milestone': milestone.number }, (err, obj) ->
cb err, _.extend milestone, { 'issues': obj } return cb err if err
# Save the milestone with issues.
project.push 'milestones', _.extend milestone, { 'issues': obj }
cb null
, cb , cb
# Run it.
async.waterfall [ async.waterfall [
# First get all the milestones. # First get all the milestones.
fetchMilestones, fetchMilestones,
# Then all the issues per milestone. # Then all the issues per milestone.
fetchIssues fetchIssues
], (err, data) => ], (err) =>
do done do done
return mediator.fire '!app/notify', { return mediator.fire '!app/notify', {
'text': do err.toString 'text': do err.toString
@ -57,7 +64,5 @@ module.exports = Ractive.extend
'ttl': null 'ttl': null
} if err } if err
# Save the milestones. # Say we are ready.
@set @set 'ready', yes
'project.milestones': data
'ready': yes