diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index d36adc423b3..6f710dc2a39 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -18,15 +18,23 @@ var controllerOpts = { isSearch: Em.computed.equal('model.filter', 'search'), + searchTerm: function(){ + return this.get('model.params.q'); + }.property('isSearch,model.params,model'), + actions: { changeSort: function(sortBy) { - if (sortBy === this.get('order')) { - this.toggleProperty('ascending'); + if (this.get('isSearch')) { + // TODO we should amend search string here } else { - this.setProperties({ order: sortBy, ascending: false }); + if (sortBy === this.get('order')) { + this.toggleProperty('ascending'); + } else { + this.setProperties({ order: sortBy, ascending: false }); + } + this.get('model').refreshSort(sortBy, this.get('ascending')); } - this.get('model').refreshSort(sortBy, this.get('ascending')); }, // Show newly inserted topics diff --git a/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 index 54f63d6d097..79fb9561bfc 100644 --- a/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 +++ b/app/assets/javascripts/discourse/controllers/navigation/default.js.es6 @@ -19,7 +19,7 @@ export default DiscourseController.extend({ search: function(){ var discovery = this.get('controllers.discovery/topics'); var model = discovery.get('model'); - discovery.set('q', this.get("searchTerm")); + discovery.set('q', this.get('searchTerm')); model.refreshSort(); } } diff --git a/app/assets/javascripts/discourse/controllers/search.js.es6 b/app/assets/javascripts/discourse/controllers/search.js.es6 index bc812e3efef..f465ee5fef0 100644 --- a/app/assets/javascripts/discourse/controllers/search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/search.js.es6 @@ -88,7 +88,13 @@ export default Em.Controller.extend(Presence, { actions: { moreOfType: function(type) { - this.set('typeFilter', type); + if (type === 'topic') { + var term = this.get('term'); + // TODO in topic and in category special handling + Discourse.URL.routeTo("/search?q=" + encodeURIComponent(term)); + } else { + this.set('typeFilter', type); + } }, cancelType: function() { diff --git a/app/assets/javascripts/discourse/models/topic-list.js.es6 b/app/assets/javascripts/discourse/models/topic-list.js.es6 index ab14099c811..d685b2f60cb 100644 --- a/app/assets/javascripts/discourse/models/topic-list.js.es6 +++ b/app/assets/javascripts/discourse/models/topic-list.js.es6 @@ -57,6 +57,8 @@ const TopicList = RestModel.extend({ } this.set('loaded', false); + this.set('params', params); + const store = this.store; store.findFiltered('topicList', {filter: this.get('filter'), params}).then(function(tl) { const newTopics = tl.get('topics'), diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 index 81b94b5a2d4..fefa7a64f41 100644 --- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 +++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 @@ -115,8 +115,12 @@ export default function(filter, extras) { const params = model.get('params'); if (params && Object.keys(params).length) { - topicOpts.order = params.order; - topicOpts.ascending = params.ascending; + if (params.order !== undefined) { + topicOpts.order = params.order; + } + if (params.ascending !== undefined) { + topicOpts.ascending = params.ascending; + } } this.controllerFor('discovery/topics').setProperties(topicOpts); diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs index 6d323d7aabe..341d355d472 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.hbs @@ -5,6 +5,7 @@ hideCategory=hideCategory topics=topics expandExcerpts=expandExcerpts + searchTerm=searchTerm }} {{else}}
diff --git a/app/assets/javascripts/discourse/templates/discovery/topics.hbs b/app/assets/javascripts/discourse/templates/discovery/topics.hbs index ec4c3d822b2..0b6f9735df8 100644 --- a/app/assets/javascripts/discourse/templates/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/topics.hbs @@ -47,6 +47,7 @@ expandGloballyPinned=expandGloballyPinned expandAllPinned=expandAllPinned expandExcerpts=isSearch + searchTerm=searchTerm topics=model.topics}} {{/if}}
diff --git a/app/assets/javascripts/discourse/views/topic-list-item.js.es6 b/app/assets/javascripts/discourse/views/topic-list-item.js.es6 index f70fa98e6d7..c61b96a15b2 100644 --- a/app/assets/javascripts/discourse/views/topic-list-item.js.es6 +++ b/app/assets/javascripts/discourse/views/topic-list-item.js.es6 @@ -65,7 +65,7 @@ export default Discourse.View.extend(StringBuffer, { }, expandPinned: function() { - if (this.get('controller.expandExcerpts')) { + if (this.get('controller.searchTerm')) { return true; } @@ -134,6 +134,17 @@ export default Discourse.View.extend(StringBuffer, { this.set('topic.highlight', false); this.highlight(); } + + var term = this.get('controller.searchTerm'); + const self = this; + if (term) { + var terms = term.split(/\s+/); + terms.forEach(function(word) { + // .main-link a is omitted cause a bit clowny + self.$('.topic-excerpt') + .highlight(word, {element: 'b', className: 'search-highlight'}); + }); + } }.on('didInsertElement') });