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) {
label: 'show_help', result.push(this.attach('link', { href: attrs.url,
className: 'show-help' })); label: 'show_help',
className: 'show-help' }));
}
result.push(h('div.clearfix')); result.push(h('div.clearfix'));
return result; return result;
}, },

View File

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

View File

@ -16,4 +16,11 @@ test("search", (assert) => {
andThen(() => { andThen(() => {
assert.ok(exists('.search-menu .results ul li'), 'it shows results'); 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');
});
}); });