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,