From e02f371247d7e6f5bb3cb40577b73e119c99716a Mon Sep 17 00:00:00 2001 From: buqiyuan <1743369777@qq.com> Date: Tue, 2 Aug 2022 15:40:01 +0800 Subject: [PATCH] fix: data source save reload immediately --- .../src/app/pages/api/api.component.ts | 1 - .../setting/common/data-storage.component.ts | 44 +++++++++++++++---- .../components/setting/setting.component.ts | 25 ++--------- .../services/storage/storage.service.ts | 4 +- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/workbench/browser/src/app/pages/api/api.component.ts b/src/workbench/browser/src/app/pages/api/api.component.ts index bd64025bb..5a5c1c6db 100644 --- a/src/workbench/browser/src/app/pages/api/api.component.ts +++ b/src/workbench/browser/src/app/pages/api/api.component.ts @@ -103,7 +103,6 @@ export class ApiComponent implements OnInit, OnDestroy { } } }); - console.log('dyWidth', this.dyWidth); } ngOnDestroy() { this.destroy$.next(); diff --git a/src/workbench/browser/src/app/shared/components/setting/common/data-storage.component.ts b/src/workbench/browser/src/app/shared/components/setting/common/data-storage.component.ts index 496836052..b9a9b5fa0 100644 --- a/src/workbench/browser/src/app/shared/components/setting/common/data-storage.component.ts +++ b/src/workbench/browser/src/app/shared/components/setting/common/data-storage.component.ts @@ -1,6 +1,8 @@ import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { ElectronService } from 'eo/workbench/browser/src/app/core/services/electron/electron.service'; +import { RemoteService } from 'eo/workbench/browser/src/app/shared/services/remote/remote.service'; +import { uniqueSlash } from 'eo/workbench/browser/src/app/utils/api'; import { NzMessageService } from 'ng-zorro-antd/message'; @Component({ @@ -66,10 +68,17 @@ import { NzMessageService } from 'ng-zorro-antd/message'; export class DataStorageComponent implements OnInit, OnChanges { @Input() model: Record = {}; @Output() modelChange: EventEmitter = new EventEmitter(); + + oldDataStorageType: 'local' | 'http'; validateForm!: FormGroup; loading = false; - constructor(private fb: FormBuilder, private message: NzMessageService, private electronService: ElectronService) {} + constructor( + private fb: FormBuilder, + private message: NzMessageService, + private electronService: ElectronService, + private remoteService: RemoteService + ) {} ngOnInit(): void { this.validateForm = this.fb.group({ @@ -83,6 +92,7 @@ export class DataStorageComponent implements OnInit, OnChanges { [Validators.required], ], }); + this.oldDataStorageType = this.validateForm.value['eoapi-common.dataStorage']; } ngOnChanges(changes: SimpleChanges): void { @@ -115,7 +125,7 @@ export class DataStorageComponent implements OnInit, OnChanges { } try { - const url = `${remoteUrl}/system/status`.replace(/(? (this.loading = false)); if (Object.is(result, true)) { this.message.success($localize`The remote data source connection is successful!`); } - this.model = { - ...this.model, - ...this.validateForm.value, - }; - this.modelChange.emit(this.model); + this.updateDataSource(); + } else if (isValid) { + this.updateDataSource(); } else { Object.values(this.validateForm.controls).forEach((control) => { if (control.invalid) { @@ -164,6 +181,15 @@ export class DataStorageComponent implements OnInit, OnChanges { } } + async updateDataSource() { + this.model = { + ...this.model, + ...this.validateForm.value, + }; + this.modelChange.emit(this.model); + await this.remoteService.switchDataSource(); + } + setFormValue(model = {}) { Object.keys(model).forEach((key) => { this.validateForm.get(key)?.setValue(model[key]); diff --git a/src/workbench/browser/src/app/shared/components/setting/setting.component.ts b/src/workbench/browser/src/app/shared/components/setting/setting.component.ts index 84aa2a61a..5434f1216 100644 --- a/src/workbench/browser/src/app/shared/components/setting/setting.component.ts +++ b/src/workbench/browser/src/app/shared/components/setting/setting.component.ts @@ -143,6 +143,7 @@ export class SettingComponent implements OnInit { .subscribe((inArg: Message) => { switch (inArg.type) { case 'toggleSettingModalVisible': { + console.log('inArg.data.isShow', inArg.data.isShow); inArg.data.isShow ? this.handleShowModal() : this.handleCancel(); break; } @@ -268,27 +269,9 @@ export class SettingComponent implements OnInit { }; async handleCancel() { - try { - const isUpdateRemoteInfo = - this.remoteServerUrl !== this.settings['eoapi-common.remoteServer.url'] || - this.remoteServerToken !== this.settings['eoapi-common.remoteServer.token'] || - this.oldDataStorage !== this.settings['eoapi-common.dataStorage']; - - if (isUpdateRemoteInfo) { - this.message.success( - 'You have modified the data source related information, the page will refresh in 2 seconds...' - ); - setTimeout(() => { - this.remoteService.switchDataSource(); - this.remoteService.refreshComponent(); - }, 2000); - } - } catch (error) { - } finally { - this.handleSave(); + this.handleSave(); - this.isShowModal = false; - this.isShowModalChange.emit(false); - } + this.isShowModal = false; + this.isShowModalChange.emit(false); } } diff --git a/src/workbench/browser/src/app/shared/services/storage/storage.service.ts b/src/workbench/browser/src/app/shared/services/storage/storage.service.ts index b7bd87c00..4c69a1ca8 100644 --- a/src/workbench/browser/src/app/shared/services/storage/storage.service.ts +++ b/src/workbench/browser/src/app/shared/services/storage/storage.service.ts @@ -3,7 +3,7 @@ import { StorageResStatus } from './index.model'; import { IndexedDBStorage } from './IndexedDB/lib'; import { HttpStorage } from './http/lib'; import { MessageService } from '../../../shared/services/message'; -import { SettingService } from 'eo/workbench/browser/src/app/core/services/settings/settings.service'; +import { getSettings, SettingService } from 'eo/workbench/browser/src/app/core/services/settings/settings.service'; export type DataSourceType = 'local' | 'http'; /** is show local data source tips */ @@ -16,7 +16,7 @@ export const IS_SHOW_REMOTE_SERVER_NOTIFICATION = 'IS_SHOW_REMOTE_SERVER_NOTIFIC @Injectable({ providedIn: 'root' }) export class StorageService { private instance; - dataSourceType: DataSourceType = 'local'; + dataSourceType: DataSourceType = getSettings()['eoapi-common.dataStorage'] || 'local'; constructor( private injector: Injector, private messageService: MessageService,