Fix advanced subscriber query exp not propagating to search

This commit is contained in:
Kailash Nadh 2020-07-09 12:17:21 +05:30
parent 525a5100f5
commit ab8dbd8314
1 changed files with 16 additions and 26 deletions

View File

@ -20,7 +20,7 @@
<form @submit.prevent="querySubscribers"> <form @submit.prevent="querySubscribers">
<div> <div>
<b-field grouped> <b-field grouped>
<b-input v-model="queryParams.query" <b-input @input="onSimpleQueryInput"
placeholder="E-mail or name" icon="account-search-outline" ref="query" placeholder="E-mail or name" icon="account-search-outline" ref="query"
:disabled="isSearchAdvanced"></b-input> :disabled="isSearchAdvanced"></b-input>
<b-button native-type="submit" type="is-primary" icon-left="account-search-outline" <b-button native-type="submit" type="is-primary" icon-left="account-search-outline"
@ -34,8 +34,8 @@
<div v-if="isSearchAdvanced"> <div v-if="isSearchAdvanced">
<b-field> <b-field>
<b-input v-model="queryParams.fullQuery" <b-input v-model="queryParams.queryExp"
type="textarea" ref="fullQuery" type="textarea" ref="queryExp"
placeholder="subscribers.name LIKE '%user%' or subscribers.status='blacklisted'"> placeholder="subscribers.name LIKE '%user%' or subscribers.status='blacklisted'">
</b-input> </b-input>
</b-field> </b-field>
@ -208,11 +208,8 @@ export default Vue.extend({
// Query params to filter the getSubscribers() API call. // Query params to filter the getSubscribers() API call.
queryParams: { queryParams: {
// Simple query field. // Search query expression.
query: '', queryExp: '',
// Advanced query filled. This value should be accessed via fullQueryExp().
fullQuery: '',
// ID of the list the current subscriber view is filtered by. // ID of the list the current subscriber view is filtered by.
listID: null, listID: null,
@ -240,12 +237,7 @@ export default Vue.extend({
// Toggling to advanced search. // Toggling to advanced search.
this.$nextTick(() => { this.$nextTick(() => {
// Turn the string in the simple query input into an SQL exprssion and this.$refs.queryExp.focus();
// show in the full query input.
if (this.queryParams.query !== '') {
this.queryParams.fullQuery = this.fullQueryExp;
}
this.$refs.fullQuery.focus();
}); });
}, },
@ -288,11 +280,18 @@ export default Vue.extend({
this.querySubscribers(); this.querySubscribers();
}, },
// Prepares an SQL expression for simple name search inputs and saves it
// in this.queryExp.
onSimpleQueryInput(v) {
const q = v.replace(/'/, "''").trim();
this.queryParams.queryExp = `(name ~* '${q}' OR email ~* '${q}')`;
},
// Search / query subscribers. // Search / query subscribers.
querySubscribers() { querySubscribers() {
this.$api.getSubscribers({ this.$api.getSubscribers({
list_id: this.queryParams.listID, list_id: this.queryParams.listID,
query: this.fullQueryExp, query: this.queryParams.queryExp,
page: this.queryParams.page, page: this.queryParams.page,
}).then(() => { }).then(() => {
this.bulk.checked = []; this.bulk.checked = [];
@ -329,7 +328,7 @@ export default Vue.extend({
// 'All' is selected, blacklist by query. // 'All' is selected, blacklist by query.
fn = () => { fn = () => {
this.$api.blacklistSubscribersByQuery({ this.$api.blacklistSubscribersByQuery({
query: this.fullQueryExp, query: this.queryParams.queryExp,
list_ids: [], list_ids: [],
}).then(() => this.querySubscribers()); }).then(() => this.querySubscribers());
}; };
@ -362,7 +361,7 @@ export default Vue.extend({
// 'All' is selected, delete by query. // 'All' is selected, delete by query.
fn = () => { fn = () => {
this.$api.deleteSubscribersByQuery({ this.$api.deleteSubscribersByQuery({
query: this.fullQueryExp, query: this.queryParams.queryExp,
list_ids: [], list_ids: [],
}).then(() => { }).then(() => {
this.querySubscribers(); this.querySubscribers();
@ -412,15 +411,6 @@ export default Vue.extend({
computed: { computed: {
...mapState(['subscribers', 'lists', 'loading']), ...mapState(['subscribers', 'lists', 'loading']),
// Turns the value into the simple input field into an SQL query expression.
fullQueryExp() {
const q = this.queryParams.query.replace(/'/g, "''").trim();
if (!q) {
return '';
}
return `(name ~* '${q}' OR email ~* '${q}')`;
},
numSelectedSubscribers() { numSelectedSubscribers() {
if (this.bulk.all) { if (this.bulk.all) {
return this.subscribers.total; return this.subscribers.total;