From 928c09eb7fc68ff820154e66c54cf48b3475e9fe Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 20 Mar 2018 17:03:42 +0900 Subject: [PATCH 1/5] meta crawler --- .../meta/crawler/service/crawler.service.ts | 2 +- .../crawler-selector.component.ts | 19 +++++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/packages/meta/crawler/service/crawler.service.ts b/src/packages/meta/crawler/service/crawler.service.ts index d62458f..2e3afbf 100644 --- a/src/packages/meta/crawler/service/crawler.service.ts +++ b/src/packages/meta/crawler/service/crawler.service.ts @@ -17,6 +17,6 @@ export class MetaCrawlerService { } public readAll(): Observable { - return this.rpcClient.call('CrawlerService.readAll'); + return this.rpcClient.call('MetaCrawlerService.readAll'); } } diff --git a/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts b/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts index 5a3bb9d..2ede9c2 100644 --- a/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts +++ b/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts @@ -16,7 +16,7 @@ import { MetaCrawler } from 'packages/meta/crawler/model/MetaCrawler'; }) export class CrawlerSelectorComponent implements OnInit, OnChanges, AfterContentInit { - crawlers$ = this.listStore.pipe(select(ReadAllCrawlerSelector.select('list'))); + crawlers$ = this.listStore.pipe(select(ReadAllCrawlerSelector.select('metaCrawlerList'))); @Input() selectedTarget: Target; crawlers: MetaCrawler[]; @@ -30,7 +30,7 @@ export class CrawlerSelectorComponent implements OnInit, OnChanges, AfterContent this.crawlers$.subscribe( (list: MetaCrawler[]) => { if (list !== null) { - console.log(list); + this.crawlers = list; } }, (error: RPCError) => { @@ -44,18 +44,9 @@ export class CrawlerSelectorComponent implements OnInit, OnChanges, AfterContent } ngOnChanges() { - if (this.selectedTarget) { - console.log('Getting valid crawlers for ' + this.selectedTarget.displayName); - } - - this.crawlers = new Array(); - for (let i = 0; i < 3; i++) { - const c: MetaCrawler = { - id: i, - name: 'Crawler' + i, - }; - this.crawlers.push(c); - } + // if (this.selectedTarget) { + // console.log('Getting valid crawlers for ' + this.selectedTarget.displayName); + // } } crawlerSelected(crawler: MetaCrawler) { From eec3f25bce7ef6aa45aedd8eed69b9ae48e590b6 Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 20 Mar 2018 19:39:33 +0900 Subject: [PATCH 2/5] crawler auth --- .../crawler-input-store.module.ts | 24 ++++ .../crawler-input.constant.ts | 3 + .../crawler-input.module.ts | 23 ++++ .../service/crawler-input-item.service.ts | 23 ++++ .../meta/crawler-input-item/service/index.ts | 5 + .../meta/crawler-input-item/store/index.ts | 30 +++++ .../crawler-input-item/store/list/index.ts | 4 + .../store/list/list.action.ts | 37 ++++++ .../store/list/list.effect.spec.ts | 15 +++ .../store/list/list.effect.ts | 51 ++++++++ .../store/list/list.reducer.ts | 43 +++++++ .../store/list/list.state.ts | 15 +++ src/packages/meta/crawler/store/index.ts | 4 +- .../crawler-auth/crawler-auth.component.ts | 40 ++++++- .../crawler-selector.component.ts | 7 +- .../sensor-item-selector.component.html | 18 ++- .../sensor-item-selector.component.ts | 111 ++++++++++++++++++ .../component/setting/setting.component.html | 6 +- .../component/setting/setting.component.ts | 5 + src/packages/sensor/sensor.module.ts | 4 +- 20 files changed, 456 insertions(+), 12 deletions(-) create mode 100644 src/packages/meta/crawler-input-item/crawler-input-store.module.ts create mode 100644 src/packages/meta/crawler-input-item/crawler-input.constant.ts create mode 100644 src/packages/meta/crawler-input-item/crawler-input.module.ts create mode 100644 src/packages/meta/crawler-input-item/service/crawler-input-item.service.ts create mode 100644 src/packages/meta/crawler-input-item/service/index.ts create mode 100644 src/packages/meta/crawler-input-item/store/index.ts create mode 100644 src/packages/meta/crawler-input-item/store/list/index.ts create mode 100644 src/packages/meta/crawler-input-item/store/list/list.action.ts create mode 100644 src/packages/meta/crawler-input-item/store/list/list.effect.spec.ts create mode 100644 src/packages/meta/crawler-input-item/store/list/list.effect.ts create mode 100644 src/packages/meta/crawler-input-item/store/list/list.reducer.ts create mode 100644 src/packages/meta/crawler-input-item/store/list/list.state.ts diff --git a/src/packages/meta/crawler-input-item/crawler-input-store.module.ts b/src/packages/meta/crawler-input-item/crawler-input-store.module.ts new file mode 100644 index 0000000..588d1a1 --- /dev/null +++ b/src/packages/meta/crawler-input-item/crawler-input-store.module.ts @@ -0,0 +1,24 @@ +import { NgModule } from '@angular/core'; +import { StoreModule } from '@ngrx/store'; +import { StoreDevtoolsModule } from '@ngrx/store-devtools'; +import { + StoreRouterConnectingModule, + RouterStateSerializer, +} from '@ngrx/router-store'; +import { EffectsModule } from '@ngrx/effects'; +import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; + +import { + REDUCERS, + EFFECTS, +} from './store'; + +import { MODULE } from './crawler-input.constant'; + +@NgModule({ + imports: [ + StoreModule.forFeature(MODULE.name, REDUCERS), + EffectsModule.forFeature(EFFECTS), + ], +}) +export class MetaCrawlerInputItemStoreModule { } diff --git a/src/packages/meta/crawler-input-item/crawler-input.constant.ts b/src/packages/meta/crawler-input-item/crawler-input.constant.ts new file mode 100644 index 0000000..54329f5 --- /dev/null +++ b/src/packages/meta/crawler-input-item/crawler-input.constant.ts @@ -0,0 +1,3 @@ +export const MODULE = { + name: 'metaCrawlerInputItem' +}; diff --git a/src/packages/meta/crawler-input-item/crawler-input.module.ts b/src/packages/meta/crawler-input-item/crawler-input.module.ts new file mode 100644 index 0000000..21d9b14 --- /dev/null +++ b/src/packages/meta/crawler-input-item/crawler-input.module.ts @@ -0,0 +1,23 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +import { } from './crawler.module'; + +import { MaterialModule } from 'packages/commons/material/material.module'; +import { SERVICES } from './service'; +import { MetaCrawlerInputItemStoreModule } from './crawler-input-store.module'; + +@NgModule({ + imports: [ + CommonModule, + MetaCrawlerInputItemStoreModule + ], + declarations: [ + ], + exports: [ + ], + providers: [ + SERVICES, + ] +}) +export class MetaCrawlerInputItemModule { } diff --git a/src/packages/meta/crawler-input-item/service/crawler-input-item.service.ts b/src/packages/meta/crawler-input-item/service/crawler-input-item.service.ts new file mode 100644 index 0000000..172ade1 --- /dev/null +++ b/src/packages/meta/crawler-input-item/service/crawler-input-item.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import 'rxjs/add/operator/map'; + +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; +import { MetaCrawlerInputItem } from '../model/MetaCrawlerInputItem'; +import { MetaCrawler } from '../../crawler/model/MetaCrawler'; + + +@Injectable() +export class MetaCrawlerInputItemService { + + public constructor( + private rpcClient: RPCClient, + ) { + + } + + public readAllByMetaCrawler(c: MetaCrawler): Observable { + return this.rpcClient.call('MetaCrawlerInputItemService.readAllByMetaCrawler', c); + } +} diff --git a/src/packages/meta/crawler-input-item/service/index.ts b/src/packages/meta/crawler-input-item/service/index.ts new file mode 100644 index 0000000..2d26125 --- /dev/null +++ b/src/packages/meta/crawler-input-item/service/index.ts @@ -0,0 +1,5 @@ +import { MetaCrawlerInputItemService } from './crawler-input-item.service'; + +export const SERVICES = [ + MetaCrawlerInputItemService, +]; diff --git a/src/packages/meta/crawler-input-item/store/index.ts b/src/packages/meta/crawler-input-item/store/index.ts new file mode 100644 index 0000000..76b4226 --- /dev/null +++ b/src/packages/meta/crawler-input-item/store/index.ts @@ -0,0 +1,30 @@ +import { + createSelector, + createFeatureSelector, + ActionReducerMap, +} from '@ngrx/store'; + +import { StateSelector } from 'packages/core/ngrx/store'; + + +import * as ListStore from './list'; +import { MODULE } from '../crawler-input.constant'; + +export interface State { + list: ListStore.State; +} + +export const REDUCERS = { + list: ListStore.reducer, +}; + +export const EFFECTS = [ + ListStore.Effects, +]; + +export const selectState = createFeatureSelector(MODULE.name); + +export const ReadCrawlerInputItemSelector = new StateSelector(createSelector( + selectState, + (state: State) => state.list +)); diff --git a/src/packages/meta/crawler-input-item/store/list/index.ts b/src/packages/meta/crawler-input-item/store/list/index.ts new file mode 100644 index 0000000..7fd86e0 --- /dev/null +++ b/src/packages/meta/crawler-input-item/store/list/index.ts @@ -0,0 +1,4 @@ +export * from './list.action'; +export * from './list.effect'; +export * from './list.reducer'; +export * from './list.state'; diff --git a/src/packages/meta/crawler-input-item/store/list/list.action.ts b/src/packages/meta/crawler-input-item/store/list/list.action.ts new file mode 100644 index 0000000..76579c7 --- /dev/null +++ b/src/packages/meta/crawler-input-item/store/list/list.action.ts @@ -0,0 +1,37 @@ +import { Action } from '@ngrx/store'; + +import { RPCError } from 'packages/core/rpc/error'; +import { MetaCrawler } from '../../../crawler/model/MetaCrawler'; +import { MetaCrawlerInputItem } from '../../model/MetaCrawlerInputItem'; + + +export enum ActionType { + ReadAll = '[meta.crawler-input-list] ReadAll', + ReadAllSuccess = '[meta.crawler-input-list] ReadAllSuccess', + ReadAllFailure = '[meta.crawler-input-list] ReadAllFailure', +} + +export class ReadAll implements Action { + readonly type = ActionType.ReadAll; + + constructor(public payload: MetaCrawler) {} +} + +export class ReadAllSuccess implements Action { + readonly type = ActionType.ReadAllSuccess; + + constructor(public payload: MetaCrawlerInputItem[]) {} +} + +export class ReadAllFailure implements Action { + readonly type = ActionType.ReadAllFailure; + + constructor(public payload: RPCError) {} +} + +export type Actions = + | ReadAll + | ReadAllSuccess + | ReadAllFailure + +; diff --git a/src/packages/meta/crawler-input-item/store/list/list.effect.spec.ts b/src/packages/meta/crawler-input-item/store/list/list.effect.spec.ts new file mode 100644 index 0000000..d8f6227 --- /dev/null +++ b/src/packages/meta/crawler-input-item/store/list/list.effect.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { Effects } from './list.effect'; + +describe('List.Effects', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [Effects] + }); + }); + + it('should be created', inject([Effects], (effects: Effects) => { + expect(effects).toBeTruthy(); + })); +}); diff --git a/src/packages/meta/crawler-input-item/store/list/list.effect.ts b/src/packages/meta/crawler-input-item/store/list/list.effect.ts new file mode 100644 index 0000000..738c833 --- /dev/null +++ b/src/packages/meta/crawler-input-item/store/list/list.effect.ts @@ -0,0 +1,51 @@ +import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Effect, Actions, ofType } from '@ngrx/effects'; +import { Action } from '@ngrx/store'; + +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; + +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/exhaustMap'; +import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/take'; + +import { RPCError } from 'packages/core/rpc/error'; + +import { DomainMember } from 'packages/domain/model'; + + +import { + ReadAll, + ReadAllSuccess, + ReadAllFailure, + ActionType, +} from './list.action'; +import { MetaCrawlerInputItemService } from '../../service/crawler-input-item.service'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private service: MetaCrawlerInputItemService, + private router: Router + ) { } + + @Effect() + readAll$: Observable = this.actions$ + .ofType(ActionType.ReadAll) + .map((action: ReadAll) => action.payload) + .switchMap(payload => this.service.readAllByMetaCrawler(payload)) + .map(list => { + return new ReadAllSuccess(list); + }) + .catch((error: RPCError) => { + return of(new ReadAllFailure(error)); + }); + +} diff --git a/src/packages/meta/crawler-input-item/store/list/list.reducer.ts b/src/packages/meta/crawler-input-item/store/list/list.reducer.ts new file mode 100644 index 0000000..ecb84ec --- /dev/null +++ b/src/packages/meta/crawler-input-item/store/list/list.reducer.ts @@ -0,0 +1,43 @@ +import { + Actions, + ActionType, +} from './list.action'; + +import { + State, + initialState, +} from './list.state'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.ReadAll: { + return { + ...state, + error: null, + pending: true, + }; + } + + case ActionType.ReadAllSuccess: { + return { + ...state, + error: null, + pending: false, + inputs: action.payload + }; + } + + case ActionType.ReadAllFailure: { + return { + ...state, + error: action.payload, + pending: false, + inputs: null, + }; + } + + default: { + return state; + } + } +} diff --git a/src/packages/meta/crawler-input-item/store/list/list.state.ts b/src/packages/meta/crawler-input-item/store/list/list.state.ts new file mode 100644 index 0000000..2b189a3 --- /dev/null +++ b/src/packages/meta/crawler-input-item/store/list/list.state.ts @@ -0,0 +1,15 @@ +import { RPCError } from 'packages/core/rpc/error'; +import { MetaCrawlerInputItem } from '../../model/MetaCrawlerInputItem'; + + +export interface State { + error: RPCError | null; + pending: boolean; + inputs: MetaCrawlerInputItem[] | null; +} + +export const initialState: State = { + error: null, + pending: false, + inputs: null, +}; diff --git a/src/packages/meta/crawler/store/index.ts b/src/packages/meta/crawler/store/index.ts index e0ceebd..1b7f256 100644 --- a/src/packages/meta/crawler/store/index.ts +++ b/src/packages/meta/crawler/store/index.ts @@ -22,9 +22,9 @@ export const EFFECTS = [ ListStore.Effects, ]; -export const selectNotificationState = createFeatureSelector(MODULE.name); +export const selectCrawlerState = createFeatureSelector(MODULE.name); export const ReadAllCrawlerSelector = new StateSelector(createSelector( - selectNotificationState, + selectCrawlerState, (state: State) => state.crawlers )); diff --git a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts index 69feba2..95cfb11 100644 --- a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts +++ b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts @@ -1,5 +1,12 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, Input, OnChanges } from '@angular/core'; import { Router } from '@angular/router'; +import { MetaCrawler } from '../../../../meta/crawler/model/MetaCrawler'; + +import { Store, select } from '@ngrx/store'; +import { RPCError } from 'packages/core/rpc/error'; +import * as ListStore from 'packages/meta/crawler-input-item/store/list'; +import { ReadCrawlerInputItemSelector } from 'packages/meta/crawler-input-item/store'; +import { MetaCrawlerInputItem } from '../../../../meta/crawler-input-item/model/MetaCrawlerInputItem'; @Component({ @@ -7,10 +14,37 @@ import { Router } from '@angular/router'; templateUrl: './crawler-auth.component.html', styleUrls: ['./crawler-auth.component.scss'] }) -export class CrawlerAuthComponent implements OnInit { +export class CrawlerAuthComponent implements OnInit, OnChanges { - constructor(private router: Router) { } + inputItems$ = this.listStore.pipe(select(ReadCrawlerInputItemSelector.select('inputs'))); + inputItems: MetaCrawlerInputItem[]; + + @Input() selectedCrawler: MetaCrawler; + constructor( + private router: Router, + private listStore: Store, + ) { } ngOnInit() { + this.inputItems$.subscribe( + (list: MetaCrawlerInputItem[]) => { + if (list !== null) { + this.inputItems = list; + console.log(list); + } + }, + (error: RPCError) => { + console.log(error.response.message); + } + ); + } + + ngOnChanges() { + if (this.selectedCrawler === null) { return; } + this.getCrawlerAuthInputItems(); + } + + getCrawlerAuthInputItems() { + this.listStore.dispatch(new ListStore.ReadAll(this.selectedCrawler)); } } diff --git a/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts b/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts index 2ede9c2..4ddc1ca 100644 --- a/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts +++ b/src/packages/sensor/component/setting/crawler-selector/crawler-selector.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, OnChanges, AfterContentInit } from '@angular/core'; +import { Component, OnInit, Input, OnChanges, AfterContentInit, Output, EventEmitter } from '@angular/core'; import { Router } from '@angular/router'; import { Target } from 'packages/target/model'; @@ -21,6 +21,9 @@ export class CrawlerSelectorComponent implements OnInit, OnChanges, AfterContent @Input() selectedTarget: Target; crawlers: MetaCrawler[]; + @Output() crawlerSelectEvent = new EventEmitter(); + + constructor( private router: Router, private listStore: Store, @@ -50,6 +53,6 @@ export class CrawlerSelectorComponent implements OnInit, OnChanges, AfterContent } crawlerSelected(crawler: MetaCrawler) { - // console.log(crawler); + this.crawlerSelectEvent.emit(crawler); } } diff --git a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html index ad5047c..fbfe631 100644 --- a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html +++ b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html @@ -8,7 +8,23 @@ - 트리 들어가야됨 + + +
+ + +
+ {{ node.data.title }} + +
+ +
+
+
diff --git a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts index d8fc1cd..fcaf066 100644 --- a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts +++ b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts @@ -9,6 +9,117 @@ import { Router } from '@angular/router'; }) export class SensorItemSelectorComponent implements OnInit { + nodes = [ + { + title: 'host - 3232235781', + className: 'className3232235781', + children: [ + { + title: 'Port - 22', + className: 'className22', + children: [ + { + title: 'SSH', + className: 'classNameSSH' + } + ] + }, + { + title: 'Port - 80', + className: 'className80', + children: [ + { + title: 'HTTP', + className: 'classNameHTTP' + } + ] + }, + { + title: 'Port - 1936', + className: 'className1936', + children: [ + { + title: 'HTTP', + className: 'classNameHTTP' + } + ] + } + ] + }, + { + title: 'host - 3232235781', + className: 'className3232235781', + children: [ + { + title: 'Port - 22', + className: 'className22', + children: [ + { + title: 'SSH', + className: 'classNameSSH' + } + ] + }, + { + title: 'Port - 80', + className: 'className80', + children: [ + { + title: 'HTTP', + className: 'classNameHTTP' + } + ] + }, + { + title: 'Port - 1936', + className: 'className1936', + children: [ + { + title: 'HTTP', + className: 'classNameHTTP' + } + ] + } + ] + }, + { + title: 'host - 3232235781', + className: 'className3232235781', + children: [ + { + title: 'Port - 22', + className: 'className22', + children: [ + { + title: 'SSH', + className: 'classNameSSH' + } + ] + }, + { + title: 'Port - 80', + className: 'className80', + children: [ + { + title: 'HTTP', + className: 'classNameHTTP' + } + ] + }, + { + title: 'Port - 1936', + className: 'className1936', + children: [ + { + title: 'HTTP', + className: 'classNameHTTP' + } + ] + } + ] + } + ]; + constructor(private router: Router) { } ngOnInit() { diff --git a/src/packages/sensor/component/setting/setting.component.html b/src/packages/sensor/component/setting/setting.component.html index eec0229..8d3c6ff 100644 --- a/src/packages/sensor/component/setting/setting.component.html +++ b/src/packages/sensor/component/setting/setting.component.html @@ -3,11 +3,11 @@ - + - + @@ -15,7 +15,7 @@ - + diff --git a/src/packages/sensor/component/setting/setting.component.ts b/src/packages/sensor/component/setting/setting.component.ts index 682ec2a..768943f 100644 --- a/src/packages/sensor/component/setting/setting.component.ts +++ b/src/packages/sensor/component/setting/setting.component.ts @@ -3,6 +3,7 @@ import { AfterContentInit } from '@angular/core/src/metadata/lifecycle_hooks'; import { Target } from '../../../target/model'; import { MAT_DIALOG_DATA } from '@angular/material'; import { Infra } from '../../../infra/model'; +import { MetaCrawler } from '../../../meta/crawler/model/MetaCrawler'; @Component({ @@ -13,6 +14,7 @@ import { Infra } from '../../../infra/model'; export class SettingComponent implements OnInit, AfterContentInit { selectedTarget: Target = null; + selectedCrawler: MetaCrawler = null; step = 1; constructor( @@ -46,4 +48,7 @@ export class SettingComponent implements OnInit, AfterContentInit { handleTargetSelection(t: Target) { this.selectedTarget = t; } + handleCrawlerSelection(c: MetaCrawler) { + this.selectedCrawler = c; + } } diff --git a/src/packages/sensor/sensor.module.ts b/src/packages/sensor/sensor.module.ts index 7f318b0..2d08bd7 100644 --- a/src/packages/sensor/sensor.module.ts +++ b/src/packages/sensor/sensor.module.ts @@ -11,6 +11,7 @@ import { SettingComponent } from './component/setting/setting.component'; import { TreeModule } from 'angular-tree-component'; import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar'; import { MetaCrawlerModule } from '../meta/crawler/crawler.module'; +import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-input.module'; @NgModule({ imports: [ @@ -20,7 +21,8 @@ import { MetaCrawlerModule } from '../meta/crawler/crawler.module'; SensorStoreModule, TreeModule, PerfectScrollbarModule, - MetaCrawlerModule + MetaCrawlerModule, + MetaCrawlerInputItemModule ], declarations: [ COMPONENTS, From 960e6645f678af31ea213b7757262ee67210b1c1 Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 20 Mar 2018 19:43:42 +0900 Subject: [PATCH 3/5] mistakeeeeeeeee --- .../component/setting/crawler-auth/crawler-auth.component.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts index 95cfb11..a74e416 100644 --- a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts +++ b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts @@ -47,4 +47,7 @@ export class CrawlerAuthComponent implements OnInit, OnChanges { getCrawlerAuthInputItems() { this.listStore.dispatch(new ListStore.ReadAll(this.selectedCrawler)); } + + generateAuthComponent() { + } } From 634aa178851f0c53050eb83dc0ac1865cbc2a760 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 20 Mar 2018 23:13:58 +0900 Subject: [PATCH 4/5] ing --- src/commons/logger/core/config.ts | 6 ++ src/commons/logger/core/index.ts | 3 + src/commons/logger/core/token.ts | 4 + src/commons/logger/core/type.ts | 26 ++++++ src/commons/logger/logger.module.ts | 39 ++++++++ src/commons/logger/service/logger.service.ts | 93 +++++++++++++++++++ src/commons/logger/store/logger.action.ts | 20 ++++ .../rpc/protocol/json/RPCClientJSONCodec.ts | 37 +++++++- 8 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 src/commons/logger/core/config.ts create mode 100644 src/commons/logger/core/index.ts create mode 100644 src/commons/logger/core/token.ts create mode 100644 src/commons/logger/core/type.ts create mode 100644 src/commons/logger/logger.module.ts create mode 100644 src/commons/logger/service/logger.service.ts create mode 100644 src/commons/logger/store/logger.action.ts diff --git a/src/commons/logger/core/config.ts b/src/commons/logger/core/config.ts new file mode 100644 index 0000000..51264af --- /dev/null +++ b/src/commons/logger/core/config.ts @@ -0,0 +1,6 @@ +import { LoggerLevel } from './type'; + +export class LoggerConfig { + level: LoggerLevel; + serverLogLevel: LoggerLevel; +} diff --git a/src/commons/logger/core/index.ts b/src/commons/logger/core/index.ts new file mode 100644 index 0000000..40a47eb --- /dev/null +++ b/src/commons/logger/core/index.ts @@ -0,0 +1,3 @@ +export * from './config'; +export * from './token'; +export * from './type'; diff --git a/src/commons/logger/core/token.ts b/src/commons/logger/core/token.ts new file mode 100644 index 0000000..6d8f313 --- /dev/null +++ b/src/commons/logger/core/token.ts @@ -0,0 +1,4 @@ +import { Inject, Injectable, InjectionToken } from '@angular/core'; +import { LoggerLevel } from './type'; + +export const LOGGER_LEVEL = new InjectionToken('LoggerLevel'); diff --git a/src/commons/logger/core/type.ts b/src/commons/logger/core/type.ts new file mode 100644 index 0000000..72d4473 --- /dev/null +++ b/src/commons/logger/core/type.ts @@ -0,0 +1,26 @@ +export enum LoggerLevel { + TRACE = 0, + DEBUG, + INFO, + LOG, + WARN, + ERROR, + OFF, +} + +export const LoggerLevelName = [ + 'TRACE', + 'DEBUG', + 'INFO', + 'LOG', + 'WARN', + 'ERROR', + 'OFF' +]; + +export interface ServerLoggingParameter { + level: string; + message: string; + addtional?: string; + timestamp: Date; +} diff --git a/src/commons/logger/logger.module.ts b/src/commons/logger/logger.module.ts new file mode 100644 index 0000000..4918285 --- /dev/null +++ b/src/commons/logger/logger.module.ts @@ -0,0 +1,39 @@ +import { + NgModule, + ModuleWithProviders, +} from '@angular/core'; +import { CommonModule } from '@angular/common'; + + + + + + + +@NgModule({ +}) +export class LoggerRootModule { } + +@NgModule({ +}) +export class LoggerFeatureModule { } + +@NgModule({ +}) +export class LoggerModule { + static forRoot(reducers: any): ModuleWithProviders { + return { + ngModule: LoggerRootModule, + providers: [ + ], + }; + } + + static forFeature(featureName: string, reducers?: any): ModuleWithProviders { + return { + ngModule: LoggerFeatureModule, + providers: [ + ], + }; + } +} diff --git a/src/commons/logger/service/logger.service.ts b/src/commons/logger/service/logger.service.ts new file mode 100644 index 0000000..1081ea8 --- /dev/null +++ b/src/commons/logger/service/logger.service.ts @@ -0,0 +1,93 @@ +import { + LoggerConfig, + LoggerLevel, +} from '../core'; + + +export abstract class LoggerService { + + public constructor( + private readonly config: LoggerConfig + ) { + + } + + public trace(message, ...additional: any[]): void { + this._log(LoggerLevel.TRACE, message, additional); + } + + public debug(message, ...additional: any[]): void { + this._log(LoggerLevel.DEBUG, message, additional); + } + + public info(message, ...additional: any[]): void { + this._log(LoggerLevel.INFO, message, additional); + } + + public log(message, ...additional: any[]): void { + this._log(LoggerLevel.LOG, message, additional); + } + + public warn(message, ...additional: any[]): void { + this._log(LoggerLevel.WARN, message, additional); + } + + public error(message, ...additional: any[]): void { + this._log(LoggerLevel.ERROR, message, additional); + } + + private _timestamp(): string { + return new Date().toISOString(); + } + + private _log(level: LoggerLevel, logOnServer: boolean, message, additional: any[] = []): void { + if (!message) { + return; + } + + // Allow logging on server even if client log level is off + // if (logOnServer) { + // this._logOnServer(level, message, additional); + // } + + // if no message or the log level is less than the environ + if (level < this.config.level) { + return; + } + + try { + message = typeof message === 'string' ? message + : JSON.stringify(message, null, 2); + } catch (e) { + additional = [message, ...additional]; + message = 'The provided "message" value could not be parsed with JSON.stringify().'; + } + + // Coloring doesn't work in IE + // if (this._isIE) { + // return this._logIE(level, message, additional); + // } + + // const color = this._getColor(level); + + // console.log(`%c${this._timestamp()} [${Levels[level]}]`, `color:${color}`, message, ...additional); + } + + private _getColor(level: LoggerLevel): 'blue' | 'teal' | 'gray' | 'red' | undefined { + switch (level) { + case LoggerLevel.TRACE: + return 'blue'; + case LoggerLevel.DEBUG: + return 'teal'; + case LoggerLevel.INFO: + case LoggerLevel.LOG: + return 'gray'; + case LoggerLevel.WARN: + case LoggerLevel.ERROR: + return 'red'; + case LoggerLevel.OFF: + default: + return; + } + } +} diff --git a/src/commons/logger/store/logger.action.ts b/src/commons/logger/store/logger.action.ts new file mode 100644 index 0000000..15b419d --- /dev/null +++ b/src/commons/logger/store/logger.action.ts @@ -0,0 +1,20 @@ +import { Action } from '@ngrx/store'; + +import { + LoggerLevel, + ServerLoggingParameter, +} from '../core'; + +export enum ActionType { + ServerLogging = '[@@LOGGER] ServerLogging', +} + +export class ServerLogging implements Action { + readonly type = ActionType.ServerLogging; + + constructor(public payload: ServerLoggingParameter) {} +} + +export type Actions = + | ServerLogging +; diff --git a/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts b/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts index d6886a4..cb0ba5c 100644 --- a/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts +++ b/src/packages/core/rpc/protocol/json/RPCClientJSONCodec.ts @@ -10,13 +10,13 @@ import { export interface ClientNotification { method: string; - params?: any[]; + params?: string[]; } export interface ClientRequest { jsonrpc: string; method: string; - params?: any[]; + params?: string[]; id?: number; } @@ -29,10 +29,12 @@ export interface ClientResponse { export class RPCClientJSONCodec extends RPCClientCodec { public request(method: string, args: any[], id?: number): any { + const params = convertParamsToStringArray(args); + const req: ClientRequest = { jsonrpc: '2.0', method: method, - params: args, + params: 0 === params.length ? null : params, id: id, }; return JSON.stringify(req); @@ -48,6 +50,35 @@ export class RPCClientJSONCodec extends RPCClientCodec { } } +function convertParamsToStringArray(args: any[]): string[] | undefined { + const values: string[] = []; + + if (undefined === args || null === args || 0 === args.length) { + return values; + } + + for (let indexI = 0; indexI < args.length; indexI++) { + const arg = args[indexI]; + + switch (typeof arg) { + case 'boolean': + case 'number': // enum + values.push(String(arg)); + break; + case 'string': + values.push(arg); + break; + case 'object': // array, map + values.push(JSON.stringify(arg)); + break; + default: + throw new Error(`Not supported type[${typeof arg}]`); + } + } + + return values; +} + export class RPCClientJSONResponseCodec extends RPCClientResponseCodec { public constructor(private _res: ClientResponse) { super(); From 0b667270ecff95bbf59b2a4911b4379abac6278c Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 21 Mar 2018 16:56:43 +0900 Subject: [PATCH 5/5] sensor item tree --- package.json | 2 +- .../sensor-display-item-store.module.ts | 24 ++ .../sensor-display-item.constant.ts | 3 + .../sensor-display-item.module.ts | 23 ++ .../meta/sensor-display-item/service/index.ts | 5 + .../service/sensor-display-item.service.ts | 23 ++ .../meta/sensor-display-item/store/index.ts | 30 +++ .../sensor-display-item/store/list/index.ts | 4 + .../store/list/list.action.ts | 37 ++++ .../store/list/list.effect.spec.ts | 15 ++ .../store/list/list.effect.ts | 52 +++++ .../store/list/list.reducer.ts | 43 ++++ .../store/list/list.state.ts | 15 ++ .../crawler-auth/crawler-auth.component.ts | 7 +- .../sensor-item-selector.component.html | 10 +- .../sensor-item-selector.component.ts | 209 ++++++++---------- .../component/setting/setting.component.html | 2 +- src/packages/sensor/sensor.module.ts | 4 +- yarn.lock | 34 ++- 19 files changed, 400 insertions(+), 142 deletions(-) create mode 100644 src/packages/meta/sensor-display-item/sensor-display-item-store.module.ts create mode 100644 src/packages/meta/sensor-display-item/sensor-display-item.constant.ts create mode 100644 src/packages/meta/sensor-display-item/sensor-display-item.module.ts create mode 100644 src/packages/meta/sensor-display-item/service/index.ts create mode 100644 src/packages/meta/sensor-display-item/service/sensor-display-item.service.ts create mode 100644 src/packages/meta/sensor-display-item/store/index.ts create mode 100644 src/packages/meta/sensor-display-item/store/list/index.ts create mode 100644 src/packages/meta/sensor-display-item/store/list/list.action.ts create mode 100644 src/packages/meta/sensor-display-item/store/list/list.effect.spec.ts create mode 100644 src/packages/meta/sensor-display-item/store/list/list.effect.ts create mode 100644 src/packages/meta/sensor-display-item/store/list/list.reducer.ts create mode 100644 src/packages/meta/sensor-display-item/store/list/list.state.ts diff --git a/package.json b/package.json index df3d17a..8ed4284 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@ngrx/router-store": "^5.2.0", "@ngrx/store": "^5.2.0", "@ngrx/store-devtools": "^5.2.0", - "angular-tree-component": "^7.0.1", + "angular-tree-component": "^7.0.2", "angularx-qrcode": "^1.0.1", "angular-l10n": "^4.1.5", "core-js": "^2.5.3", diff --git a/src/packages/meta/sensor-display-item/sensor-display-item-store.module.ts b/src/packages/meta/sensor-display-item/sensor-display-item-store.module.ts new file mode 100644 index 0000000..f9ea191 --- /dev/null +++ b/src/packages/meta/sensor-display-item/sensor-display-item-store.module.ts @@ -0,0 +1,24 @@ +import { NgModule } from '@angular/core'; +import { StoreModule } from '@ngrx/store'; +import { StoreDevtoolsModule } from '@ngrx/store-devtools'; +import { + StoreRouterConnectingModule, + RouterStateSerializer, +} from '@ngrx/router-store'; +import { EffectsModule } from '@ngrx/effects'; +import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; + +import { + REDUCERS, + EFFECTS, +} from './store'; + +import { MODULE } from './sensor-display-item.constant'; + +@NgModule({ + imports: [ + StoreModule.forFeature(MODULE.name, REDUCERS), + EffectsModule.forFeature(EFFECTS), + ], +}) +export class MetaSensorDisplayItemStoreModule { } diff --git a/src/packages/meta/sensor-display-item/sensor-display-item.constant.ts b/src/packages/meta/sensor-display-item/sensor-display-item.constant.ts new file mode 100644 index 0000000..d49d9cb --- /dev/null +++ b/src/packages/meta/sensor-display-item/sensor-display-item.constant.ts @@ -0,0 +1,3 @@ +export const MODULE = { + name: 'metaSensorDisplayItem' +}; diff --git a/src/packages/meta/sensor-display-item/sensor-display-item.module.ts b/src/packages/meta/sensor-display-item/sensor-display-item.module.ts new file mode 100644 index 0000000..58b9f07 --- /dev/null +++ b/src/packages/meta/sensor-display-item/sensor-display-item.module.ts @@ -0,0 +1,23 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +import { } from './crawler.module'; + +import { MaterialModule } from 'packages/commons/material/material.module'; +import { SERVICES } from './service'; +import { MetaSensorDisplayItemStoreModule } from './sensor-display-item-store.module'; + +@NgModule({ + imports: [ + CommonModule, + MetaSensorDisplayItemStoreModule + ], + declarations: [ + ], + exports: [ + ], + providers: [ + SERVICES, + ] +}) +export class MetaSensorDisplayItemModule { } diff --git a/src/packages/meta/sensor-display-item/service/index.ts b/src/packages/meta/sensor-display-item/service/index.ts new file mode 100644 index 0000000..db97bf7 --- /dev/null +++ b/src/packages/meta/sensor-display-item/service/index.ts @@ -0,0 +1,5 @@ +import { MetaSensorDisplayItemService } from './sensor-display-item.service'; + +export const SERVICES = [ + MetaSensorDisplayItemService, +]; diff --git a/src/packages/meta/sensor-display-item/service/sensor-display-item.service.ts b/src/packages/meta/sensor-display-item/service/sensor-display-item.service.ts new file mode 100644 index 0000000..98e211f --- /dev/null +++ b/src/packages/meta/sensor-display-item/service/sensor-display-item.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import 'rxjs/add/operator/map'; + +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; +import { MetaCrawler } from 'packages/meta/crawler/model/MetaCrawler'; +import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem'; + + +@Injectable() +export class MetaSensorDisplayItemService { + + public constructor( + private rpcClient: RPCClient, + ) { + + } + + public readAllByMetaCrawler(c: MetaCrawler): Observable { + return this.rpcClient.call('MetaSensorDisplayItemService.readAllByCrawler', c); + } +} diff --git a/src/packages/meta/sensor-display-item/store/index.ts b/src/packages/meta/sensor-display-item/store/index.ts new file mode 100644 index 0000000..f8d6dac --- /dev/null +++ b/src/packages/meta/sensor-display-item/store/index.ts @@ -0,0 +1,30 @@ +import { + createSelector, + createFeatureSelector, + ActionReducerMap, +} from '@ngrx/store'; + +import { StateSelector } from 'packages/core/ngrx/store'; + + +import * as ListStore from './list'; +import { MODULE } from '../sensor-display-item.constant'; + +export interface State { + list: ListStore.State; +} + +export const REDUCERS = { + list: ListStore.reducer, +}; + +export const EFFECTS = [ + ListStore.Effects, +]; + +export const selectState = createFeatureSelector(MODULE.name); + +export const ReadAllSensorDisplayItemByCrawlerSelector = new StateSelector(createSelector( + selectState, + (state: State) => state.list +)); diff --git a/src/packages/meta/sensor-display-item/store/list/index.ts b/src/packages/meta/sensor-display-item/store/list/index.ts new file mode 100644 index 0000000..7fd86e0 --- /dev/null +++ b/src/packages/meta/sensor-display-item/store/list/index.ts @@ -0,0 +1,4 @@ +export * from './list.action'; +export * from './list.effect'; +export * from './list.reducer'; +export * from './list.state'; diff --git a/src/packages/meta/sensor-display-item/store/list/list.action.ts b/src/packages/meta/sensor-display-item/store/list/list.action.ts new file mode 100644 index 0000000..f7063bc --- /dev/null +++ b/src/packages/meta/sensor-display-item/store/list/list.action.ts @@ -0,0 +1,37 @@ +import { Action } from '@ngrx/store'; + +import { RPCError } from 'packages/core/rpc/error'; +import { MetaCrawler } from '../../../crawler/model/MetaCrawler'; +import { MetaSensorDisplayItem } from '../../model/MetaSensorDisplayItem'; + + +export enum ActionType { + ReadAllByCrawler = '[meta.sensor-display-item] ReadAllByCrawler', + ReadAllByCrawlerSuccess = '[meta.sensor-display-item] ReadAllByCrawlerSuccess', + ReadAllByCrawlerFailure = '[meta.sensor-display-item] ReadAllByCrawlerFailure', +} + +export class ReadAllByCrawler implements Action { + readonly type = ActionType.ReadAllByCrawler; + + constructor(public payload: MetaCrawler) {} +} + +export class ReadAllByCrawlerSuccess implements Action { + readonly type = ActionType.ReadAllByCrawlerSuccess; + + constructor(public payload: MetaSensorDisplayItem[]) {} +} + +export class ReadAllByCrawlerFailure implements Action { + readonly type = ActionType.ReadAllByCrawlerFailure; + + constructor(public payload: RPCError) {} +} + +export type Actions = + | ReadAllByCrawler + | ReadAllByCrawlerSuccess + | ReadAllByCrawlerFailure + +; diff --git a/src/packages/meta/sensor-display-item/store/list/list.effect.spec.ts b/src/packages/meta/sensor-display-item/store/list/list.effect.spec.ts new file mode 100644 index 0000000..d8f6227 --- /dev/null +++ b/src/packages/meta/sensor-display-item/store/list/list.effect.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { Effects } from './list.effect'; + +describe('List.Effects', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [Effects] + }); + }); + + it('should be created', inject([Effects], (effects: Effects) => { + expect(effects).toBeTruthy(); + })); +}); diff --git a/src/packages/meta/sensor-display-item/store/list/list.effect.ts b/src/packages/meta/sensor-display-item/store/list/list.effect.ts new file mode 100644 index 0000000..a2c3ed2 --- /dev/null +++ b/src/packages/meta/sensor-display-item/store/list/list.effect.ts @@ -0,0 +1,52 @@ +import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + +import { Effect, Actions, ofType } from '@ngrx/effects'; +import { Action } from '@ngrx/store'; + +import { Observable } from 'rxjs/Observable'; +import { of } from 'rxjs/observable/of'; + +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/exhaustMap'; +import 'rxjs/add/operator/switchMap'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/take'; + +import { RPCError } from 'packages/core/rpc/error'; + +import { DomainMember } from 'packages/domain/model'; + + +import { + ReadAllByCrawler, + ReadAllByCrawlerSuccess, + ReadAllByCrawlerFailure, + ActionType, +} from './list.action'; +import { MetaSensorDisplayItem } from '../../model/MetaSensorDisplayItem'; +import { MetaSensorDisplayItemService } from '../../service/sensor-display-item.service'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private service: MetaSensorDisplayItemService, + private router: Router + ) { } + + @Effect() + readAllByCrawler$: Observable = this.actions$ + .ofType(ActionType.ReadAllByCrawler) + .map((action: ReadAllByCrawler) => action.payload) + .switchMap(payload => this.service.readAllByMetaCrawler(payload)) + .map(list => { + return new ReadAllByCrawlerSuccess(list); + }) + .catch((error: RPCError) => { + return of(new ReadAllByCrawlerFailure(error)); + }); + +} diff --git a/src/packages/meta/sensor-display-item/store/list/list.reducer.ts b/src/packages/meta/sensor-display-item/store/list/list.reducer.ts new file mode 100644 index 0000000..31c0616 --- /dev/null +++ b/src/packages/meta/sensor-display-item/store/list/list.reducer.ts @@ -0,0 +1,43 @@ +import { + Actions, + ActionType, +} from './list.action'; + +import { + State, + initialState, +} from './list.state'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.ReadAllByCrawler: { + return { + ...state, + error: null, + pending: true, + }; + } + + case ActionType.ReadAllByCrawlerSuccess: { + return { + ...state, + error: null, + pending: false, + list: action.payload + }; + } + + case ActionType.ReadAllByCrawlerFailure: { + return { + ...state, + error: action.payload, + pending: false, + list: null, + }; + } + + default: { + return state; + } + } +} diff --git a/src/packages/meta/sensor-display-item/store/list/list.state.ts b/src/packages/meta/sensor-display-item/store/list/list.state.ts new file mode 100644 index 0000000..6f19c58 --- /dev/null +++ b/src/packages/meta/sensor-display-item/store/list/list.state.ts @@ -0,0 +1,15 @@ +import { RPCError } from 'packages/core/rpc/error'; +import { MetaSensorDisplayItem } from '../../model/MetaSensorDisplayItem'; + + +export interface State { + error: RPCError | null; + pending: boolean; + list: MetaSensorDisplayItem[] | null; +} + +export const initialState: State = { + error: null, + pending: false, + list: null, +}; diff --git a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts index a74e416..0c7c858 100644 --- a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts +++ b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.ts @@ -29,8 +29,11 @@ export class CrawlerAuthComponent implements OnInit, OnChanges { this.inputItems$.subscribe( (list: MetaCrawlerInputItem[]) => { if (list !== null) { - this.inputItems = list; + console.log('###Auth Inputs###'); console.log(list); + console.log('###################'); + this.inputItems = list; + this.generateAuthComponent(); } }, (error: RPCError) => { @@ -49,5 +52,7 @@ export class CrawlerAuthComponent implements OnInit, OnChanges { } generateAuthComponent() { + this.inputItems.map(function(v, i) { + }); } } diff --git a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html index fbfe631..48fbdc0 100644 --- a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html +++ b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.html @@ -8,17 +8,17 @@ - +
- - + +
- {{ node.data.title }} + (click)="checkItem(node)"> + {{ node.data.title }} {{node.data.key}}
diff --git a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts index fcaf066..fb3cb20 100644 --- a/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts +++ b/src/packages/sensor/component/setting/sensor-item-selector/sensor-item-selector.component.ts @@ -1,127 +1,110 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnChanges, Input, Output, EventEmitter, ViewChild, AfterViewInit } from '@angular/core'; import { Router } from '@angular/router'; +import { Store, select } from '@ngrx/store'; +import { RPCError } from 'packages/core/rpc/error'; +import * as ListStore from 'packages/meta/sensor-display-item/store/list'; +import { ReadAllSensorDisplayItemByCrawlerSelector } from 'packages/meta/sensor-display-item/store'; +import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem'; +import { MetaCrawler } from '../../../../meta/crawler/model/MetaCrawler'; +import { ITreeOptions } from 'angular-tree-component'; @Component({ selector: 'of-sensor-item-selector', templateUrl: './sensor-item-selector.component.html', styleUrls: ['./sensor-item-selector.component.scss'] }) -export class SensorItemSelectorComponent implements OnInit { +export class SensorItemSelectorComponent implements OnInit, AfterViewInit, OnChanges { - nodes = [ - { - title: 'host - 3232235781', - className: 'className3232235781', - children: [ - { - title: 'Port - 22', - className: 'className22', - children: [ - { - title: 'SSH', - className: 'classNameSSH' - } - ] - }, - { - title: 'Port - 80', - className: 'className80', - children: [ - { - title: 'HTTP', - className: 'classNameHTTP' - } - ] - }, - { - title: 'Port - 1936', - className: 'className1936', - children: [ - { - title: 'HTTP', - className: 'classNameHTTP' - } - ] - } - ] - }, - { - title: 'host - 3232235781', - className: 'className3232235781', - children: [ - { - title: 'Port - 22', - className: 'className22', - children: [ - { - title: 'SSH', - className: 'classNameSSH' - } - ] - }, - { - title: 'Port - 80', - className: 'className80', - children: [ - { - title: 'HTTP', - className: 'classNameHTTP' - } - ] - }, - { - title: 'Port - 1936', - className: 'className1936', - children: [ - { - title: 'HTTP', - className: 'classNameHTTP' - } - ] - } - ] - }, - { - title: 'host - 3232235781', - className: 'className3232235781', - children: [ - { - title: 'Port - 22', - className: 'className22', - children: [ - { - title: 'SSH', - className: 'classNameSSH' - } - ] - }, - { - title: 'Port - 80', - className: 'className80', - children: [ - { - title: 'HTTP', - className: 'classNameHTTP' - } - ] - }, - { - title: 'Port - 1936', - className: 'className1936', - children: [ - { - title: 'HTTP', - className: 'classNameHTTP' - } - ] - } - ] - } - ]; + @Input() selectedCrawler: MetaCrawler; + @Output() selectedItems = new EventEmitter(); + items$ = this.listStore.pipe(select(ReadAllSensorDisplayItemByCrawlerSelector.select('list'))); + sensorDisplayItems: MetaSensorDisplayItem[]; + @ViewChild('tree') tree; + nodes; - constructor(private router: Router) { } + constructor( + private router: Router, + private listStore: Store, + ) { } ngOnInit() { + this.items$.subscribe( + (list: MetaSensorDisplayItem[]) => { + if (list !== null) { + console.log('###Display Items###'); + console.log(list); + console.log('###################'); + this.sensorDisplayItems = list; + this.generateTreeNode(list); + } + }, + (error: RPCError) => { + console.log(error.response.message); + } + ); + } + + ngAfterViewInit() { + } + + ngOnChanges() { + this.listStore.dispatch(new ListStore.ReadAllByCrawler(this.selectedCrawler)); + } + + generateTreeNode(list: MetaSensorDisplayItem[]) { + this.nodes = new Array(); + for (const item of list) { + const categoryNode = this.existCategory(item); + if (categoryNode === null) { + const childrenNode = new Array(); + childrenNode.push(this.getChildNode(item)); + const node = { + title: item.itemType.name, + children: childrenNode, + isExpanded: true + }; + this.nodes.push(node); + } else { + categoryNode.children.push(this.getChildNode(item)); + } + } + } + + getChildNode(item) { + const childNode = { + title: item.displayName, + key: ' - ' + item.key, + default: item.default + }; + return childNode; + } + + existCategory(item: MetaSensorDisplayItem) { + let categoryNode = null; + for (const node of this.nodes) { + if (node.title === item.itemType.name) { + categoryNode = node; + } + } + return categoryNode; + } + + checkItem(node) { + node.toggleActivated(true); + console.log(node); + // if (node.isActive) { + // if (this.checkedSet.has(node.data) === false) { + // this.checkedSet.add(node.data); + // } + // } else { + // if (this.checkedSet.has(node.data)) { + // this.checkedSet.delete(node.data); + // } + // } + } + + onTreeDataLoad(tree) { + tree.treeModel.expandAll(); } } diff --git a/src/packages/sensor/component/setting/setting.component.html b/src/packages/sensor/component/setting/setting.component.html index 8d3c6ff..4bfbe80 100644 --- a/src/packages/sensor/component/setting/setting.component.html +++ b/src/packages/sensor/component/setting/setting.component.html @@ -11,7 +11,7 @@ - + diff --git a/src/packages/sensor/sensor.module.ts b/src/packages/sensor/sensor.module.ts index 2d08bd7..adca861 100644 --- a/src/packages/sensor/sensor.module.ts +++ b/src/packages/sensor/sensor.module.ts @@ -12,6 +12,7 @@ import { TreeModule } from 'angular-tree-component'; import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar'; import { MetaCrawlerModule } from '../meta/crawler/crawler.module'; import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-input.module'; +import { MetaSensorDisplayItemModule } from '../meta/sensor-display-item/sensor-display-item.module'; @NgModule({ imports: [ @@ -22,7 +23,8 @@ import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-i TreeModule, PerfectScrollbarModule, MetaCrawlerModule, - MetaCrawlerInputItemModule + MetaCrawlerInputItemModule, + MetaSensorDisplayItemModule ], declarations: [ COMPONENTS, diff --git a/yarn.lock b/yarn.lock index 321c918..c24076e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -559,13 +559,13 @@ angular-l10n@^4.1.5: dependencies: tslib "^1.7.1" -angular-tree-component@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/angular-tree-component/-/angular-tree-component-7.0.1.tgz#fc8d0e72d8c34b87131a3ba2bd32ad20945689ac" +angular-tree-component@^7.0.2: + version "7.0.2" + resolved "https://registry.yarnpkg.com/angular-tree-component/-/angular-tree-component-7.0.2.tgz#a70c2ed62b0bf5f14d20ada1e68fbc3649bdf783" dependencies: - lodash "4.17.4" - mobx ">=3" - mobx-angular ">=1" + lodash "^4.17.4" + mobx "^3.6.2" + mobx-angular "^2.1.1" angularx-qrcode@^1.0.1: version "1.0.1" @@ -1425,12 +1425,6 @@ chownr@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.0.1.tgz#e2a75042a9551908bebd25b8523d5f9769d79181" -cidr-range@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/cidr-range/-/cidr-range-1.0.6.tgz#8ce6a648dca7eceb34e82013c22479f843f1c452" - dependencies: - ip "^1.1.3" - cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: version "1.0.4" resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.4.tgz#8760e4ecc272f4c363532f926d874aae2c1397de" @@ -3530,7 +3524,7 @@ ip@1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/ip/-/ip-1.0.1.tgz#c7e356cdea225ae71b36d70f2e71a92ba4e42590" -ip@^1.1.0, ip@^1.1.2, ip@^1.1.3, ip@^1.1.5: +ip@^1.1.0, ip@^1.1.2, ip@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a" @@ -4292,7 +4286,7 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -lodash@4.17.4, lodash@^4.0.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.5.0, lodash@~4.17.4: +lodash@^4.0.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.5.0, lodash@~4.17.4: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -4595,13 +4589,13 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkd dependencies: minimist "0.0.8" -mobx-angular@>=1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/mobx-angular/-/mobx-angular-3.0.1.tgz#881379acea563c0767550d1f7801ab3434449bb1" +mobx-angular@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/mobx-angular/-/mobx-angular-2.2.0.tgz#f9612160eb585ef3343dfdb476185dbb7b49e1ef" -mobx@>=3: - version "4.0.1" - resolved "https://registry.yarnpkg.com/mobx/-/mobx-4.0.1.tgz#321945580f7d3bf7b1f60ddaa1d623835683b5a2" +mobx@^3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/mobx/-/mobx-3.6.2.tgz#fb9f5ff5090539a1ad54e75dc4c098b602693320" module-deps@^4.0.8: version "4.1.1"