From 93e78e2b773f12ec8724d2eacc8e53c86561ec98 Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Fri, 1 Apr 2022 13:22:33 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=BD=D0=B5=D0=B5=20?= =?UTF-8?q?=D1=81=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popup/src/components/mocks/script.ts | 62 ++++++++++++++++-------- popup/src/components/mocks/template.html | 4 +- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/popup/src/components/mocks/script.ts b/popup/src/components/mocks/script.ts index d09fe2d..0925af4 100644 --- a/popup/src/components/mocks/script.ts +++ b/popup/src/components/mocks/script.ts @@ -27,45 +27,50 @@ export default class Mocks extends Vue { } @Watch('personalCode', { immediate: true }) - onPersonalCodeChanged (value: string, oldValue: string) { + onPersonalCodeChanged () { + this.refreshMocks() + } + + refreshMocks () { this.mode === Mode.UPDATE && httpClient.mockConfigurations({ personalCode: this.personalCode }) .then((data: any) => { + const existServiceKeys = [] 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 + existServiceKeys.push(mockConfiguration.code) + } + for (const serviceCode in this.registers) { + if (existServiceKeys.indexOf(serviceCode) > -1) { + continue + } + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // @ts-ignore + this.registers[serviceCode] = '' + delete this.register2Id[serviceCode] } }) } - onXteeMtaChanged () { + async onServiceChanged (serviceKey: string) { if (this.mode !== Mode.UPDATE) { return } - if (this.register2Id.xtee_mta === 'undefined') { + if (typeof this.register2Id[serviceKey] === 'undefined') { + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // @ts-ignore + await this.saveMock(this.personalCode, serviceKey, Number(this.registers[serviceKey])) + await this.refreshMocks() return } - httpClient.changeMockValueConfiguration({ - id: this.register2Id.xtee_mta, - value: this.registers.xtee_mta - }) - .then((data: any) => { - console.log('updateMock') - console.log(data) - }) - } - onRiaChanged () { - if (this.mode !== Mode.UPDATE) { - return - } - if (this.register2Id.ria === 'undefined') { - return - } httpClient.changeMockValueConfiguration({ - id: this.register2Id.ria, - value: this.registers.ria + id: this.register2Id[serviceKey], + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // @ts-ignore + value: this.registers[serviceKey] }) .then((data: any) => { console.log('updateMock') @@ -94,4 +99,19 @@ export default class Mocks extends Vue { console.log(data) }) } + + saveMock (personalCode: string, serviceCode: string, value: number): Promise { + const mockConfigurations: MockConfiguration[] = [] + const mockConfiguration = new MockConfiguration() + mockConfiguration.personalCode = personalCode + mockConfiguration.code = serviceCode + mockConfiguration.value = value + mockConfiguration.active = 'true' + mockConfigurations.push(mockConfiguration) + return httpClient.addMockConfigurations({ items: mockConfigurations }) + .then((data: any) => { + console.log('saveMocks') + console.log(data) + }) + } } diff --git a/popup/src/components/mocks/template.html b/popup/src/components/mocks/template.html index 465920e..c32a28b 100644 --- a/popup/src/components/mocks/template.html +++ b/popup/src/components/mocks/template.html @@ -2,7 +2,7 @@
XTEE MTA
- @@ -20,7 +20,7 @@
XTEE RIA
-