componentify caches

This commit is contained in:
Lisa Passing 2015-04-17 13:06:21 +02:00
parent 64dc75fa2d
commit 23e719ed78
6 changed files with 98 additions and 65 deletions

View File

@ -0,0 +1,27 @@
`import Ember from 'ember'`
`import Ajax from 'travis/utils/ajax'`
CachesItemComponent = Ember.Component.extend
tagName: 'li'
classNames: ['tile', 'tile--xs', 'row']
classNameBindings: ['cache.type']
isDeleting: false
actions:
delete: ->
return if @get('isDeleting')
if confirm('Are you sure?')
@set('isDeleting', true)
data = { branch: @get('cache.branch') }
deletingDone = => @set('isDeleting', false)
repo = @get('repo')
Ajax.ajax("/repos/#{repo.get('id')}/caches", "DELETE", data: data).then(deletingDone, deletingDone).then =>
@get('caches').removeObject(@get('cache'))
`export default CachesItemComponent`

View File

@ -1,10 +1,8 @@
`import Ember from 'ember'`
`import Ajax from 'travis/utils/ajax'`
Controller = Ember.ArrayController.extend
Controller = Ember.Controller.extend
isDeleting: false
needs: ['repo']
repo: Ember.computed.alias('controllers.repo.repo')
actions:
deleteRepoCache: ->
@ -17,6 +15,6 @@ Controller = Ember.ArrayController.extend
repo = @get('repo')
Ajax.ajax("/repos/#{repo.get('id')}/caches", "DELETE").then(deletingDone, deletingDone).then =>
@clear()
@set('model', {})
`export default Controller`

View File

@ -4,34 +4,44 @@
Route = TravisRoute.extend
needsAuth: true
setupController: ->
setupController: (controller) ->
@_super.apply this, arguments
@controllerFor('repo').activate('caches')
controller.set('repo', @controllerFor('repo').get('repo'))
model: ->
repo = @modelFor('repo')
Ajax.get("/repos/#{repo.get('id')}/caches").then( (data) ->
groups = {}
counter = 1
caches = {}
data["caches"].forEach (cacheData) ->
branch = cacheData["branch"]
group = groups[branch]
unless group
group = groups[branch] = Ember.Object.create(branch: branch, caches: [])
branch = cacheData.branch
cache = caches[branch]
if cache
cache.size += cacheData.size
cache = Ember.Object.create(cacheData)
cache.set('parent', group)
group.get('caches').pushObject(cache)
result = []
for branch, caches of groups
if /PR./.test(branch)
caches.set('type', 'pull_request')
if cache.last_modified < cacheData.last_modified
cache.last_modified = cacheData.last_modified
else
caches.set('type', 'push')
result.push caches
caches[branch] = cacheData
result
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`

View File

@ -1,58 +1,25 @@
{{#if length}}
{{#if model.pushes.length}}
<div class="caches-header">
<h1 class="build-title">All caches <small>(<a href="http://docs.travis-ci.com/user/caching/" title="">documentation</a>)</small></h1>
<a href="#" {{action "deleteRepoCache"}} {{bind-attr class="isDeleting:deleting :delete-repo-caches :button--delete"}}>
Delete all repository caches
</a>
</div>
{{!-- <h2 class="build-title">Pushes</h2> --}}
<h2 class="build-title">Pushes</h2>
<ul id="caches" class="caches">
{{#each controller itemController="cachesByBranch"}}
<li {{bind-attr class=":tile :tile--xs :tile :row controller.type" }}>
{{#each cache in caches itemController="cachesItem"}}
<p class="tile-item caches-branch column">
<span {{bind-attr class=":icon :icon--grey"}}></span>
{{cache.branch}}
</p>
<p class="tile-item caches-date column">{{format-time cache.last_modified}}</p>
<p class="tile-item caches-size column">{{mb cache.size}}MB</p>
<p class="tile-item caches-button column">
<a href="#" {{action "delete"}} {{bind-attr class="isDeleting:deleting :delete-by-slug :delete :button--delete"}}>
Delete
</a>
</p>
{{/each}}
</li>
{{#each cache in model.pushes }}
{{caches-item cache=cache repo=repo caches=model.pushes}}
{{/each}}
</ul>
{{!-- <h2 class="build-title">Pull Requests</h2>
<h2 class="build-title">Pull Requests</h2>
<ul class="caches">
{{#each controller itemController="cachesByBranch"}}
{{#each cache in caches itemController="cachesItem"}}
<li {{bind-attr class=":tile :tile--xs :tile :row" }}>
<p class="tile-item column">
<span {{bind-attr class=":icon :icon--grey pull_request"}}></span>
{{cache.branch}}
</p>
<p class="tile-item column">{{format-time cache.last_modified}}</p>
<p class="tile-item column">{{mb cache.size}}MB</p>
<p class="tile-item column">
<a href="#" {{action "delete"}} {{bind-attr class="isDeleting:deleting :delete-by-slug :delete :button--delete"}}>
delete
</a>
</p>
</li>
{{/each}}
{{/each}} --}}
{{#each cache in model.pullRequests }}
{{caches-item cache=cache repo=repo caches=model.pullRequests}}
{{/each}}
</ul>
{{else}}
<p>No caches have been created yet,<br>read more on <a href="http://docs.travis-ci.com/user/caching/" title="">how to setup caching with your build</a>.</p>
{{/if}}

View File

@ -0,0 +1,14 @@
<p class="tile-item caches-branch column">
<span {{bind-attr class=":icon :icon--grey"}}></span>
{{cache.branch}}
</p>
<p class="tile-item caches-date column">{{format-time cache.last_modified}}</p>
<p class="tile-item caches-size column">{{mb cache.size}}MB</p>
<p class="tile-item caches-button column">
<a href="#" {{action "delete"}} {{bind-attr class="isDeleting:deleting :delete-by-slug :delete :button--delete"}}>
Delete
</a>
</p>

View File

@ -0,0 +1,17 @@
`import { test, moduleForComponent } from 'ember-qunit'`
moduleForComponent 'caches-item', 'CachesItemComponent', {
# specify the other units that are required for this test
# needs: ['component:foo', 'helper:bar']
}
test 'it renders', ->
expect 2
# creates the component instance
component = @subject()
equal component._state, 'preRender'
# appends the component to the page
@append()
equal component._state, 'inDOM'