From 3d42a5961df31df0ff857840ea2f920ec56f33ed Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 20 Jan 2015 14:55:20 +0100 Subject: [PATCH] More ember-cli preparation --- assets/scripts/app/controllers/build.coffee | 10 ++- assets/scripts/app/controllers/repos.coffee | 6 +- assets/scripts/app/controllers/request.coffee | 2 +- assets/scripts/app/helpers/urls.coffee | 74 +++++++++++-------- .../app/templates/{jobs/show.hbs => job.hbs} | 0 .../app/templates/{jobs/list.hbs => jobs.hbs} | 0 .../templates/{repos/show.hbs => repo.hbs} | 0 .../templates/{repos/list.hbs => repos.hbs} | 0 assets/scripts/app/views.coffee | 2 + assets/scripts/app/views/job.coffee | 2 - assets/scripts/app/views/jobs.coffee | 1 - .../scripts/app/views/repo-show-tabs.coffee | 57 ++++++++++++++ assets/scripts/app/views/repo.coffee | 39 +++++++++- .../scripts/app/views/repos-list-tabs.coffee | 25 +++++++ assets/scripts/app/views/repos-list.coffee | 25 +++++++ assets/scripts/lib/travis/ajax.coffee | 10 +-- 16 files changed, 206 insertions(+), 47 deletions(-) rename assets/scripts/app/templates/{jobs/show.hbs => job.hbs} (100%) rename assets/scripts/app/templates/{jobs/list.hbs => jobs.hbs} (100%) rename assets/scripts/app/templates/{repos/show.hbs => repo.hbs} (100%) rename assets/scripts/app/templates/{repos/list.hbs => repos.hbs} (100%) create mode 100644 assets/scripts/app/views/repo-show-tabs.coffee create mode 100644 assets/scripts/app/views/repos-list-tabs.coffee create mode 100644 assets/scripts/app/views/repos-list.coffee diff --git a/assets/scripts/app/controllers/build.coffee b/assets/scripts/app/controllers/build.coffee index d5555b17..48ea6918 100644 --- a/assets/scripts/app/controllers/build.coffee +++ b/assets/scripts/app/controllers/build.coffee @@ -1,4 +1,6 @@ -Travis.BuildController = Ember.Controller.extend Travis.GithubUrlProperties, +gravatarImage = Travis.Urls.gravatarImage + +Controller = Ember.Controller.extend Travis.GithubUrlProperties, needs: ['repo'] repoBinding: 'controllers.repo.repo' commitBinding: 'build.commit' @@ -12,9 +14,11 @@ Travis.BuildController = Ember.Controller.extend Travis.GithubUrlProperties, ).property('build.isLoading') urlCommitterGravatarImage: (-> - Travis.Urls.gravatarImage(@get('commit.committerEmail'), 40) + gravatarImage(@get('commit.committerEmail'), 40) ).property('commit.committerEmail') urlAuthorGravatarImage: (-> - Travis.Urls.gravatarImage(@get('commit.authorEmail'), 40) + gravatarImage(@get('commit.authorEmail'), 40) ).property('commit.authorEmail') + +Travis.BuildController = Controller diff --git a/assets/scripts/app/controllers/repos.coffee b/assets/scripts/app/controllers/repos.coffee index c9583a13..3434ceda 100644 --- a/assets/scripts/app/controllers/repos.coffee +++ b/assets/scripts/app/controllers/repos.coffee @@ -1,5 +1,7 @@ require 'travis/limited_array' +Repo = Travis.Repo + Travis.ReposController = Ember.ArrayController.extend actions: activate: (name) -> @@ -32,7 +34,7 @@ Travis.ReposController = Ember.ArrayController.extend recentRepos: (-> Ember.ArrayProxy.extend( isLoadedBinding: 'repos.isLoaded' - repos: Travis.Repo.withLastBuild() + repos: Repo.withLastBuild() sorted: Ember.computed.sort('repos', 'sortedReposKeys') content: Ember.computed.limit('sorted', 'limit') sortedReposKeys: ['sortOrder:asc'] @@ -47,7 +49,7 @@ Travis.ReposController = Ember.ArrayController.extend activate: (tab, params) -> @set('sortProperties', ['sortOrder']) @set('tab', tab) - this["view#{$.camelize(tab)}"](params) + this["view#{tab.camelize()}"](params) viewRecent: -> @set('content', @get('recentRepos')) diff --git a/assets/scripts/app/controllers/request.coffee b/assets/scripts/app/controllers/request.coffee index 0714c884..2a75ebc1 100644 --- a/assets/scripts/app/controllers/request.coffee +++ b/assets/scripts/app/controllers/request.coffee @@ -22,7 +22,7 @@ Travis.RequestController = Ember.ObjectController.extend message: (-> message = @get('model.message') - if Travis.config.pro && message == "private repository" + if @config.pro && message == "private repository" '' else message diff --git a/assets/scripts/app/helpers/urls.coffee b/assets/scripts/app/helpers/urls.coffee index 9e7d5fbc..b204bc59 100644 --- a/assets/scripts/app/helpers/urls.coffee +++ b/assets/scripts/app/helpers/urls.coffee @@ -1,41 +1,53 @@ -@Travis.Urls = - plainTextLog: (id) -> - "#{Travis.config.api_endpoint}/jobs/#{id}/log.txt?deansi=true" +plainTextLog = (id) -> + "#{Travis.config.api_endpoint}/jobs/#{id}/log.txt?deansi=true" - githubPullRequest: (slug, pullRequestNumber) -> - "#{Travis.config.source_endpoint}/#{slug}/pull/#{pullRequestNumber}" +githubPullRequest = (slug, pullRequestNumber) -> + "#{Travis.config.source_endpoint}/#{slug}/pull/#{pullRequestNumber}" - githubCommit: (slug, sha) -> - "#{Travis.config.source_endpoint}/#{slug}/commit/#{sha}" +githubCommit = (slug, sha) -> + "#{Travis.config.source_endpoint}/#{slug}/commit/#{sha}" - githubRepo: (slug) -> - "#{Travis.config.source_endpoint}/#{slug}" +githubRepo = (slug) -> + "#{Travis.config.source_endpoint}/#{slug}" - githubWatchers: (slug) -> - "#{Travis.config.source_endpoint}/#{slug}/watchers" +githubWatchers = (slug) -> + "#{Travis.config.source_endpoint}/#{slug}/watchers" - githubNetwork: (slug) -> - "#{Travis.config.source_endpoint}/#{slug}/network" +githubNetwork = (slug) -> + "#{Travis.config.source_endpoint}/#{slug}/network" - githubAdmin: (slug) -> - "#{Travis.config.source_endpoint}/#{slug}/settings/hooks#travis_minibucket" +githubAdmin = (slug) -> + "#{Travis.config.source_endpoint}/#{slug}/settings/hooks#travis_minibucket" - statusImage: (slug, branch) -> - if Travis.config.pro - token = Travis.__container__.lookup('controller:currentUser').get('token') - "#{location.protocol}//#{location.host}/#{slug}.svg?token=#{token}" + if branch then "&branch=#{branch}" else '' - else - "#{location.protocol}//#{location.host}/#{slug}.svg" + if branch then "?branch=#{encodeURIComponent(branch)}" else '' +statusImage = (slug, branch) -> + if Travis.config.pro + token = Travis.__container__.lookup('controller:currentUser').get('token') + "#{location.protocol}//#{location.host}/#{slug}.svg?token=#{token}" + if branch then "&branch=#{branch}" else '' + else + "#{location.protocol}//#{location.host}/#{slug}.svg" + if branch then "?branch=#{encodeURIComponent(branch)}" else '' - ccXml: (slug) -> - if Travis.config.pro - token = Travis.__container__.lookup('controller:currentUser').get('token') - "##{Travis.config.api_endpoint}/repos/#{slug}/cc.xml?token=#{token}" - else - "#{Travis.config.api_endpoint}/repos/#{slug}/cc.xml" +ccXml = (slug) -> + if Travis.config.pro + token = Travis.__container__.lookup('controller:currentUser').get('token') + "##{Travis.config.api_endpoint}/repos/#{slug}/cc.xml?token=#{token}" + else + "#{Travis.config.api_endpoint}/repos/#{slug}/cc.xml" - email: (email) -> - "mailto:#{email}" +email = (email) -> + "mailto:#{email}" - gravatarImage: (email, size) -> - "https://www.gravatar.com/avatar/#{md5(email)}?s=#{size}&d=#{encodeURIComponent(Travis.config.avatar_default_url)}" +gravatarImage = (email, size) -> + "https://www.gravatar.com/avatar/#{md5(email)}?s=#{size}&d=#{encodeURIComponent(Travis.config.avatar_default_url)}" + +Travis.Urls = { + plainTextLog: plainTextLog, + githubPullRequest: githubPullRequest, + githubCommit: githubCommit, + githubRepo: githubRepo, + githubWatchers: githubWatchers, + githubNetwork: githubNetwork, + githubAdmin: githubAdmin, + statusImage: statusImage, + ccXml: ccXml, + email: email +} diff --git a/assets/scripts/app/templates/jobs/show.hbs b/assets/scripts/app/templates/job.hbs similarity index 100% rename from assets/scripts/app/templates/jobs/show.hbs rename to assets/scripts/app/templates/job.hbs diff --git a/assets/scripts/app/templates/jobs/list.hbs b/assets/scripts/app/templates/jobs.hbs similarity index 100% rename from assets/scripts/app/templates/jobs/list.hbs rename to assets/scripts/app/templates/jobs.hbs diff --git a/assets/scripts/app/templates/repos/show.hbs b/assets/scripts/app/templates/repo.hbs similarity index 100% rename from assets/scripts/app/templates/repos/show.hbs rename to assets/scripts/app/templates/repo.hbs diff --git a/assets/scripts/app/templates/repos/list.hbs b/assets/scripts/app/templates/repos.hbs similarity index 100% rename from assets/scripts/app/templates/repos/list.hbs rename to assets/scripts/app/templates/repos.hbs diff --git a/assets/scripts/app/views.coffee b/assets/scripts/app/views.coffee index 7fea9840..55ecc56d 100644 --- a/assets/scripts/app/views.coffee +++ b/assets/scripts/app/views.coffee @@ -11,6 +11,8 @@ require 'views/jobs' require 'views/jobs-item' require 'views/log' require 'views/repo' +require 'views/repos-list' +require 'views/repos-list-tabs' require 'views/profile' require 'views/stats' require 'views/signin' diff --git a/assets/scripts/app/views/job.coffee b/assets/scripts/app/views/job.coffee index a9c52f93..ce549cb0 100644 --- a/assets/scripts/app/views/job.coffee +++ b/assets/scripts/app/views/job.coffee @@ -5,8 +5,6 @@ githubCommit = Travis.Urls.githubCommit gravatarImage = Travis.Urls.gravatarImage View = Ember.View.extend - templateName: 'jobs/show' - repoBinding: 'controller.repo' jobBinding: 'controller.job' commitBinding: 'job.commit' diff --git a/assets/scripts/app/views/jobs.coffee b/assets/scripts/app/views/jobs.coffee index 5584023a..05d27278 100644 --- a/assets/scripts/app/views/jobs.coffee +++ b/assets/scripts/app/views/jobs.coffee @@ -1,5 +1,4 @@ View = Ember.View.extend - templateName: 'jobs/list' buildBinding: 'controller.build' jobTableId: Ember.computed(-> diff --git a/assets/scripts/app/views/repo-show-tabs.coffee b/assets/scripts/app/views/repo-show-tabs.coffee new file mode 100644 index 00000000..cd6fa149 --- /dev/null +++ b/assets/scripts/app/views/repo-show-tabs.coffee @@ -0,0 +1,57 @@ +View = Travis.View.extend + templateName: 'repos/show/tabs' + + tabBinding: 'controller.tab' + contextBinding: 'controller' + + # 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 display-inline' if @get('tab') == 'job' + ).property('tab') + + classRequests: (-> + 'active display-inline' if @get('tab') == 'requests' + ).property('tab') + + classCaches: (-> + 'active display-inline' if @get('tab') == 'caches' + ).property('tab') + + classSettings: (-> + 'active display-inline' if @get('tab') == 'settings' + ).property('tab') + + classRequest: (-> + 'active display-inline' if @get('tab') == 'request' + ).property('tab') + +Travis.RepoShowTabsView = View diff --git a/assets/scripts/app/views/repo.coffee b/assets/scripts/app/views/repo.coffee index d4e7a7b6..8f9fd259 100644 --- a/assets/scripts/app/views/repo.coffee +++ b/assets/scripts/app/views/repo.coffee @@ -1,2 +1,37 @@ -require 'views/repo/list' -require 'views/repo/show' +statusImage = Travis.Urls.statusImage +StatusImagesView = Travis.StatusImagesView + +View = Travis.View.extend + reposBinding: 'controllers.repos' + repoBinding: 'controller.repo' + buildBinding: 'controller.build' + jobBinding: 'controller.job' + tabBinding: 'controller.tab' + + classNameBindings: ['controller.isLoading:loading'] + + isEmpty: (-> + @get('repos.isLoaded') && @get('repos.length') == 0 + ).property('repos.isLoaded', 'repos.length') + + statusImageUrl: (-> + statusImage(@get('controller.repo.slug')) + ).property('controller.repo.slug') + + actions: + statusImages: () -> + @popupCloseAll() + view = StatusImagesView.create(toolsView: this) + Travis.View.currentPopupView = view + view.appendTo($('body')) + return false + + ReposEmptyView: Travis.View.extend + template: (-> + if Travis.config.pro + 'pro/repos/show/empty' + else + '' + ).property() + +Travis.RepoView = View diff --git a/assets/scripts/app/views/repos-list-tabs.coffee b/assets/scripts/app/views/repos-list-tabs.coffee new file mode 100644 index 00000000..7df35729 --- /dev/null +++ b/assets/scripts/app/views/repos-list-tabs.coffee @@ -0,0 +1,25 @@ +View = Travis.View.extend + templateName: 'repos/list/tabs' + tabBinding: 'controller.tab' + currentUserBinding: 'controller.currentUser.id' + + classRecent: (-> + 'active' if @get('tab') == 'recent' + ).property('tab') + + classOwned: (-> + classes = [] + classes.push('active') if @get('tab') == 'owned' + classes.push('display-inline') if @get('currentUser') + classes.join(' ') + ).property('tab', 'currentUser') + + classSearch: (-> + 'active' if @get('tab') == 'search' + ).property('tab') + + classNew: (-> + 'display-inline' if @get('currentUser') + ).property('currentUser') + +Travis.ReposListTabsView = View diff --git a/assets/scripts/app/views/repos-list.coffee b/assets/scripts/app/views/repos-list.coffee new file mode 100644 index 00000000..d4fc21a0 --- /dev/null +++ b/assets/scripts/app/views/repos-list.coffee @@ -0,0 +1,25 @@ +colorForState = Travis.Helpers.colorForState + +View = Em.CollectionView.extend + elementId: 'repos' + tagName: 'ul' + + emptyView: Ember.View.extend + template: Ember.Handlebars.compile('
Loading
') + + itemViewClass: Travis.View.extend + repoBinding: 'content' + classNames: ['repo'] + classNameBindings: ['color', 'selected'] + selected: (-> + @get('content') == @get('controller.selectedRepo') + ).property('controller.selectedRepo') + + color: (-> + colorForState(@get('repo.lastBuildState')) + ).property('repo.lastBuildState') + + click: -> + @get('controller').transitionToRoute('/' + @get('repo.slug')) + +Travis.ReposListView = View diff --git a/assets/scripts/lib/travis/ajax.coffee b/assets/scripts/lib/travis/ajax.coffee index 5b3a37ed..8b5e2d8f 100644 --- a/assets/scripts/lib/travis/ajax.coffee +++ b/assets/scripts/lib/travis/ajax.coffee @@ -1,13 +1,13 @@ jQuery.support.cors = true +default_options = + accepts: + json: 'application/json; version=2' + Travis.ajax = Em.Object.create publicEndpoints: [/\/repos\/?.*/, /\/builds\/?.*/, /\/jobs\/?.*/] privateEndpoints: [/\/repos\/\d+\/caches/] - DEFAULT_OPTIONS: - accepts: - json: 'application/json; version=2' - get: (url, callback, errorCallback) -> @ajax(url, 'get', success: callback, error: errorCallback) @@ -67,7 +67,7 @@ Travis.ajax = Em.Object.create delete data.flash if data? error.apply(this, arguments) - options = $.extend(options, Travis.ajax.DEFAULT_OPTIONS) + options = $.extend(options, default_options) if testMode? console.log('Running ajax with', options.url)