From ddaec79ab605b04d617812c4fc781b75bf5c17b4 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 19 Sep 2018 14:04:53 +0900 Subject: [PATCH] ing --- angular.json | 1 + package.json | 1 + src/app/pages/home/home-page.component.html | 2 + src/app/pages/home/home-page.component.ts | 69 +++++++++++++++------ yarn.lock | 4 ++ 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/angular.json b/angular.json index c723f31..aa2cce9 100644 --- a/angular.json +++ b/angular.json @@ -30,6 +30,7 @@ "src/assets" ], "styles": [ + "node_modules/primeicons/primeicons.css", "node_modules/primeng/resources/primeng.min.css", "src/styles.scss" ], diff --git a/package.json b/package.json index f0ad0ed..65a49f4 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "karma-jasmine": "~1.1.1", "ngrx-store-freeze": "^0.2.4", "npm-run-all": "^4.1.3", + "primeicons": "^1.0.0-beta.10", "primeng": "^6.1.3", "primer-support": "^4.0.0", "protractor": "~5.3.0", diff --git a/src/app/pages/home/home-page.component.html b/src/app/pages/home/home-page.component.html index 7689399..5fb9344 100644 --- a/src/app/pages/home/home-page.component.html +++ b/src/app/pages/home/home-page.component.html @@ -80,6 +80,8 @@ + +
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"