Created
November 20, 2013 01:23
-
-
Save SinisterMinister/7555897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('underscore'); | |
Kumo.AppsAppController = Ember.ObjectController.extend({ | |
branches: null, | |
_refreshContainer: null, | |
_active: false, | |
init: function () { | |
var self = this; | |
this._super(); | |
Kumo.PollManager.addPoller('app.branches', 10, function () { | |
self._refreshBranches(); | |
}); | |
}, | |
_refreshBranches: function () { | |
var self = this; | |
ORM.factory('branch').where('repositoryId').isEqual(self.get('repositoryId')).findAll().then(function (branches) { | |
var toAdd = [], toRemove = []; | |
_.each(self.get('branches'), function (branch) { | |
var has = false; | |
for (var i = branches.length - 1; i >= 0; i--) { | |
if (branches[i].get('id') === branch.get('id')) { | |
has = true; | |
break; | |
} | |
} | |
if ( ! has) | |
toRemove.push(branch); | |
}); | |
_.each(branches, function (branch) { | |
var has = false; | |
for (var i = self.get('branches').length - 1; i >= 0; i--) { | |
if (self.get('branches')[i].get('id') === branch.get('id')) { | |
has = true; | |
self.get('branches')[i].reload(); | |
break; | |
} | |
} | |
if ( ! has) | |
toAdd.push(branch); | |
}); | |
self.get('branches').removeObjects(toRemove); | |
self.get('branches').pushObjects(toAdd); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment