diff --git a/assets/scripts/app/controllers/repos.coffee b/assets/scripts/app/controllers/repos.coffee index f1953204..ccb238f3 100644 --- a/assets/scripts/app/controllers/repos.coffee +++ b/assets/scripts/app/controllers/repos.coffee @@ -61,22 +61,20 @@ Travis.ReposController = Ember.ArrayController.extend [] ).property('currentUser.login') - viewSearch: (params) -> - @set('content', Travis.Repo.search(params.search)) + viewSearch: (phrase) -> + @set('search', phrase) + @set('content', Travis.Repo.search(phrase)) searchObserver: (-> search = @get('search') if search @searchFor search - else - @activate 'recent' - 'recent' ).observes('search') searchFor: (phrase) -> Ember.run.cancel(@searchLater) if @searchLater @searchLater = Ember.run.later(this, (-> - @activate 'search', search: phrase + @transitionTo('index.search', phrase) ), 500) noReposMessage: (-> diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index c83ab422..c498eb1f 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -54,6 +54,7 @@ Travis.Router.map -> @resource 'getting_started' @route 'recent' @route 'my_repositories' + @route 'search', path: '/search/:phrase' @resource 'repo', path: '/:owner/:name', -> @route 'index', path: '/' @resource 'build', path: '/builds/:build_id' @@ -185,6 +186,27 @@ Travis.IndexMyRepositoriesRoute = Travis.IndexTabRoute.extend Travis.IndexRecentRoute = Travis.IndexTabRoute.extend reposTabName: 'recent' +Travis.IndexSearchRoute = Travis.IndexTabRoute.extend + renderTemplate: -> + @render 'repo' + @render 'build', into: 'repo' + + setupController: (controller, searchPhrase) -> + # TODO: this method is almost the same as _super, refactor this + @controllerFor('repo').activate('index') + @controllerFor('repos').activate('search', searchPhrase) + + @currentRepoDidChange() + @controllerFor('repos').addObserver('firstObject', this, 'currentRepoDidChange') + + model: (params) -> + params.phrase + + deactivate: -> + @_super.apply(this, arguments) + + @controllerFor('repos').set('search', undefined) + Travis.AbstractBuildsRoute = Travis.Route.extend renderTemplate: -> @render 'builds'