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';
|
||||
|
||||
export default Ember.Object.extend({
|
||||
searchContextEnabled: false,
|
||||
searchContextEnabled: false, // checkbox to scope search
|
||||
searchContext: null,
|
||||
term: null,
|
||||
highlightTerm: null,
|
||||
|
|
|
@ -172,7 +172,6 @@ export default createWidget('header', {
|
|||
searchVisible: false,
|
||||
hamburgerVisible: false,
|
||||
userVisible: false,
|
||||
contextEnabled: false,
|
||||
ringBackdrop: true
|
||||
};
|
||||
|
||||
|
@ -192,6 +191,19 @@ export default createWidget('header', {
|
|||
flagCount: attrs.flagCount })];
|
||||
|
||||
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 }));
|
||||
} else if (state.hamburgerVisible) {
|
||||
panels.push(this.attach('hamburger-menu'));
|
||||
|
@ -318,6 +330,16 @@ export default createWidget('header', {
|
|||
}
|
||||
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) {
|
||||
// This indicates the checkbox has been clicked, NOT that the context has changed.
|
||||
searchData.typeFilter = null;
|
||||
this.sendWidgetAction('searchMenuContextChanged', enabled);
|
||||
searchData.contextEnabled = enabled;
|
||||
|
|
|
@ -24,3 +24,26 @@ test("search", (assert) => {
|
|||
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…
Reference in New Issue