BUGFIX/FEATURE: call out context for search.
This commit is contained in:
@@ -9,9 +9,32 @@
|
||||
export default Em.ArrayController.extend(Discourse.Presence, {
|
||||
|
||||
contextChanged: function(){
|
||||
this.setProperties({ term: "", content: [], resultCount: 0, urls: [] });
|
||||
if(this.get('searchContextEnabled')){
|
||||
this._dontSearch = true;
|
||||
this.set('searchContextEnabled', false);
|
||||
this._dontSearch = false;
|
||||
}
|
||||
}.observes("searchContext"),
|
||||
|
||||
searchContextDescription: function(){
|
||||
var ctx = this.get('searchContext');
|
||||
if (ctx) {
|
||||
switch(Em.get(ctx, 'type')) {
|
||||
case 'topic':
|
||||
return I18n.t('search.context.topic');
|
||||
case 'user':
|
||||
return I18n.t('search.context.user', {username: Em.get(ctx, 'user.username')});
|
||||
case 'category':
|
||||
return I18n.t('search.context.category', {category: Em.get(ctx, 'category.name')});
|
||||
}
|
||||
}
|
||||
}.property('searchContext'),
|
||||
|
||||
searchContextEnabledChanged: function(){
|
||||
if(this._dontSearch){ return; }
|
||||
this.newSearchNeeded();
|
||||
}.observes('searchContextEnabled'),
|
||||
|
||||
// If we need to perform another search
|
||||
newSearchNeeded: function() {
|
||||
this.set('noResults', false);
|
||||
@@ -29,9 +52,14 @@ export default Em.ArrayController.extend(Discourse.Presence, {
|
||||
var self = this;
|
||||
this.setProperties({ resultCount: 0, urls: [] });
|
||||
|
||||
var context;
|
||||
if(this.get('searchContextEnabled')){
|
||||
context = this.get('searchContext');
|
||||
}
|
||||
|
||||
return Discourse.Search.forTerm(term, {
|
||||
typeFilter: typeFilter,
|
||||
searchContext: this.get('searchContext')
|
||||
searchContext: context
|
||||
}).then(function(results) {
|
||||
var urls = [];
|
||||
if (results) {
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
{{view 'search-text-field' value=term searchContext=searchContext id="search-term"}}
|
||||
{{#unless loading}}
|
||||
{{view 'search-text-field' value=term searchContextEnabled=searchContextEnabled searchContext=searchContext id="search-term"}}
|
||||
{{#if searchContext}}
|
||||
<div>
|
||||
<label>
|
||||
{{input type="checkbox" name="searchContext" checked=searchContextEnabled}} {{searchContextDescription}}
|
||||
</label>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if loading}}
|
||||
<div class='searching'></div>
|
||||
{{else}}
|
||||
{{#unless noResults}}
|
||||
{{#each resultType in content}}
|
||||
<ul>
|
||||
@@ -21,6 +30,4 @@
|
||||
{{i18n search.no_results}}
|
||||
</div>
|
||||
{{/unless}}
|
||||
{{else}}
|
||||
<div class='searching'><i class='fa fa-spinner fa-spin'></i></div>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
|
||||
@@ -18,16 +18,10 @@ export default TextField.extend({
|
||||
**/
|
||||
placeholder: function() {
|
||||
|
||||
var ctx = this.get('searchContext');
|
||||
if (ctx) {
|
||||
switch(Em.get(ctx, 'type')) {
|
||||
case 'user':
|
||||
return I18n.t('search.prefer.user', {username: Em.get(ctx, 'user.username')});
|
||||
case 'category':
|
||||
return I18n.t('search.prefer.category', {category: Em.get(ctx, 'category.name')});
|
||||
}
|
||||
if(this.get('searchContextEnabled')){
|
||||
return "";
|
||||
}
|
||||
|
||||
return I18n.t('search.title');
|
||||
}.property('searchContext')
|
||||
}.property('searchContextEnabled')
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user