mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 04:31:56 +08:00
Improve full page search handling
- add highlighting, clean up url
This commit is contained in:
parent
4cb8f0ffdb
commit
0768a3b2e9
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
hideCategory=hideCategory
|
||||
topics=topics
|
||||
expandExcerpts=expandExcerpts
|
||||
searchTerm=searchTerm
|
||||
}}
|
||||
{{else}}
|
||||
<div class='alert alert-info'>
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
expandGloballyPinned=expandGloballyPinned
|
||||
expandAllPinned=expandAllPinned
|
||||
expandExcerpts=isSearch
|
||||
searchTerm=searchTerm
|
||||
topics=model.topics}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
|
@ -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')
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user