FIX: Advanced Search to utilize Category Selector so it can distinguish uncategorized from no category selected
This commit is contained in:
parent
e07dfe16d7
commit
f59c11b4ab
|
@ -60,7 +60,7 @@ export default Em.Component.extend({
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
searchedTerms: {
|
searchedTerms: {
|
||||||
username: '',
|
username: '',
|
||||||
category: null,
|
category: '',
|
||||||
group: [],
|
group: [],
|
||||||
badge: [],
|
badge: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
|
@ -167,21 +167,21 @@ export default Em.Component.extend({
|
||||||
const userInput = Discourse.Category.findBySlug(subcategories[1], subcategories[0]);
|
const userInput = Discourse.Category.findBySlug(subcategories[1], subcategories[0]);
|
||||||
if ((!existingInput && userInput)
|
if ((!existingInput && userInput)
|
||||||
|| (existingInput && userInput && existingInput.id !== userInput.id))
|
|| (existingInput && userInput && existingInput.id !== userInput.id))
|
||||||
this.set('searchedTerms.category', userInput.id);
|
this.set('searchedTerms.category', [userInput]);
|
||||||
} else
|
} else
|
||||||
if (isNaN(subcategories)) {
|
if (isNaN(subcategories)) {
|
||||||
const userInput = Discourse.Category.findSingleBySlug(subcategories[0]);
|
const userInput = Discourse.Category.findSingleBySlug(subcategories[0]);
|
||||||
if ((!existingInput && userInput)
|
if ((!existingInput && userInput)
|
||||||
|| (existingInput && userInput && existingInput.id !== userInput.id))
|
|| (existingInput && userInput && existingInput.id !== userInput.id))
|
||||||
this.set('searchedTerms.category', userInput.id);
|
this.set('searchedTerms.category', [userInput]);
|
||||||
} else {
|
} else {
|
||||||
const userInput = Discourse.Category.findById(subcategories[0]);
|
const userInput = Discourse.Category.findById(subcategories[0]);
|
||||||
if ((!existingInput && userInput)
|
if ((!existingInput && userInput)
|
||||||
|| (existingInput && userInput && existingInput.id !== userInput.id))
|
|| (existingInput && userInput && existingInput.id !== userInput.id))
|
||||||
this.set('searchedTerms.category', userInput.id);
|
this.set('searchedTerms.category', [userInput]);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
this.set('searchedTerms.category', null);
|
this.set('searchedTerms.category', '');
|
||||||
},
|
},
|
||||||
|
|
||||||
setSearchedTermValueForGroup() {
|
setSearchedTermValueForGroup() {
|
||||||
|
@ -278,16 +278,16 @@ export default Em.Component.extend({
|
||||||
@observes('searchedTerms.category')
|
@observes('searchedTerms.category')
|
||||||
updateSearchTermForCategory() {
|
updateSearchTermForCategory() {
|
||||||
const match = this.filterBlocks(REGEXP_CATEGORY_PREFIX);
|
const match = this.filterBlocks(REGEXP_CATEGORY_PREFIX);
|
||||||
const categoryFilter = Discourse.Category.findById(this.get('searchedTerms.category'));
|
const categoryFilter = this.get('searchedTerms.category');
|
||||||
let searchTerm = this.get('searchTerm') || '';
|
let searchTerm = this.get('searchTerm') || '';
|
||||||
|
|
||||||
const slugCategoryMatches = (match.length !== 0) ? match[0].match(REGEXP_CATEGORY_SLUG) : null;
|
const slugCategoryMatches = (match.length !== 0) ? match[0].match(REGEXP_CATEGORY_SLUG) : null;
|
||||||
const idCategoryMatches = (match.length !== 0) ? match[0].match(REGEXP_CATEGORY_ID) : null;
|
const idCategoryMatches = (match.length !== 0) ? match[0].match(REGEXP_CATEGORY_ID) : null;
|
||||||
if (categoryFilter && categoryFilter.length !== 0) {
|
if (categoryFilter && categoryFilter[0]) {
|
||||||
const id = categoryFilter.id;
|
const id = categoryFilter[0].id;
|
||||||
const slug = categoryFilter.slug;
|
const slug = categoryFilter[0].slug;
|
||||||
if (categoryFilter && categoryFilter.parentCategory) {
|
if (categoryFilter[0].parentCategory) {
|
||||||
const parentSlug = categoryFilter.parentCategory.slug;
|
const parentSlug = categoryFilter[0].parentCategory.slug;
|
||||||
if (slugCategoryMatches)
|
if (slugCategoryMatches)
|
||||||
searchTerm = searchTerm.replace(slugCategoryMatches[0], `#${parentSlug}:${slug}`);
|
searchTerm = searchTerm.replace(slugCategoryMatches[0], `#${parentSlug}:${slug}`);
|
||||||
else if (idCategoryMatches)
|
else if (idCategoryMatches)
|
||||||
|
@ -296,7 +296,7 @@ export default Em.Component.extend({
|
||||||
searchTerm += ` #${parentSlug}:${slug}`;
|
searchTerm += ` #${parentSlug}:${slug}`;
|
||||||
|
|
||||||
this.set('searchTerm', searchTerm.trim());
|
this.set('searchTerm', searchTerm.trim());
|
||||||
} else if (categoryFilter) {
|
} else {
|
||||||
if (slugCategoryMatches)
|
if (slugCategoryMatches)
|
||||||
searchTerm = searchTerm.replace(slugCategoryMatches[0], `#${slug}`);
|
searchTerm = searchTerm.replace(slugCategoryMatches[0], `#${slug}`);
|
||||||
else if (idCategoryMatches)
|
else if (idCategoryMatches)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<div class="control-group pull-left">
|
<div class="control-group pull-left">
|
||||||
<label class="control-label" for="search-in-category">{{i18n "search.advanced.in_category.label"}}</label>
|
<label class="control-label" for="search-in-category">{{i18n "search.advanced.in_category.label"}}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{category-chooser value=searchedTerms.category}}
|
{{category-selector categories=searchedTerms.category single="true"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -76,7 +76,7 @@ test("validate population of advanced search", assert => {
|
||||||
|
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
assert.ok(exists('.search-advanced-options span:contains("admin")'), 'has "admin" pre-populated');
|
assert.ok(exists('.search-advanced-options span:contains("admin")'), 'has "admin" pre-populated');
|
||||||
assert.ok(exists('.search-advanced-options .category-combobox .select2-choice .select2-chosen:contains("bug")'), 'has "bug" pre-populated');
|
assert.ok(exists('.search-advanced-options .badge-category:contains("bug")'), 'has "bug" pre-populated');
|
||||||
//assert.ok(exists('.search-advanced-options span:contains("moderators")'), 'has "moderators" pre-populated');
|
//assert.ok(exists('.search-advanced-options span:contains("moderators")'), 'has "moderators" pre-populated');
|
||||||
//assert.ok(exists('.search-advanced-options span:contains("Reader")'), 'has "Reader" pre-populated');
|
//assert.ok(exists('.search-advanced-options span:contains("Reader")'), 'has "Reader" pre-populated');
|
||||||
assert.ok(exists('.search-advanced-options .tag-chooser .tag-monkey'), 'has "monkey" pre-populated');
|
assert.ok(exists('.search-advanced-options .tag-chooser .tag-monkey'), 'has "monkey" pre-populated');
|
||||||
|
@ -118,11 +118,13 @@ test("update category through advanced search ui", assert => {
|
||||||
visit("/search");
|
visit("/search");
|
||||||
fillIn('.search input.full-page-search', 'none');
|
fillIn('.search input.full-page-search', 'none');
|
||||||
click('.search-advanced-btn');
|
click('.search-advanced-btn');
|
||||||
selectDropdown('.search-advanced-options .category-combobox', 4);
|
fillIn('.search-advanced-options .category-selector', 'faq');
|
||||||
click('.search-advanced-options'); // need to click off the combobox for the search-term to get updated
|
click('.search-advanced-options .category-selector');
|
||||||
|
keyEvent('.search-advanced-options .category-selector', 'keydown', 8);
|
||||||
|
keyEvent('.search-advanced-options .category-selector', 'keydown', 9);
|
||||||
|
|
||||||
andThen(() => {
|
andThen(() => {
|
||||||
assert.ok(exists('.search-advanced-options .category-combobox .select2-choice .select2-chosen:contains("faq")'), 'has "faq" populated');
|
assert.ok(exists('.search-advanced-options .badge-category:contains("faq")'), 'has "faq" populated');
|
||||||
assert.equal(find('.search input.full-page-search').val(), "none #faq", 'has updated search term to "none #faq"');
|
assert.equal(find('.search input.full-page-search').val(), "none #faq", 'has updated search term to "none #faq"');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue