From a0ca1ec66bbbd12155d754f83a42438012518072 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 6 Aug 2015 13:14:41 +0200 Subject: [PATCH] Change running jobs and queue into components --- app/components/queued-jobs.coffee | 16 ++++++++++ app/components/running-jobs.coffee | 20 +++++++++++++ app/controllers/queue.coffee | 14 --------- app/controllers/repos.coffee | 29 ++++++++++++++++--- app/controllers/running-jobs.coffee | 24 --------------- .../{queue.hbs => components/queued-jobs.hbs} | 6 ++-- .../{ => components}/running-jobs.hbs | 6 ++-- app/templates/repos.hbs | 4 +-- app/views/running-jobs.coffee | 8 ----- 9 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 app/components/queued-jobs.coffee create mode 100644 app/components/running-jobs.coffee delete mode 100644 app/controllers/queue.coffee delete mode 100644 app/controllers/running-jobs.coffee rename app/templates/{queue.hbs => components/queued-jobs.hbs} (90%) rename app/templates/{ => components}/running-jobs.hbs (91%) delete mode 100644 app/views/running-jobs.coffee diff --git a/app/components/queued-jobs.coffee b/app/components/queued-jobs.coffee new file mode 100644 index 00000000..dfea033e --- /dev/null +++ b/app/components/queued-jobs.coffee @@ -0,0 +1,16 @@ +`import Ember from 'ember'` +`import config from 'travis/config/environment'` + +QueuedJobsComponent = Ember.Component.extend + store: Ember.inject.service() + + init: -> + @_super.apply this, arguments + if !Ember.testing + Visibility.every config.intervals.updateTimes, @updateTimes.bind(this) + + updateTimes: -> + if jobs = @get('jobs') + jobs.forEach (job) -> job.updateTimes() + +`export default QueuedJobsComponent` diff --git a/app/components/running-jobs.coffee b/app/components/running-jobs.coffee new file mode 100644 index 00000000..3e97c933 --- /dev/null +++ b/app/components/running-jobs.coffee @@ -0,0 +1,20 @@ +`import Ember from 'ember'` +`import Polling from 'travis/mixins/polling'` +`import config from 'travis/config/environment'` + +RunningJobsComponent = Ember.Component.extend Polling, + store: Ember.inject.service() + + pollHook: (store) -> + @get('store').find('job', {}) + + init: -> + @_super.apply this, arguments + if !Ember.testing + Visibility.every config.intervals.updateTimes, @updateTimes.bind(this) + + updateTimes: -> + if jobs = @get('jobs') + jobs.forEach (job) -> job.updateTimes() + +`export default RunningJobsComponent` diff --git a/app/controllers/queue.coffee b/app/controllers/queue.coffee deleted file mode 100644 index a89d1b28..00000000 --- a/app/controllers/queue.coffee +++ /dev/null @@ -1,14 +0,0 @@ -`import Ember from 'ember'` - -Controller = Ember.ArrayController.extend - isLoaded: false - content: (-> - result = @store.filter('job', {}, (job) -> - ['created', 'queued'].indexOf(job.get('state')) != -1 - ) - result.then => - @set('isLoaded', true) - result - ).property() - -`export default Controller` diff --git a/app/controllers/repos.coffee b/app/controllers/repos.coffee index dcf43dda..ccecfba8 100644 --- a/app/controllers/repos.coffee +++ b/app/controllers/repos.coffee @@ -31,7 +31,7 @@ Controller = Ember.Controller.extend @container.lookup('router:main').send('redirectToGettingStarted') isLoadedBinding: 'repos.isLoaded' - needs: ['currentUser', 'repo', 'runningJobs', 'queue'] + needs: ['currentUser', 'repo'] currentUserBinding: 'controllers.currentUser.model' selectedRepo: (-> # we need to observe also repo.content here, because we use @@ -40,16 +40,37 @@ Controller = Ember.Controller.extend @get('controllers.repo.repo.content') || @get('controllers.repo.repo') ).property('controllers.repo.repo', 'controllers.repo.repo.content') - startedJobsCount: Ember.computed.alias('controllers.runningJobs.length') + startedJobsCount: Ember.computed.alias('runningJobs.length') allJobsCount: (-> - @get('startedJobsCount') + @get('controllers.queue.length') - ).property('startedJobsCount', 'controllers.queue.length') + @get('startedJobsCount') + @get('queuedJobs.length') + ).property('startedJobsCount', 'queuedJobs.length') init: -> @_super.apply this, arguments if !Ember.testing Visibility.every @config.intervals.updateTimes, @updateTimes.bind(this) + runningJobs: (-> + # TODO: this should also query for received jobs + result = @store.filter('job', {}, (job) -> + ['started', 'received'].indexOf(job.get('state')) != -1 + ) + result.set('isLoaded', false) + result.then => + result.set('isLoaded', true) + result + ).property() + + queuedJobs: (-> + result = @get('store').filter('job', {}, (job) -> + ['created', 'queued'].indexOf(job.get('state')) != -1 + ) + result.set('isLoaded', false) + result.then => + result.set('isLoaded', true) + result + ).property() + recentRepos: (-> # I return an empty array here, because we're removing left sidebar, but # I don't want to refactor too much code (it will be all changed anyway diff --git a/app/controllers/running-jobs.coffee b/app/controllers/running-jobs.coffee deleted file mode 100644 index 1058b304..00000000 --- a/app/controllers/running-jobs.coffee +++ /dev/null @@ -1,24 +0,0 @@ -`import Ember from 'ember'` - -Controller = Ember.ArrayController.extend - init: -> - @_super.apply this, arguments - if !Ember.testing - Visibility.every @config.intervals.updateTimes, @updateTimes.bind(this) - - updateTimes: -> - if content = @get('content') - content.forEach (job) -> job.updateTimes() - - isLoaded: false - content: (-> - # TODO: this should also query for received jobs - result = @store.filter('job', {}, (job) -> - ['started', 'received'].indexOf(job.get('state')) != -1 - ) - result.then => - @set('isLoaded', true) - result - ).property() - -`export default Controller` diff --git a/app/templates/queue.hbs b/app/templates/components/queued-jobs.hbs similarity index 90% rename from app/templates/queue.hbs rename to app/templates/components/queued-jobs.hbs index a2d70ec2..27b545e3 100644 --- a/app/templates/queue.hbs +++ b/app/templates/components/queued-jobs.hbs @@ -1,6 +1,6 @@ -{{#if isLoaded}} - {{#if length}} - {{#each job in controller}} +{{#if jobs.isLoaded}} + {{#if jobs.length}} + {{#each jobs as |job|}}
{{#if job.repo.slug}} diff --git a/app/templates/running-jobs.hbs b/app/templates/components/running-jobs.hbs similarity index 91% rename from app/templates/running-jobs.hbs rename to app/templates/components/running-jobs.hbs index a04e187b..a1a45fc2 100644 --- a/app/templates/running-jobs.hbs +++ b/app/templates/components/running-jobs.hbs @@ -1,6 +1,6 @@ -{{#if isLoaded}} - {{#if controller.length}} - {{#each job in controller}} +{{#if jobs.isLoaded}} + {{#if jobs.length}} + {{#each jobs as |job| }}
{{#if job.repo.slug}} diff --git a/app/templates/repos.hbs b/app/templates/repos.hbs index 6ffa6c76..0451b2af 100644 --- a/app/templates/repos.hbs +++ b/app/templates/repos.hbs @@ -9,11 +9,11 @@ {{#if showRunningJobs}} {{else}} diff --git a/app/views/running-jobs.coffee b/app/views/running-jobs.coffee deleted file mode 100644 index 11c9a768..00000000 --- a/app/views/running-jobs.coffee +++ /dev/null @@ -1,8 +0,0 @@ -`import BasicView from 'travis/views/basic'` -`import Polling from 'travis/mixins/polling'` - -View = BasicView.extend Polling, - pollHook: (store) -> - @get('controller.store').find('job', {}) - -`export default View`