From 338be594bd0bb3225051f330a6632d4226f1db39 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 16:38:33 +0200 Subject: [PATCH 1/9] No need to keep "top" as an outlet. We render the same thing for "top" part of the site for every layout, there is no need to keep it as an outlet, we can just render it directly. --- assets/scripts/app/routes.coffee | 6 ------ assets/scripts/app/templates/layouts/home.hbs | 2 +- assets/scripts/app/templates/layouts/profile.hbs | 2 +- assets/scripts/app/templates/layouts/simple.hbs | 2 +- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index af908324..539114c0 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -128,7 +128,6 @@ Travis.SimpleLayoutRoute = Travis.Route.extend @_super.apply(this, arguments) renderTemplate: -> - @render 'top', outlet: 'top' @_super.apply(this, arguments) Travis.FirstSyncRoute = Travis.SimpleLayoutRoute.extend @@ -280,7 +279,6 @@ Travis.IndexRoute = Travis.Route.extend $('body').attr('id', 'home') @render 'repos', outlet: 'left' - @render 'top', outlet: 'top' @render 'flash', outlet: 'flash' setupController: (controller)-> @@ -291,7 +289,6 @@ Travis.StatsRoute = Travis.Route.extend renderTemplate: -> $('body').attr('id', 'stats') - @render 'top', outlet: 'top' @render 'stats' setupController: -> @@ -301,7 +298,6 @@ Travis.NotFoundRoute = Travis.Route.extend renderTemplate: -> $('body').attr('id', 'not-found') - @render 'top', outlet: 'top' @render 'not_found' setupController: -> @@ -317,7 +313,6 @@ Travis.ProfileRoute = Travis.Route.extend renderTemplate: -> $('body').attr('id', 'profile') - @render 'top', outlet: 'top' @render 'accounts', outlet: 'left' @render 'flash', outlet: 'flash' @_super.apply(this, arguments) @@ -380,7 +375,6 @@ 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/layouts/home.hbs b/assets/scripts/app/templates/layouts/home.hbs index fdc853ab..bb9ed94c 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"}}
diff --git a/assets/scripts/app/templates/layouts/profile.hbs b/assets/scripts/app/templates/layouts/profile.hbs index dec97380..2cf95e02 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"}}
diff --git a/assets/scripts/app/templates/layouts/simple.hbs b/assets/scripts/app/templates/layouts/simple.hbs index 1fc1ae36..e9ec817c 100644 --- a/assets/scripts/app/templates/layouts/simple.hbs +++ b/assets/scripts/app/templates/layouts/simple.hbs @@ -1,5 +1,5 @@
- {{outlet top}} + {{render "top"}}
From 51b9f02da90f79bd7335d197ec7a923cf77c5eaa Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 16:42:05 +0200 Subject: [PATCH 2/9] Don't render "flash" as an outlet. Just as with "top", we always render "flash" into flash outlet, so we can render it straight away. --- assets/scripts/app/routes.coffee | 2 -- assets/scripts/app/templates/layouts/home.hbs | 2 +- assets/scripts/app/templates/layouts/profile.hbs | 2 +- assets/scripts/app/templates/layouts/simple.hbs | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 539114c0..87030421 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -279,7 +279,6 @@ Travis.IndexRoute = Travis.Route.extend $('body').attr('id', 'home') @render 'repos', outlet: 'left' - @render 'flash', outlet: 'flash' setupController: (controller)-> @container.lookup('controller:repos').activate() @@ -314,7 +313,6 @@ Travis.ProfileRoute = Travis.Route.extend $('body').attr('id', 'profile') @render 'accounts', outlet: 'left' - @render 'flash', outlet: 'flash' @_super.apply(this, arguments) Travis.ProfileIndexRoute = Travis.Route.extend diff --git a/assets/scripts/app/templates/layouts/home.hbs b/assets/scripts/app/templates/layouts/home.hbs index bb9ed94c..d33f9aa7 100644 --- a/assets/scripts/app/templates/layouts/home.hbs +++ b/assets/scripts/app/templates/layouts/home.hbs @@ -7,6 +7,6 @@
- {{outlet flash}} + {{render "flash"}} {{outlet main}}
diff --git a/assets/scripts/app/templates/layouts/profile.hbs b/assets/scripts/app/templates/layouts/profile.hbs index 2cf95e02..3b760c18 100644 --- a/assets/scripts/app/templates/layouts/profile.hbs +++ b/assets/scripts/app/templates/layouts/profile.hbs @@ -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 e9ec817c..cd930a31 100644 --- a/assets/scripts/app/templates/layouts/simple.hbs +++ b/assets/scripts/app/templates/layouts/simple.hbs @@ -3,6 +3,6 @@
- {{outlet flash}} + {{render "flash"}} {{outlet main}}
From 27ae7c4ec23914b58e780deae27d82d15b2b7545 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 16:43:15 +0200 Subject: [PATCH 3/9] No need to name outlet 'main' --- assets/scripts/app/templates/layouts/home.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/scripts/app/templates/layouts/home.hbs b/assets/scripts/app/templates/layouts/home.hbs index d33f9aa7..4e6fc0fe 100644 --- a/assets/scripts/app/templates/layouts/home.hbs +++ b/assets/scripts/app/templates/layouts/home.hbs @@ -8,5 +8,5 @@
{{render "flash"}} - {{outlet main}} + {{outlet}}
From de14a03de15c988ff885950a2679ab3c14a44a66 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 17:04:15 +0200 Subject: [PATCH 4/9] Simplify logic for displaying 'no builds for repository' error We use promise when fetching a repository which means that any nested routes already have all the repository data loaded. Thanks to that there is no need to setup observers, we can check what to render right away in RepoIndexRoute --- assets/scripts/app/routes.coffee | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 87030421..0d1da918 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -82,18 +82,6 @@ Travis.Router.map -> @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' @@ -142,7 +130,7 @@ 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' @@ -236,13 +224,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', into: 'repo', outlet: 'pane' + else + @render('builds/not_found', into: 'repo', outlet: 'pane') Travis.RepoRoute = Travis.Route.extend renderTemplate: -> From 42becfc01949e3064fba8f0985f3dcd66404de49 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 17:13:39 +0200 Subject: [PATCH 5/9] Don't specify outlet name for 'pane' outlets Specyfing "pane" as an outlet name here was a legacy thing. In current form it doesn't give us anything and results in more code, as we need to specify outlet everytime we want to render something there. --- assets/scripts/app/routes.coffee | 26 +++++-------------- assets/scripts/app/templates/profile/show.hbs | 2 +- assets/scripts/app/templates/repos/show.hbs | 2 +- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 0d1da918..ed3e7b36 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -83,9 +83,6 @@ Travis.Router.map -> @route 'notFound', path: "/*path" Travis.RequestsRoute = Travis.Route.extend - renderTemplate: -> - @render 'requests', into: 'repo', outlet: 'pane' - setupController: -> @_super.apply this, arguments @controllerFor('repo').activate('requests') @@ -94,9 +91,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') @@ -133,7 +127,7 @@ Travis.InsufficientOauthPermissionsRoute = Travis.SimpleLayoutRoute.extend Travis.IndexCurrentRoute = Travis.Route.extend renderTemplate: -> @render 'repo' - @render 'build', into: 'repo', outlet: 'pane' + @render 'build', into: 'repo' setupController: -> @_super.apply this, arguments @@ -157,7 +151,7 @@ Travis.IndexCurrentRoute = Travis.Route.extend Travis.AbstractBuildsRoute = Travis.Route.extend renderTemplate: -> - @render 'builds', into: 'repo', outlet: 'pane' + @render 'builds' setupController: -> @controllerFor('repo').activate(@get('contentType')) @@ -181,9 +175,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 @@ -202,9 +193,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 @@ -231,9 +219,9 @@ Travis.RepoIndexRoute = Travis.Route.extend renderTemplate: -> if @modelFor('repo').get('lastBuildId') - @render 'build', into: 'repo', outlet: 'pane' + @render 'build' else - @render('builds/not_found', into: 'repo', outlet: 'pane') + @render 'builds/not_found' Travis.RepoRoute = Travis.Route.extend renderTemplate: -> @@ -311,7 +299,7 @@ Travis.ProfileIndexRoute = Travis.Route.extend @container.lookup('controller:profile').activate 'hooks' renderTemplate: -> - @render 'hooks', outlet: 'pane', into: 'profile', controller: 'profile' + @render 'hooks', controller: 'profile' Travis.AccountRoute = Travis.Route.extend setupController: (controller, account) -> @@ -351,14 +339,14 @@ Travis.AccountIndexRoute = Travis.Route.extend @container.lookup('controller:profile').activate 'hooks' renderTemplate: -> - @render 'hooks', outlet: 'pane', into: 'profile' + @render 'hooks' Travis.AccountProfileRoute = 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: -> 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/repos/show.hbs b/assets/scripts/app/templates/repos/show.hbs index ff253def..01dbc972 100644 --- a/assets/scripts/app/templates/repos/show.hbs +++ b/assets/scripts/app/templates/repos/show.hbs @@ -17,7 +17,7 @@ {{/with}}
- {{outlet pane}} + {{outlet}}
{{else}}
Loading
From cc8219ba7a9733e633ae5887b0b16b216340cf09 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 17:16:38 +0200 Subject: [PATCH 6/9] No need to add renderFirstSync method --- assets/scripts/app/routes.coffee | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index ed3e7b36..a5261786 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') From a39d03192575e0e70a44a72f48b156e6592cc25e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 17:30:54 +0200 Subject: [PATCH 7/9] Don't specify index routes They're generated by default --- assets/scripts/app/routes.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index a5261786..07dccbce 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -72,9 +72,7 @@ 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' @route 'notFound', path: "/*path" From 459089f0cd934f8ca1306e43fdffeebbef45d947 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 23 May 2014 18:10:41 +0200 Subject: [PATCH 8/9] Make profiles code a bit simpler We don't need to nest "profile" tab in account view --- assets/scripts/app/routes.coffee | 21 ++++++++----------- assets/scripts/app/templates/profile/tabs.hbs | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 07dccbce..9c1b59ce 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -73,7 +73,7 @@ Travis.Router.map -> @resource 'profile', path: '/profile', -> @resource 'account', path: '/:login', -> - @route 'profile', path: '/profile' + @route 'info', path: '/info' @route 'notFound', path: "/*path" @@ -297,14 +297,6 @@ Travis.ProfileIndexRoute = Travis.Route.extend @render 'hooks', controller: 'profile' Travis.AccountRoute = Travis.Route.extend - setupController: (controller, account) -> - profileController = @container.lookup('controller:profile') - profileController.activate 'hooks' - - if account - params = { login: account.get('login') } - profileController.setParams(params) - model: (params) -> controller = @container.lookup('controller:accounts') account = controller.findByLogin(params.login) @@ -330,13 +322,18 @@ Travis.AccountRoute = Travis.Route.extend {} Travis.AccountIndexRoute = Travis.Route.extend - setupController: -> - @container.lookup('controller:profile').activate 'hooks' + setupController: (controller) -> + profileController = @container.lookup('controller:profile') + profileController.activate 'hooks' + + if account = @modelFor('account') + params = { login: account.get('login') } + profileController.setParams(params) renderTemplate: -> @render 'hooks' -Travis.AccountProfileRoute = Travis.Route.extend +Travis.ProfileInfoRoute = Travis.Route.extend setupController: -> @container.lookup('controller:profile').activate 'user' diff --git a/assets/scripts/app/templates/profile/tabs.hbs b/assets/scripts/app/templates/profile/tabs.hbs index 6afb10c8..eb45d004 100644 --- a/assets/scripts/app/templates/profile/tabs.hbs +++ b/assets/scripts/app/templates/profile/tabs.hbs @@ -11,7 +11,7 @@ {{#if view.displayUser}}
  • - {{#link-to "account.profile" view.account}}Profile{{/link-to}} + {{#link-to "profile.info"}}Profile{{/link-to}}
  • {{/if}} From 52dea338ee256466efdb7aacfa4c2bd11131e65b Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 27 May 2014 19:05:56 +0200 Subject: [PATCH 9/9] Refactor handling accounts This commit changes a way we load accounts for profile view: * instead of using several views with profile controllers, always use one view to render hooks. This is achieved by redirecting to individual account page from main profile page (for example when going into /profile as a user drogus, the effective address will be /profile/drogus) * instead of using observers to wait for accounts to load I just use promise in ProfileRoute#model which effectively ensures that accounts are loaded at the time we want to select an individual account * profile controller is split into profile and account controller --- assets/scripts/app/controllers.coffee | 1 + assets/scripts/app/controllers/account.coffee | 35 ++++++++++++ .../app/controllers/account_index.coffee | 20 ------- .../scripts/app/controllers/accounts.coffee | 3 - assets/scripts/app/controllers/profile.coffee | 51 +---------------- assets/scripts/app/routes.coffee | 57 +++++++------------ .../{profile/tabs/hooks.hbs => account.hbs} | 0 assets/scripts/app/templates/loading.hbs | 1 + .../app/templates/profile/accounts.hbs | 2 +- assets/scripts/app/templates/profile/tabs.hbs | 6 +- assets/scripts/app/views/accounts.coffee | 2 +- assets/scripts/app/views/profile.coffee | 4 +- 12 files changed, 64 insertions(+), 118 deletions(-) create mode 100644 assets/scripts/app/controllers/account.coffee delete mode 100644 assets/scripts/app/controllers/account_index.coffee rename assets/scripts/app/templates/{profile/tabs/hooks.hbs => account.hbs} (100%) create mode 100644 assets/scripts/app/templates/loading.hbs 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 9c1b59ce..79d150a1 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -72,7 +72,7 @@ Travis.Router.map -> @route 'auth', path: '/auth' @resource 'profile', path: '/profile', -> - @resource 'account', path: '/:login', -> + @resource 'account', path: '/:login' @route 'info', path: '/info' @route 'notFound', path: "/*path" @@ -279,41 +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 'accounts', outlet: 'left' + @_super.apply(this, arguments) Travis.ProfileIndexRoute = Travis.Route.extend - setupController: -> - @container.lookup('controller:profile').activate 'hooks' - - renderTemplate: -> - @render 'hooks', 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) -> + @_super.apply this, arguments + + @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 @@ -321,18 +316,6 @@ Travis.AccountRoute = Travis.Route.extend else {} -Travis.AccountIndexRoute = Travis.Route.extend - setupController: (controller) -> - profileController = @container.lookup('controller:profile') - profileController.activate 'hooks' - - if account = @modelFor('account') - params = { login: account.get('login') } - profileController.setParams(params) - - renderTemplate: -> - @render 'hooks' - Travis.ProfileInfoRoute = Travis.Route.extend setupController: -> @container.lookup('controller:profile').activate 'user' 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/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/tabs.hbs b/assets/scripts/app/templates/profile/tabs.hbs index eb45d004..ac00dfcf 100644 --- a/assets/scripts/app/templates/profile/tabs.hbs +++ b/assets/scripts/app/templates/profile/tabs.hbs @@ -1,11 +1,7 @@

    • - {{#with view.account}} - {{#if login}} - {{#link-to "account.index" this}}Repositories{{/link-to}} - {{/if}} - {{/with}} + {{#link-to "account" account}}Repositories{{/link-to}}
    • {{#if view.displayUser}} diff --git a/assets/scripts/app/views/accounts.coffee b/assets/scripts/app/views/accounts.coffee index 5606f814..cceb899b 100644 --- a/assets/scripts/app/views/accounts.coffee +++ b/assets/scripts/app/views/accounts.coffee @@ -31,4 +31,4 @@ ).property('account.login') click: -> - @get('controller').transitionToRoute("account", @get('account.login')) \ No newline at end of file + @get('controller').transitionToRoute("account", @get('account.login')) diff --git a/assets/scripts/app/views/profile.coffee b/assets/scripts/app/views/profile.coffee index 879a163b..e1dcbc67 100644 --- a/assets/scripts/app/views/profile.coffee +++ b/assets/scripts/app/views/profile.coffee @@ -22,8 +22,6 @@ Travis.reopen 'active' if @get('tab') == 'user' ).property('tab') - accountBinding: 'controller.account' - displayUser: (-> @get('controller.account.login') == @get('controller.user.login') ).property('controller.account.login', 'controller.user.login') @@ -42,4 +40,4 @@ Travis.reopen gravatarUrl: (-> "#{location.protocol}//www.gravatar.com/avatar/#{@get('user.gravatarId')}?s=200&d=mm" - ).property('user.gravatarId') \ No newline at end of file + ).property('user.gravatarId')