travis-web/app/routes/caches.coffee
2015-04-17 13:39:36 +02:00

47 lines
1.1 KiB
CoffeeScript

`import Ember from 'ember'`
`import TravisRoute from 'travis/routes/basic'`
`import Ajax from 'travis/utils/ajax'`
Route = TravisRoute.extend
needsAuth: true
setupController: (controller) ->
@_super.apply this, arguments
@controllerFor('repo').activate('caches')
model: ->
repo = @modelFor('repo')
Ajax.get("/repos/#{repo.get('id')}/caches").then( (data) ->
caches = {}
data["caches"].forEach (cacheData) ->
branch = cacheData.branch
cache = caches[branch]
if cache
cache.size += cacheData.size
if cache.last_modified < cacheData.last_modified
cache.last_modified = cacheData.last_modified
else
caches[branch] = cacheData
pushes = []
pullRequests = []
for branch, cache of caches
if /PR./.test(branch)
cache.type = "pull_request"
pullRequests.push cache
else
cache.type = "push"
pushes.push cache
{
pushes: pushes,
pullRequests: pullRequests
}
)
`export default Route`