diff --git a/src/lib/api/api-debug.component.ts b/src/lib/api/api-debug.component.ts index 9fd875fb8ffc93cd6fa13d259c7cbd915f1b39ca..fb3e65e500f74f0fcfc264b3f755cf78c03b1adb 100644 --- a/src/lib/api/api-debug.component.ts +++ b/src/lib/api/api-debug.component.ts @@ -7,8 +7,6 @@ import { Output, } from '@angular/core'; -// TODO injecter -import { Configuration } from '../configuration'; import { DebugStateService } from '../debug-state.service'; import { ApiDebugInterceptor, DebugEvent } from './api-debug.interceptor'; @@ -28,6 +26,8 @@ interface ResponseInfo { tokenLink?: string; } +export const ApiBaseUrlToken = new InjectionToken<string>('apiBaseUrl'); + @Component({ selector: 'dbg-api-debug', templateUrl: './api-debug.component.html', @@ -46,10 +46,8 @@ export class ApiDebugComponent { interceptor: ApiDebugInterceptor, public readonly debug: DebugStateService, private readonly cd: ChangeDetectorRef, - conf: Configuration + @Inject(ApiBaseUrlToken) private readonly apiPrefix: string, ) { - this.apiPrefix = conf.apiBaseURL; - interceptor.events$.subscribe(ev => { this.handle(ev); }); diff --git a/src/lib/api/api-debug.interceptor.ts b/src/lib/api/api-debug.interceptor.ts index d8f9b8d275fa8933e3e7c1712f47dee76f000edd..a42608dd50c5bf4e36840c6fb38c88ac4ea2ba21 100644 --- a/src/lib/api/api-debug.interceptor.ts +++ b/src/lib/api/api-debug.interceptor.ts @@ -9,9 +9,6 @@ import * as _ from 'lodash'; import { Observable, ReplaySubject } from 'rxjs'; import { finalize, tap } from 'rxjs/operators'; -// TODO injecter -import { Configuration } from '../configuration'; - export interface RequestDebugEvent { id: string; type: 'request'; @@ -37,11 +34,7 @@ export type DebugEvent = export class ApiDebugInterceptor implements HttpInterceptor { private readonly sink$ = new ReplaySubject<DebugEvent>(10); public readonly events$ = this.sink$.asObservable(); - private readonly enabled: boolean; - - constructor(conf: Configuration) { - this.enabled = conf.debug; - } + private readonly enabled = true; public intercept( request: HttpRequest<any>, diff --git a/src/lib/debug-state.service.ts b/src/lib/debug-state.service.ts index 1a5c072f4796ae9d11294e2337d7fb42ea929e75..f78d88348db7950edf39a7d5013a5e2ea449bf66 100644 --- a/src/lib/debug-state.service.ts +++ b/src/lib/debug-state.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Inject, Injectable, InjectionToken, Optional } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; import { distinctUntilChanged, map } from 'rxjs/operators'; @@ -8,6 +8,8 @@ export const enum DebugState { ENABLED = 1, } +export const ProductionToken = new InjectionToken<boolean>('production'); + @Injectable() export class DebugStateService { private readonly state$: BehaviorSubject<DebugState>; @@ -26,7 +28,9 @@ export class DebugStateService { return this.state === DebugState.ENABLED; } - public constructor(production: boolean = false) { + public constructor( + @Inject(ProductionToken) @Optional() production: boolean = false + ) { this.state$ = new BehaviorSubject<DebugState>( production ? DebugState.UNAVAILABLE : DebugState.ENABLED ); diff --git a/src/lib/debug.module.ts b/src/lib/debug.module.ts index cb97aeb235e9196a444ac2b7f59e7e84a07d20a0..a00db58eb133bafebe7d110100f2e548bb47a1b7 100644 --- a/src/lib/debug.module.ts +++ b/src/lib/debug.module.ts @@ -15,7 +15,6 @@ import { TreeModule } from 'primeng/tree'; import { TreeTableModule } from 'primeng/treetable'; import { ApiDebugComponent } from './api/api-debug.component'; -import { Configuration, configurationFactory } from './configuration'; import { DebugStateService } from './debug-state.service'; import { DebugToggleComponent } from './debug-toggle.component'; import { DumpPanelComponent } from './dump-panel.component'; @@ -51,7 +50,6 @@ const EXPORTED_COMPONENTS = [ providers: [ WatchService, DebugStateService, - { provide: Configuration, useFactory: configurationFactory }, { provide: LOCALE_ID, useValue: 'fr' }, ], declarations: [