mirror of
https://github.com/discourse/discourse.git
synced 2025-02-26 05:00:11 +08:00
UX: Display a message when the search term is too short on full page
This commit is contained in:
parent
28436a604a
commit
fd3a8583dd
@ -26,6 +26,7 @@ export default Ember.Controller.extend({
|
|||||||
searching: false,
|
searching: false,
|
||||||
sortOrder: 0,
|
sortOrder: 0,
|
||||||
sortOrders: SortOrders,
|
sortOrders: SortOrders,
|
||||||
|
invalidSearch: false,
|
||||||
|
|
||||||
@computed('model.posts')
|
@computed('model.posts')
|
||||||
resultCount(posts) {
|
resultCount(posts) {
|
||||||
@ -69,11 +70,6 @@ export default Ember.Controller.extend({
|
|||||||
return isValidSearchTerm(q);
|
return isValidSearchTerm(q);
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed('searchTerm', 'searching')
|
|
||||||
searchButtonDisabled(searchTerm, searching) {
|
|
||||||
return !!(searching || !isValidSearchTerm(searchTerm));
|
|
||||||
},
|
|
||||||
|
|
||||||
@computed('q')
|
@computed('q')
|
||||||
noSortQ(q) {
|
noSortQ(q) {
|
||||||
if (q) {
|
if (q) {
|
||||||
@ -107,7 +103,7 @@ export default Ember.Controller.extend({
|
|||||||
@observes('sortOrder')
|
@observes('sortOrder')
|
||||||
triggerSearch() {
|
triggerSearch() {
|
||||||
if (this._searchOnSortChange) {
|
if (this._searchOnSortChange) {
|
||||||
this.search();
|
this._search();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -147,14 +143,21 @@ export default Ember.Controller.extend({
|
|||||||
return this.currentUser && !this.site.mobileView;
|
return this.currentUser && !this.site.mobileView;
|
||||||
},
|
},
|
||||||
|
|
||||||
search(){
|
_search() {
|
||||||
if (this.get("searching")) return;
|
if (this.get("searching")) { return; }
|
||||||
this.set("searching", true);
|
|
||||||
|
|
||||||
|
this.set('invalidSearch', false);
|
||||||
|
const searchTerm = this.get('searchTerm');
|
||||||
|
if (!isValidSearchTerm(searchTerm)) {
|
||||||
|
this.set('invalidSearch', true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.set("searching", true);
|
||||||
this.set('bulkSelectEnabled', false);
|
this.set('bulkSelectEnabled', false);
|
||||||
this.get('selected').clear();
|
this.get('selected').clear();
|
||||||
|
|
||||||
var args = { q: this.get("searchTerm") };
|
var args = { q: searchTerm };
|
||||||
|
|
||||||
const sortOrder = this.get("sortOrder");
|
const sortOrder = this.get("sortOrder");
|
||||||
if (sortOrder && SortOrders[sortOrder].term) {
|
if (sortOrder && SortOrders[sortOrder].term) {
|
||||||
@ -203,18 +206,13 @@ export default Ember.Controller.extend({
|
|||||||
this.get('selected').clear();
|
this.get('selected').clear();
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh() {
|
|
||||||
this.search();
|
|
||||||
},
|
|
||||||
|
|
||||||
showSearchHelp() {
|
showSearchHelp() {
|
||||||
// TODO: dupe code should be centralized
|
// TODO: dupe code should be centralized
|
||||||
ajax("/static/search_help.html", { dataType: 'html' }).then(model => showModal('searchHelp', { model }));
|
ajax("/static/search_help.html", { dataType: 'html' }).then(model => showModal('searchHelp', { model }));
|
||||||
},
|
},
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
if (this.get("searchButtonDisabled")) return;
|
this._search();
|
||||||
this.search();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<div class="search row clearfix">
|
<div class="search row clearfix">
|
||||||
{{search-text-field value=searchTerm class="full-page-search input-xxlarge search no-blur" action="search" hasAutofocus=hasAutofocus}}
|
{{search-text-field value=searchTerm class="full-page-search input-xxlarge search no-blur" action="search" hasAutofocus=hasAutofocus}}
|
||||||
{{d-button action="search" icon="search" class="btn-primary" disabled=searchButtonDisabled}}
|
{{d-button action="search" icon="search" class="btn-primary" disabled=searching}}
|
||||||
|
|
||||||
{{#if canCreateTopic}}
|
{{#if canCreateTopic}}
|
||||||
<span class="new-topic-btn">{{d-button id="create-topic" class="btn-default" action="createTopic" actionParam=searchTerm icon="plus" label="topic.create"}}</span>
|
<span class="new-topic-btn">{{d-button id="create-topic" class="btn-default" action="createTopic" actionParam=searchTerm icon="plus" label="topic.create"}}</span>
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
{{#if canBulkSelect}}
|
{{#if canBulkSelect}}
|
||||||
{{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"}}
|
||||||
{{bulk-select-button selected=selected action="refresh"}}
|
{{bulk-select-button selected=selected action="search"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -19,6 +19,12 @@
|
|||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if invalidSearch}}
|
||||||
|
<div class='fps-invalid'>
|
||||||
|
{{i18n "search.too_short"}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if context}}
|
{{#if context}}
|
||||||
<div class='fps-search-context'>
|
<div class='fps-search-context'>
|
||||||
<label>
|
<label>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
.fps-invalid {
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
.fps-result {
|
.fps-result {
|
||||||
|
|
||||||
.author {
|
.author {
|
||||||
|
@ -1185,6 +1185,7 @@ en:
|
|||||||
most_liked: "Most Liked"
|
most_liked: "Most Liked"
|
||||||
select_all: "Select All"
|
select_all: "Select All"
|
||||||
clear_all: "Clear All"
|
clear_all: "Clear All"
|
||||||
|
too_short: "Sorry, your search term is too short. Please try a longer query."
|
||||||
result_count:
|
result_count:
|
||||||
one: "1 result for <span class='term'>\"{{term}}\"</span>"
|
one: "1 result for <span class='term'>\"{{term}}\"</span>"
|
||||||
other: "{{count}} results for <span class='term'>\"{{term}}\"</span>"
|
other: "{{count}} results for <span class='term'>\"{{term}}\"</span>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user