From 2c0d4ba69a29440b8e97e251385ab9b92f65b593 Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Thu, 17 Mar 2022 14:00:58 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B8=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D0=B3=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popup/src/api/HttpClient.ts | 12 +++++- popup/src/api/Main/HttpClient.ts | 5 +++ .../api/Main/Schemas/ChangeMockValueSchema.ts | 11 +++++ popup/src/components/mocks-tab/template.html | 2 +- popup/src/components/mocks/script.ts | 41 ++++++++++++++++++- popup/src/components/mocks/template.html | 4 +- 6 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 popup/src/api/Main/Schemas/ChangeMockValueSchema.ts diff --git a/popup/src/api/HttpClient.ts b/popup/src/api/HttpClient.ts index cfb8ded..e6c3405 100644 --- a/popup/src/api/HttpClient.ts +++ b/popup/src/api/HttpClient.ts @@ -43,11 +43,19 @@ export class HttpClient { } send (schema: SchemaInterface, data: any | null = null): Promise { + let url = schema.url + const preparedData = data + for (const key in data) { + if (url.indexOf('{' + key + '}') > -1) { + url = url.replace('{' + key + '}', preparedData[key]) + delete preparedData[key] + } + } console.log(data, 'data') const requestData = { method: schema.method as Method, - url: this.baseUrl + schema.url, - data: data, + url: this.baseUrl + url, + data: preparedData, headers: { 'Content-Type': 'application/json;charset=utf-8' } diff --git a/popup/src/api/Main/HttpClient.ts b/popup/src/api/Main/HttpClient.ts index 01809ab..fad0b37 100644 --- a/popup/src/api/Main/HttpClient.ts +++ b/popup/src/api/Main/HttpClient.ts @@ -3,6 +3,7 @@ import MocksSchema, { MockConfigurationsRequest } from '../../api/Main/Schemas/M import { SchemaInterface } from '@/api/SchemaInterface' import { TokenRequestHandler } from '@/api/Handlers/TokenRequestHandler' import AddMockSchema, { AddMockConfigurationsRequest } from '@/api/Main/Schemas/AddMockSchema' +import ChangeMockValueSchema, { ChangeMockConfigurationValueRequest } from '@/api/Main/Schemas/ChangeMockValueSchema' export class HttpClient extends BaseClient { mockConfigurations (data: MockConfigurationsRequest): any { @@ -12,6 +13,10 @@ export class HttpClient extends BaseClient { addMockConfigurations (data: AddMockConfigurationsRequest): any { return this.send(AddMockSchema as SchemaInterface, data) } + + changeMockValueConfiguration (data: ChangeMockConfigurationValueRequest): any { + return this.send(ChangeMockValueSchema as SchemaInterface, data) + } } export default new HttpClient('http://placetgroup.sipachev.sv') diff --git a/popup/src/api/Main/Schemas/ChangeMockValueSchema.ts b/popup/src/api/Main/Schemas/ChangeMockValueSchema.ts new file mode 100644 index 0000000..d6cf96d --- /dev/null +++ b/popup/src/api/Main/Schemas/ChangeMockValueSchema.ts @@ -0,0 +1,11 @@ +export class ChangeMockConfigurationValueRequest { + id!: string + value!: string +} + +export default { + code: 'api_plugin_change_configuration_value', + method: 'PATCH', + url: '/plugin/mock-configurations/{id}/value', + prefix: 'mockConfigurations' +} diff --git a/popup/src/components/mocks-tab/template.html b/popup/src/components/mocks-tab/template.html index 9efcca7..4e146f8 100644 --- a/popup/src/components/mocks-tab/template.html +++ b/popup/src/components/mocks-tab/template.html @@ -5,6 +5,6 @@

- +
diff --git a/popup/src/components/mocks/script.ts b/popup/src/components/mocks/script.ts index 36c9387..a607f45 100644 --- a/popup/src/components/mocks/script.ts +++ b/popup/src/components/mocks/script.ts @@ -1,4 +1,4 @@ -import { Component, Prop, Vue } from 'vue-property-decorator' +import { Component, Prop, Vue, Watch } from 'vue-property-decorator' import VueClipboard from 'vue-clipboard2' import { Registers } from '@/classes/DTO/Registers' import httpClient from '@/api/Main/HttpClient' @@ -6,15 +6,51 @@ import { MockConfiguration } from '@/api/Main/Schemas/AddMockSchema' Vue.use(VueClipboard) +export enum Mode { + ADD = 'add', + UPDATE = 'update', +} + @Component export default class Mocks extends Vue { @Prop() personalCode!: string + mode: Mode = Mode.ADD registers = new Registers() + register2Id: Record = {} mounted () { - console.log('mounted') + console.log('mounted', this.personalCode) + } + + @Watch('personalCode', { immediate: true }) + onPersonalCodeChanged (value: string, oldValue: string) { + this.mode = Mode.ADD + httpClient.mockConfigurations({ personalCode: this.personalCode }) + .then((data: any) => { + for (const mockConfiguration of data.data) { + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // @ts-ignore + this.registers[mockConfiguration.code] = mockConfiguration.value + this.register2Id[mockConfiguration.code] = mockConfiguration.id + this.mode = Mode.UPDATE + } + }) + } + + onXteeMtaChanged () { + if (this.register2Id.xtee_mta === 'undefined') { + return + } + httpClient.changeMockValueConfiguration({ + id: this.register2Id.xtee_mta, + value: this.registers.xtee_mta + }) + .then((data: any) => { + console.log('updateMock') + console.log(data) + }) } saveMocks () { @@ -23,6 +59,7 @@ export default class Mocks extends Vue { const mockConfiguration = new MockConfiguration() mockConfiguration.personalCode = this.personalCode mockConfiguration.code = serviceCode + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore // @ts-ignore mockConfiguration.value = this.registers[serviceCode] if (!mockConfiguration.value) { diff --git a/popup/src/components/mocks/template.html b/popup/src/components/mocks/template.html index 52ab005..29ddc6c 100644 --- a/popup/src/components/mocks/template.html +++ b/popup/src/components/mocks/template.html @@ -11,7 +11,7 @@