Browse Source

fix : ui-culture used in config-state-service

pull/20935/head
erhanilze 2 years ago
parent
commit
dca0a08c2e
  1. 36
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
  2. 10
      npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts

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

@ -17,6 +17,8 @@ export class ConfigStateService {
private updateSubject = new Subject<void>(); private updateSubject = new Subject<void>();
private readonly store = new InternalStore({} as ApplicationConfigurationDto); private readonly store = new InternalStore({} as ApplicationConfigurationDto);
public uiCultureFromAuthCodeFlow: string;
setState(config: ApplicationConfigurationDto) { setState(config: ApplicationConfigurationDto) {
this.store.set(config); this.store.set(config);
} }
@ -53,7 +55,11 @@ export class ConfigStateService {
if (!appState.localization.currentCulture.cultureName) { if (!appState.localization.currentCulture.cultureName) {
throw new Error('culture name should defined'); throw new Error('culture name should defined');
} }
return this.getlocalizationResource(appState.localization.currentCulture.cultureName).pipe(
const cultureName =
this.uiCultureFromAuthCodeFlow ?? appState.localization.currentCulture.cultureName;
return this.getlocalizationResource(cultureName).pipe(
map(result => ({ ...appState, localization: { ...appState.localization, ...result } })), map(result => ({ ...appState, localization: { ...appState.localization, ...result } })),
); );
} }
@ -71,10 +77,10 @@ export class ConfigStateService {
} }
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));
} }
return this.getlocalizationResource(lang) return this.getlocalizationResource(lang)
.pipe( .pipe(
tap(result => tap(result =>
@ -145,7 +151,7 @@ export class ConfigStateService {
return keys.reduce((acc, key) => ({ ...acc, [key]: features.values[key] }), {}); return keys.reduce((acc, key) => ({ ...acc, [key]: features.values[key] }), {});
} }
getFeatures$(keys: string[]): Observable<{ [key: string]: string; } | undefined> { getFeatures$(keys: string[]): Observable<{ [key: string]: string } | undefined> {
return this.store.sliceState(({ features }) => { return this.store.sliceState(({ features }) => {
if (!features?.values) return; if (!features?.values) return;
@ -168,10 +174,13 @@ export class ConfigStateService {
const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1); const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1);
return keysFound.reduce((acc, key) => { return keysFound.reduce(
acc[key] = settings[key]; (acc, key) => {
return acc; acc[key] = settings[key];
}, {} as Record<string, string>); return acc;
},
{} as Record<string, string>,
);
} }
getSettings$(keyword?: string) { getSettings$(keyword?: string) {
@ -183,10 +192,13 @@ export class ConfigStateService {
const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1); const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1);
return keysFound.reduce((acc, key) => { return keysFound.reduce(
acc[key] = settings[key]; (acc, key) => {
return acc; acc[key] = settings[key];
}, {} as Record<string, string>); return acc;
},
{} as Record<string, string>,
);
}), }),
); );
} }

10
npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts

@ -9,10 +9,10 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
async init() { async init() {
this.checkRememberMeOption(); this.checkRememberMeOption();
this.setUICulture();
return super return super
.init() .init()
.then(() => this.setLanguageWithUICulture())
.then(() => this.oAuthService.tryLogin().catch(noop)) .then(() => this.oAuthService.tryLogin().catch(noop))
.then(() => this.oAuthService.setupAutomaticSilentRefresh()); .then(() => this.oAuthService.setupAutomaticSilentRefresh());
} }
@ -70,14 +70,14 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
return { ...(lang && culture), ...queryParams }; return { ...(lang && culture), ...queryParams };
} }
private setLanguageWithUICulture() { private setUICulture() {
this.oAuthService.events this.oAuthService.events
.pipe( .pipe(
filter(event => event.type === 'token_received'), filter(event => event.type === 'token_received'),
tap(e => { tap(e => {
const urlParams = window.location.search; const urlParams = new URLSearchParams(window.location.search);
const uiCulture = new URLSearchParams(urlParams).get('ui-culture'); this.configState.uiCultureFromAuthCodeFlow = urlParams.get('ui-culture');
this.sessionState.setLanguage(uiCulture); window.history.replaceState(null, '', window.location.pathname);
}), }),
) )
.subscribe(); .subscribe();

Loading…
Cancel
Save