diff --git a/app/components/caches-item.coffee b/app/components/caches-item.coffee new file mode 100644 index 00000000..2b693580 --- /dev/null +++ b/app/components/caches-item.coffee @@ -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` diff --git a/app/controllers/caches.coffee b/app/controllers/caches.coffee index 8c5ad621..246101d4 100644 --- a/app/controllers/caches.coffee +++ b/app/controllers/caches.coffee @@ -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` diff --git a/app/routes/caches.coffee b/app/routes/caches.coffee index d1f5c470..3b6132fe 100644 --- a/app/routes/caches.coffee +++ b/app/routes/caches.coffee @@ -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` diff --git a/app/templates/caches.hbs b/app/templates/caches.hbs index f735ded1..0c1d9de3 100644 --- a/app/templates/caches.hbs +++ b/app/templates/caches.hbs @@ -1,58 +1,25 @@ -{{#if length}} +{{#if model.pushes.length}} +

All caches (documentation)

Delete all repository caches
- {{!--

Pushes

--}} +

Pushes

-{{!--

Pull Requests

+

Pull Requests

+ {{else}}

No caches have been created yet,
read more on how to setup caching with your build.

{{/if}} diff --git a/app/templates/components/caches-item.hbs b/app/templates/components/caches-item.hbs new file mode 100644 index 00000000..cdcfeb3e --- /dev/null +++ b/app/templates/components/caches-item.hbs @@ -0,0 +1,14 @@ +

+ + {{cache.branch}} +

+ +

{{format-time cache.last_modified}}

+ +

{{mb cache.size}}MB

+ +

+ + Delete + +

diff --git a/tests/unit/components/caches-item-test.coffee b/tests/unit/components/caches-item-test.coffee new file mode 100644 index 00000000..3eef9311 --- /dev/null +++ b/tests/unit/components/caches-item-test.coffee @@ -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'