FIX: Advanced search should retain search term.

This commit is contained in:
Guo Xiang Tan 2016-10-25 11:46:50 +08:00
parent 55e33414bb
commit adfd9733c6
3 changed files with 45 additions and 14 deletions

View File

@ -44,9 +44,12 @@ createWidget('search-context', {
]));
}
result.push(this.attach('link', { href: Discourse.getURL('/search?expanded=true'),
if (!attrs.contextEnabled) {
result.push(this.attach('link', { href: attrs.url,
label: 'show_help',
className: 'show-help' }));
}
result.push(h('div.clearfix'));
return result;
},

View File

@ -67,7 +67,7 @@ const SearchHelper = {
export default createWidget('search-menu', {
tagName: 'div.search-menu',
fullSearchUrl() {
fullSearchUrl(opts) {
const contextEnabled = searchData.contextEnabled;
const ctx = contextEnabled ? this.searchContext() : null;
@ -77,25 +77,46 @@ export default createWidget('search-menu', {
return;
}
let url = '/search?q=' + encodeURIComponent(searchData.term);
let url = '/search';
const params = [];
if (searchData.term) {
let query = '';
query += `q=${encodeURIComponent(searchData.term)}`;
if (contextEnabled) {
if (this.currentUser &&
ctx.id.toString().toLowerCase() === this.currentUser.username_lower &&
type === "private_messages") {
url += ' in:private';
query += ' in:private';
} else {
url += encodeURIComponent(" " + type + ":" + ctx.id);
query += encodeURIComponent(" " + type + ":" + ctx.id);
}
}
if (query) params.push(query);
}
if (opts && opts.expanded) params.push('expanded=true');
if (params.length > 0) {
url = `${url}?${params.join("&")}`;
}
return Discourse.getURL(url);
},
panelContents() {
const contextEnabled = searchData.contextEnabled;
const results = [this.attach('search-term', { value: searchData.term, contextEnabled }),
this.attach('search-context', { contextEnabled })];
const results = [
this.attach('search-term', { value: searchData.term, contextEnabled }),
this.attach('search-context', {
contextEnabled,
url: this.fullSearchUrl({ expanded: true })
})
];
if (searchData.term) {
if (searchData.loading) {

View File

@ -16,4 +16,11 @@ test("search", (assert) => {
andThen(() => {
assert.ok(exists('.search-menu .results ul li'), 'it shows results');
});
click('.show-help');
andThen(() => {
assert.equal(find('.full-page-search').val(), 'dev', 'it shows the search term');
assert.ok(exists('.search-advanced-options'), 'advanced search is expanded');
});
});