mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 23:59:55 +08:00
FEATURE: search should default scope to current category or user
This commit is contained in:
parent
476ae57af3
commit
1dda998a4e
@ -1,7 +1,7 @@
|
|||||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
export default Ember.Object.extend({
|
export default Ember.Object.extend({
|
||||||
searchContextEnabled: false,
|
searchContextEnabled: false, // checkbox to scope search
|
||||||
searchContext: null,
|
searchContext: null,
|
||||||
term: null,
|
term: null,
|
||||||
highlightTerm: null,
|
highlightTerm: null,
|
||||||
|
@ -172,7 +172,6 @@ export default createWidget('header', {
|
|||||||
searchVisible: false,
|
searchVisible: false,
|
||||||
hamburgerVisible: false,
|
hamburgerVisible: false,
|
||||||
userVisible: false,
|
userVisible: false,
|
||||||
contextEnabled: false,
|
|
||||||
ringBackdrop: true
|
ringBackdrop: true
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -192,6 +191,19 @@ export default createWidget('header', {
|
|||||||
flagCount: attrs.flagCount })];
|
flagCount: attrs.flagCount })];
|
||||||
|
|
||||||
if (state.searchVisible) {
|
if (state.searchVisible) {
|
||||||
|
const contextType = this.searchContextType();
|
||||||
|
|
||||||
|
if (state.searchContextType !== contextType) {
|
||||||
|
state.contextEnabled = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.searchContextType = contextType;
|
||||||
|
|
||||||
|
if (state.contextEnabled === undefined) {
|
||||||
|
if (contextType === 'category' || contextType === 'user') {
|
||||||
|
state.contextEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
panels.push(this.attach('search-menu', { contextEnabled: state.contextEnabled }));
|
panels.push(this.attach('search-menu', { contextEnabled: state.contextEnabled }));
|
||||||
} else if (state.hamburgerVisible) {
|
} else if (state.hamburgerVisible) {
|
||||||
panels.push(this.attach('hamburger-menu'));
|
panels.push(this.attach('hamburger-menu'));
|
||||||
@ -318,6 +330,16 @@ export default createWidget('header', {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
searchContextType() {
|
||||||
|
const service = this.register.lookup('search-service:main');
|
||||||
|
if (service) {
|
||||||
|
const ctx = service.get('searchContext');
|
||||||
|
if (ctx) {
|
||||||
|
return Ember.get(ctx, 'type');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -170,6 +170,7 @@ export default createWidget('search-menu', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
searchContextChanged(enabled) {
|
searchContextChanged(enabled) {
|
||||||
|
// This indicates the checkbox has been clicked, NOT that the context has changed.
|
||||||
searchData.typeFilter = null;
|
searchData.typeFilter = null;
|
||||||
this.sendWidgetAction('searchMenuContextChanged', enabled);
|
this.sendWidgetAction('searchMenuContextChanged', enabled);
|
||||||
searchData.contextEnabled = enabled;
|
searchData.contextEnabled = enabled;
|
||||||
|
@ -24,3 +24,26 @@ test("search", (assert) => {
|
|||||||
assert.ok(exists('.search-advanced-options'), 'advanced search is expanded');
|
assert.ok(exists('.search-advanced-options'), 'advanced search is expanded');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("search scope checkbox", () => {
|
||||||
|
visit("/c/bug");
|
||||||
|
click('#search-button');
|
||||||
|
andThen(() => {
|
||||||
|
ok(exists('.search-context input:checked'), 'scope to category checkbox is checked');
|
||||||
|
});
|
||||||
|
click('#search-button');
|
||||||
|
|
||||||
|
visit("/t/internationalization-localization/280");
|
||||||
|
click('#search-button');
|
||||||
|
andThen(() => {
|
||||||
|
not(exists('.search-context input:checked'), 'scope to topic checkbox is not checked');
|
||||||
|
});
|
||||||
|
click('#search-button');
|
||||||
|
|
||||||
|
visit("/users/eviltrout");
|
||||||
|
click('#search-button');
|
||||||
|
andThen(() => {
|
||||||
|
ok(exists('.search-context input:checked'), 'scope to user checkbox is checked');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user