componentify caches
This commit is contained in:
parent
64dc75fa2d
commit
23e719ed78
27
app/components/caches-item.coffee
Normal file
27
app/components/caches-item.coffee
Normal 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`
|
|
@ -1,10 +1,8 @@
|
||||||
`import Ember from 'ember'`
|
`import Ember from 'ember'`
|
||||||
`import Ajax from 'travis/utils/ajax'`
|
`import Ajax from 'travis/utils/ajax'`
|
||||||
|
|
||||||
Controller = Ember.ArrayController.extend
|
Controller = Ember.Controller.extend
|
||||||
isDeleting: false
|
isDeleting: false
|
||||||
needs: ['repo']
|
|
||||||
repo: Ember.computed.alias('controllers.repo.repo')
|
|
||||||
|
|
||||||
actions:
|
actions:
|
||||||
deleteRepoCache: ->
|
deleteRepoCache: ->
|
||||||
|
@ -17,6 +15,6 @@ Controller = Ember.ArrayController.extend
|
||||||
|
|
||||||
repo = @get('repo')
|
repo = @get('repo')
|
||||||
Ajax.ajax("/repos/#{repo.get('id')}/caches", "DELETE").then(deletingDone, deletingDone).then =>
|
Ajax.ajax("/repos/#{repo.get('id')}/caches", "DELETE").then(deletingDone, deletingDone).then =>
|
||||||
@clear()
|
@set('model', {})
|
||||||
|
|
||||||
`export default Controller`
|
`export default Controller`
|
||||||
|
|
|
@ -4,34 +4,44 @@
|
||||||
|
|
||||||
Route = TravisRoute.extend
|
Route = TravisRoute.extend
|
||||||
needsAuth: true
|
needsAuth: true
|
||||||
setupController: ->
|
setupController: (controller) ->
|
||||||
@_super.apply this, arguments
|
@_super.apply this, arguments
|
||||||
@controllerFor('repo').activate('caches')
|
@controllerFor('repo').activate('caches')
|
||||||
|
controller.set('repo', @controllerFor('repo').get('repo'))
|
||||||
|
|
||||||
model: ->
|
model: ->
|
||||||
repo = @modelFor('repo')
|
repo = @modelFor('repo')
|
||||||
Ajax.get("/repos/#{repo.get('id')}/caches").then( (data) ->
|
Ajax.get("/repos/#{repo.get('id')}/caches").then( (data) ->
|
||||||
groups = {}
|
caches = {}
|
||||||
counter = 1
|
|
||||||
data["caches"].forEach (cacheData) ->
|
data["caches"].forEach (cacheData) ->
|
||||||
branch = cacheData["branch"]
|
branch = cacheData.branch
|
||||||
group = groups[branch]
|
cache = caches[branch]
|
||||||
unless group
|
|
||||||
group = groups[branch] = Ember.Object.create(branch: branch, caches: [])
|
if cache
|
||||||
|
cache.size += cacheData.size
|
||||||
|
|
||||||
cache = Ember.Object.create(cacheData)
|
if cache.last_modified < cacheData.last_modified
|
||||||
cache.set('parent', group)
|
cache.last_modified = cacheData.last_modified
|
||||||
group.get('caches').pushObject(cache)
|
|
||||||
|
|
||||||
result = []
|
|
||||||
for branch, caches of groups
|
|
||||||
if /PR./.test(branch)
|
|
||||||
caches.set('type', 'pull_request')
|
|
||||||
else
|
else
|
||||||
caches.set('type', 'push')
|
caches[branch] = cacheData
|
||||||
result.push caches
|
|
||||||
|
|
||||||
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`
|
`export default Route`
|
||||||
|
|
|
@ -1,58 +1,25 @@
|
||||||
{{#if length}}
|
{{#if model.pushes.length}}
|
||||||
|
|
||||||
<div class="caches-header">
|
<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>
|
<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"}}>
|
<a href="#" {{action "deleteRepoCache"}} {{bind-attr class="isDeleting:deleting :delete-repo-caches :button--delete"}}>
|
||||||
Delete all repository caches
|
Delete all repository caches
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{{!-- <h2 class="build-title">Pushes</h2> --}}
|
<h2 class="build-title">Pushes</h2>
|
||||||
<ul id="caches" class="caches">
|
<ul id="caches" class="caches">
|
||||||
{{#each controller itemController="cachesByBranch"}}
|
{{#each cache in model.pushes }}
|
||||||
<li {{bind-attr class=":tile :tile--xs :tile :row controller.type" }}>
|
{{caches-item cache=cache repo=repo caches=model.pushes}}
|
||||||
{{#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}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{{!-- <h2 class="build-title">Pull Requests</h2>
|
<h2 class="build-title">Pull Requests</h2>
|
||||||
<ul class="caches">
|
<ul class="caches">
|
||||||
{{#each controller itemController="cachesByBranch"}}
|
{{#each cache in model.pullRequests }}
|
||||||
{{#each cache in caches itemController="cachesItem"}}
|
{{caches-item cache=cache repo=repo caches=model.pullRequests}}
|
||||||
<li {{bind-attr class=":tile :tile--xs :tile :row" }}>
|
{{/each}}
|
||||||
|
|
||||||
<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}} --}}
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{{else}}
|
{{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>
|
<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}}
|
{{/if}}
|
||||||
|
|
14
app/templates/components/caches-item.hbs
Normal file
14
app/templates/components/caches-item.hbs
Normal 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>
|
17
tests/unit/components/caches-item-test.coffee
Normal file
17
tests/unit/components/caches-item-test.coffee
Normal 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'
|
Loading…
Reference in New Issue
Block a user