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 readonly store = new InternalStore({} as ApplicationConfigurationDto);
public uiCultureFromAuthCodeFlow: string;
setState(config: ApplicationConfigurationDto) {
this.store.set(config);
}
@ -53,7 +55,11 @@ export class ConfigStateService {
if (!appState.localization.currentCulture.cultureName) {
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 } })),
);
}
@ -71,10 +77,10 @@ export class ConfigStateService {
}
refreshLocalization(lang: string): Observable<null> {
if(this.includeLocalizationResources){
if (this.includeLocalizationResources) {
return this.refreshAppState().pipe(map(() => null));
}
return this.getlocalizationResource(lang)
.pipe(
tap(result =>
@ -145,7 +151,7 @@ export class ConfigStateService {
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 }) => {
if (!features?.values) return;
@ -168,10 +174,13 @@ export class ConfigStateService {
const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1);
return keysFound.reduce((acc, key) => {
acc[key] = settings[key];
return acc;
}, {} as Record<string, string>);
return keysFound.reduce(
(acc, key) => {
acc[key] = settings[key];
return acc;
},
{} as Record<string, string>,
);
}
getSettings$(keyword?: string) {
@ -183,10 +192,13 @@ export class ConfigStateService {
const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1);
return keysFound.reduce((acc, key) => {
acc[key] = settings[key];
return acc;
}, {} as Record<string, string>);
return keysFound.reduce(
(acc, key) => {
acc[key] = settings[key];
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() {
this.checkRememberMeOption();
this.setUICulture();
return super
.init()
.then(() => this.setLanguageWithUICulture())
.then(() => this.oAuthService.tryLogin().catch(noop))
.then(() => this.oAuthService.setupAutomaticSilentRefresh());
}
@ -70,14 +70,14 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
return { ...(lang && culture), ...queryParams };
}
private setLanguageWithUICulture() {
private setUICulture() {
this.oAuthService.events
.pipe(
filter(event => event.type === 'token_received'),
tap(e => {
const urlParams = window.location.search;
const uiCulture = new URLSearchParams(urlParams).get('ui-culture');
this.sessionState.setLanguage(uiCulture);
const urlParams = new URLSearchParams(window.location.search);
this.configState.uiCultureFromAuthCodeFlow = urlParams.get('ui-culture');
window.history.replaceState(null, '', window.location.pathname);
}),
)
.subscribe();

Loading…
Cancel
Save