Skip to content

Commit

Permalink
Add config service
Browse files Browse the repository at this point in the history
  • Loading branch information
TIL-EBP committed Nov 13, 2024
1 parent 88c6dd2 commit 51e5ff0
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions apps/client-asset-sg/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
appSharedStateActions,
AuthService,
AuthState,
ConfigService,
ErrorService,
setCssCustomProperties,
} from '@asset-sg/client-shared';
Expand All @@ -13,6 +14,7 @@ import { Store } from '@ngrx/store';
import { WINDOW } from 'ngx-window-token';
import { debounceTime, fromEvent, startWith, switchMap } from 'rxjs';
import { assert } from 'tsafe';
import { environment } from '../environments/environment';
import { AppState } from './state/app-state';

const fullHdWidth = 1920;
Expand All @@ -31,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
2 changes: 1 addition & 1 deletion apps/client-asset-sg/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
LanguageSelectorComponent,
TranslateTsLoader,
} from '@asset-sg/client-shared';
import { environment } from '@asset-sg/client-shared';
import { storeLogger } from '@asset-sg/core';
import { provideSvgIcons, SvgIconComponent } from '@ngneat/svg-icon';
import { EffectsModule } from '@ngrx/effects';
Expand All @@ -40,6 +39,7 @@ 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 { adminGuard } from './app-guards';
import { AppComponent } from './app.component';
import { AppBarComponent, MenuBarComponent, NotFoundComponent, RedirectToLangComponent } from './components';
Expand Down
2 changes: 1 addition & 1 deletion apps/client-asset-sg/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CompileTimeEnvironment } from '@asset-sg/client-shared';
import { CompileTimeEnvironment } from './environment-type';

export const environment: CompileTimeEnvironment = {
ngrxStoreLoggerEnabled: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CompileTimeEnvironment } from './environment-type';

export const environment: CompileTimeEnvironment = {
ngrxStoreLoggerEnabled: true,
ngrxStoreLoggerEnabled: false,
hideDisclaimer: true,
};
2 changes: 0 additions & 2 deletions libs/client-shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ export * from './lib/directives/can-create.directive';
export * from './lib/directives/can-delete.directive';
export * from './lib/directives/can-show.directive';
export * from './lib/directives/can-update.directive';
export * from './lib/environments/environment';
export * from './lib/environments/environment-type';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AsyncPipe } from '@angular/common';
import { Component, inject } from '@angular/core';
import { MatDialogActions, MatDialogContent, MatDialogRef } from '@angular/material/dialog';
import { MatDivider } from '@angular/material/divider';
import { TranslateService } from '@ngx-translate/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { map } from 'rxjs';
import { ButtonComponent } from '../../components/button';
import { LanguageSelectorComponent } from '../../components/language-selector';
Expand All @@ -15,7 +15,15 @@ const LEGAL_BASE_URL = 'https://www.swissgeol.ch/datenschutz';
selector: 'asset-sg-disclaimer-dialog',
templateUrl: './disclaimer-dialog.component.html',
styleUrl: './disclaimer-dialog.component.scss',
imports: [LanguageSelectorComponent, MatDivider, MatDialogActions, MatDialogContent, ButtonComponent, AsyncPipe],
imports: [
LanguageSelectorComponent,
MatDivider,
MatDialogActions,
MatDialogContent,
ButtonComponent,
AsyncPipe,
TranslateModule,
],
})
export class DisclaimerDialogComponent {
public text = '';
Expand Down
5 changes: 3 additions & 2 deletions libs/client-shared/src/lib/features/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { OAuthService } from 'angular-oauth2-oidc';
import { plainToInstance } from 'class-transformer';
import { BehaviorSubject, map, Observable, startWith } from 'rxjs';
import { DisclaimerDialogComponent } from '../../components/disclaimer-dialog/disclaimer-dialog.component';
import { environment } from '../../environments/environment';
import { ConfigService } from '../../services';
import { appSharedStateActions, AppState } from '../../state';
import { ApiError } from '../../utils';

Expand All @@ -21,6 +21,7 @@ export class AuthService {
private readonly store = inject(Store<AppState>);
private readonly router = inject(Router);
private readonly dialogService = inject(MatDialog);
private readonly configService = inject(ConfigService);

private readonly _state$ = new BehaviorSubject(AuthState.Ongoing);
private readonly _isInitialized$ = new BehaviorSubject(false);
Expand Down Expand Up @@ -62,7 +63,7 @@ export class AuthService {
if (this._state$.value === AuthState.Ongoing) {
this._state$.next(AuthState.Success);

if (!environment.hideDisclaimer) {
if (!this.configService.getHideDisclaimer()) {
this.dialogService.open(DisclaimerDialogComponent, {
width: '500px',
disableClose: true,
Expand Down
14 changes: 14 additions & 0 deletions libs/client-shared/src/lib/services/config.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';

@Injectable({ providedIn: 'root' })
export class ConfigService {
private hideDisclaimer = false;

public setHideDisclaimer(value: boolean): void {
this.hideDisclaimer = value;
}

public getHideDisclaimer(): boolean {
return this.hideDisclaimer;
}
}
1 change: 1 addition & 0 deletions libs/client-shared/src/lib/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './app-portal.service';
export * from './dateid-module';
export * from './window.service';
export * from './config.service';

0 comments on commit 51e5ff0

Please sign in to comment.