Skip to content

Commit

Permalink
feat(cvars): add response toggle for POST variable change (#2486)
Browse files Browse the repository at this point in the history
Fixes #2481
  • Loading branch information
sogehige committed Aug 12, 2019
1 parent 9d8e405 commit 7122829
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions locales/cs/ui.registry.customvariables.json
Expand Up @@ -3,6 +3,7 @@
"generateurl": "Vygenerovat novou URL",
"show-examples": "Ukázat CURL příklady",
"response": {
"show": "Zobrazit odpověď po POST",
"name": "Odpověď po nastavení",
"default": "Výchozí",
"default-placeholder": "Nastavte svou odpověď",
Expand Down
1 change: 1 addition & 0 deletions locales/en/ui.registry.customvariables.json
Expand Up @@ -3,6 +3,7 @@
"generateurl": "Generate new URL",
"show-examples": "show CURL examples",
"response": {
"show": "Show response after POST",
"name": "Response after variable set",
"default": "Default",
"default-placeholder": "Set your bot response",
Expand Down
14 changes: 14 additions & 0 deletions src/bot/customvariables.js
Expand Up @@ -53,7 +53,21 @@ class CustomVariables {
if (variable) {
if (_.get(variable.urls.find(url => url.id === req.params.id), 'access.POST', false)) {
const value = await this.setValueOf(variable.variableName, req.body.value, {});

if (value.isOk) {
if (_.get(variable.urls.find(url => url.id === req.params.id), 'showResponse', false)) {
if (value.updated.responseType === 0) {
commons.sendMessage(
commons.prepare('filters.setVariable', { value: state.updated.setValue, variable: variable }),
commons.getOwner(), { skip: true, quiet: _.get(attr, 'quiet', false) }
);
} else if (value.updated.responseType === 1) {
commons.sendMessage(
value.updated.responseText.replace('$value', value.updated.setValue),
commons.getOwner(), { skip: true, quiet: _.get(attr, 'quiet', false) }
);
}
}
return res.status(200).send({ oldValue: variable.currentValue, value: value.updated.setValue });
} else {
return res.status(400).send({ error: 'This value is not applicable for this endpoint', code: 400 });
Expand Down
Expand Up @@ -115,6 +115,7 @@
<b-button-group size="sm" class="btn-block" style="flex-basis: 0;">
<b-button :variant="url.access.GET ? 'success' : 'danger'" @click="url.access.GET = !url.access.GET">GET</b-button>
<b-button :variant="url.access.POST ? 'success' : 'danger'" @click="url.access.POST = !url.access.POST">POST</b-button>
<b-button :variant="url.showResponse ? 'success' : 'danger'" @click="url.showResponse = !url.showResponse">{{ translate('registry.customvariables.response.show') }}</b-button>
</b-button-group>
<div class="w-100 p-2">{{origin}}/customvariables/{{url.id}}</div>
<b-button-group size="sm" class="btn-block" style="flex-basis: 0;">
Expand Down Expand Up @@ -359,7 +360,7 @@ export default class customVariablesEdit extends Vue {
usableOptions: string = '';
readOnly: boolean = false;
permission: string | null = null;
urls: { id: string; access: { GET: boolean; POST: boolean }}[] = [];
urls: { id: string; showResponse: boolean; access: { GET: boolean; POST: boolean }}[] = [];
evalValue: string = evalDefault;
evalError: string | null = null
Expand Down Expand Up @@ -508,6 +509,7 @@ export default class customVariablesEdit extends Vue {
generateURL() {
this.urls.push({
id: uuid(),
showResponse: false,
access: { GET: false, POST: false }
});
}
Expand Down

0 comments on commit 7122829

Please sign in to comment.