|
|
|
@ -1,12 +1,13 @@ |
|
|
|
import { Injectable } from '@angular/core'; |
|
|
|
import { Inject, Injectable } from '@angular/core'; |
|
|
|
import { Observable, Subject, of } from 'rxjs'; |
|
|
|
import { map, switchMap, take } from 'rxjs/operators'; |
|
|
|
import { map, switchMap, take, tap } from 'rxjs/operators'; |
|
|
|
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service'; |
|
|
|
import { AbpApplicationLocalizationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-localization.service'; |
|
|
|
import { |
|
|
|
ApplicationConfigurationDto, |
|
|
|
ApplicationGlobalFeatureConfigurationDto, |
|
|
|
} from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/models'; |
|
|
|
import { INCUDE_LOCALIZATION_RESOURCES_TOKEN } from '../tokens/include-localization-resources.token'; |
|
|
|
import { InternalStore } from '../utils/internal-store-utils'; |
|
|
|
|
|
|
|
@Injectable({ |
|
|
|
@ -14,7 +15,6 @@ import { InternalStore } from '../utils/internal-store-utils'; |
|
|
|
}) |
|
|
|
export class ConfigStateService { |
|
|
|
private readonly store = new InternalStore({} as ApplicationConfigurationDto); |
|
|
|
private includeLocalizationResources = false; |
|
|
|
|
|
|
|
get createOnUpdateStream() { |
|
|
|
return this.store.sliceUpdate; |
|
|
|
@ -25,6 +25,8 @@ export class ConfigStateService { |
|
|
|
constructor( |
|
|
|
private abpConfigService: AbpApplicationConfigurationService, |
|
|
|
private abpApplicationLocalizationService: AbpApplicationLocalizationService, |
|
|
|
@Inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN) |
|
|
|
private readonly includeLocalizationResources: boolean, |
|
|
|
) { |
|
|
|
this.initUpdateStream(); |
|
|
|
} |
|
|
|
@ -45,20 +47,36 @@ export class ConfigStateService { |
|
|
|
private getLocalizationAndCombineWithAppState( |
|
|
|
appState: ApplicationConfigurationDto, |
|
|
|
): Observable<ApplicationConfigurationDto> { |
|
|
|
return this.abpApplicationLocalizationService |
|
|
|
.get({ cultureName: appState.localization.currentCulture.name, onlyDynamics: false }) |
|
|
|
.pipe( |
|
|
|
switchMap(result => |
|
|
|
of({ ...appState, localization: { ...appState.localization, ...result } }), |
|
|
|
), |
|
|
|
); |
|
|
|
return this.getlocalizationResource(appState.localization.currentCulture.cultureName).pipe( |
|
|
|
map(result => ({ ...appState, localization: { ...appState.localization, ...result } })), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private getlocalizationResource(cultureName: string) { |
|
|
|
return this.abpApplicationLocalizationService.get({ |
|
|
|
cultureName: cultureName, |
|
|
|
onlyDynamics: false, |
|
|
|
}); |
|
|
|
} |
|
|
|
refreshAppState() { |
|
|
|
this.updateSubject.next(); |
|
|
|
return this.createOnUpdateStream(state => state).pipe(take(1)); |
|
|
|
} |
|
|
|
|
|
|
|
refreshLocalization(lang: string): Observable<null> { |
|
|
|
if (this.includeLocalizationResources) { |
|
|
|
return this.refreshAppState().pipe(map(() => null)); |
|
|
|
} else { |
|
|
|
return this.getlocalizationResource(lang) |
|
|
|
.pipe( |
|
|
|
tap(result => |
|
|
|
this.store.patch({ localization: { ...this.store.state.localization, ...result } }), |
|
|
|
), |
|
|
|
) |
|
|
|
.pipe(map(() => null)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getOne$(key: string) { |
|
|
|
return this.store.sliceState(state => state[key]); |
|
|
|
} |
|
|
|
|