mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-31 14:30:43 +00:00
Requests to server visible in console
This commit is contained in:
parent
fc746f04cb
commit
fee26eff87
@ -10,6 +10,7 @@ import { Link } from '../../../models/link';
|
||||
import { Node } from '../../../cartography/models/node';
|
||||
import { Port } from '../../../models/port';
|
||||
import { LogEventsDataSource } from './log-events-datasource';
|
||||
import { HttpServer } from '../../../services/http-server.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -25,6 +26,7 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
private nodeSubscription: Subscription;
|
||||
private linkSubscription: Subscription;
|
||||
private drawingSubscription: Subscription;
|
||||
private serverRequestsSubscription: Subscription;
|
||||
command: string = '';
|
||||
|
||||
private regexStart: RegExp = /^start (.*?)$/;
|
||||
@ -37,7 +39,8 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
private projectWebServiceHandler: ProjectWebServiceHandler,
|
||||
private nodeService: NodeService,
|
||||
private nodesDataSource: NodesDataSource,
|
||||
private logEventsDataSource: LogEventsDataSource
|
||||
private logEventsDataSource: LogEventsDataSource,
|
||||
private httpService: HttpServer
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@ -56,6 +59,9 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
let message = `Event received: ${event.action} - ${this.printDrawing(drawing)}.`
|
||||
this.showMessage(message);
|
||||
});
|
||||
this.serverRequestsSubscription = this.httpService.requestsNotificationEmitter.subscribe((event) => {
|
||||
this.showMessage(event);
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@ -199,7 +205,6 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return `drawing_id: ${drawing.drawing_id},
|
||||
project_id: ${drawing.project_id},
|
||||
rotation: ${drawing.rotation},
|
||||
svg: ${drawing.svg},
|
||||
x: ${drawing.x},
|
||||
y: ${drawing.y},
|
||||
z: ${drawing.z}`;
|
||||
|
@ -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 { Observable, throwError } from 'rxjs';
|
||||
@ -79,11 +79,15 @@ export class ServerErrorHandler {
|
||||
|
||||
@Injectable()
|
||||
export class HttpServer {
|
||||
public requestsNotificationEmitter = new EventEmitter<string>();
|
||||
|
||||
constructor(private http: HttpClient, private errorHandler: ServerErrorHandler) {}
|
||||
|
||||
get<T>(server: Server, url: string, options?: JsonOptions): Observable<T> {
|
||||
options = this.getJsonOptions(options);
|
||||
const intercepted = this.getOptionsForServer<JsonOptions>(server, url, options);
|
||||
this.requestsNotificationEmitter.emit(`GET ${intercepted.url}`);
|
||||
|
||||
return this.http
|
||||
.get<T>(intercepted.url, intercepted.options as JsonOptions)
|
||||
.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> {
|
||||
options = this.getTextOptions(options);
|
||||
const intercepted = this.getOptionsForServer<TextOptions>(server, url, options);
|
||||
this.requestsNotificationEmitter.emit(`GET ${intercepted.url}`);
|
||||
|
||||
return this.http
|
||||
.get(intercepted.url, intercepted.options as TextOptions)
|
||||
.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> {
|
||||
options = this.getJsonOptions(options);
|
||||
const intercepted = this.getOptionsForServer(server, url, options);
|
||||
this.requestsNotificationEmitter.emit(`POST ${intercepted.url}`);
|
||||
|
||||
return this.http
|
||||
.post<T>(intercepted.url, body, intercepted.options)
|
||||
.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> {
|
||||
options = this.getJsonOptions(options);
|
||||
const intercepted = this.getOptionsForServer(server, url, options);
|
||||
this.requestsNotificationEmitter.emit(`PUT ${intercepted.url}`);
|
||||
|
||||
return this.http
|
||||
.put<T>(intercepted.url, body, intercepted.options)
|
||||
.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> {
|
||||
options = this.getJsonOptions(options);
|
||||
const intercepted = this.getOptionsForServer(server, url, options);
|
||||
this.requestsNotificationEmitter.emit(`DELETE ${intercepted.url}`);
|
||||
|
||||
return this.http
|
||||
.delete<T>(intercepted.url, intercepted.options)
|
||||
.pipe(catchError<T, any>(this.errorHandler.handleError)) as Observable<T>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user