Skip to content

Commit

Permalink
Merge pull request #331 from swisstopo/develop
Browse files Browse the repository at this point in the history
INT Release
  • Loading branch information
daniel-va authored Nov 1, 2024
2 parents 9359f4f + b602148 commit fe394f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
8 changes: 6 additions & 2 deletions apps/client-asset-sg/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import {
AdminOnlyDirective,
AlertModule,
AnchorComponent,
assetsPageMatcher,
ButtonComponent,
CanCreateDirective,
CURRENT_LANG,
currentLangFactory,
icons,
TranslateTsLoader,
} from '@asset-sg/client-shared';
import { assetsPageMatcher } from '@asset-sg/client-shared';
import { storeLogger } from '@asset-sg/core';
import { provideSvgIcons, SvgIconComponent } from '@ngneat/svg-icon';
import { EffectsModule } from '@ngrx/effects';
Expand Down Expand Up @@ -78,9 +78,13 @@ registerLocaleData(locale_deCH, 'de-CH');
loadChildren: () => import('@asset-sg/asset-viewer').then((m) => m.AssetViewerModule),
},
{
path: '**',
path: 'not-found',
component: NotFoundComponent,
},
{
path: '**',
component: RedirectToLangComponent,
},
]),
TranslateModule.forRoot({
loader: { provide: TranslateLoader, useFactory: () => new TranslateTsLoader(appTranslations) },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Router } from '@angular/router';
import { AuthService } from '@asset-sg/auth';
import { Lang } from '@asset-sg/shared';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import * as E from 'fp-ts/Either';
import * as D from 'io-ts/Decoder';
import queryString from 'query-string';
import { UntilDestroy } from '@ngneat/until-destroy';

@UntilDestroy()
@Component({
selector: 'asset-sg-redirect-to-lang',
template: 'Redirect to main page...',
})
export class RedirectToLangComponent {
constructor(route: ActivatedRoute, router: Router, authService: AuthService) {
route.queryParams.pipe(untilDestroyed(this)).subscribe((params) => {
const paramsDecoded = D.struct({
lang: Lang,
}).decode(params);

if (E.isRight(paramsDecoded)) {
const { url, query } = queryString.parseUrl(router.url);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { lang, ...rest } = query;
const newUrl = `/${paramsDecoded.right.lang}${url}?${queryString.stringify(rest)}`;
router.navigateByUrl(newUrl);
} else if (!authService.isLoggedIn()) {
setTimeout(() => {
router.navigate(['/de']);
}, 500);
} else {
router.navigate(['/de']);
constructor(router: Router, authService: AuthService) {
authService.isInitialized$.subscribe((isInitialized) => {
if (isInitialized) {
router.navigate(['/de'], { queryParamsHandling: 'merge' });
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import { Actions, concatLatestFrom, createEffect, ofType } from '@ngrx/effects';
import { ROUTER_NAVIGATED } from '@ngrx/router-store';
import { Store } from '@ngrx/store';
import * as D from 'io-ts/Decoder';
import { EMPTY, filter, map, merge, of, share, switchMap, takeUntil, withLatestFrom } from 'rxjs';
import { EMPTY, filter, map, merge, of, shareReplay, switchMap, takeUntil, withLatestFrom } from 'rxjs';

import { AllStudyService } from '../../services/all-study.service';
import { AssetSearchService } from '../../services/asset-search.service';

import * as actions from './asset-search.actions';
import {
selectAssetSearchNoActiveFilters,
selectAssetSearchQuery,
selectAssetSearchResultData,
selectCurrentAssetDetail,
selectAssetSearchNoActiveFilters,
selectStudies,
selectAssetSearchResultData,
} from './asset-search.selector';

@UntilDestroy()
Expand Down Expand Up @@ -162,7 +162,7 @@ export class AssetSearchEffects {
query.workgroupIds = readArrayParam<number>(params, QUERY_PARAM_MAPPING.workgroupIds);
return { query, assetId };
}),
share()
shareReplay()
);

public readSearchQueryParams$ = createEffect(() =>
Expand Down Expand Up @@ -201,7 +201,7 @@ export class AssetSearchEffects {
public updateQueryParams$ = createEffect(
() =>
this.actions$.pipe(
ofType(actions.updateQueryParams, actions.updateAssetDetail, actions.resetAssetDetail),
ofType(actions.updateQueryParams, actions.updateAssetDetail, actions.resetAssetDetail, actions.loadSearch),
concatLatestFrom(() => [
this.store.select(selectAssetSearchQuery),
this.store.select(selectCurrentAssetDetail),
Expand Down
12 changes: 10 additions & 2 deletions libs/auth/src/lib/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ export class AuthService {
private readonly router = inject(Router);

private readonly _state$ = new BehaviorSubject(AuthState.Ongoing);
private readonly _isInitialized$ = new BehaviorSubject(false);

async initialize(oAuthConfig: Record<string, unknown>) {
if (oAuthConfig['anonymous_mode']) {
this.setState(AuthState.Success);
this.store.dispatch(appSharedStateActions.setAnonymousMode());
} else {
const callbackUrl = sessionStorage.getItem(CALLBACK_PATH_KEY);
sessionStorage.setItem(CALLBACK_PATH_KEY, this.router.url);
sessionStorage.setItem(CALLBACK_PATH_KEY, window.location.pathname + window.location.search);
this.configureOAuth(
oAuthConfig['oauth_issuer'] as string,
oAuthConfig['oauth_clientId'] as string,
Expand All @@ -35,11 +36,14 @@ export class AuthService {
);
await this.signIn();
if (callbackUrl != null) {
sessionStorage.removeItem(CALLBACK_PATH_KEY);
await this.router.navigateByUrl(callbackUrl);
}
if (this.oauthService.hasValidAccessToken()) {
sessionStorage.removeItem(CALLBACK_PATH_KEY);
}
this.store.dispatch(appSharedStateActions.loadUserProfile());
}
this._isInitialized$.next(true);
}

async signIn(): Promise<void> {
Expand Down Expand Up @@ -71,6 +75,10 @@ export class AuthService {
return this._state$.asObservable();
}

get isInitialized$(): Observable<boolean> {
return this._isInitialized$.asObservable();
}

setState(state: AuthState): void {
this._state$.next(state);
}
Expand Down

0 comments on commit fe394f3

Please sign in to comment.