Frontend CHANGE move notification service to netconf-lib
diff --git a/frontend/src/app/classes/Notification.ts b/frontend/projects/netconf-lib/src/lib/classes/Notification.ts
similarity index 100%
rename from frontend/src/app/classes/Notification.ts
rename to frontend/projects/netconf-lib/src/lib/classes/Notification.ts
diff --git a/frontend/projects/netconf-lib/src/lib/components/now-connecting-form/now-connecting-form.component.ts b/frontend/projects/netconf-lib/src/lib/components/now-connecting-form/now-connecting-form.component.ts
index 50454fd..e62158a 100644
--- a/frontend/projects/netconf-lib/src/lib/components/now-connecting-form/now-connecting-form.component.ts
+++ b/frontend/projects/netconf-lib/src/lib/components/now-connecting-form/now-connecting-form.component.ts
@@ -8,6 +8,7 @@
import {SocketService} from '../../services/socket.service';
import {ConnectionStatus} from '../../classes/ConnectionStatus';
import {DeviceWithStatus} from '../../classes/DeviceWithStatus';
+import {NotificationService} from '../../services/notification.service';
enum ssh_hostcheck_status {
@@ -35,7 +36,8 @@
constructor(public deviceService: DeviceService,
public socketService: SocketService,
- public sessionService: SessionService) {
+ public sessionService: SessionService,
+ public notificationService: NotificationService) {
}
ngOnInit() {
@@ -142,7 +144,8 @@
_ => {
this.sessionService.sessions = [];
this.deviceService.clearWaitList();
- alert('Connecting canceled!');
+ this.notificationService.sendNotification(
+ this.notificationService.createNotification('Connecting canceled!', '', 'internal'));
this.close();
},
err => {
diff --git a/frontend/src/app/services/notification.service.ts b/frontend/projects/netconf-lib/src/lib/services/notification.service.ts
similarity index 78%
rename from frontend/src/app/services/notification.service.ts
rename to frontend/projects/netconf-lib/src/lib/services/notification.service.ts
index e471b70..65adcd3 100644
--- a/frontend/src/app/services/notification.service.ts
+++ b/frontend/projects/netconf-lib/src/lib/services/notification.service.ts
@@ -4,20 +4,27 @@
*/
import {EventEmitter, Injectable} from '@angular/core';
import {Observable} from 'rxjs';
-import {Notification} from "../classes/Notification";
+import {Notification} from '../classes/Notification';
@Injectable({
providedIn: 'root'
})
export class NotificationService {
- public onNewNotification: EventEmitter<Notification> = new EventEmitter<Notification>();
-
constructor() {
}
+ public onNewNotification: EventEmitter<Notification> = new EventEmitter<Notification>();
+
currentId = 0;
+ public static getCurrentTime(): string {
+ const now = new Date();
+ return ('0' + now.getHours()).slice(-2) + ':' +
+ ('0' + now.getMinutes()).slice(-2) + ':' +
+ ('0' + now.getSeconds()).slice(-2);
+ }
+
public createNotification(title: string, deviceName: string, channel: string): Notification {
return {
id: this.getNextAvailableId(),
@@ -25,21 +32,14 @@
time: NotificationService.getCurrentTime(),
deviceName,
channel
- }
- };
+ };
+ }
public sendNotification(notification: Notification) {
this.onNewNotification.emit(notification);
}
- public static getCurrentTime(): string {
- let now = new Date();
- return ("0" + now.getHours()).slice(-2) + ":" +
- ("0" + now.getMinutes()).slice(-2) + ":" +
- ("0" + now.getSeconds()).slice(-2);
- }
-
public getNextAvailableId(): number {
this.currentId++;
return this.currentId;
diff --git a/frontend/projects/netconf-lib/src/public_api.ts b/frontend/projects/netconf-lib/src/public_api.ts
index 10aea67..46bfeec 100644
--- a/frontend/projects/netconf-lib/src/public_api.ts
+++ b/frontend/projects/netconf-lib/src/public_api.ts
@@ -8,5 +8,7 @@
export * from './lib/services/device.service';
export * from './lib/services/schemas.service';
export * from './lib/services/session.service';
+export * from './lib/services/notification.service';
+export * from './lib/classes/Notification';
export * from './lib/classes/DeviceWithStatus';
export * from './lib/classes/session';
diff --git a/frontend/src/app/components/netconf.component.ts b/frontend/src/app/components/netconf.component.ts
index 6b2e5bc..b05651b 100644
--- a/frontend/src/app/components/netconf.component.ts
+++ b/frontend/src/app/components/netconf.component.ts
@@ -4,11 +4,9 @@
*/
import {Component, OnInit} from '@angular/core';
-import {ConfigService} from "../services/config.service";
-import {ProfileService} from "../services/profile.service";
-import {NotificationService} from "../services/notification.service";
-import {DeviceService, SessionService} from "../netconf-lib";
-import {DeviceWithStatus} from "../netconf-lib";
+import {ConfigService} from '../services/config.service';
+import {ProfileService} from '../services/profile.service';
+import {DeviceService, SessionService, NotificationService} from '../netconf-lib';
@Component({
selector: 'nc-base',
@@ -26,22 +24,21 @@
) {
}
- statusMessage: string = "Loading...";
+ statusMessage = 'Loading...';
config: object = {};
ngOnInit() {
- this.statusMessage = "Loading config...";
+ this.statusMessage = 'Loading config...';
this.configService.getConfig().subscribe(
config => {
this.config = config;
- this.statusMessage = "Checking open sessions...";
+ this.statusMessage = 'Checking open sessions...';
this.sessionService.loadOpenSessions().subscribe(
sessions => {
if (sessions.length > 0) {
- if(confirm('Found active device sessions. Load them? (Answering "cancel" will discard these sessions)')) {
+ if (confirm('Found active device sessions. Load them? (Answering "cancel" will discard these sessions)')) {
this.sessionService.sessions = sessions;
- }
- else {
+ } else {
this.sessionService.destroyAllSessions().subscribe();
this.loadProfile();
}
@@ -53,47 +50,47 @@
this.loadProfile();
},
err => {
- this.statusMessage = "";
+ this.statusMessage = '';
}
);
}
loadProfile() {
- this.statusMessage = "Loading profile...";
+ this.statusMessage = 'Loading profile...';
this.profileService.getOnLoginProfile().subscribe(
data => {
- this.statusMessage = "";
+ this.statusMessage = '';
if (data.connectOnLogin) {
this.deviceService.createConnectionRequest(data.devices);
}
},
err => {
- this.statusMessage = "";
+ this.statusMessage = '';
}
);
-
- /*setTimeout(() => {
+/*
+ setTimeout(() => {
this.notificationService.sendNotification(
- this.notificationService.createNotification("Notification 1", "Internal", "Channel 1")
+ this.notificationService.createNotification('Notification 1', 'Internal', 'Channel 1')
);
}, 250);
setTimeout(() => {
this.notificationService.sendNotification(
- this.notificationService.createNotification("Notification 2", "Internal", "Channel 1")
+ this.notificationService.createNotification('Notification 2', 'Internal', 'Channel 1')
);
}, 1500);
setTimeout(() => {
this.notificationService.sendNotification(
- this.notificationService.createNotification("Notification 3", "Internal", "Channel 1")
+ this.notificationService.createNotification('Notification 3', 'Internal', 'Channel 1')
);
}, 3000);
setTimeout(() => {
this.notificationService.sendNotification(
- this.notificationService.createNotification("Notification 4", "Internal", "Channel 1")
+ this.notificationService.createNotification('Notification 4', 'Internal', 'Channel 1')
);
- }, 5000);*/
-
+ }, 5000);
+*/
}
}
diff --git a/frontend/src/app/components/shared/notification-display/notification-display.component.ts b/frontend/src/app/components/shared/notification-display/notification-display.component.ts
index 005a050..33bf30a 100644
--- a/frontend/src/app/components/shared/notification-display/notification-display.component.ts
+++ b/frontend/src/app/components/shared/notification-display/notification-display.component.ts
@@ -3,8 +3,8 @@
* Container for notifications in the bottom-right corner of the screen
*/
import {Component, OnInit} from '@angular/core';
-import {NotificationService} from "../../../services/notification.service";
-import {Notification} from "../../../classes/Notification";
+import {NotificationService} from '../../../netconf-lib';
+import {Notification} from '../../../netconf-lib';
@Component({
selector: 'nc-notification-display',
@@ -31,11 +31,11 @@
addNotification(notification: Notification) {
- this.displayedNotifications.push({notification, state: "initial"});
+ this.displayedNotifications.push({notification, state: 'initial'});
if (this.displayedNotifications.length > 3) {
- for(let i = 0; i < this.displayedNotifications.length - 3; i++) {
+ for (let i = 0; i < this.displayedNotifications.length - 3; i++) {
this.toRemove.push(this.displayedNotifications[i].notification.id);
- this.displayedNotifications[i].state = "final"
+ this.displayedNotifications[i].state = 'final';
}
}
diff --git a/frontend/src/app/components/shared/notification-info/notification-info.component.ts b/frontend/src/app/components/shared/notification-info/notification-info.component.ts
index 7ab1b91..0e4d97c 100644
--- a/frontend/src/app/components/shared/notification-info/notification-info.component.ts
+++ b/frontend/src/app/components/shared/notification-info/notification-info.component.ts
@@ -3,8 +3,7 @@
* Content of a single notification
*/
import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
-import {NotificationService} from "../../../services/notification.service";
-import {Notification} from "../../../classes/Notification";
+import {NotificationService, Notification} from '../../../netconf-lib';
import {trigger, state, style, animate, transition} from '@angular/animations';
@Component({