diff --git a/assets/scripts/app/controllers.coffee b/assets/scripts/app/controllers.coffee index a6adbfc0..45ae67d1 100644 --- a/assets/scripts/app/controllers.coffee +++ b/assets/scripts/app/controllers.coffee @@ -62,6 +62,7 @@ Travis.RepoSettingsController = Em.ObjectController.extend require 'controllers/accounts' require 'controllers/auth' +require 'controllers/account' require 'controllers/build' require 'controllers/builds' require 'controllers/flash' diff --git a/assets/scripts/app/controllers/account.coffee b/assets/scripts/app/controllers/account.coffee new file mode 100644 index 00000000..d8cc6838 --- /dev/null +++ b/assets/scripts/app/controllers/account.coffee @@ -0,0 +1,35 @@ +Travis.AccountController = Ember.ObjectController.extend + allHooks: [] + + init: -> + @_super.apply this, arguments + + self = this + Travis.on("user:synced", (-> + self.reloadHooks() + )) + + toggle: (hook) -> + hook.toggle() + + reloadHooks: -> + if login = @get('login') + @set('allHooks', Travis.Hook.find(all: true, owner_name: login)) + + hooks: (-> + @reloadHooks() unless hooks = @get('allHooks') + @get('allHooks').filter (hook) -> hook.get('admin') + ).property('allHooks.length', 'allHooks') + + hooksWithoutAdmin: (-> + @reloadHooks() unless hooks = @get('allHooks') + @get('allHooks').filter (hook) -> !hook.get('admin') + ).property('allHooks.length', 'allHooks') + + showPrivateReposHint: (-> + Travis.config.show_repos_hint == 'private' + ) .property() + + showPublicReposHint: (-> + Travis.config.show_repos_hint == 'public' + ) .property() diff --git a/assets/scripts/app/controllers/account_index.coffee b/assets/scripts/app/controllers/account_index.coffee deleted file mode 100644 index 754e5b98..00000000 --- a/assets/scripts/app/controllers/account_index.coffee +++ /dev/null @@ -1,20 +0,0 @@ -Travis.AccountIndexController = Em.Controller.extend - needs: ['profile', 'currentUser'] - hooksBinding: 'controllers.profile.hooks' - allHooksBinding: 'controllers.profile.allHooks' - hooksWithoutAdminBinding: 'controllers.profile.hooksWithoutAdmin' - userBinding: 'controllers.currentUser' - - sync: -> - @get('user').sync() - - toggle: (hook) -> - hook.toggle() - - showPrivateReposHint: (-> - Travis.config.show_repos_hint == 'private' - ) .property() - - showPublicReposHint: (-> - Travis.config.show_repos_hint == 'public' - ) .property() diff --git a/assets/scripts/app/controllers/accounts.coffee b/assets/scripts/app/controllers/accounts.coffee index 213d2c85..b96965a1 100644 --- a/assets/scripts/app/controllers/accounts.coffee +++ b/assets/scripts/app/controllers/accounts.coffee @@ -1,5 +1,2 @@ Travis.AccountsController = Ember.ArrayController.extend tab: 'accounts' - - findByLogin: (login) -> - @find (account) -> account.get('login') == login diff --git a/assets/scripts/app/controllers/profile.coffee b/assets/scripts/app/controllers/profile.coffee index 330f6482..65a52dce 100644 --- a/assets/scripts/app/controllers/profile.coffee +++ b/assets/scripts/app/controllers/profile.coffee @@ -1,52 +1,19 @@ Travis.ProfileController = Travis.Controller.extend name: 'profile' - needs: ['currentUser', 'accounts'] + needs: ['currentUser', 'accounts', 'account'] userBinding: 'controllers.currentUser' - accountsBinding: 'controllers.accounts' - - init: -> - @_super.apply this, arguments - - self = this - Travis.on("user:synced", (-> - self.reloadHooks() - )) - - account: (-> - login = @get('params.login') || @get('user.login') - account = @get('accounts').filter((account) -> account if account.get('login') == login)[0] - account.select() if account - account - ).property('accounts.length', 'params.login') + accountBinding: 'controllers.account' sync: -> @get('user').sync() - toggle: (hook) -> - hook.toggle() - activate: (action, params) -> - @setParams(params || @get('params')) this["view#{$.camelize(action)}"]() viewHooks: -> @connectTab('hooks') - @reloadHooks() - - reloadHooks: -> - # TODO: figure out why user is not available sometimes - @set('allHooks', Travis.Hook.find(all: true, owner_name: @get('params.login') || @get('user.login') || Travis.lookup('controller:currentUser').get('login'))) - - hooks: (-> - @reloadHooks() unless hooks = @get('allHooks') - @get('allHooks').filter (hook) -> hook.get('admin') - ).property('allHooks.length', 'allHooks') - - hooksWithoutAdmin: (-> - @reloadHooks() unless hooks = @get('allHooks') - @get('allHooks').filter (hook) -> !hook.get('admin') - ).property('allHooks.length', 'allHooks') + @get('controllers.account').reloadHooks() viewUser: -> @connectTab('user') @@ -54,15 +21,3 @@ Travis.ProfileController = Travis.Controller.extend connectTab: (tab) -> viewClass = Travis["#{$.camelize(tab)}View"] @set('tab', tab) - - setParams: (params) -> - @set('params', {}) - @set("params.#{key}", params[key]) for key, value of params - - showPrivateReposHint: (-> - Travis.config.show_repos_hint == 'private' - ) .property() - - showPublicReposHint: (-> - Travis.config.show_repos_hint == 'public' - ) .property() diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index af908324..79d150a1 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -8,9 +8,6 @@ Ember.Router.reopen @_super(url) Travis.Route = Ember.Route.extend - renderFirstSync: -> - @transitionTo 'first_sync' - beforeModel: (transition) -> @auth.autoSignIn() unless @signedIn() @@ -40,7 +37,7 @@ Travis.ApplicationRoute = Travis.Route.extend return true renderFirstSync: -> - @renderFirstSync() + @transitionTo 'first_sync' afterSignIn: -> if transition = @auth.get('afterSignInTransition') @@ -75,29 +72,12 @@ Travis.Router.map -> @route 'auth', path: '/auth' @resource 'profile', path: '/profile', -> - @route 'index', path: '/' - @resource 'account', path: '/:login', -> - @route 'index', path: '/' - @route 'profile', path: '/profile' + @resource 'account', path: '/:login' + @route 'info', path: '/info' @route 'notFound', path: "/*path" -Travis.SetupLastBuild = Ember.Mixin.create - setupController: -> - @repoDidLoad() - @controllerFor('repo').addObserver('repo.isLoaded', this, 'repoDidLoad') - - repoDidLoad: -> - # TODO: it would be nicer to do it with promises - repo = @controllerFor('repo').get('repo') - if repo && repo.get('isLoaded') && !repo.get('lastBuildId') - Ember.run.next => - @render('builds/not_found', into: 'repo', outlet: 'pane') - Travis.RequestsRoute = Travis.Route.extend - renderTemplate: -> - @render 'requests', into: 'repo', outlet: 'pane' - setupController: -> @_super.apply this, arguments @controllerFor('repo').activate('requests') @@ -106,9 +86,6 @@ Travis.RequestsRoute = Travis.Route.extend Travis.Request.fetch repository_id: @modelFor('repo').get('id') Travis.RequestRoute = Travis.Route.extend - renderTemplate: -> - @render 'request', into: 'repo', outlet: 'pane' - setupController: -> @_super.apply this, arguments @controllerFor('repo').activate('request') @@ -128,7 +105,6 @@ Travis.SimpleLayoutRoute = Travis.Route.extend @_super.apply(this, arguments) renderTemplate: -> - @render 'top', outlet: 'top' @_super.apply(this, arguments) Travis.FirstSyncRoute = Travis.SimpleLayoutRoute.extend @@ -143,10 +119,10 @@ Travis.InsufficientOauthPermissionsRoute = Travis.SimpleLayoutRoute.extend existingUser = document.location.hash.match(/#existing[_-]user/) controller.set('existingUser', existingUser) -Travis.IndexCurrentRoute = Travis.Route.extend Travis.SetupLastBuild, +Travis.IndexCurrentRoute = Travis.Route.extend renderTemplate: -> @render 'repo' - @render 'build', into: 'repo', outlet: 'pane' + @render 'build', into: 'repo' setupController: -> @_super.apply this, arguments @@ -170,7 +146,7 @@ Travis.IndexCurrentRoute = Travis.Route.extend Travis.SetupLastBuild, Travis.AbstractBuildsRoute = Travis.Route.extend renderTemplate: -> - @render 'builds', into: 'repo', outlet: 'pane' + @render 'builds' setupController: -> @controllerFor('repo').activate(@get('contentType')) @@ -194,9 +170,6 @@ Travis.PullRequestsRoute = Travis.AbstractBuildsRoute.extend(contentType: 'pull_ Travis.BranchesRoute = Travis.AbstractBuildsRoute.extend(contentType: 'branches') Travis.BuildRoute = Travis.Route.extend - renderTemplate: -> - @render 'build', into: 'repo', outlet: 'pane' - serialize: (model, params) -> id = if model.get then model.get('id') else model @@ -215,9 +188,6 @@ Travis.BuildRoute = Travis.Route.extend Travis.Build.fetch(params.build_id) Travis.JobRoute = Travis.Route.extend - renderTemplate: -> - @render 'job', into: 'repo', outlet: 'pane' - serialize: (model, params) -> id = if model.get then model.get('id') else model @@ -237,13 +207,16 @@ Travis.JobRoute = Travis.Route.extend model: (params) -> Travis.Job.fetch(params.job_id) -Travis.RepoIndexRoute = Travis.Route.extend Travis.SetupLastBuild, +Travis.RepoIndexRoute = Travis.Route.extend setupController: (controller, model) -> @_super.apply this, arguments @controllerFor('repo').activate('current') renderTemplate: -> - @render 'build', into: 'repo', outlet: 'pane' + if @modelFor('repo').get('lastBuildId') + @render 'build' + else + @render 'builds/not_found' Travis.RepoRoute = Travis.Route.extend renderTemplate: -> @@ -280,8 +253,6 @@ Travis.IndexRoute = Travis.Route.extend $('body').attr('id', 'home') @render 'repos', outlet: 'left' - @render 'top', outlet: 'top' - @render 'flash', outlet: 'flash' setupController: (controller)-> @container.lookup('controller:repos').activate() @@ -291,7 +262,6 @@ Travis.StatsRoute = Travis.Route.extend renderTemplate: -> $('body').attr('id', 'stats') - @render 'top', outlet: 'top' @render 'stats' setupController: -> @@ -301,7 +271,6 @@ Travis.NotFoundRoute = Travis.Route.extend renderTemplate: -> $('body').attr('id', 'not-found') - @render 'top', outlet: 'top' @render 'not_found' setupController: -> @@ -310,51 +279,36 @@ Travis.NotFoundRoute = Travis.Route.extend Travis.ProfileRoute = Travis.Route.extend needsAuth: true - setupController: -> + setupController: (controller, model) -> @container.lookup('controller:application').connectLayout('profile') - @container.lookup('controller:accounts').set('content', Travis.Account.find(all: true)) + @controllerFor('accounts').set('model', model) + + model: -> + Travis.Account.fetch(all: true) renderTemplate: -> $('body').attr('id', 'profile') - - @render 'top', outlet: 'top' @render 'accounts', outlet: 'left' - @render 'flash', outlet: 'flash' + @_super.apply(this, arguments) Travis.ProfileIndexRoute = Travis.Route.extend - setupController: -> - @container.lookup('controller:profile').activate 'hooks' - - renderTemplate: -> - @render 'hooks', outlet: 'pane', into: 'profile', controller: 'profile' + redirect: -> + # TODO: setting accounts model in ProfileRoute is wrong, but + # at this stage it's better than what we had before + accounts = @modelFor('profile') + login = @controllerFor('currentUser').get('login') + account = accounts.find (account) -> account.get('login') == login + @transitionTo 'account', account Travis.AccountRoute = Travis.Route.extend setupController: (controller, account) -> - profileController = @container.lookup('controller:profile') - profileController.activate 'hooks' + @_super.apply this, arguments - if account - params = { login: account.get('login') } - profileController.setParams(params) + @controllerFor('profile').activate 'hooks' model: (params) -> - controller = @container.lookup('controller:accounts') - account = controller.findByLogin(params.login) - - if account - account - else - content = Ember.Object.create(login: params.login) - proxy = Ember.ObjectProxy.create(content: content) - - observer = -> - if account = controller.findByLogin(params.login) - controller.removeObserver 'content.length', observer - proxy.set('content', account) - controller.addObserver 'content.length', observer - - proxy + @modelFor('profile').find (account) -> account.get('login') == params.login serialize: (account) -> if account && account.get @@ -362,25 +316,17 @@ Travis.AccountRoute = Travis.Route.extend else {} -Travis.AccountIndexRoute = Travis.Route.extend - setupController: -> - @container.lookup('controller:profile').activate 'hooks' - - renderTemplate: -> - @render 'hooks', outlet: 'pane', into: 'profile' - -Travis.AccountProfileRoute = Travis.Route.extend +Travis.ProfileInfoRoute = Travis.Route.extend setupController: -> @container.lookup('controller:profile').activate 'user' renderTemplate: -> - @render 'user', outlet: 'pane', into: 'profile' + @render 'user' Travis.AuthRoute = Travis.Route.extend renderTemplate: -> $('body').attr('id', 'auth') - @render 'top', outlet: 'top' @render 'auth.signin' setupController: -> diff --git a/assets/scripts/app/templates/profile/tabs/hooks.hbs b/assets/scripts/app/templates/account.hbs similarity index 100% rename from assets/scripts/app/templates/profile/tabs/hooks.hbs rename to assets/scripts/app/templates/account.hbs diff --git a/assets/scripts/app/templates/layouts/home.hbs b/assets/scripts/app/templates/layouts/home.hbs index fdc853ab..4e6fc0fe 100644 --- a/assets/scripts/app/templates/layouts/home.hbs +++ b/assets/scripts/app/templates/layouts/home.hbs @@ -1,5 +1,5 @@
- {{outlet top}} + {{render "top"}}
@@ -7,6 +7,6 @@
- {{outlet flash}} - {{outlet main}} + {{render "flash"}} + {{outlet}}
diff --git a/assets/scripts/app/templates/layouts/profile.hbs b/assets/scripts/app/templates/layouts/profile.hbs index dec97380..3b760c18 100644 --- a/assets/scripts/app/templates/layouts/profile.hbs +++ b/assets/scripts/app/templates/layouts/profile.hbs @@ -1,5 +1,5 @@
- {{outlet top}} + {{render "top"}}
@@ -7,7 +7,7 @@
- {{outlet flash}} + {{render "flash"}} {{outlet main}}
diff --git a/assets/scripts/app/templates/layouts/simple.hbs b/assets/scripts/app/templates/layouts/simple.hbs index 1fc1ae36..cd930a31 100644 --- a/assets/scripts/app/templates/layouts/simple.hbs +++ b/assets/scripts/app/templates/layouts/simple.hbs @@ -1,8 +1,8 @@
- {{outlet top}} + {{render "top"}}
- {{outlet flash}} + {{render "flash"}} {{outlet main}}
diff --git a/assets/scripts/app/templates/loading.hbs b/assets/scripts/app/templates/loading.hbs new file mode 100644 index 00000000..0277cf2e --- /dev/null +++ b/assets/scripts/app/templates/loading.hbs @@ -0,0 +1 @@ +
Loading
diff --git a/assets/scripts/app/templates/profile/accounts.hbs b/assets/scripts/app/templates/profile/accounts.hbs index 09c3a2df..3a02f44f 100644 --- a/assets/scripts/app/templates/profile/accounts.hbs +++ b/assets/scripts/app/templates/profile/accounts.hbs @@ -9,7 +9,7 @@
{{#collection Travis.AccountsListView contentBinding="controller"}} - {{#link-to "account.index" view.account class="name"}}{{view.name}}{{/link-to}} + {{#link-to "account" view.account class="name"}}{{view.name}}{{/link-to}}

Repositories: {{view.account.reposCount}} diff --git a/assets/scripts/app/templates/profile/show.hbs b/assets/scripts/app/templates/profile/show.hbs index ffaade71..39a2c90e 100644 --- a/assets/scripts/app/templates/profile/show.hbs +++ b/assets/scripts/app/templates/profile/show.hbs @@ -3,6 +3,6 @@ {{view Travis.ProfileTabsView}}

- {{outlet pane}} + {{outlet}}
diff --git a/assets/scripts/app/templates/profile/tabs.hbs b/assets/scripts/app/templates/profile/tabs.hbs index 6afb10c8..ac00dfcf 100644 --- a/assets/scripts/app/templates/profile/tabs.hbs +++ b/assets/scripts/app/templates/profile/tabs.hbs @@ -1,17 +1,13 @@