Support for log events added

This commit is contained in:
Piotr Pekala 2019-08-26 08:16:36 -07:00
parent 40ef11edbe
commit 69934fb870
4 changed files with 46 additions and 5 deletions

View File

@ -18,6 +18,9 @@ export class MockedProjectWebServiceHandler {
public nodeNotificationEmitter = new EventEmitter<WebServiceMessage>();
public linkNotificationEmitter = new EventEmitter<WebServiceMessage>();
public drawingNotificationEmitter = new EventEmitter<WebServiceMessage>();
public infoNotificationEmitter = new EventEmitter<any>();
public warningNotificationEmitter = new EventEmitter<any>();
public errorNotificationEmitter = new EventEmitter<any>();
}
describe('LogConsoleComponent', () => {

View File

@ -28,9 +28,12 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
private linkSubscription: Subscription;
private drawingSubscription: Subscription;
private serverRequestsSubscription: Subscription;
private errorSubscription: Subscription;
private warningSubscription: Subscription;
private infoSubscription: Subscription;
command: string = '';
filters: string[] = ['all', 'errors', 'warnings', 'map updates', 'server requests'];
filters: string[] = ['all', 'errors', 'warnings', 'info', 'map updates', 'server requests'];
selectedFilter: string = 'all';
filteredEvents: LogEvent[] = [];
@ -79,6 +82,24 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
message: message
});
});
this.errorSubscription = this.projectWebServiceHandler.errorNotificationEmitter.subscribe((message) => {
this.showMessage({
type: 'error',
message: message
});
});
this.errorSubscription = this.projectWebServiceHandler.warningNotificationEmitter.subscribe((message) => {
this.showMessage({
type: 'warning',
message: message
});
});
this.errorSubscription = this.projectWebServiceHandler.infoNotificationEmitter.subscribe((message) => {
this.showMessage({
type: 'info',
message: message
});
});
}
ngAfterViewInit() {
@ -90,6 +111,9 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
this.linkSubscription.unsubscribe();
this.drawingSubscription.unsubscribe();
this.serverRequestsSubscription.unsubscribe();
this.errorSubscription.unsubscribe();
this.warningSubscription.unsubscribe();
this.infoSubscription.unsubscribe();
}
applyFilter() {
@ -181,11 +205,13 @@ export class LogConsoleComponent implements OnInit, AfterViewInit, OnDestroy {
getFilteredEvents(): LogEvent[] {
if (this.selectedFilter === 'server requests') {
return this.logEventsDataSource.getItems().filter(n => n.type === 'server request' || n.type === 'command');
return this.logEventsDataSource.getItems().filter(n => n.type === 'server request');
} else if (this.selectedFilter === 'errors') {
return this.logEventsDataSource.getItems().filter(n => n.type === 'error' || n.type === 'command');
return this.logEventsDataSource.getItems().filter(n => n.type === 'error');
} else if (this.selectedFilter === 'warnings') {
return this.logEventsDataSource.getItems().filter(n => n.type === 'warning' || n.type === 'command');
return this.logEventsDataSource.getItems().filter(n => n.type === 'warning');
} else if (this.selectedFilter === 'info') {
return this.logEventsDataSource.getItems().filter(n => n.type === 'info');
} else if (this.selectedFilter === 'map updates') {
return this.logEventsDataSource.getItems().filter(n => n.type === 'map update' || n.type === 'command');
} else {

View File

@ -276,7 +276,6 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
this.ws = new WebSocket(this.projectService.notificationsPath(this.server, project.project_id));
this.ws.onmessage = (event: MessageEvent) => {
// console.log(event);
this.projectWebServiceHandler.handleMessage(JSON.parse(event.data));
};

View File

@ -19,6 +19,10 @@ export class ProjectWebServiceHandler {
public linkNotificationEmitter = new EventEmitter<WebServiceMessage>();
public drawingNotificationEmitter = new EventEmitter<WebServiceMessage>();
public infoNotificationEmitter = new EventEmitter<any>();
public warningNotificationEmitter = new EventEmitter<any>();
public errorNotificationEmitter = new EventEmitter<any>();
constructor(
private nodesDataSource: NodesDataSource,
private linksDataSource: LinksDataSource,
@ -62,5 +66,14 @@ export class ProjectWebServiceHandler {
this.drawingsDataSource.remove(message.event as Drawing);
this.drawingNotificationEmitter.emit(message);
}
if (message.action === 'log.error') {
this.errorNotificationEmitter.emit(message.event);
}
if (message.action === 'log.warning') {
this.warningNotificationEmitter.emit(message.event);
}
if (message.action === 'log.info') {
this.infoNotificationEmitter.emit(message.event);
}
}
}