Browse Source

format config-state.service.ts

pull/14562/head
Mahmut Gundogdu 3 years ago
parent
commit
f69a17e00b
  1. 35
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

35
npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

@ -15,7 +15,7 @@ import { InternalStore } from '../utils/internal-store-utils';
}) })
export class ConfigStateService { export class ConfigStateService {
private readonly store = new InternalStore({} as ApplicationConfigurationDto); private readonly store = new InternalStore({} as ApplicationConfigurationDto);
get createOnUpdateStream() { get createOnUpdateStream() {
return this.store.sliceUpdate; return this.store.sliceUpdate;
} }
@ -25,7 +25,8 @@ export class ConfigStateService {
constructor( constructor(
private abpConfigService: AbpApplicationConfigurationService, private abpConfigService: AbpApplicationConfigurationService,
private abpApplicationLocalizationService: AbpApplicationLocalizationService, private abpApplicationLocalizationService: AbpApplicationLocalizationService,
@Inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN) private readonly includeLocalizationResources: boolean, @Inject(INCUDE_LOCALIZATION_RESOURCES_TOKEN)
private readonly includeLocalizationResources: boolean,
) { ) {
this.initUpdateStream(); this.initUpdateStream();
} }
@ -37,7 +38,7 @@ export class ConfigStateService {
this.abpConfigService.get({ this.abpConfigService.get({
includeLocalizationResources: this.includeLocalizationResources, includeLocalizationResources: this.includeLocalizationResources,
}), }),
) ),
) )
.pipe(switchMap(appState => this.getLocalizationAndCombineWithAppState(appState))) .pipe(switchMap(appState => this.getLocalizationAndCombineWithAppState(appState)))
.subscribe(res => this.store.set(res)); .subscribe(res => this.store.set(res));
@ -46,31 +47,33 @@ export class ConfigStateService {
private getLocalizationAndCombineWithAppState( private getLocalizationAndCombineWithAppState(
appState: ApplicationConfigurationDto, appState: ApplicationConfigurationDto,
): Observable<ApplicationConfigurationDto> { ): Observable<ApplicationConfigurationDto> {
return this.getlocalizationResource(appState.localization.currentCulture.cultureName) return this.getlocalizationResource(appState.localization.currentCulture.cultureName).pipe(
.pipe( map(result => ({ ...appState, localization: { ...appState.localization, ...result } })),
map(result =>({ ...appState, localization: { ...appState.localization, ...result } }), );
),
);
} }
private getlocalizationResource(cultureName:string){ private getlocalizationResource(cultureName: string) {
return this.abpApplicationLocalizationService return this.abpApplicationLocalizationService.get({
.get({ cultureName: cultureName, onlyDynamics: false }) cultureName: cultureName,
onlyDynamics: false,
});
} }
refreshAppState() { refreshAppState() {
this.updateSubject.next(); this.updateSubject.next();
return this.createOnUpdateStream(state => state).pipe(take(1)); return this.createOnUpdateStream(state => state).pipe(take(1));
} }
refreshLocalization(lang:string): Observable<null> { refreshLocalization(lang: string): Observable<null> {
if (this.includeLocalizationResources) { if (this.includeLocalizationResources) {
return this.refreshAppState().pipe(map(()=> null)); return this.refreshAppState().pipe(map(() => null));
} else { } else {
return this.getlocalizationResource(lang) return this.getlocalizationResource(lang)
.pipe( .pipe(
tap(result => this.store.patch({ localization: { ...this.store.state.localization, ...result } })) tap(result =>
this.store.patch({ localization: { ...this.store.state.localization, ...result } }),
),
) )
.pipe(map(()=> null)); .pipe(map(() => null));
} }
} }

Loading…
Cancel
Save