Commit fe497231 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Tentative de configuration DebugModule.forRoot().

No related merge requests found
Showing with 56 additions and 22 deletions
+56 -22
...@@ -2003,6 +2003,7 @@ ...@@ -2003,6 +2003,7 @@
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@devatscience/ngx-rxtools/-/ngx-rxtools-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@devatscience/ngx-rxtools/-/ngx-rxtools-1.1.0.tgz",
"integrity": "sha512-UCIavkf2dYoeScSiYk3iBRkXPnqL2FJ5WlVZepOehaUgy7RPLIomWMh0wLGLYHTFLlvy1v3V1FLyDmS8GDOz2w==", "integrity": "sha512-UCIavkf2dYoeScSiYk3iBRkXPnqL2FJ5WlVZepOehaUgy7RPLIomWMh0wLGLYHTFLlvy1v3V1FLyDmS8GDOz2w==",
"dev": true,
"requires": { "requires": {
"tslib": "^1.9.0" "tslib": "^1.9.0"
} }
...@@ -6001,9 +6002,9 @@ ...@@ -6001,9 +6002,9 @@
"dev": true "dev": true
}, },
"handlebars": { "handlebars": {
"version": "4.2.0", "version": "4.4.3",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.2.0.tgz", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.3.tgz",
"integrity": "sha512-Kb4xn5Qh1cxAKvQnzNWZ512DhABzyFNmsaJf3OAkWNa4NkaqWcNI8Tao8Tasi0/F4JD9oyG0YxuFyvyR57d+Gw==", "integrity": "sha512-B0W4A2U1ww3q7VVthTKfh+epHx+q4mCt6iK+zEAzbMBpWQAwxCeKxEGpj/1oQTpzPXDNSOG7hmG14TsISH50yw==",
"dev": true, "dev": true,
"requires": { "requires": {
"neo-async": "^2.6.0", "neo-async": "^2.6.0",
...@@ -12204,13 +12205,13 @@ ...@@ -12204,13 +12205,13 @@
"dev": true "dev": true
}, },
"uglify-js": { "uglify-js": {
"version": "3.6.0", "version": "3.6.1",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.1.tgz",
"integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", "integrity": "sha512-+dSJLJpXBb6oMHP+Yvw8hUgElz4gLTh82XuX68QiJVTXaE5ibl6buzhNkQdYhBlIhozWOC9ge16wyRmjG4TwVQ==",
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"commander": "~2.20.0", "commander": "2.20.0",
"source-map": "~0.6.1" "source-map": "~0.6.1"
}, },
"dependencies": { "dependencies": {
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
"type": "git", "type": "git",
"url": "https://gitlab.irstea.fr/pole-is/packages/ngx-debug.git" "url": "https://gitlab.irstea.fr/pole-is/packages/ngx-debug.git"
}, },
"dependencies": {
"tslib": "^1.10.0"
},
"peerDependencies": { "peerDependencies": {
"@angular/common": "^8", "@angular/common": "^8",
"@angular/core": "^8", "@angular/core": "^8",
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
* Public API Surface of ngx-debug * Public API Surface of ngx-debug
*/ */
export * from './lib/debug.module';
export * from './lib/spy/spy.operator';
export * from './lib/api/api-debug.interceptor'; export * from './lib/api/api-debug.interceptor';
export * from './lib/api/api-debug.component'; export * from './lib/api/api-debug.component';
export * from './lib/debug.module';
export * from './lib/dump-value.component';
export * from './lib/watch/watch.component';
export * from './lib/watch/watch.service'; export * from './lib/watch/watch.service';
export * from './lib/debug-toggle.component';
export * from './lib/debug-state.service';
export * from './lib/spy/spy.operator';
import { HttpRequest, HttpResponseBase } from '@angular/common/http'; import { HttpRequest, HttpResponseBase } from '@angular/common/http';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Inject, InjectionToken, Output } from '@angular/core'; import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Inject,
InjectionToken,
Output,
} from '@angular/core';
import { DebugStateService } from '../debug-state.service'; import { DebugStateService } from '../debug-state.service';
...@@ -38,7 +46,7 @@ export class ApiDebugComponent { ...@@ -38,7 +46,7 @@ export class ApiDebugComponent {
interceptor: ApiDebugInterceptor, interceptor: ApiDebugInterceptor,
public readonly debug: DebugStateService, public readonly debug: DebugStateService,
private readonly cd: ChangeDetectorRef, private readonly cd: ChangeDetectorRef,
@Inject(ApiBaseUrlToken) private readonly apiPrefix: string, @Inject(ApiBaseUrlToken) private readonly apiPrefix: string
) { ) {
interceptor.events$.subscribe(ev => { interceptor.events$.subscribe(ev => {
this.handle(ev); this.handle(ev);
...@@ -78,7 +86,7 @@ export class ApiDebugComponent { ...@@ -78,7 +86,7 @@ export class ApiDebugComponent {
private addRequest( private addRequest(
id: string, id: string,
{ urlWithParams, method }: HttpRequest<any>, { urlWithParams, method }: HttpRequest<any>
): void { ): void {
if (urlWithParams.startsWith(this.apiPrefix)) { if (urlWithParams.startsWith(this.apiPrefix)) {
urlWithParams = new URL(urlWithParams).pathname; urlWithParams = new URL(urlWithParams).pathname;
...@@ -96,7 +104,7 @@ export class ApiDebugComponent { ...@@ -96,7 +104,7 @@ export class ApiDebugComponent {
private setResponse( private setResponse(
request: RequestInfo, request: RequestInfo,
{ status, statusText, headers }: HttpResponseBase, { status, statusText, headers }: HttpResponseBase
): void { ): void {
request.response = { request.response = {
status, status,
...@@ -124,7 +132,7 @@ export class ApiDebugComponent { ...@@ -124,7 +132,7 @@ export class ApiDebugComponent {
} }
public get last(): RequestInfo | null { public get last(): RequestInfo | null {
return this.ids.length ? this.requests.get(this.ids[ 0 ]) : null; return this.ids.length ? this.requests.get(this.ids[0]) : null;
} }
public get previous(): RequestInfo[] { public get previous(): RequestInfo[] {
......
export * from './api-debug.component';
export * from './api-debug.interceptor';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { LOCALE_ID, NgModule } from '@angular/core'; import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LOCALE_ID, ModuleWithProviders, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { import {
ButtonModule, ButtonModule,
...@@ -14,8 +15,9 @@ import { ...@@ -14,8 +15,9 @@ import {
import { TreeModule } from 'primeng/tree'; import { TreeModule } from 'primeng/tree';
import { TreeTableModule } from 'primeng/treetable'; import { TreeTableModule } from 'primeng/treetable';
import { ApiDebugComponent } from './api'; import { ApiBaseUrlToken, ApiDebugComponent } from './api/api-debug.component';
import { DebugStateService } from './debug-state.service'; import { ApiDebugInterceptor } from './api/api-debug.interceptor';
import { DebugStateService, ProductionToken } from './debug-state.service';
import { DebugToggleComponent } from './debug-toggle.component'; import { DebugToggleComponent } from './debug-toggle.component';
import { DumpPanelComponent } from './dump-panel.component'; import { DumpPanelComponent } from './dump-panel.component';
import { DumpValueComponent } from './dump-value.component'; import { DumpValueComponent } from './dump-value.component';
...@@ -61,4 +63,23 @@ const EXPORTED_COMPONENTS = [ ...@@ -61,4 +63,23 @@ const EXPORTED_COMPONENTS = [
], ],
exports: [...EXPORTED_COMPONENTS], exports: [...EXPORTED_COMPONENTS],
}) })
export class DebugModule {} export class DebugModule {
public static forRoot(
apiBaseUrl: string,
production: boolean
): ModuleWithProviders {
// TODO: fournir un module différent en prod (+ léger) et en dev (complet)
return {
ngModule: DebugModule,
providers: [
{ provide: ProductionToken, useValue: production },
{ provide: ApiBaseUrlToken, useValue: apiBaseUrl },
{
provide: HTTP_INTERCEPTORS,
useClass: ApiDebugInterceptor,
multi: true,
},
],
};
}
}
...@@ -20,6 +20,6 @@ ...@@ -20,6 +20,6 @@
"strictInjectionParameters": true, "strictInjectionParameters": true,
"enableResourceInlining": true "enableResourceInlining": true
}, },
"files": ["src/**/*.ts"], "include": ["src/**/*.ts"],
"exclude": ["src/test.ts", "**/*.spec.ts"] "exclude": ["src/test.ts", "**/*.spec.ts"]
} }
...@@ -4,6 +4,5 @@ ...@@ -4,6 +4,5 @@
"outDir": "out-tsc/spec", "outDir": "out-tsc/spec",
"types": ["jasmine", "node"] "types": ["jasmine", "node"]
}, },
"files": ["src/test.ts"],
"exclude": [] "exclude": []
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment