From b774fc3722519338a037e230badf4a99a28a6579 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 1 Jun 2018 19:54:44 +0900 Subject: [PATCH 1/3] ing --- @overflow/sensor/component/index.ts | 4 +- ...nent.html => sensor-detail.component.html} | 0 ...pec.ts => sensor-detail.component.spec.ts} | 12 ++-- ...omponent.ts => sensor-detail.component.ts} | 2 +- ...html => sensor-list-filter.component.html} | 0 ...s => sensor-list-filter.component.spec.ts} | 12 ++-- ...ent.ts => sensor-list-filter.component.ts} | 8 +-- ...ponent.html => sensor-list.component.html} | 0 ....spec.ts => sensor-list.component.spec.ts} | 12 ++-- ....component.ts => sensor-list.component.ts} | 66 +++++++++++++++++-- @overflow/sensor/container/index.ts | 9 --- .../sensor-detail-container.component.html | 1 - .../sensor-detail-container.component.ts | 14 ---- .../sensor-list-container.component.html | 1 - .../sensor-list-container.component.ts | 47 ------------- .../sensor-setting-container.component.html | 1 - .../sensor-setting-container.component.ts | 15 ----- @overflow/sensor/sensor.module.ts | 6 -- .../sensors/sensor/sensor-page.component.html | 8 +-- 19 files changed, 89 insertions(+), 129 deletions(-) rename @overflow/sensor/component/{detail/detail.component.html => sensor-detail.component.html} (100%) rename @overflow/sensor/component/{list/list.component.spec.ts => sensor-detail.component.spec.ts} (53%) rename @overflow/sensor/component/{detail/detail.component.ts => sensor-detail.component.ts} (97%) rename @overflow/sensor/component/{list/filter/filter.component.html => sensor-list-filter.component.html} (100%) rename @overflow/sensor/component/{list/filter/filter.component.spec.ts => sensor-list-filter.component.spec.ts} (51%) rename @overflow/sensor/component/{list/filter/filter.component.ts => sensor-list-filter.component.ts} (64%) rename @overflow/sensor/component/{list/list.component.html => sensor-list.component.html} (100%) rename @overflow/sensor/component/{detail/detail.component.spec.ts => sensor-list.component.spec.ts} (54%) rename @overflow/sensor/component/{list/list.component.ts => sensor-list.component.ts} (58%) delete mode 100644 @overflow/sensor/container/index.ts delete mode 100644 @overflow/sensor/container/sensor-detail-container.component.html delete mode 100644 @overflow/sensor/container/sensor-detail-container.component.ts delete mode 100644 @overflow/sensor/container/sensor-list-container.component.html delete mode 100644 @overflow/sensor/container/sensor-list-container.component.ts delete mode 100644 @overflow/sensor/container/sensor-setting-container.component.html delete mode 100644 @overflow/sensor/container/sensor-setting-container.component.ts diff --git a/@overflow/sensor/component/index.ts b/@overflow/sensor/component/index.ts index 8681872..cacb22e 100644 --- a/@overflow/sensor/component/index.ts +++ b/@overflow/sensor/component/index.ts @@ -1,5 +1,5 @@ -import { SensorListComponent } from './list/list.component'; -import { SensorDetailComponent } from './detail/detail.component'; +import { SensorListComponent } from './sensor-list.component'; +import { SensorDetailComponent } from './sensor-detail.component'; import { SensorSettingComponent } from './setting/setting.component'; export const COMPONENTS = [ diff --git a/@overflow/sensor/component/detail/detail.component.html b/@overflow/sensor/component/sensor-detail.component.html similarity index 100% rename from @overflow/sensor/component/detail/detail.component.html rename to @overflow/sensor/component/sensor-detail.component.html diff --git a/@overflow/sensor/component/list/list.component.spec.ts b/@overflow/sensor/component/sensor-detail.component.spec.ts similarity index 53% rename from @overflow/sensor/component/list/list.component.spec.ts rename to @overflow/sensor/component/sensor-detail.component.spec.ts index beacd15..64df94e 100644 --- a/@overflow/sensor/component/list/list.component.spec.ts +++ b/@overflow/sensor/component/sensor-detail.component.spec.ts @@ -1,20 +1,20 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { ListComponent } from './list.component'; +import { SensorDetailComponent } from './sensor-detail.component'; -describe('ListComponent', () => { - let component: ListComponent; - let fixture: ComponentFixture; +describe('SensorDetailComponent', () => { + let component: SensorDetailComponent; + let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ ListComponent ] + declarations: [ SensorDetailComponent ] }) .compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(ListComponent); + fixture = TestBed.createComponent(SensorDetailComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/@overflow/sensor/component/detail/detail.component.ts b/@overflow/sensor/component/sensor-detail.component.ts similarity index 97% rename from @overflow/sensor/component/detail/detail.component.ts rename to @overflow/sensor/component/sensor-detail.component.ts index 3c105c2..7eaae2c 100644 --- a/@overflow/sensor/component/detail/detail.component.ts +++ b/@overflow/sensor/component/sensor-detail.component.ts @@ -9,7 +9,7 @@ import { Subscription } from 'rxjs/Subscription'; @Component({ selector: 'of-sensor-detail', - templateUrl: './detail.component.html', + templateUrl: './sensor-detail.component.html', providers: [ConfirmationService] }) export class SensorDetailComponent { diff --git a/@overflow/sensor/component/list/filter/filter.component.html b/@overflow/sensor/component/sensor-list-filter.component.html similarity index 100% rename from @overflow/sensor/component/list/filter/filter.component.html rename to @overflow/sensor/component/sensor-list-filter.component.html diff --git a/@overflow/sensor/component/list/filter/filter.component.spec.ts b/@overflow/sensor/component/sensor-list-filter.component.spec.ts similarity index 51% rename from @overflow/sensor/component/list/filter/filter.component.spec.ts rename to @overflow/sensor/component/sensor-list-filter.component.spec.ts index fc30049..791e9d3 100644 --- a/@overflow/sensor/component/list/filter/filter.component.spec.ts +++ b/@overflow/sensor/component/sensor-list-filter.component.spec.ts @@ -1,20 +1,20 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { FilterComponent } from './filter.component'; +import { SensorListFilterComponent } from './sensor-list-filter.component'; -describe('FilterComponent', () => { - let component: FilterComponent; - let fixture: ComponentFixture; +describe('SensorListFilterComponent', () => { + let component: SensorListFilterComponent; + let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ FilterComponent ] + declarations: [ SensorListFilterComponent ] }) .compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(FilterComponent); + fixture = TestBed.createComponent(SensorListFilterComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/@overflow/sensor/component/list/filter/filter.component.ts b/@overflow/sensor/component/sensor-list-filter.component.ts similarity index 64% rename from @overflow/sensor/component/list/filter/filter.component.ts rename to @overflow/sensor/component/sensor-list-filter.component.ts index 9ca9b1f..7b11f2b 100644 --- a/@overflow/sensor/component/list/filter/filter.component.ts +++ b/@overflow/sensor/component/sensor-list-filter.component.ts @@ -3,11 +3,11 @@ import { Router } from '@angular/router'; @Component({ - selector: 'of-target-filter', - templateUrl: './filter.component.html', - styleUrls: ['./filter.component.scss'] + selector: 'of-sensor-list-filter', + templateUrl: './sensor-list-filter.component.html', + styleUrls: ['./sensor-list-filter.component.scss'] }) -export class FilterComponent implements OnInit { +export class SensorListFilterComponent implements OnInit { crawlers = [ {value: 'ALL', name: 'All'}, diff --git a/@overflow/sensor/component/list/list.component.html b/@overflow/sensor/component/sensor-list.component.html similarity index 100% rename from @overflow/sensor/component/list/list.component.html rename to @overflow/sensor/component/sensor-list.component.html diff --git a/@overflow/sensor/component/detail/detail.component.spec.ts b/@overflow/sensor/component/sensor-list.component.spec.ts similarity index 54% rename from @overflow/sensor/component/detail/detail.component.spec.ts rename to @overflow/sensor/component/sensor-list.component.spec.ts index 149b9be..69b86f5 100644 --- a/@overflow/sensor/component/detail/detail.component.spec.ts +++ b/@overflow/sensor/component/sensor-list.component.spec.ts @@ -1,20 +1,20 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { DetailComponent } from './detail.component'; +import { SensorListComponent } from './sensor-list.component'; -describe('DetailComponent', () => { - let component: DetailComponent; - let fixture: ComponentFixture; +describe('SensorListComponent', () => { + let component: SensorListComponent; + let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ DetailComponent ] + declarations: [ SensorListComponent ] }) .compileComponents(); })); beforeEach(() => { - fixture = TestBed.createComponent(DetailComponent); + fixture = TestBed.createComponent(SensorListComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/@overflow/sensor/component/list/list.component.ts b/@overflow/sensor/component/sensor-list.component.ts similarity index 58% rename from @overflow/sensor/component/list/list.component.ts rename to @overflow/sensor/component/sensor-list.component.ts index b0ae8ad..8b48d98 100644 --- a/@overflow/sensor/component/list/list.component.ts +++ b/@overflow/sensor/component/sensor-list.component.ts @@ -1,23 +1,77 @@ import { Component, Input, OnInit, OnChanges, SimpleChanges, Output, EventEmitter } from '@angular/core'; +import { Store, select } from '@ngrx/store'; + +import { Observable, of, Subscription } from 'rxjs'; +import { catchError, exhaustMap, map, tap } from 'rxjs/operators'; + +import { AuthSelector } from '@overflow/shared/auth/store'; + import { Sensor } from '@overflow/commons-typescript/model/sensor'; import { Page } from '@overflow/commons-typescript/model/commons/Page'; import { Target } from '@overflow/commons-typescript/model/target'; +import { DomainMember } from '@overflow/commons-typescript/model/domain'; +import { SensorService } from '../service/sensor.service'; +import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams'; @Component({ selector: 'of-sensor-list', - templateUrl: './list.component.html', + templateUrl: './sensor-list.component.html', }) -export class SensorListComponent implements OnChanges { - - @Input() page: Page; - @Output() addSensor = new EventEmitter(); +export class SensorListComponent implements OnInit, OnChanges { + @Input() pageNo: number; @Output() select = new EventEmitter(); + @Output() addSensor = new EventEmitter(); + + page: Page; + pending$: Observable; + error$: Observable; totalLength: number; targetSensors: Object; constructor( - ) { } + private store: Store, + private sensorService: SensorService, + ) { + + } + + ngOnInit() { + if (1 > this.pageNo) { + this.pageNo = 0; + } + + this.store.pipe( + tap(() => { + this.pending$ = of(true); + }), + select(AuthSelector.selectDomainMember), + exhaustMap((domainMember: DomainMember) => { + const pageParams: PageParams = { + pageNo: this.pageNo, + countPerPage: 10, + sortCol: 'id', + sortDirection: 'descending', + }; + + return this.sensorService.readAllByDomainID(domainMember.domain.id, pageParams) + .pipe( + map((page: Page) => { + this.page = page; + }), + catchError(error => { + this.error$ = of(error); + return of(); + }) + ); + } + ), + tap(() => { + this.pending$ = of(false); + }), + ).take(1).subscribe(); + + } ngOnChanges(changes: SimpleChanges): void { this.generateSensorMap(); diff --git a/@overflow/sensor/container/index.ts b/@overflow/sensor/container/index.ts deleted file mode 100644 index f46d623..0000000 --- a/@overflow/sensor/container/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { SensorListContainerComponent } from './sensor-list-container.component'; -import { SensorDetailContainerComponent } from './sensor-detail-container.component'; -import { SensorSettingContainerComponent } from './sensor-setting-container.component'; - -export const CONTAINER_COMPONENTS = [ - SensorListContainerComponent, - SensorDetailContainerComponent, - SensorSettingContainerComponent -]; diff --git a/@overflow/sensor/container/sensor-detail-container.component.html b/@overflow/sensor/container/sensor-detail-container.component.html deleted file mode 100644 index b557836..0000000 --- a/@overflow/sensor/container/sensor-detail-container.component.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/@overflow/sensor/container/sensor-detail-container.component.ts b/@overflow/sensor/container/sensor-detail-container.component.ts deleted file mode 100644 index 6496776..0000000 --- a/@overflow/sensor/container/sensor-detail-container.component.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Component } from '@angular/core'; -import { Observable } from 'rxjs'; -import { Store, select } from '@ngrx/store'; -// import * as ProbeStore from '../store/entity/probe'; -// import { ProbeEntitySelector, ProbeDetailContainerSelector } from '../store'; - -@Component({ - selector: 'of-sensor-detail-container', - templateUrl: './sensor-detail-container.component.html', -}) -export class SensorDetailContainerComponent { - - -} diff --git a/@overflow/sensor/container/sensor-list-container.component.html b/@overflow/sensor/container/sensor-list-container.component.html deleted file mode 100644 index 58b4952..0000000 --- a/@overflow/sensor/container/sensor-list-container.component.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/@overflow/sensor/container/sensor-list-container.component.ts b/@overflow/sensor/container/sensor-list-container.component.ts deleted file mode 100644 index f81220a..0000000 --- a/@overflow/sensor/container/sensor-list-container.component.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Component, EventEmitter, Output, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; -import { Store, select } from '@ngrx/store'; -import { Sensor } from '@overflow/commons-typescript/model/sensor'; -import { AuthSelector } from '@overflow/shared/auth/store'; -import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams'; -import { Page } from '@overflow/commons-typescript/model/commons/Page'; -import { Target } from '@overflow/commons-typescript/model/target'; -import { DomainMember } from '@overflow/commons-typescript/model/domain'; - -@Component({ - selector: 'of-sensor-list-container', - templateUrl: './sensor-list-container.component.html', -}) -export class SensorListContainerComponent implements OnInit { - - page$: Observable>; - pending$: Observable; - @Output() select = new EventEmitter(); - @Output() addSensor = new EventEmitter(); - pageNo: number; - - constructor(private store: Store) { - this.pageNo = 0; - } - - ngOnInit() { - // this.page$ = this.store.pipe(select(SensorListContainerSelector.selectPage)); - // this.page$ = this.store.pipe(select(SensorListContainerSelector.selectPage)); - - this.getSensors(); - } - - getSensors() { - this.store.select(AuthSelector.selectDomainMember).subscribe( - (domainMember: DomainMember) => { - const pageParams: PageParams = { - pageNo: this.pageNo, - countPerPage: 10, - sortCol: 'id', - sortDirection: 'descending', - }; - // this.store.dispatch(new SensorEntityStore.ReadAllByDomainID({ domainID: domainMember.domain.id, pageParams })); - } - ); - } -} diff --git a/@overflow/sensor/container/sensor-setting-container.component.html b/@overflow/sensor/container/sensor-setting-container.component.html deleted file mode 100644 index c1a506a..0000000 --- a/@overflow/sensor/container/sensor-setting-container.component.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/@overflow/sensor/container/sensor-setting-container.component.ts b/@overflow/sensor/container/sensor-setting-container.component.ts deleted file mode 100644 index 5277b0d..0000000 --- a/@overflow/sensor/container/sensor-setting-container.component.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Component, EventEmitter, Output, OnInit } from '@angular/core'; -import { Observable } from 'rxjs'; -import { Store, select } from '@ngrx/store'; -import { Sensor } from '@overflow/commons-typescript/model/sensor'; - -@Component({ - selector: 'of-sensor-setting-container', - templateUrl: './sensor-setting-container.component.html', -}) -export class SensorSettingContainerComponent { - - constructor(private store: Store) { - } - -} diff --git a/@overflow/sensor/sensor.module.ts b/@overflow/sensor/sensor.module.ts index 0dde472..13e4460 100644 --- a/@overflow/sensor/sensor.module.ts +++ b/@overflow/sensor/sensor.module.ts @@ -7,10 +7,6 @@ import { UIModule } from '@overflow/shared/ui/ui.module'; import { COMPONENTS } from './component'; import { SERVICES } from './service'; import { SensorItemModule } from '../sensor-item/sensor-item.module'; -import { CONTAINER_COMPONENTS } from './container'; -// import { MetaCrawlerModule } from '../meta/crawler/crawler.module'; -// import { MetaSensorDisplayItemModule } from '../meta/sensor-display-item/sensor-display-item.module'; -// import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-input.module'; @NgModule({ imports: [ @@ -20,11 +16,9 @@ import { CONTAINER_COMPONENTS } from './container'; SensorItemModule, ], declarations: [ - CONTAINER_COMPONENTS, COMPONENTS, ], exports: [ - CONTAINER_COMPONENTS, COMPONENTS, ], providers: [ diff --git a/src/app/pages/sensors/sensor/sensor-page.component.html b/src/app/pages/sensors/sensor/sensor-page.component.html index 9dbaeb4..3b2eef8 100644 --- a/src/app/pages/sensors/sensor/sensor-page.component.html +++ b/src/app/pages/sensors/sensor/sensor-page.component.html @@ -1,4 +1,4 @@ - - - - \ No newline at end of file + + + + \ No newline at end of file From a67a3eca5f71d0b683deda47a3f28efd5a753cb0 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 1 Jun 2018 19:56:50 +0900 Subject: [PATCH 2/3] ing --- @overflow/probe/component/probe-download.component.ts | 2 +- src/app/pages/probes/download/download-page.component.html | 2 +- src/app/pages/probes/download/download-page.component.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/@overflow/probe/component/probe-download.component.ts b/@overflow/probe/component/probe-download.component.ts index 0e2d714..c48dcd8 100644 --- a/@overflow/probe/component/probe-download.component.ts +++ b/@overflow/probe/component/probe-download.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; @Component({ - selector: 'of-download', + selector: 'of-probe-download', templateUrl: './probe-download.component.html', }) export class ProbeDownloadComponent implements OnInit { diff --git a/src/app/pages/probes/download/download-page.component.html b/src/app/pages/probes/download/download-page.component.html index 1947a35..7860fed 100644 --- a/src/app/pages/probes/download/download-page.component.html +++ b/src/app/pages/probes/download/download-page.component.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/app/pages/probes/download/download-page.component.ts b/src/app/pages/probes/download/download-page.component.ts index ac65dce..597d6a8 100644 --- a/src/app/pages/probes/download/download-page.component.ts +++ b/src/app/pages/probes/download/download-page.component.ts @@ -3,7 +3,7 @@ import { Router, ActivatedRoute } from '@angular/router'; import { BreadcrumbService } from '@app/commons/service/breadcrumb.service'; @Component({ - selector: 'of-pages-download', + selector: 'of-pages-probe-download', templateUrl: './download-page.component.html', }) export class ProbeDownloadPageComponent implements OnInit { From 54f5a6190154da84d26ef3c1619ad051c7d4a7cf Mon Sep 17 00:00:00 2001 From: insanity Date: Fri, 1 Jun 2018 20:25:51 +0900 Subject: [PATCH 3/3] discovery --- @overflow/discovery/component/animation.ts | 8 +- .../component/discovery.component.html | 7 +- .../component/discovery.component.ts | 6 +- .../component/search-result.component.html | 36 +++-- .../component/search-result.component.ts | 129 +++++++++++++++--- 5 files changed, 152 insertions(+), 34 deletions(-) diff --git a/@overflow/discovery/component/animation.ts b/@overflow/discovery/component/animation.ts index cbcd834..6d8f3ca 100644 --- a/@overflow/discovery/component/animation.ts +++ b/@overflow/discovery/component/animation.ts @@ -24,11 +24,11 @@ export const Anim = [ trigger('discoveryResultAnim', [ transition('void => *', [ query('*', style({ opacity: 0 }), { optional: true }), - query('*', stagger('500ms', [ + query('*', stagger('30ms', [ animate('0.08s ease-in', keyframes([ - style({ opacity: 0, transform: 'translateX(-75%)', offset: 0 }), - style({ opacity: .5, transform: 'translateX(35px)', offset: 0.3 }), - style({ opacity: 1, transform: 'translateY(0)', offset: 1.0 }), + style({ opacity: 0, transform: 'translateX(-95%)', offset: 0 }), + style({ opacity: .5, transform: 'translateX(95px)', offset: 0.3 }), + style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 }), ]))]), { optional: true }), ]), ]), diff --git a/@overflow/discovery/component/discovery.component.html b/@overflow/discovery/component/discovery.component.html index 369c82b..2471582 100644 --- a/@overflow/discovery/component/discovery.component.html +++ b/@overflow/discovery/component/discovery.component.html @@ -16,13 +16,16 @@
- + + +
-
+
Network Discovery 설명 페이지
\ No newline at end of file diff --git a/@overflow/discovery/component/discovery.component.ts b/@overflow/discovery/component/discovery.component.ts index 766307c..6541b5f 100644 --- a/@overflow/discovery/component/discovery.component.ts +++ b/@overflow/discovery/component/discovery.component.ts @@ -1,5 +1,5 @@ import { - Component, Input, Output, EventEmitter, OnDestroy, + Component, Input, Output, EventEmitter, OnDestroy, ViewChild, } from '@angular/core'; import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe'; import { Anim } from './animation'; @@ -9,6 +9,7 @@ import { DiscoveryService } from '../service/discovery.service'; import { catchError, exhaustMap, map, tap } from 'rxjs/operators'; import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery'; import { DiscoverySubscriber, DiscoveryNotify } from '../subscriber/discovery.subscriber'; +import { SearchResultComponent } from './search-result.component'; @Component({ selector: 'of-discovery', @@ -26,6 +27,8 @@ export class DiscoveryComponent implements OnDestroy { requested: boolean; discoverZone: DiscoverZone; + @ViewChild('discoveryResult') discoveryResult: SearchResultComponent; + constructor( private discoveryService: DiscoveryService, private discoverySubscriber: DiscoverySubscriber, @@ -58,6 +61,7 @@ export class DiscoveryComponent implements OnDestroy { this.discoverySubscription.unsubscribe(); this.discoverySubscription = null; + break; } case 'DiscoveryService.discoveredZone': { diff --git a/@overflow/discovery/component/search-result.component.html b/@overflow/discovery/component/search-result.component.html index 2bab881..2d7a03a 100644 --- a/@overflow/discovery/component/search-result.component.html +++ b/@overflow/discovery/component/search-result.component.html @@ -1,14 +1,32 @@ - -
- - - - -
- + + + + + + + +
+ {{node.label}}
+ + + + +
+ +
+
+ + + +
+ +
+
+
\ No newline at end of file diff --git a/@overflow/discovery/component/search-result.component.ts b/@overflow/discovery/component/search-result.component.ts index 0fa1214..84f406b 100644 --- a/@overflow/discovery/component/search-result.component.ts +++ b/@overflow/discovery/component/search-result.component.ts @@ -2,56 +2,149 @@ import { AfterContentInit, Component, Input, EventEmitter, Output, - OnChanges, - SimpleChanges + SimpleChanges, + OnInit, } from '@angular/core'; import { Anim } from './animation'; import { TreeNode } from 'primeng/primeng'; +import { DiscoveryNotify } from '../subscriber/discovery.subscriber'; +import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery'; +import { Subscription } from 'rxjs'; +import { ProbeHost } from '@overflow/commons-typescript/model/probe'; @Component({ selector: 'of-discovery-result', templateUrl: './search-result.component.html', animations: Anim }) -export class SearchResultComponent implements OnChanges { +export class SearchResultComponent implements OnInit { + @Input() probeHost: ProbeHost; @Output() stop = new EventEmitter(); - @Input() started: boolean; + @Input() started: boolean; // Temporary + discoverySubscription: Subscription; zoneNode: TreeNode[] = []; hostNode: TreeNode[] = []; + selectedItems = []; + + tempHostId = 0; // Temporary constructor( ) { + } + + ngOnInit(): void { this.zoneNode.push({ - label: 'zone', + label: this.probeHost.probe.cidr, + type: 'ZONE', + data: { + }, children: this.hostNode, expanded: true }); } - ngOnChanges(changes: SimpleChanges): void { + tempHost() { + const idx = Math.floor(Math.random() * (255)); + const host: Host = { + id: this.tempHostId++, + ipv4: '192.168.1.' + idx, + }; + this.addHostNode(host); } - onStop() { - this.stop.emit(); + tempService() { + const idx = Math.floor(Math.random() * (255)); + const hostId = Math.floor(Math.random() * (this.tempHostId - 1)); + const service: Service = { + id: idx, + serviceName: 'Service', + port: { + portNumber: idx, + portType: idx % 2 === 0 ? 'TCP' : 'UDP', + host: { + id: hostId + } + } + }; + this.addServiceNode(service); } - test() { - } - - addHostNode() { - const idx = Math.floor(Math.random() * (this.hostNode.length - 1)); + addHostNode(host: Host) { + const idx = this.findHostIndex(host); this.hostNode.splice(idx, 0, { - label: 'host', + type: 'HOST', + label: host.ipv4, + data: { + id: host.id, + ip: this.convertIPtoNumber(host.ipv4), + }, expanded: true, children: [] }); } - addServiceNode() { - const idx = Math.floor(Math.random() * (this.hostNode.length - 1)); - this.hostNode[idx].children.push({ - label: 'service', + addServiceNode(service: Service) { + const targetHostNode = this.findHostNodeByService(service); + const idx = this.findServiceIndex(targetHostNode.children, service); + targetHostNode.children[idx] = { + type: 'SERVICE', + label: service.serviceName, + data: { + id: service.id, + portType: service.port.portType, + portNumber: service.port.portNumber, + }, + }; + } + + + onTargetSelect(e, data) { + if (e.checked) { + this.selectedItems.push(data); + } else { + const index = this.selectedItems.indexOf(data); + this.selectedItems.splice(index, 1); + } + } + + + findHostIndex(host: Host): number { + let index = 0; + this.hostNode.forEach(node => { + if (node.data.ip < this.convertIPtoNumber(host.ipv4)) { + index++; + } + }); + return index; + } + + findServiceIndex(serviceNodes: TreeNode[], service: Service) { + let index = 0; + serviceNodes.forEach(node => { + if (node.data.portNumber < service.port.portNumber) { + index++; + } + }); + return index; + } + + findHostNodeByService(service: Service) { + let targetHost = null; + this.hostNode.forEach((value, i) => { + if (value.data.id === service.port.host.id) { + targetHost = this.hostNode[i]; + } + }); + return targetHost; + } + + convertIPtoNumber(ip: string) { + return ip.split('.').map((octet, index, array) => { + // tslint:disable-next-line:radix + return parseInt(octet) * Math.pow(256, (array.length - index - 1)); + }).reduce((prev, curr) => { + return prev + curr; }); } }