mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
REFACTOR: remove hacky search from discovery
This commit is contained in:
@@ -16,37 +16,15 @@ const controllerOpts = {
|
||||
expandGloballyPinned: false,
|
||||
expandAllPinned: false,
|
||||
|
||||
isSearch: Em.computed.equal('model.filter', 'search'),
|
||||
|
||||
searchTerm: function(){
|
||||
return this.get('model.params.q');
|
||||
}.property('isSearch,model.params,model'),
|
||||
|
||||
actions: {
|
||||
|
||||
changeSort(sortBy) {
|
||||
if (this.get('isSearch')) {
|
||||
let term = this.get('searchTerm');
|
||||
let order;
|
||||
|
||||
if (sortBy === 'activity') { order = 'latest'; }
|
||||
if (sortBy === 'views') { order = 'views'; }
|
||||
|
||||
if (order && term.indexOf("order:" + order) === -1) {
|
||||
term = term.replace(/order:[a-z]+/, '');
|
||||
term = term.trim() + " order:" + order;
|
||||
this.set('model.params.q', term);
|
||||
this.get('model').refreshSort();
|
||||
}
|
||||
|
||||
if (sortBy === this.get('order')) {
|
||||
this.toggleProperty('ascending');
|
||||
} else {
|
||||
if (sortBy === this.get('order')) {
|
||||
this.toggleProperty('ascending');
|
||||
} else {
|
||||
this.setProperties({ order: sortBy, ascending: false });
|
||||
}
|
||||
this.get('model').refreshSort(sortBy, this.get('ascending'));
|
||||
this.setProperties({ order: sortBy, ascending: false });
|
||||
}
|
||||
this.get('model').refreshSort(sortBy, this.get('ascending'));
|
||||
},
|
||||
|
||||
// Show newly inserted topics
|
||||
|
||||
@@ -24,7 +24,7 @@ export default DiscourseController.extend({
|
||||
this.set('q', this.get('searchTerm'));
|
||||
this.set('model', null);
|
||||
|
||||
Discourse.ajax('/search2', {data: {q: this.get('searchTerm')}}).then(function(results) {
|
||||
Discourse.ajax('/search', {data: {q: this.get('searchTerm')}}).then(function(results) {
|
||||
self.set('model', translateResults(results) || {});
|
||||
self.set('model.q', self.get('q'));
|
||||
});
|
||||
|
||||
@@ -9,18 +9,6 @@ export default DiscourseController.extend({
|
||||
|
||||
navItems: function() {
|
||||
return Discourse.NavItem.buildList(null, {filterMode: this.get('filterMode')});
|
||||
}.property('filterMode'),
|
||||
}.property('filterMode')
|
||||
|
||||
isSearch: Em.computed.equal('filterMode', 'search'),
|
||||
|
||||
searchTerm: Em.computed.alias('controllers.discovery/topics.model.params.q'),
|
||||
|
||||
actions: {
|
||||
search: function(){
|
||||
var discovery = this.get('controllers.discovery/topics');
|
||||
var model = discovery.get('model');
|
||||
discovery.set('q', this.get('searchTerm'));
|
||||
model.refreshSort();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -100,5 +100,5 @@ export default function() {
|
||||
|
||||
this.resource('queued-posts', { path: '/queued-posts' });
|
||||
|
||||
this.route('full-page-search', {path: '/search2'});
|
||||
this.route('full-page-search', {path: '/search'});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export default Discourse.Route.extend({
|
||||
},
|
||||
model: function(params) {
|
||||
return PreloadStore.getAndRemove("search", function() {
|
||||
return Discourse.ajax('/search2', {data: {q: params.q}});
|
||||
return Discourse.ajax('/search', {data: {q: params.q}});
|
||||
}).then(function(results){
|
||||
var model = translateResults(results) || {};
|
||||
model.q = params.q;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
hideCategory=hideCategory
|
||||
topics=topics
|
||||
expandExcerpts=expandExcerpts
|
||||
searchTerm=searchTerm
|
||||
}}
|
||||
{{else}}
|
||||
<div class='alert alert-info'>
|
||||
|
||||
@@ -46,8 +46,6 @@
|
||||
selected=selected
|
||||
expandGloballyPinned=expandGloballyPinned
|
||||
expandAllPinned=expandAllPinned
|
||||
expandExcerpts=isSearch
|
||||
searchTerm=searchTerm
|
||||
topics=model.topics}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
{{#if isSearch}}
|
||||
<div class="search row">
|
||||
{{input type="text" value=searchTerm class="input-xxlarge search" action="search"}}
|
||||
<button {{action "search"}} class="btn btn-primary"><i class='fa fa-search'></i></button>
|
||||
</div>
|
||||
{{else}}
|
||||
{{bread-crumbs categories=categories}}
|
||||
|
||||
{{navigation-bar navItems=navItems filterMode=filterMode}}
|
||||
@@ -11,4 +5,3 @@
|
||||
{{#if canCreateTopic}}
|
||||
<button id="create-topic" class='btn btn-default' {{action "createTopic"}}><i class='fa fa-plus'></i>{{i18n 'topic.create'}}</button>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
@@ -9,7 +9,8 @@ export default Ember.View.extend(ScrollTop, {
|
||||
if(!_.isEmpty(term)) {
|
||||
Em.run.next(function(){
|
||||
self.$('.blurb').highlight(term.split(/\s+/), {className: 'search-highlight'});
|
||||
self.$('.topic-title').highlight(term.split(/\s+/), {className: 'search-highlight'} );
|
||||
// we can highlight title, but I feel its a bit too much
|
||||
// self.$('.topic-title').highlight(term.split(/\s+/), {className: 'search-highlight'} );
|
||||
});
|
||||
}
|
||||
}.observes('controller.model').on('didInsertElement')
|
||||
|
||||
@@ -65,10 +65,6 @@ export default Discourse.View.extend(StringBuffer, {
|
||||
},
|
||||
|
||||
expandPinned: function() {
|
||||
if (this.get('controller.searchTerm')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const pinned = this.get('topic.pinned');
|
||||
if (!pinned) {
|
||||
return false;
|
||||
@@ -134,22 +130,6 @@ 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+/);
|
||||
// .main-link a is omitted cause a bit clowny
|
||||
var excerpt = self.$('.topic-excerpt');
|
||||
// some sane wrapping
|
||||
excerpt.text(excerpt.text().replace(/\S{40,}/g, function(match){
|
||||
return match.replace(/(\S)/g, "$1\u200B");
|
||||
}));
|
||||
|
||||
terms.forEach(function(word) {
|
||||
excerpt.highlight(word, {element: 'b', className: 'search-highlight'});
|
||||
});
|
||||
}
|
||||
}.on('didInsertElement')
|
||||
|
||||
});
|
||||
|
||||
@@ -106,7 +106,6 @@ class Topic < ActiveRecord::Base
|
||||
has_one :first_post, -> {where post_number: 1}, class_name: Post
|
||||
|
||||
# When we want to temporarily attach some data to a forum topic (usually before serialization)
|
||||
attr_accessor :search_data
|
||||
attr_accessor :user_data
|
||||
|
||||
attr_accessor :posters # TODO: can replace with posters_summary once we remove old list code
|
||||
|
||||
@@ -11,7 +11,6 @@ class ListableTopicSerializer < BasicTopicSerializer
|
||||
:bumped_at,
|
||||
:unseen,
|
||||
:last_read_post_number,
|
||||
:linked_post_number,
|
||||
:unread,
|
||||
:new_posts,
|
||||
:pinned,
|
||||
@@ -79,19 +78,7 @@ class ListableTopicSerializer < BasicTopicSerializer
|
||||
end
|
||||
|
||||
def excerpt
|
||||
if object.search_data
|
||||
object.search_data[:excerpt]
|
||||
else
|
||||
object.excerpt
|
||||
end
|
||||
end
|
||||
|
||||
def include_linked_post_number?
|
||||
object.search_data
|
||||
end
|
||||
|
||||
def linked_post_number
|
||||
object.search_data[:post_number]
|
||||
object.excerpt
|
||||
end
|
||||
|
||||
alias :include_last_read_post_number? :has_user_data
|
||||
@@ -107,7 +94,7 @@ class ListableTopicSerializer < BasicTopicSerializer
|
||||
alias :include_new_posts? :has_user_data
|
||||
|
||||
def include_excerpt?
|
||||
pinned || object.search_data
|
||||
pinned
|
||||
end
|
||||
|
||||
def pinned
|
||||
|
||||
Reference in New Issue
Block a user