fix: data source switch inaccurate

This commit is contained in:
renqian805 2022-08-10 23:18:59 +08:00
parent d71a264327
commit fb40e3ce51
9 changed files with 34 additions and 53 deletions

View File

@ -28,16 +28,16 @@ export class AppComponent {
console.log('isSuccess', isSuccess);
if (!isSuccess) {
const timer = setTimeout(() => {
this.remoteService.switchDataSource();
this.remoteService.switchDataSource('local');
}, 5000);
this.modal.info({
nzContent: $localize `:{can not connect}:Unable to connect to remote data sources, please check and reconnect. In order not to affect use, the app will help you jump to local`,
nzContent: $localize`:{can not connect}:Unable to connect to remote data sources, please check and reconnect. In order not to affect use, the app will help you jump to local`,
nzFooter: null,
nzCentered: true,
nzClosable: false,
nzOnOk: () => {
clearTimeout(timer);
timer && this.remoteService.switchDataSource();
timer && this.remoteService.switchDataSource('local');
},
});
}

View File

@ -10,14 +10,7 @@
(click)="handleShowModal()">
<eo-iconpark-icon name="setting-two"></eo-iconpark-icon>
</span>
<!-- <span
i18n-title
class="flex items-center justify-center mx-1 icon"
title="{{ dataSourceText }}数据源"
(click)="switchDataSource()"
>
<eo-iconpark-icon [name]="isRemote ? 'link-cloud-sucess' : 'link-cloud-faild'"></eo-iconpark-icon>
</span> -->
<span class="flex items-center justify-center mx-1 icon" nz-dropdown [nzDropdownMenu]="menu">
<eo-iconpark-icon name="help"> </eo-iconpark-icon>
</span>

View File

@ -71,7 +71,9 @@ export class NavbarComponent implements OnInit {
fetch('https://api.github.com/repos/eolinker/eoapi/releases')
.then((response) => response.json())
.then((data) => {
if(!(data instanceof Array)) {return;}
if (!(data instanceof Array)) {
return;
}
[...this.resourceInfo]
.sort((a1, a2) => a2.suffix.length - a1.suffix.length)
.forEach((item) => {
@ -110,13 +112,6 @@ export class NavbarComponent implements OnInit {
this.isSettingVisible = true;
}
/**
* switch data
*/
switchDataSource = async () => {
this.remoteService.switchDataSource();
};
getModules(): Array<ModuleInfo> {
return Array.from(this.modules.values());
}

View File

@ -1,10 +1,10 @@
<eo-navbar></eo-navbar>
<div class="page-body"
[style.--remote-notification-height]="isShowNotification && electron.isElectron ? '50px' : '0px'">
<div *ngIf="isShowNotification && electron.isElectron" class="remote-notification">
<div *ngIf="!isRemote && isShowNotification && electron.isElectron" class="remote-notification">
<i nz-icon [nzType]="isRemote ? 'cloud' : 'exclamation-circle'" nzTheme="outline" class="text-[13px] mr-[2px]"></i>
<span i18n>Current data storage exists {{ dataSourceText }},please switch if you want to collaborate</span>
<a class="eo-blod ml-0.5" (click)="switchDataSource()" i18n>{{ isRemote ? 'Remote Server' : 'Localhost' }} Data Storage</a>
<a class="eo-blod ml-0.5" (click)="switchDataSource()" i18n>Remote Server Data Storage</a>
<i nz-icon nzType="close" nzTheme="outline" class="absolute right-[20px] cursor-pointer"
(click)="closeNotification()"></i>
</div>

View File

@ -66,7 +66,7 @@ export class PagesComponent implements OnInit {
}
switchDataSource = () => {
this.remoteService.switchDataSource();
this.remoteService.switchDataSource('http');
};
updateState = async () => {
@ -86,7 +86,7 @@ export class PagesComponent implements OnInit {
.subscribe((inArg: Message) => {
switch (inArg.type) {
case 'onDataSourceChange': {
this.rawChange$.next(inArg.type);
// this.rawChange$.next(inArg.type);
break;
}
}

View File

@ -187,7 +187,7 @@ export class DataStorageComponent implements OnInit, OnChanges {
...this.validateForm.value,
};
this.modelChange.emit(this.model);
await this.remoteService.switchDataSource();
await this.remoteService.switchDataSource(this.model['eoapi-common.dataStorage']);
}
setFormValue(model = {}) {

View File

@ -149,9 +149,9 @@ export class SettingComponent implements OnInit {
break;
}
case 'onDataSourceChange': {
if (inArg.data.showWithSetting) {
this.remoteService.refreshComponent();
}
// if (inArg.data.showWithSetting) {
// this.remoteService.refreshComponent();
// }
break;
}
}
@ -160,17 +160,6 @@ export class SettingComponent implements OnInit {
hasChild = (_: number, node: FlatNode): boolean => node.expandable;
/**
* switch data source
*/
switchDataSource() {
this.switchDataSourceLoading = true;
this.remoteService.switchDataSource().finally(() => {
this.switchDataSourceLoading = false;
});
// this.messageService.send({ type: 'switchDataSource', data: { showWithSetting: true } });
}
/**
* Get the title of the module
*
@ -183,7 +172,9 @@ export class SettingComponent implements OnInit {
}
handleScroll = debounce((e: Event) => {
if (this.isClick) {return;}
if (this.isClick) {
return;
}
const target = e.target as HTMLDivElement;
const treeNodes = this.dataSource._flattenedData.value;
treeNodes.some((node) => {

View File

@ -22,7 +22,9 @@ export const IS_SHOW_DATA_SOURCE_TIP = 'IS_SHOW_DATA_SOURCE_TIP';
export class RemoteService {
private destroy$: Subject<void> = new Subject<void>();
/** data source type @type { DataSourceType } */
dataSourceType: DataSourceType = 'local';
get dataSourceType(): DataSourceType {
return this.settingService.settings['eoapi-common.dataStorage'] ?? 'local';
}
get isElectron() {
return this.electronService.isElectron;
}
@ -49,14 +51,12 @@ export class RemoteService {
private settingService: SettingService,
private router: Router
) {
this.dataSourceType = this.settingService.settings['eoapi-common.dataStorage'] ?? this.dataSourceType;
this.messageService
.get()
.pipe(takeUntil(this.destroy$))
.subscribe((inArg: Message) => {
switch (inArg.type) {
case 'onDataSourceChange': {
this.dataSourceType = inArg.data.dataSourceType;
if (localStorage.getItem(IS_SHOW_DATA_SOURCE_TIP) === 'true') {
this.showMessage();
}
@ -86,7 +86,7 @@ export class RemoteService {
* Test if remote server address is available
*/
async pingRmoteServerUrl(): Promise<[boolean, any]> {
const { url: remoteUrl, token } = window.eo?.getModuleSettings('eoapi-common.remoteServer') || {};
const { url: remoteUrl, token } = this.settingService.getConfiguration('eoapi-common.remoteServer') || {};
if (!remoteUrl) {
return [false, remoteUrl];
@ -160,12 +160,9 @@ export class RemoteService {
/**
* switch data
*/
switchDataSource = async () => {
if (this.isRemote) {
localStorage.setItem(IS_SHOW_DATA_SOURCE_TIP, 'true');
this.switchToLocal();
this.refreshComponent();
} else {
switchDataSource = async (dataSource: DataSourceType) => {
const isRemote = dataSource === 'http';
if (isRemote) {
const [isSuccess] = await this.pingRmoteServerUrl();
if (isSuccess) {
localStorage.setItem(IS_SHOW_DATA_SOURCE_TIP, 'true');
@ -175,6 +172,10 @@ export class RemoteService {
this.message.create('error', $localize`Remote data source not available`);
localStorage.setItem(IS_SHOW_DATA_SOURCE_TIP, 'false');
}
} else {
localStorage.setItem(IS_SHOW_DATA_SOURCE_TIP, 'true');
this.switchToLocal();
this.refreshComponent();
}
};

View File

@ -16,7 +16,9 @@ export const IS_SHOW_REMOTE_SERVER_NOTIFICATION = 'IS_SHOW_REMOTE_SERVER_NOTIFIC
@Injectable({ providedIn: 'root' })
export class StorageService {
private instance;
dataSourceType: DataSourceType = getSettings()['eoapi-common.dataStorage'] || 'local';
get dataSourceType(): DataSourceType {
return getSettings()['eoapi-common.dataStorage'] || 'local';
}
constructor(
private injector: Injector,
private messageService: MessageService,
@ -47,7 +49,7 @@ export class StorageService {
callback(handleResult);
},
(error: any) => {
console.log('EOERROR:',action, error);
console.log('EOERROR:', action, error);
handleResult.status = StorageResStatus.error;
callback(handleResult);
}
@ -73,8 +75,7 @@ export class StorageService {
};
toggleDataSource = (options: any = {}) => {
const { dataSourceType } = options;
this.dataSourceType = dataSourceType ?? (this.dataSourceType === 'http' ? 'local' : 'http');
this.setStorage(this.dataSourceType, options);
this.setStorage(dataSourceType ?? (this.dataSourceType === 'http' ? 'local' : 'http'), options);
};
setDataStorage(value) {
this.settingService.putSettings({