From 759e56d7ba03c3e8d201d9ab6dbbd3f3d99017ee Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 5 Aug 2015 13:11:57 +0200 Subject: [PATCH] Change repos-list into a component --- app/components/repo-show-tabs.coffee | 54 +++++++++++++ app/components/repos-list-item.coffee | 29 +++++++ app/components/repos-list.coffee | 6 ++ app/controllers/repos.coffee | 13 +-- app/routes/main-tab.coffee | 8 +- app/templates/components/repo-show-tabs.hbs | 83 ++++++++++++++++++++ app/templates/components/repos-list-item.hbs | 35 +++++++++ app/templates/components/repos-list.hbs | 7 ++ app/templates/repo.hbs | 2 +- app/templates/repos.hbs | 45 +---------- app/templates/repos/show/tabs.hbs | 82 ------------------- 11 files changed, 228 insertions(+), 136 deletions(-) create mode 100644 app/components/repo-show-tabs.coffee create mode 100644 app/components/repos-list-item.coffee create mode 100644 app/components/repos-list.coffee create mode 100644 app/templates/components/repo-show-tabs.hbs create mode 100644 app/templates/components/repos-list-item.hbs create mode 100644 app/templates/components/repos-list.hbs diff --git a/app/components/repo-show-tabs.coffee b/app/components/repo-show-tabs.coffee new file mode 100644 index 00000000..aa15b348 --- /dev/null +++ b/app/components/repo-show-tabs.coffee @@ -0,0 +1,54 @@ +`import Ember from 'ember'` + +RepoShowTabsComponent = Ember.Component.extend + # hrm. how to parametrize bind-attr? + classCurrent: (-> + 'active' if @get('tab') == 'current' + ).property('tab') + + classBuilds: (-> + 'active' if @get('tab') == 'builds' + ).property('tab') + + classPullRequests: (-> + 'active' if @get('tab') == 'pull_requests' + ).property('tab') + + classBranches: (-> + 'active' if @get('tab') == 'branches' + ).property('tab') + + classEvents: (-> + 'active' if @get('tab') == 'events' + ).property('tab') + + classBuild: (-> + tab = @get('tab') + classes = [] + classes.push('active') if tab == 'build' + classes.push('display-inline') if tab == 'build' || tab == 'job' + classes.join(' ') + ).property('tab') + + # TODO: refactor tabs, most of the things here are not really DRY + classJob: (-> + 'active' if @get('tab') == 'job' + ).property('tab') + + classRequests: (-> + 'active' if @get('tab') == 'requests' + ).property('tab') + + classCaches: (-> + 'active' if @get('tab') == 'caches' + ).property('tab') + + classSettings: (-> + 'active' if @get('tab') == 'settings' + ).property('tab') + + classRequest: (-> + 'active' if @get('tab') == 'request' + ).property('tab') + +`export default RepoShowTabsComponent` diff --git a/app/components/repos-list-item.coffee b/app/components/repos-list-item.coffee new file mode 100644 index 00000000..1d620188 --- /dev/null +++ b/app/components/repos-list-item.coffee @@ -0,0 +1,29 @@ +`import Ember from 'ember'` +`import Polling from 'travis/mixins/polling'` +`import { colorForState } from 'travis/utils/helpers'` + +ReposListItemComponent = Ember.Component.extend Polling, + tagName: 'li' + + pollModels: 'repo' + + classNames: ['repo'] + classNameBindings: ['color', 'selected'] + selected: (-> + @get('repo') == @get('selectedRepo') + ).property('selectedRepo') + + color: (-> + colorForState(@get('repo.lastBuildState')) + ).property('repo.lastBuildState') + + scrollTop: (-> + if (window.scrollY > 0) + $('html, body').animate({scrollTop: 0}, 200) + ) + + click: -> + @scrollTop() + @get('controller').transitionToRoute('/' + @get('repo.slug')) + +`export default ReposListItemComponent` diff --git a/app/components/repos-list.coffee b/app/components/repos-list.coffee new file mode 100644 index 00000000..3dcf8f8c --- /dev/null +++ b/app/components/repos-list.coffee @@ -0,0 +1,6 @@ +`import Ember from 'ember'` + +ReposListComponent = Ember.Component.extend + tagName: 'ul' + +`export default ReposListComponent` diff --git a/app/controllers/repos.coffee b/app/controllers/repos.coffee index bce174fa..dcf43dda 100644 --- a/app/controllers/repos.coffee +++ b/app/controllers/repos.coffee @@ -2,7 +2,8 @@ `import limit from 'travis/utils/computed-limit'` `import Repo from 'travis/models/repo'` -Controller = Ember.ArrayController.extend +Controller = Ember.Controller.extend + contentBinding: 'repos' actions: activate: (name) -> @activate(name) @@ -29,7 +30,7 @@ Controller = Ember.ArrayController.extend if @get('tab') == 'owned' && @get('isLoaded') && @get('length') == 0 @container.lookup('router:main').send('redirectToGettingStarted') - isLoadedBinding: 'content.isLoaded' + isLoadedBinding: 'repos.isLoaded' needs: ['currentUser', 'repo', 'runningJobs', 'queue'] currentUserBinding: 'controllers.currentUser.model' selectedRepo: (-> @@ -57,8 +58,8 @@ Controller = Ember.ArrayController.extend ).property() updateTimes: -> - if content = @get('content') - content.forEach (r) -> r.updateTimes() + if repos = @get('repos') + repos.forEach (r) -> r.updateTimes() activate: (tab, params) -> @set('sortProperties', ['sortOrder']) @@ -66,7 +67,7 @@ Controller = Ember.ArrayController.extend this["view_#{tab}".camelize()](params) viewOwned: -> - @set('content', @get('userRepos')) + @set('repos', @get('userRepos')) viewRunning: -> @@ -79,7 +80,7 @@ Controller = Ember.ArrayController.extend viewSearch: (phrase) -> @set('search', phrase) - @set('content', Repo.search(@store, phrase)) + @set('repos', Repo.search(@store, phrase)) searchObserver: (-> search = @get('search') diff --git a/app/routes/main-tab.coffee b/app/routes/main-tab.coffee index bbc1d4da..6cf21fb6 100644 --- a/app/routes/main-tab.coffee +++ b/app/routes/main-tab.coffee @@ -12,15 +12,17 @@ Route = TravisRoute.extend @controllerFor('repos').activate(@get('reposTabName')) @currentRepoDidChange() - @controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange') + if repos = @controllerFor('repos').get('repos') + repos.addObserver('firstObject', this, 'currentRepoDidChange') deactivate: -> - @controllerFor('repos').removeObserver('firstObject', this, 'currentRepoDidChange') + if repos = @controllerFor('repos').get('repos') + repos.removeObserver('firstObject', this, 'currentRepoDidChange') @_super.apply(this, arguments) currentRepoDidChange: -> - if repo = @controllerFor('repos').get('firstObject') + if repo = @controllerFor('repos').get('repos.firstObject') @controllerFor('repo').set('repo', repo) actions: diff --git a/app/templates/components/repo-show-tabs.hbs b/app/templates/components/repo-show-tabs.hbs new file mode 100644 index 00000000..670869db --- /dev/null +++ b/app/templates/components/repo-show-tabs.hbs @@ -0,0 +1,83 @@ +
+ +
diff --git a/app/templates/components/repos-list-item.hbs b/app/templates/components/repos-list-item.hbs new file mode 100644 index 00000000..8b7f4b97 --- /dev/null +++ b/app/templates/components/repos-list-item.hbs @@ -0,0 +1,35 @@ +
+

