Requests to server visible in console

This commit is contained in:
Piotr Pekala 2019-08-22 05:26:48 -07:00
parent fc746f04cb
commit fee26eff87
2 changed files with 20 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import { Link } from '../../../models/link';
import { Node } from '../../../cartography/models/node'; import { Node } from '../../../cartography/models/node';
import { Port } from '../../../models/port'; import { Port } from '../../../models/port';
import { LogEventsDataSource } from './log-events-datasource'; import { LogEventsDataSource } from './log-events-datasource';
import { HttpServer } from '../../../services/http-server.service';
@Component({ @Component({
@ -25,6 +26,7 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
private nodeSubscription: Subscription; private nodeSubscription: Subscription;
private linkSubscription: Subscription; private linkSubscription: Subscription;
private drawingSubscription: Subscription; private drawingSubscription: Subscription;
private serverRequestsSubscription: Subscription;
command: string = ''; command: string = '';
private regexStart: RegExp = /^start (.*?)$/; private regexStart: RegExp = /^start (.*?)$/;
@ -37,7 +39,8 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
private projectWebServiceHandler: ProjectWebServiceHandler, private projectWebServiceHandler: ProjectWebServiceHandler,
private nodeService: NodeService, private nodeService: NodeService,
private nodesDataSource: NodesDataSource, private nodesDataSource: NodesDataSource,
private logEventsDataSource: LogEventsDataSource private logEventsDataSource: LogEventsDataSource,
private httpService: HttpServer
) {} ) {}
ngOnInit() { ngOnInit() {
@ -56,6 +59,9 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
let message = `Event received: ${event.action} - ${this.printDrawing(drawing)}.` let message = `Event received: ${event.action} - ${this.printDrawing(drawing)}.`
this.showMessage(message); this.showMessage(message);
}); });
this.serverRequestsSubscription = this.httpService.requestsNotificationEmitter.subscribe((event) => {
this.showMessage(event);
});
} }
ngAfterViewInit() { ngAfterViewInit() {
@ -199,7 +205,6 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
return `drawing_id: ${drawing.drawing_id}, return `drawing_id: ${drawing.drawing_id},
project_id: ${drawing.project_id}, project_id: ${drawing.project_id},
rotation: ${drawing.rotation}, rotation: ${drawing.rotation},
svg: ${drawing.svg},
x: ${drawing.x}, x: ${drawing.x},
y: ${drawing.y}, y: ${drawing.y},
z: ${drawing.z}`; z: ${drawing.z}`;

View File

@ -1,4 +1,4 @@
import { Injectable } from '@angular/core'; import { Injectable, EventEmitter } from '@angular/core';
import { HttpHeaders, HttpClient, HttpParams, HttpErrorResponse } from '@angular/common/http'; import { HttpHeaders, HttpClient, HttpParams, HttpErrorResponse } from '@angular/common/http';
import { Observable, throwError } from 'rxjs'; import { Observable, throwError } from 'rxjs';
@ -79,11 +79,15 @@ export class ServerErrorHandler {
@Injectable() @Injectable()
export class HttpServer { export class HttpServer {
public requestsNotificationEmitter = new EventEmitter<string>();
constructor(private http: HttpClient, private errorHandler: ServerErrorHandler) {} constructor(private http: HttpClient, private errorHandler: ServerErrorHandler) {}
get<T>(server: Server, url: string, options?: JsonOptions): Observable<T> { get<T>(server: Server, url: string, options?: JsonOptions): Observable<T> {
options = this.getJsonOptions(options); options = this.getJsonOptions(options);
const intercepted = this.getOptionsForServer<JsonOptions>(server, url, options); const intercepted = this.getOptionsForServer<JsonOptions>(server, url, options);
this.requestsNotificationEmitter.emit(`GET ${intercepted.url}`);
return this.http return this.http
.get<T>(intercepted.url, intercepted.options as JsonOptions) .get<T>(intercepted.url, intercepted.options as JsonOptions)
.pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>; .pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>;
@ -92,6 +96,8 @@ export class HttpServer {
getText(server: Server, url: string, options?: TextOptions): Observable<string> { getText(server: Server, url: string, options?: TextOptions): Observable<string> {
options = this.getTextOptions(options); options = this.getTextOptions(options);
const intercepted = this.getOptionsForServer<TextOptions>(server, url, options); const intercepted = this.getOptionsForServer<TextOptions>(server, url, options);
this.requestsNotificationEmitter.emit(`GET ${intercepted.url}`);
return this.http return this.http
.get(intercepted.url, intercepted.options as TextOptions) .get(intercepted.url, intercepted.options as TextOptions)
.pipe(catchError(this.errorHandler.handleError)); .pipe(catchError(this.errorHandler.handleError));
@ -100,6 +106,8 @@ export class HttpServer {
post<T>(server: Server, url: string, body: any | null, options?: JsonOptions): Observable<T> { post<T>(server: Server, url: string, body: any | null, options?: JsonOptions): Observable<T> {
options = this.getJsonOptions(options); options = this.getJsonOptions(options);
const intercepted = this.getOptionsForServer(server, url, options); const intercepted = this.getOptionsForServer(server, url, options);
this.requestsNotificationEmitter.emit(`POST ${intercepted.url}`);
return this.http return this.http
.post<T>(intercepted.url, body, intercepted.options) .post<T>(intercepted.url, body, intercepted.options)
.pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>; .pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>;
@ -108,6 +116,8 @@ export class HttpServer {
put<T>(server: Server, url: string, body: any, options?: JsonOptions): Observable<T> { put<T>(server: Server, url: string, body: any, options?: JsonOptions): Observable<T> {
options = this.getJsonOptions(options); options = this.getJsonOptions(options);
const intercepted = this.getOptionsForServer(server, url, options); const intercepted = this.getOptionsForServer(server, url, options);
this.requestsNotificationEmitter.emit(`PUT ${intercepted.url}`);
return this.http return this.http
.put<T>(intercepted.url, body, intercepted.options) .put<T>(intercepted.url, body, intercepted.options)
.pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>; .pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>;
@ -116,6 +126,8 @@ export class HttpServer {
delete<T>(server: Server, url: string, options?: JsonOptions): Observable<T> { delete<T>(server: Server, url: string, options?: JsonOptions): Observable<T> {
options = this.getJsonOptions(options); options = this.getJsonOptions(options);
const intercepted = this.getOptionsForServer(server, url, options); const intercepted = this.getOptionsForServer(server, url, options);
this.requestsNotificationEmitter.emit(`DELETE ${intercepted.url}`);
return this.http return this.http
.delete<T>(intercepted.url, intercepted.options) .delete<T>(intercepted.url, intercepted.options)
.pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>; .pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>;