DEV: Add special *in* items on the advanced search using the API
This commit is contained in:
parent
5090a56aa2
commit
8cb5eb7abf
|
@ -67,9 +67,9 @@
|
|||
<div class="control-group advanced-search-topics-posts">
|
||||
<div class="controls">
|
||||
<fieldset class="grouped-control">
|
||||
<legend class="grouped-control-label">{{i18n
|
||||
"search.advanced.filters.label"
|
||||
}}</legend>
|
||||
<legend class="grouped-control-label">
|
||||
{{i18n "search.advanced.filters.label"}}
|
||||
</legend>
|
||||
|
||||
{{#if this.currentUser}}
|
||||
<div class="grouped-control-field">
|
||||
|
@ -146,6 +146,27 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#each this.inSpecialOptions as |option|}}
|
||||
<div class="grouped-control-field">
|
||||
<Input
|
||||
id={{concat "matching-in-" option.value}}
|
||||
@type="checkbox"
|
||||
class={{concat "in-" option.value}}
|
||||
@checked={{get this.searchedTerms.special.in option.value}}
|
||||
{{on
|
||||
"click"
|
||||
(fn this.onChangeSearchTermForSpecialIn option.value)
|
||||
}}
|
||||
/>
|
||||
<label
|
||||
class="checkbox-label"
|
||||
for={{concat "matching-in-" option.value}}
|
||||
>
|
||||
{{option.name}}
|
||||
</label>
|
||||
</div>
|
||||
{{/each}}
|
||||
|
||||
<ComboBox
|
||||
@id="in"
|
||||
@valueProperty="value"
|
||||
|
|
|
@ -2,6 +2,7 @@ import Component from "@ember/component";
|
|||
import { action } from "@ember/object";
|
||||
import { escapeExpression } from "discourse/lib/utilities";
|
||||
import Category from "discourse/models/category";
|
||||
import escapeRegExp from "discourse-common/utils/escape-regexp";
|
||||
import I18n from "discourse-i18n";
|
||||
|
||||
const REGEXP_BLOCKS = /(([^" \t\n\x0B\f\r]+)?(("[^"]+")?))/g;
|
||||
|
@ -88,6 +89,13 @@ export default Component.extend({
|
|||
init() {
|
||||
this._super(...arguments);
|
||||
|
||||
const allInOptions = this.currentUser
|
||||
? inOptionsForUsers().concat(inOptionsForAll())
|
||||
: inOptionsForAll();
|
||||
|
||||
const inOptions = allInOptions.filter((option) => !option.special);
|
||||
const inSpecialOptions = allInOptions.filter((option) => option.special);
|
||||
|
||||
this.setProperties({
|
||||
searchedTerms: {
|
||||
username: null,
|
||||
|
@ -113,9 +121,8 @@ export default Component.extend({
|
|||
days: null,
|
||||
},
|
||||
},
|
||||
inOptions: this.currentUser
|
||||
? inOptionsForUsers().concat(inOptionsForAll())
|
||||
: inOptionsForAll(),
|
||||
inOptions,
|
||||
inSpecialOptions,
|
||||
statusOptions: statusOptions(),
|
||||
postTimeOptions: postTimeOptions(),
|
||||
showAllTagsCheckbox: false,
|
||||
|
@ -158,6 +165,13 @@ export default Component.extend({
|
|||
REGEXP_SPECIAL_IN_SEEN_MATCH
|
||||
);
|
||||
|
||||
this.inSpecialOptions.forEach((option) =>
|
||||
this.setSearchedTermSpecialInValue(
|
||||
`searchedTerms.special.in.${option.value}`,
|
||||
new RegExp(`^in:${escapeRegExp(option.value)}$`, "gi")
|
||||
)
|
||||
);
|
||||
|
||||
let regExpStatusMatch = this.statusOptions
|
||||
.map((status) => status.value)
|
||||
.join("|");
|
||||
|
@ -477,6 +491,12 @@ export default Component.extend({
|
|||
this.updateInRegex(REGEXP_SPECIAL_IN_TITLE_MATCH, "title");
|
||||
},
|
||||
|
||||
@action
|
||||
onChangeSearchTermForSpecialIn(name, evt) {
|
||||
this.set("searchedTerms.special.in." + name, evt.target.checked);
|
||||
this.updateInRegex(new RegExp(`^in:${escapeRegExp(name)}$`, "gi"), name);
|
||||
},
|
||||
|
||||
@action
|
||||
onChangeSearchedTermField(path, updateFnName, value) {
|
||||
this.set(`searchedTerms.${path}`, value);
|
||||
|
|
Loading…
Reference in New Issue