Skip to content

Commit

Permalink
Merge pull request #341 from swisstopo/hotfix/fix-routing
Browse files Browse the repository at this point in the history
Hotfix/fix routing
  • Loading branch information
vej-ananas authored Nov 13, 2024
2 parents 5a396b4 + 51e5ff0 commit ee18eea
Show file tree
Hide file tree
Showing 28 changed files with 339 additions and 276 deletions.
15 changes: 12 additions & 3 deletions apps/client-asset-sg/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { HttpClient } from '@angular/common/http';
import { Component, inject } from '@angular/core';
import { AppPortalService, appSharedStateActions, setCssCustomProperties } from '@asset-sg/client-shared';
import {
AppPortalService,
appSharedStateActions,
AuthService,
AuthState,
ConfigService,
ErrorService,
setCssCustomProperties,
} from '@asset-sg/client-shared';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Store } from '@ngrx/store';
import { WINDOW } from 'ngx-window-token';
import { debounceTime, fromEvent, startWith, switchMap } from 'rxjs';
import { assert } from 'tsafe';
import { AuthService, AuthState } from './features/auth/auth.service';
import { ErrorService } from './features/auth/error.service';
import { environment } from '../environments/environment';
import { AppState } from './state/app-state';

const fullHdWidth = 1920;
Expand All @@ -26,8 +33,10 @@ export class AppComponent {
readonly errorService = inject(ErrorService);
readonly authService = inject(AuthService);
private readonly store = inject(Store<AppState>);
private readonly configService = inject(ConfigService);

constructor() {
this.configService.setHideDisclaimer(environment.hideDisclaimer);
this._httpClient
.get<Record<string, unknown>>('api/oauth-config/config')
.pipe(switchMap(async (config) => await this.authService.initialize(config)))
Expand Down
8 changes: 3 additions & 5 deletions apps/client-asset-sg/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import {
AlertModule,
AnchorComponent,
assetsPageMatcher,
AuthModule,
ButtonComponent,
CanCreateDirective,
CURRENT_LANG,
currentLangFactory,
ErrorService,
icons,
LanguageSelectorComponent,
TranslateTsLoader,
Expand All @@ -36,16 +38,13 @@ import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-transla
import { ForModule } from '@rx-angular/template/for';
import { LetModule } from '@rx-angular/template/let';
import { PushModule } from '@rx-angular/template/push';
import { environment } from '../environments/environment';

import { environment } from '../environments/environment';
import { adminGuard } from './app-guards';
import { AppComponent } from './app.component';
import { AppBarComponent, MenuBarComponent, NotFoundComponent, RedirectToLangComponent } from './components';
import { DisclaimerDialogComponent } from './components/disclaimer-dialog/disclaimer-dialog.component';
import { MenuBarItemComponent } from './components/menu-bar-item/menu-bar-item.component';
import { SplashScreenComponent } from './components/splash-screen/splash-screen.component';
import { AuthModule } from './features/auth/auth.module';
import { ErrorService } from './features/auth/error.service';
import { appTranslations } from './i18n';
import { HttpInterceptor } from './services/http.interceptor';
import { AppSharedStateEffects } from './state';
Expand All @@ -62,7 +61,6 @@ registerLocaleData(locale_deCH, 'de-CH');
MenuBarComponent,
MenuBarItemComponent,
SplashScreenComponent,
DisclaimerDialogComponent,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import {
ViewChild,
} from '@angular/core';
import { Router } from '@angular/router';
import { appSharedStateActions, fromAppShared } from '@asset-sg/client-shared';
import { appSharedStateActions, AuthService, fromAppShared } from '@asset-sg/client-shared';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Store } from '@ngrx/store';
import * as O from 'fp-ts/Option';
import { EMPTY, filter, map, Observable, Subject, switchMap } from 'rxjs';
import { AuthService } from '../../features/auth/auth.service';
import { AppState } from '../../state/app-state';
import { Version } from './version';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '@asset-sg/client-shared';
import { UntilDestroy } from '@ngneat/until-destroy';
import { AuthService } from '../../features/auth/auth.service';

@UntilDestroy()
@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, inject } from '@angular/core';
import { CURRENT_LANG } from '@asset-sg/client-shared';
import { AuthService, AuthState, CURRENT_LANG } from '@asset-sg/client-shared';
import { TranslateService } from '@ngx-translate/core';
import { AuthService, AuthState } from '../../features/auth/auth.service';

@Component({
selector: 'app-splash-screen',
Expand Down
3 changes: 1 addition & 2 deletions apps/client-asset-sg/src/app/services/http.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpRequest } from '@angular/common/http';
import { inject, Injectable, OnDestroy } from '@angular/core';
import { NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router';
import { AlertType, fromAppShared, showAlert } from '@asset-sg/client-shared';
import { AlertType, AuthService, AuthState, fromAppShared, showAlert } from '@asset-sg/client-shared';
import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import { OAuthService } from 'angular-oauth2-oidc';
import { catchError, EMPTY, from, Observable, Subscription, switchMap } from 'rxjs';
import { AuthService, AuthState } from '../features/auth/auth.service';

@Injectable()
export class HttpInterceptor implements HttpInterceptor, OnDestroy {
Expand Down
3 changes: 1 addition & 2 deletions apps/client-asset-sg/src/app/state/app.effects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, Injectable } from '@angular/core';
import { NavigationEnd, Router, RouterStateSnapshot } from '@angular/router';
import { appSharedStateActions, fromAppShared } from '@asset-sg/client-shared';
import { appSharedStateActions, AuthService, fromAppShared } from '@asset-sg/client-shared';
import { ORD } from '@asset-sg/core';
import { eqLangRight, Lang } from '@asset-sg/shared';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
Expand All @@ -10,7 +10,6 @@ import { Store } from '@ngrx/store';
import { TranslateService } from '@ngx-translate/core';
import * as E from 'fp-ts/Either';
import { combineLatest, distinctUntilChanged, filter, map, switchMap, take } from 'rxjs';
import { AuthService } from '../features/auth/auth.service';

import { AppSharedStateService } from './app-shared-state.service';
import { AppState } from './app-state';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
<ng-template #detail>
<div class="header">
<span translate="search.detailedInformation"></span>
<a
[routerLink]="['.']"
[queryParams]="{ assetId: undefined }"
(click)="resetAssetDetail()"
queryParamsHandling="merge"
<button
(click)="clearSelectedAsset()"
asset-sg-icon-button
class="close-button"
[attr.alt]="'search.closeAssetDetails' | translate"
>
<svg-icon key="close"></svg-icon>
</a>
</button>
</div>
<div class="asset-detail-scroll-container">
<div class="asset-detail">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class AssetSearchDetailComponent {

public loadingState = this.store.select(selectAssetDetailLoadingState);

public resetAssetDetail() {
this.store.dispatch(actions.resetAssetDetail());
public clearSelectedAsset() {
this.store.dispatch(actions.clearSelectedAsset());
}

public searchForReferenceAsset(assetId: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AssetSearchFilterComponent<T> {
activeValues.add(filter.value);
}
this.store.dispatch(
actions.search({
actions.mergeQuery({
query: { [filter.queryKey]: activeValues.size > 0 ? [...activeValues] : undefined },
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class AssetSearchRefineComponent implements OnInit, OnDestroy, AfterViewI
}

public removePolygon() {
this.store.dispatch(actions.removePolygon());
this.store.dispatch(actions.clearPolygon());
}

public toggleDrawPolygon() {
Expand All @@ -109,7 +109,7 @@ export class AssetSearchRefineComponent implements OnInit, OnDestroy, AfterViewI

public updateSearch(filterConfiguration: Partial<AssetSearchQuery>) {
if (this.isFiltersOpen) {
this.store.dispatch(actions.search({ query: filterConfiguration }));
this.store.dispatch(actions.mergeQuery({ query: filterConfiguration }));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class AssetSearchResultsComponent implements OnInit, OnDestroy {
}

public toggleResultsOpen() {
this._store.dispatch(actions.manualToggleResult());
this._store.dispatch(actions.toggleResults());
}

public onScroll(event: Event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import {
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { AppPortalService, AppState, LifecycleHooks, LifecycleHooksDirective } from '@asset-sg/client-shared';
import {
AppPortalService,
AppState,
AuthService,
LifecycleHooks,
LifecycleHooksDirective,
} from '@asset-sg/client-shared';
import { AssetEditDetail } from '@asset-sg/shared';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { Store } from '@ngrx/store';
Expand All @@ -22,13 +28,15 @@ import {
asyncScheduler,
combineLatest,
filter,
identity,
map,
Observable,
observeOn,
partition,
share,
Subject,
switchMap,
take,
withLatestFrom,
} from 'rxjs';

Expand Down Expand Up @@ -92,9 +100,14 @@ export class AssetViewerPageComponent implements OnInit, OnDestroy {
public assetsForPicker$: Observable<AssetEditDetail[]>;
public highlightedAssetId: number | null = null;

private readonly authService = inject(AuthService);

public ngOnInit() {
this._store.dispatch(actions.initializeSearch());
this._store.dispatch(actions.openFilters());

this.authService.isInitialized$.pipe(filter(identity), take(1)).subscribe(() => {
this._store.dispatch(actions.initialize());
});
this._appPortalService.setAppBarPortalContent(null);
}

Expand Down Expand Up @@ -154,8 +167,8 @@ export class AssetViewerPageComponent implements OnInit, OnDestroy {
.pipe(
map(
flow(
O.map((text) => actions.search({ query: { text } })),
O.getOrElseW(() => actions.clearSearchText())
O.map((text) => actions.mergeQuery({ query: { text } })),
O.getOrElseW(() => actions.mergeQuery({ query: { text: '' } }))
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion libs/asset-viewer/src/lib/components/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class MapComponent implements AfterViewInit, OnChanges, OnDestroy {
)
.subscribe(([polygon, _]) =>
this.store.dispatch(
searchActions.search({
searchActions.mergeQuery({
query: { polygon: polygon },
})
)
Expand Down
12 changes: 6 additions & 6 deletions libs/asset-viewer/src/lib/services/asset-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export class AssetSearchService {
);
}

public loadAssetDetailData(assetId: number): Observable<AssetEditDetail> {
public searchStats(searchQuery: AssetSearchQuery): Observable<AssetSearchStats> {
return this._httpClient
.get(`/api/asset-edit/${assetId}`)
.pipe(map((res) => (AssetEditDetail.decode(res) as E.Right<AssetEditDetail>).right));
.post('/api/assets/search/stats', searchQuery)
.pipe(map((res) => plainToInstance(AssetSearchStatsDTO, res)));
}

public updateSearchResultStats(searchQuery: AssetSearchQuery): Observable<AssetSearchStats> {
public fetchAssetEditDetail(assetId: number): Observable<AssetEditDetail> {
return this._httpClient
.post('/api/assets/search/stats', searchQuery)
.pipe(map((res) => plainToInstance(AssetSearchStatsDTO, res)));
.get(`/api/asset-edit/${assetId}`)
.pipe(map((res) => (AssetEditDetail.decode(res) as E.Right<AssetEditDetail>).right));
}
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
import { AssetEditDetail, AssetSearchQuery, AssetSearchResult, AssetSearchStats } from '@asset-sg/shared';
import { AssetId } from '@asset-sg/shared/v2';
import { createAction, props } from '@ngrx/store';
import { AllStudyDTOs } from '../../models';

export const initialize = createAction('[Asset Search] Initialize');
export const runCombinedSearch = createAction(
'[Asset Search] Run Combined Search',
props<{
assetId: number | undefined;
query: AssetSearchQuery;
}>()
);
export const search = createAction(
'[Asset Search] Search',
props<{
query: Partial<AssetSearchQuery>;
query: AssetSearchQuery;
}>()
);
export const updateStats = createAction(
'[Asset Search] Update search stats',
export const mergeQuery = createAction(
'[Asset Search] Merge Query',
props<{
searchStats: AssetSearchStats;
query: AssetSearchQuery;
}>()
);
export const updateSearchResults = createAction(
'[Asset Search] Update search results',
export const executeSearch = createAction('[Asset Search] Execute Search', props<{ query: AssetSearchQuery }>());

export const updateResults = createAction(
'[Asset Search] Update Results',
props<{
searchResults: AssetSearchResult;
results: AssetSearchResult;
}>()
);
export const clearSearchText = createAction('[Asset Search] Clear search text');
export const resetSearch = createAction('[Asset Search] Reset Search');
export const removePolygon = createAction('[Asset Search] Remove polygon');
export const initializeSearch = createAction('[Asset Search] Initialize search');
export const assetClicked = createAction('[Asset Search] Asset clicked', props<{ assetId: number }>());
export const showAssetDetail = createAction('[Asset Search] Show Asset Detail', props<{ assetId: number }>());
export const updateAssetDetail = createAction(
'[Asset Search] Update Asset Detail',
props<{ assetDetail: AssetEditDetail }>()
export const updateStats = createAction(
'[Asset Search] Update Stats',
props<{
stats: AssetSearchStats;
}>()
);
export const resetAssetDetail = createAction('[Asset Search] Reset Asset Detail');
export const resetSearch = createAction('[Asset Search] Reset Search');

export const assetClicked = createAction('[Asset Search] Asset Clicked', props<{ assetId: number }>());
export const selectAsset = createAction('[Asset Search] Select Asset', props<{ assetId: AssetId }>());
export const setSelectedAsset = createAction('[Asset Search] Set Selected Asset', props<{ asset: AssetEditDetail }>());
export const clearSelectedAsset = createAction('[Asset Search] Clear Selected Asset');
export const clearPolygon = createAction('[Asset Search] Clear Polygon');
export const setStudies = createAction('[Asset Search] Set Studies', props<{ studies: AllStudyDTOs }>());

export const openFilters = createAction('[Asset Search] Open Filters');
export const closeFilters = createAction('[Asset Search] Close Filters');
export const openResults = createAction('[Asset Search] Open Results');
export const closeResults = createAction('[Asset Search] Close Results');
export const setStudies = createAction('[Asset Search] Load Studies', props<{ studies: AllStudyDTOs }>());
export const loadSearch = createAction('[Asset Search] Load Search', props<{ query: AssetSearchQuery }>());
export const updateQueryParams = createAction('[Asset Search] Update Query Params');
export const manualToggleResult = createAction('[Asset Search] Manual Toggle Params');
export const toggleResults = createAction('[Asset Search] Toggle Results');
Loading

0 comments on commit ee18eea

Please sign in to comment.