From 4dbd06502615b8891f44706cd0ed61742e8edbfc Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 2 Apr 2015 16:02:07 +1100 Subject: [PATCH] work-in-progress full page search --- .../controllers/navigation/default.js.es6 | 18 ++++++++++++++++-- .../javascripts/discourse/models/nav_item.js | 10 +++++++++- .../javascripts/discourse/models/topic_list.js | 4 ++-- .../discourse/templates/navigation/default.hbs | 7 +++++++ app/assets/stylesheets/desktop/topic-list.scss | 5 +++++ config/locales/client.en.yml | 4 ++++ lib/discourse.rb | 2 +- lib/topic_query.rb | 4 ++++ 8 files changed, 48 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 index 0824990e5a7..b2b612a422a 100644 --- a/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 +++ b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 @@ -1,11 +1,25 @@ import DiscourseController from 'discourse/controllers/controller'; export default DiscourseController.extend({ + needs: ['discovery', 'discovery/topics'], categories: function() { return Discourse.Category.list(); }.property(), navItems: function() { - return Discourse.NavItem.buildList(); - }.property() + return Discourse.NavItem.buildList(null, {filterMode: this.get('filterMode')}); + }.property('filterMode'), + + isSearch: Em.computed.equal('filterMode', 'search'), + + searchTerm: Em.computed.alias('controllers.discovery/topics.model.params.search'), + + actions: { + search: function(){ + var discovery = this.get('controllers.discovery/topics'); + var model = discovery.get('model'); + discovery.set('search', this.get("searchTerm")); + model.refreshSort(); + } + } }); diff --git a/app/assets/javascripts/discourse/models/nav_item.js b/app/assets/javascripts/discourse/models/nav_item.js index c081fbcd2f8..41280548f76 100644 --- a/app/assets/javascripts/discourse/models/nav_item.js +++ b/app/assets/javascripts/discourse/models/nav_item.js @@ -84,7 +84,15 @@ Discourse.NavItem.reopenClass({ args = args || {}; if (category) { args.category = category } - return Discourse.SiteSettings.top_menu.split("|").map(function(i) { + var items = Discourse.SiteSettings.top_menu.split("|"); + + if (args.filterMode && !_.some(items, function(i){ + return i.indexOf(args.filterMode) !== -1; + })) { + items.push(args.filterMode); + } + + return items.map(function(i) { return Discourse.NavItem.fromText(i, args); }).filter(function(i) { return i !== null && !(category && i.get("name").indexOf("categor") === 0); diff --git a/app/assets/javascripts/discourse/models/topic_list.js b/app/assets/javascripts/discourse/models/topic_list.js index 01e3f12697c..2b970d94369 100644 --- a/app/assets/javascripts/discourse/models/topic_list.js +++ b/app/assets/javascripts/discourse/models/topic_list.js @@ -41,8 +41,8 @@ Discourse.TopicList = Discourse.Model.extend({ var self = this, params = this.get('params'); - params.order = order; - params.ascending = ascending; + params.order = order || params.order; + params.ascending = ascending || params.ascending || true; this.set('loaded', false); var finder = finderFor(this.get('filter'), params); diff --git a/app/assets/javascripts/discourse/templates/navigation/default.hbs b/app/assets/javascripts/discourse/templates/navigation/default.hbs index bd3015d44a6..d95de6b0435 100644 --- a/app/assets/javascripts/discourse/templates/navigation/default.hbs +++ b/app/assets/javascripts/discourse/templates/navigation/default.hbs @@ -1,3 +1,9 @@ +{{#if isSearch}} + +{{else}} {{bread-crumbs categories=categories}}