diff --git a/src/app/pages/home/home-page.component.ts b/src/app/pages/home/home-page.component.ts
index 2e1e943..8b66ca6 100644
--- a/src/app/pages/home/home-page.component.ts
+++ b/src/app/pages/home/home-page.component.ts
@@ -1,27 +1,34 @@
import { Component, OnInit, OnDestroy, ViewChild, ElementRef, ChangeDetectorRef, HostListener } from '@angular/core';
-
-import { ProbeService, requesterID } from '../../../commons/service/probe.service';
-
-import { Zone, Host, Port, Service, DiscoverHost } from '@overflow/model/discovery';
-
-import { RPCSubscriber } from '@overflow/commons/ui/decorator/RPCSubscriber';
-import { DiscoveryConfigService } from '../../../commons/service/discovery-config.service';
+import { Subject, Subscription, of } from 'rxjs';
+import { map, catchError, take } from 'rxjs/operators';
import * as d3 from 'd3';
-import { Node } from '../../../commons/model/node';
-import { Link } from '../../../commons/model/link';
+import { ConfirmationService } from 'primeng/primeng';
+
+import { Zone, Host, Port, Service, DiscoverHost } from '@overflow/model/discovery';
+import { RPCSubscriber } from '@overflow/commons/ui/decorator/RPCSubscriber';
+import { TypeUtil } from '@overflow/core-js';
import { RPCError } from '@overflow/rpc-js';
import { toMetaIPType, MetaIPTypeEnum, toMetaCryptoType, MetaCryptoTypeEnum, toMetaPortType, MetaPortTypeEnum } from '@overflow/model/meta';
import { DiscoveryModeType } from '@overflow/model/discovery/discovery';
import { PingResult } from '@overflow/model/ping';
+import { ProbeService, requesterID } from '../../../commons/service/probe.service';
+import { DiscoveryConfigService } from '../../../commons/service/discovery-config.service';
+import { Node } from '../../../commons/model/node';
+import { Link } from '../../../commons/model/link';
+
+
@Component({
selector: 'app-pages-home',
templateUrl: './home-page.component.html',
styleUrls: ['./home-page.component.scss'],
+ providers: [
+ ConfirmationService,
+ ],
})
export class HomePageComponent implements OnInit, OnDestroy {
@@ -45,15 +52,16 @@ export class HomePageComponent implements OnInit, OnDestroy {
private zoomBehavior: d3.ZoomBehavior
;
private discoveryContainerWidth: number;
private discoveryContainerHeight: number;
- private discoveryStartDate: Date;
- private discoveryRequestID: string | null;
private readonly maxScale: number;
private readonly minScale: number;
+ private discoveryStartDate: Date;
+ private discoveryRequestID: string | null;
hosts: Map;
ports: Map>;
-
resultMsg: string[];
+ private preventBrowserCloseSubject: Subject;
+ private preventBrowserCloseSubscription: Subscription;
@HostListener('window:resize', ['$event'])
onResize(event) {
@@ -69,11 +77,11 @@ export class HomePageComponent implements OnInit, OnDestroy {
}
@HostListener('window:beforeunload', ['$event'])
- onBeforeUnload(event) {
+ onBeforeUnload($event: Event) {
if (null !== this.discoveryRequestID) {
- this.probeService.send('DiscoveryService.DiscoverStop', requesterID, this.discoveryRequestID);
+ this.preventBrowserCloseSubject.next();
+ $event.returnValue = true;
}
- // event.returnValue = true;
}
@ViewChild('discoveryTarget') set discoveryTarget(content: ElementRef) {
@@ -82,18 +90,20 @@ export class HomePageComponent implements OnInit, OnDestroy {
constructor(
private changeDetector: ChangeDetectorRef,
+ private confirmationService: ConfirmationService,
private probeService: ProbeService,
private discoveryConfigService: DiscoveryConfigService,
) {
this.nodes = [];
this.links = [];
+ this.maxScale = 1;
+ this.minScale = 0.7;
+
this.hosts = new Map();
this.ports = new Map();
this.discoveryRequestID = null;
-
- this.maxScale = 1;
- this.minScale = 0.7;
+ this.preventBrowserCloseSubject = new Subject();
}
ngOnInit() {
@@ -114,10 +124,31 @@ export class HomePageComponent implements OnInit, OnDestroy {
}
}
});
+ this.preventBrowserCloseSubscription = this.preventBrowserCloseSubject
+ .pipe(
+ map(() => {
+ this.confirmationService.confirm({
+ message: 'Discovery is in progress.',
+ header: 'Alert',
+ icon: 'pi pi-info-circle',
+ acceptLabel: 'Yes',
+ acceptVisible: true,
+ rejectVisible: false,
+ });
+ }),
+ catchError(error => {
+ console.log(error);
+ alert('An error has occurred.');
+ return of();
+ }),
+ take(1)
+ )
+ .subscribe();
}
ngOnDestroy(): void {
this.probeService.unsubscribeNotification(this);
+ this.preventBrowserCloseSubscription.unsubscribe();
}
blockDocument() {
@@ -635,8 +666,6 @@ export class HomePageComponent implements OnInit, OnDestroy {
this.resultMsg.push(hostCount + '');
this.resultMsg.push(serviceCount + '');
this.resultMsg.push(hours + ':' + minutes + ':' + seconds);
-
- // this.simulation.stop();
}
/**
diff --git a/yarn.lock b/yarn.lock
index 734a645..d3c0a91 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6005,6 +6005,10 @@ pretty-error@^2.0.2:
renderkid "^2.0.1"
utila "~0.4"
+primeicons@^1.0.0-beta.10:
+ version "1.0.0-beta.10"
+ resolved "https://nexus.loafle.net/repository/npm-all/primeicons/-/primeicons-1.0.0-beta.10.tgz#b1a27a8a279c0b28d4bd537a29709b39cfebbd9f"
+
primeng@^6.1.3:
version "6.1.3"
resolved "https://nexus.loafle.net/repository/npm-all/primeng/-/primeng-6.1.3.tgz#720590da9e671fd47de15911636d1c0a7a442852"