+ {{#if repo.slug}} + + {{#link-to "repo" repo class="slug"}}{{repo.slug}}{{/link-to}} + {{/if}} +

+ {{#with repo.lastBuildHash as lastBuild}} + {{#if repo.slug}} + {{#if lastBuild.id}} +

+ + {{#link-to "build" repo lastBuild.id + class="last_build"}}{{lastBuild.number}}{{/link-to}} +

+ {{/if}} + {{/if}} + {{/with}} + +

+ + Duration: + + {{format-duration repo.lastBuildDuration}} + +

+ +

+ + Finished: + + {{format-time repo.lastBuildFinishedAt}} + +

+
diff --git a/app/templates/components/repos-list.hbs b/app/templates/components/repos-list.hbs new file mode 100644 index 00000000..faf4b471 --- /dev/null +++ b/app/templates/components/repos-list.hbs @@ -0,0 +1,7 @@ +{{#each repos as |repo|}} + {{repos-list-item repo=repo selectedRepo=selectedRepo}} +{{else}} +

{{noReposMessage}}

+{{/each}} + + diff --git a/app/templates/repo.hbs b/app/templates/repo.hbs index 59131043..75e135c8 100644 --- a/app/templates/repo.hbs +++ b/app/templates/repo.hbs @@ -20,7 +20,7 @@
{{view 'repo-show-tools'}} - {{view 'repo-show-tabs'}} + {{repo-show-tabs repo=repo tab=tab}}
{{outlet}} diff --git a/app/templates/repos.hbs b/app/templates/repos.hbs index 7bf3f1d4..6ffa6c76 100644 --- a/app/templates/repos.hbs +++ b/app/templates/repos.hbs @@ -19,50 +19,7 @@ {{else}}