travis-web/app/routes/caches.coffee
Piotr Sarnacki bfb4946df8 Show caches also if there're no caches for push builds
This commit fixes caches view to show caches also if only PR caches
exist. Previous version checked for pushes only.
2015-05-06 11:34:02 +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`