diff --git a/assets/images/ui/round-spinner.svg b/assets/images/ui/round-spinner.svg new file mode 100644 index 00000000..d9501046 --- /dev/null +++ b/assets/images/ui/round-spinner.svg @@ -0,0 +1,26 @@ + diff --git a/assets/scripts/app/controllers.coffee b/assets/scripts/app/controllers.coffee index 0c74d1e3..718b331b 100644 --- a/assets/scripts/app/controllers.coffee +++ b/assets/scripts/app/controllers.coffee @@ -86,3 +86,4 @@ require 'controllers/stats' require 'controllers/current_user' require 'controllers/request' require 'controllers/requests' +require 'controllers/caches' diff --git a/assets/scripts/app/controllers/caches.coffee b/assets/scripts/app/controllers/caches.coffee new file mode 100644 index 00000000..9f10a5f1 --- /dev/null +++ b/assets/scripts/app/controllers/caches.coffee @@ -0,0 +1,61 @@ +Travis.CachesController = Ember.ArrayController.extend + isDeleting: false + needs: ['repo'] + repo: Ember.computed.alias('controllers.repo.repo') + + actions: + deleteRepoCache: -> + return if @get('isDeleting') + + if confirm('Are you sure?') + @set('isDeleting', true) + + deletingDone = => @set('isDeleting', false) + + repo = @get('repo') + Travis.ajax.ajax("/repos/#{repo.get('id')}/caches", "DELETE").then(deletingDone, deletingDone).then => + @clear() + +Travis.CachesByBranchController = Ember.ObjectController.extend + isDeleting: false + needs: ['repo', 'caches'] + repo: Ember.computed.alias('controllers.repo.repo') + + actions: + delete: -> + return if @get('isDeleting') + + if confirm('Are you sure?') + @set('isDeleting', true) + + data = { branch: @get('branch') } + + deletingDone = => @set('isDeleting', false) + + repo = @get('repo') + Travis.ajax.ajax("/repos/#{repo.get('id')}/caches", "DELETE", data: data).then(deletingDone, deletingDone).then => + model = @get('model') + @get('controllers.caches').removeObject(model) + +Travis.CacheItemController = Ember.ObjectController.extend + isDeleting: false + needs: ['repo', 'caches'] + repo: Ember.computed.alias('controllers.repo.repo') + + actions: + delete: -> + return if @get('isDeleting') + + if confirm('Are you sure?') + @set('isDeleting', true) + + data = { branch: @get('branch'), slug: @get('slug') } + + deletingDone = => @set('isDeleting', false) + + repo = @get('repo') + Travis.ajax.ajax("/repos/#{repo.get('id')}/caches", "DELETE", data: data).then(deletingDone, deletingDone).then => + model = @get('model') + @get('parent.caches').removeObject(model) + if @get('parent.caches.length') == 0 + @get('controllers.caches').removeObject(@get('parent')) diff --git a/assets/scripts/app/controllers/repo.coffee b/assets/scripts/app/controllers/repo.coffee index 5113fa52..79733236 100644 --- a/assets/scripts/app/controllers/repo.coffee +++ b/assets/scripts/app/controllers/repo.coffee @@ -53,6 +53,9 @@ Travis.RepoController = Travis.Controller.extend viewRequests: -> @connectTab('requests') + viewCaches: -> + @connectTab('caches') + viewRequest: -> @connectTab('request') diff --git a/assets/scripts/app/helpers/handlebars.coffee b/assets/scripts/app/helpers/handlebars.coffee index cbd630be..6d183b4a 100644 --- a/assets/scripts/app/helpers/handlebars.coffee +++ b/assets/scripts/app/helpers/handlebars.coffee @@ -3,6 +3,11 @@ require 'ext/ember/bound_helper' safe = (string) -> new Handlebars.SafeString(string) +Ember.Handlebars.helper('mb', (size) -> + if size + (size / 1024 / 1024).toFixed(2) +, 'size') + Travis.Tab = Ember.Object.extend show: -> @get('tabs').forEach( (t) -> t.hide() ) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 1d933d54..b30fb1fe 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -59,6 +59,7 @@ Travis.Router.map -> @resource 'pullRequests', path: '/pull_requests' @resource 'branches', path: '/branches' @resource 'requests', path: '/requests' + @resource 'caches', path: '/caches' if Travis.config.caches_enabled @resource 'request', path: '/requests/:request_id' # this can't be nested in repo, because we want a set of different @@ -85,6 +86,31 @@ Travis.RequestsRoute = Travis.Route.extend model: -> Travis.Request.fetch repository_id: @modelFor('repo').get('id') +Travis.CachesRoute = Travis.Route.extend + setupController: -> + @_super.apply this, arguments + @controllerFor('repo').activate('caches') + + model: -> + repo = @modelFor('repo') + Travis.ajax.get("/repos/#{repo.get('id')}/caches").then( (data) -> + groups = {} + data["caches"].forEach (cacheData) -> + branch = cacheData["branch"] + group = groups[branch] + unless group + group = groups[branch] = Ember.Object.create(branch: branch, caches: []) + cache = Ember.Object.create(cacheData) + cache.set('parent', group) + group.get('caches').pushObject(cache) + + result = [] + for branch, caches of groups + result.push caches + + result + ) + Travis.RequestRoute = Travis.Route.extend setupController: -> @_super.apply this, arguments diff --git a/assets/scripts/app/templates/caches.hbs b/assets/scripts/app/templates/caches.hbs new file mode 100644 index 00000000..7b5bdfda --- /dev/null +++ b/assets/scripts/app/templates/caches.hbs @@ -0,0 +1,33 @@ +{{#if length}} + + Delete repo cache + + +