mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 12:11:16 -05:00
UX: Don't allow search if searchTerm is not valid.
This commit is contained in:
parent
4252a2ee1e
commit
b4974f5876
5 changed files with 24 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
import {searchForTerm, searchContextDescription} from 'discourse/lib/search';
|
import {searchForTerm, searchContextDescription, isValidSearchTerm } from 'discourse/lib/search';
|
||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
import showModal from 'discourse/lib/show-modal';
|
import showModal from 'discourse/lib/show-modal';
|
||||||
|
@ -61,8 +61,8 @@ export default Ember.Component.extend({
|
||||||
@observes('searchService.term', 'typeFilter')
|
@observes('searchService.term', 'typeFilter')
|
||||||
newSearchNeeded() {
|
newSearchNeeded() {
|
||||||
this.set('noResults', false);
|
this.set('noResults', false);
|
||||||
const term = (this.get('searchService.term') || '').trim();
|
const term = this.get('searchService.term')
|
||||||
if (term.length >= Discourse.SiteSettings.min_search_term_length) {
|
if (isValidSearchTerm(term)) {
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
Ember.run.debounce(this, 'searchTerm', term, this.get('typeFilter'), 400);
|
Ember.run.debounce(this, 'searchTerm', term, this.get('typeFilter'), 400);
|
||||||
} else {
|
} else {
|
||||||
|
@ -154,8 +154,7 @@ export default Ember.Component.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
keyDown(e) {
|
keyDown(e) {
|
||||||
const term = this.get('searchService.term');
|
if (e.which === 13 && isValidSearchTerm(this.get('searchService.term'))) {
|
||||||
if (e.which === 13 && term && term.length >= this.siteSettings.min_search_term_length) {
|
|
||||||
this.set('visible', false);
|
this.set('visible', false);
|
||||||
this.send('fullSearch');
|
this.send('fullSearch');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { translateResults, searchContextDescription, getSearchKey } from "discourse/lib/search";
|
import { translateResults, searchContextDescription, getSearchKey, isValidSearchTerm } from "discourse/lib/search";
|
||||||
import showModal from 'discourse/lib/show-modal';
|
import showModal from 'discourse/lib/show-modal';
|
||||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
import Category from 'discourse/models/category';
|
import Category from 'discourse/models/category';
|
||||||
|
@ -37,7 +37,12 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
@computed('q')
|
@computed('q')
|
||||||
searchActive(q){
|
searchActive(q){
|
||||||
return q && q.length > 0;
|
return isValidSearchTerm(q);
|
||||||
|
},
|
||||||
|
|
||||||
|
@computed('searchTerm')
|
||||||
|
isNotValidSearchTerm(searchTerm) {
|
||||||
|
return !isValidSearchTerm(searchTerm);
|
||||||
},
|
},
|
||||||
|
|
||||||
@observes('model')
|
@observes('model')
|
||||||
|
@ -129,6 +134,7 @@ export default Ember.Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
|
if (this.get("isNotValidSearchTerm")) return;
|
||||||
this.search();
|
this.search();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,4 +106,12 @@ const getSearchKey = function(args){
|
||||||
((args.searchContext && args.searchContext.id) || "")
|
((args.searchContext && args.searchContext.id) || "")
|
||||||
};
|
};
|
||||||
|
|
||||||
export { searchForTerm, searchContextDescription, getSearchKey };
|
const isValidSearchTerm = function(searchTerm) {
|
||||||
|
if (searchTerm) {
|
||||||
|
return searchTerm.trim().length >= Discourse.SiteSettings.min_search_term_length;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { searchForTerm, searchContextDescription, getSearchKey, isValidSearchTerm };
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { translateResults, getSearchKey } from "discourse/lib/search";
|
import { translateResults, getSearchKey, isValidSearchTerm } from "discourse/lib/search";
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
queryParams: { q: {}, context_id: {}, context: {} },
|
queryParams: { q: {}, context_id: {}, context: {} },
|
||||||
|
@ -23,7 +23,7 @@ export default Discourse.Route.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
return PreloadStore.getAndRemove("search", function() {
|
return PreloadStore.getAndRemove("search", function() {
|
||||||
if (params.q && params.q.length > 2) {
|
if (isValidSearchTerm(params.q)) {
|
||||||
return Discourse.ajax("/search", { data: args });
|
return Discourse.ajax("/search", { data: args });
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="search row clearfix">
|
<div class="search row clearfix">
|
||||||
{{input type="text" value=searchTerm class="input-xxlarge search no-blur" action="search"}}
|
{{input type="text" value=searchTerm class="input-xxlarge search no-blur" action="search"}}
|
||||||
{{d-button action="search" icon="search" class="btn-primary"}}
|
{{d-button action="search" icon="search" class="btn-primary" disabled=isNotValidSearchTerm}}
|
||||||
{{#if canBulkSelect}}
|
{{#if canBulkSelect}}
|
||||||
{{#if model.posts}}
|
{{#if model.posts}}
|
||||||
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
|
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
|
||||||
|
|
Loading…
Reference in a new issue