Skip to content

Commit

Permalink
feat: возможность скрыть JSON запросов в консоли
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Jul 2, 2018
1 parent 71de9a9 commit 0600cee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
5 changes: 5 additions & 0 deletions components/Dialog.vue
Expand Up @@ -59,6 +59,7 @@ import {
SET_WEBHOOK_URL,
SET_WEBHOOK_URLS,
SET_IS_BOTTOM_TESTS,
SET_IS_CONSOLE_REQUESTS,
ADD_MESSAGE,
AUTHOR_NAME,
SESSION_START
Expand Down Expand Up @@ -168,6 +169,10 @@ export default {
this.$store.commit(SET_WEBHOOK_URLS, this.getWebhookURLs());
this.$store.dispatch(SET_WEBHOOK_URL, localStorage.getItem('webhookURL'));
this.$store.commit(SET_IS_BOTTOM_TESTS, JSON.parse(localStorage.getItem('isBottomTests')));
this.$store.commit(
SET_IS_CONSOLE_REQUESTS,
JSON.parse(localStorage.getItem('isConsoleRequests'))
);
},
// scroll to messages bottom on messages updated
Expand Down
15 changes: 14 additions & 1 deletion components/Sidebar.vue
Expand Up @@ -14,6 +14,10 @@
<el-switch active-text="Показывать тесты внизу" v-if="$store.state.tests.length > 0" v-model="isBottomTests"></el-switch>
</el-row>

<el-row>
<el-switch active-text="Показывать JSON в консоли" v-model="isConsoleRequests"></el-switch>
</el-row>

<el-row>
<a class="app-link" :href="$store.state.homepage" target="_blank">
<icon name="brands/github"></icon>
Expand Down Expand Up @@ -62,7 +66,7 @@

<script>
import 'vue-awesome/icons/brands/github';
import { SET_IS_PROXY, SET_IS_BOTTOM_TESTS } from '~/store';
import { SET_IS_PROXY, SET_IS_BOTTOM_TESTS, SET_IS_CONSOLE_REQUESTS } from '~/store';
import MessageButton from '~/components/MessageButton';
export default {
Expand Down Expand Up @@ -91,6 +95,15 @@ export default {
}
},
isConsoleRequests: {
get() {
return this.$store.state.isConsoleRequests;
},
set(val) {
this.$store.commit('SET_IS_CONSOLE_REQUESTS', val);
}
},
webhookURLs() {
return this.$store.state.webhookURLs;
}
Expand Down
20 changes: 15 additions & 5 deletions store/index.js
Expand Up @@ -5,6 +5,7 @@ export const SET_ANSWERS = 'SET_ANSWERS';
export const ALICE_REQUEST = 'ALICE_REQUEST';
export const SET_IS_PROXY = 'SET_IS_PROXY';
export const SET_IS_BOTTOM_TESTS = 'SET_IS_BOTTOM_TESTS';
export const SET_IS_CONSOLE_REQUESTS = 'SET_IS_CONSOLE_REQUESTS';
export const SET_USER_ID = 'SET_USER_ID';
export const SET_SESSION_ID = 'SET_SESSION_ID';
export const SET_SESSION_NEW = 'SET_SESSION_NEW';
Expand Down Expand Up @@ -60,6 +61,7 @@ export const state = () => ({
// app state
isProxy: process.env.isProxy,
isBottomTests: false,
isConsoleRequests: false,
userId: '',
sessionId: '',
sessionNew: true,
Expand All @@ -77,7 +79,11 @@ export const mutations = {
[SET_IS_BOTTOM_TESTS](state, isBottomTests) {
state.isBottomTests = isBottomTests;
localStorage.setItem('isBottomTests', isBottomTests);
console.log(localStorage.getItem('isBottomTests'));
},

[SET_IS_CONSOLE_REQUESTS](state, isConsoleRequests) {
state.isConsoleRequests = isConsoleRequests;
localStorage.setItem('isConsoleRequests', isConsoleRequests);
},

[SET_USER_ID](state, userId) {
Expand Down Expand Up @@ -189,15 +195,19 @@ export const actions = {
try {
if (state.webhookURL) {
let responseData;
expandedLog({ request: data });
console.log('\n');
if (state.isConsoleRequests) {
expandedLog({ request: data });
console.log('\n');
}
if (state.isProxy) {
responseData = await this.$axios.$post('/api/request', axiosData);
} else {
responseData = await this.$axios.$post(state.webhookURL, data);
}
expandedLog({ response: responseData });
console.log('\n\n\n\n\n');
if (state.isConsoleRequests) {
expandedLog({ response: responseData });
console.log('\n\n\n\n\n');
}

commit(ADD_MESSAGE, {
text: responseData.response.text,
Expand Down

0 comments on commit 0600cee

Please sign in to comment.