From dd15424eecbf35fa155201579c607135e36856d0 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 28 Sep 2018 15:13:12 +0900 Subject: [PATCH] discovery result modified --- src/app/pages/home/home-page.component.html | 8 +-- src/app/pages/home/home-page.component.ts | 66 +++++++++++++++++++-- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/app/pages/home/home-page.component.html b/src/app/pages/home/home-page.component.html index 68374ad..9057f50 100644 --- a/src/app/pages/home/home-page.component.html +++ b/src/app/pages/home/home-page.component.html @@ -68,15 +68,15 @@ - +
-
Total Hosts:
{{resultMsg[0]}} +
Total Hosts:
{{discoveryResult.totalHosts}}
-
Total Services:
{{resultMsg[1]}} +
Total Services:
{{discoveryResult.totalServices}}
-
Elapsed:
{{resultMsg[2]}} +
Elapsed:
{{discoveryResult.elapsedTime}}
diff --git a/src/app/pages/home/home-page.component.ts b/src/app/pages/home/home-page.component.ts index 9018126..f15cc44 100644 --- a/src/app/pages/home/home-page.component.ts +++ b/src/app/pages/home/home-page.component.ts @@ -20,6 +20,52 @@ import { Node } from '../../../commons/model/node'; import { Link } from '../../../commons/model/link'; +export class DiscoveryResult { + totalHosts: number; + totalServices: number; + elapsedTime: string; + + hTimer: any; + + constructor() { + this.totalHosts = 0; + this.totalServices = 0; + this.elapsedTime = '00:00:00'; + } + + start() { + const __this = this; + const startTime = new Date().getTime(); + this.hTimer = setInterval(function () { + // Get todays date and time + const now = new Date().getTime(); + + // Find the distance between now and the count down date + const distance = now - startTime; + + // Time calculations for days, hours, minutes and seconds + const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); + const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); + const seconds = Math.floor((distance % (1000 * 60)) / 1000); + + __this.elapsedTime = hours + ':' + minutes + ':' + seconds; + }, 1000); + } + + stop(elapsedTime: string) { + clearInterval(this.hTimer); + this.elapsedTime = elapsedTime; + } + + increaseHost() { + this.totalHosts++; + } + + increaseService() { + this.totalServices++; + } +} + @Component({ selector: 'app-pages-home', templateUrl: './home-page.component.html', @@ -58,7 +104,7 @@ export class HomePageComponent implements OnInit, OnDestroy { discoveryRequestID: string | null; hosts: Map; ports: Map>; - resultMsg: string[]; + discoveryResult: DiscoveryResult; private preventBrowserCloseSubject: Subject; private preventBrowserCloseSubscription: Subscription; @@ -103,6 +149,7 @@ export class HomePageComponent implements OnInit, OnDestroy { this.discoveryRequestID = null; this.preventBrowserCloseSubject = new Subject(); + this.discoveryResult = null; } ngOnInit() { @@ -187,7 +234,7 @@ export class HomePageComponent implements OnInit, OnDestroy { console.log(this.discoverHost); console.log('########################################################'); - this.resultMsg = null; + this.discoveryResult = new DiscoveryResult(); this.showIntro = false; this.changeDetector.detectChanges(); @@ -630,6 +677,8 @@ export class HomePageComponent implements OnInit, OnDestroy { public DiscoveryStart(startDate: Date) { console.log('DiscoveryStart', startDate); this.discoveryStartDate = startDate; + + this.discoveryResult.start(); } /** @@ -677,10 +726,11 @@ export class HomePageComponent implements OnInit, OnDestroy { this.simulationRestart(true); this.zoomToFit(0.95, 500); - this.resultMsg = []; - this.resultMsg.push(hostCount + ''); - this.resultMsg.push(serviceCount + ''); - this.resultMsg.push(hours + ':' + minutes + ':' + seconds); + this.discoveryResult.stop(hours + ':' + minutes + ':' + seconds); + // this.resultMsg = []; + // this.resultMsg.push(hostCount + ''); + // this.resultMsg.push(serviceCount + ''); + // this.resultMsg.push(hours + ':' + minutes + ':' + seconds); this.stopping = false; } @@ -738,6 +788,8 @@ export class HomePageComponent implements OnInit, OnDestroy { this.nodes.push(hostNode); this.links.push(new Link(this.zoneNode, hostNode)); + + this.discoveryResult.increaseHost(); } this.simulationRestart(); @@ -784,6 +836,8 @@ export class HomePageComponent implements OnInit, OnDestroy { this.nodes.push(serviceNode); this.links.push(new Link(hostNode, serviceNode)); + + this.discoveryResult.increaseService(); } this.simulationRestart();