crawler auth

This commit is contained in:
insanity 2018-03-20 19:39:33 +09:00
parent 928c09eb7f
commit eec3f25bce
20 changed files with 456 additions and 12 deletions

View File

@ -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 { }

View File

@ -0,0 +1,3 @@
export const MODULE = {
name: 'metaCrawlerInputItem'
};

View File

@ -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 { }

View File

@ -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<MetaCrawlerInputItem[]> {
return this.rpcClient.call('MetaCrawlerInputItemService.readAllByMetaCrawler', c);
}
}

View File

@ -0,0 +1,5 @@
import { MetaCrawlerInputItemService } from './crawler-input-item.service';
export const SERVICES = [
MetaCrawlerInputItemService,
];

View File

@ -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<State>(MODULE.name);
export const ReadCrawlerInputItemSelector = new StateSelector<ListStore.State>(createSelector(
selectState,
(state: State) => state.list
));

View File

@ -0,0 +1,4 @@
export * from './list.action';
export * from './list.effect';
export * from './list.reducer';
export * from './list.state';

View File

@ -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
;

View File

@ -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();
}));
});

View File

@ -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<Action> = 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));
});
}

View File

@ -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;
}
}
}

View File

@ -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,
};

View File

@ -22,9 +22,9 @@ export const EFFECTS = [
ListStore.Effects, ListStore.Effects,
]; ];
export const selectNotificationState = createFeatureSelector<State>(MODULE.name); export const selectCrawlerState = createFeatureSelector<State>(MODULE.name);
export const ReadAllCrawlerSelector = new StateSelector<ListStore.State>(createSelector( export const ReadAllCrawlerSelector = new StateSelector<ListStore.State>(createSelector(
selectNotificationState, selectCrawlerState,
(state: State) => state.crawlers (state: State) => state.crawlers
)); ));

View File

@ -1,5 +1,12 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, Input, OnChanges } from '@angular/core';
import { Router } from '@angular/router'; 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({ @Component({
@ -7,10 +14,37 @@ import { Router } from '@angular/router';
templateUrl: './crawler-auth.component.html', templateUrl: './crawler-auth.component.html',
styleUrls: ['./crawler-auth.component.scss'] 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<ListStore.State>,
) { }
ngOnInit() { 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));
} }
} }

View File

@ -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 { Router } from '@angular/router';
import { Target } from 'packages/target/model'; import { Target } from 'packages/target/model';
@ -21,6 +21,9 @@ export class CrawlerSelectorComponent implements OnInit, OnChanges, AfterContent
@Input() selectedTarget: Target; @Input() selectedTarget: Target;
crawlers: MetaCrawler[]; crawlers: MetaCrawler[];
@Output() crawlerSelectEvent = new EventEmitter<MetaCrawler>();
constructor( constructor(
private router: Router, private router: Router,
private listStore: Store<ListStore.State>, private listStore: Store<ListStore.State>,
@ -50,6 +53,6 @@ export class CrawlerSelectorComponent implements OnInit, OnChanges, AfterContent
} }
crawlerSelected(crawler: MetaCrawler) { crawlerSelected(crawler: MetaCrawler) {
// console.log(crawler); this.crawlerSelectEvent.emit(crawler);
} }
} }

View File

@ -8,7 +8,23 @@
<mat-card-content> <mat-card-content>
<perfect-scrollbar style="height: 150px"> <perfect-scrollbar style="height: 150px">
트리 들어가야됨 <tree-root id="tree2" [focused]="true" [nodes]="nodes">
<ng-template #treeNodeFullTemplate let-node let-index="index" let-templates="templates">
<div class="tree-node">
<mat-checkbox [checked]="node.isActive" (change)="checkDiscoveryResult(node)"></mat-checkbox>
<tree-node-expander [node]="node"></tree-node-expander>
<div
class="node-content-wrapper"
[class.node-content-wrapper-active]="node.isActive"
[class.node-content-wrapper-focused]="node.isFocused"
(click)="checkDiscoveryResult(node)">
<span [class]="node.data.className" [class.title]="true">{{ node.data.title }}</span>
</div>
<tree-node-children [node]="node" [templates]="templates"></tree-node-children>
</div>
</ng-template>
</tree-root>
</perfect-scrollbar> </perfect-scrollbar>
</mat-card-content> </mat-card-content>

View File

@ -9,6 +9,117 @@ import { Router } from '@angular/router';
}) })
export class SensorItemSelectorComponent implements OnInit { 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) { } constructor(private router: Router) { }
ngOnInit() { ngOnInit() {

View File

@ -3,11 +3,11 @@
<mat-grid-list cols="2" rowHeight="5:1"> <mat-grid-list cols="2" rowHeight="5:1">
<mat-grid-tile [colspan]="1" [rowspan]="3" style="background-color: lightblue"> <mat-grid-tile [colspan]="1" [rowspan]="3" style="background-color: lightblue">
<of-target-selector [target]="selectedTarget" (targetSelectEvent)="handleTargetSelection($event)" [target]="target"></of-target-selector> <of-target-selector [target]="selectedTarget" (targetSelectEvent)="handleTargetSelection($event)" ></of-target-selector>
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="1" [rowspan]="2" style="background-color: lightcoral"> <mat-grid-tile [colspan]="1" [rowspan]="2" style="background-color: lightcoral">
<of-crawler-auth></of-crawler-auth> <of-crawler-auth [selectedCrawler]="selectedCrawler"></of-crawler-auth>
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="1" [rowspan]="3" style="background-color: lightgrey"> <mat-grid-tile [colspan]="1" [rowspan]="3" style="background-color: lightgrey">
@ -15,7 +15,7 @@
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="1" [rowspan]="2" style="background-color: lightpink"> <mat-grid-tile [colspan]="1" [rowspan]="2" style="background-color: lightpink">
<of-crawler-selector [selectedTarget]="selectedTarget"></of-crawler-selector> <of-crawler-selector [selectedTarget]="selectedTarget" (crawlerSelectEvent)="handleCrawlerSelection($event)"></of-crawler-selector>
</mat-grid-tile> </mat-grid-tile>
</mat-grid-list> </mat-grid-list>

View File

@ -3,6 +3,7 @@ import { AfterContentInit } from '@angular/core/src/metadata/lifecycle_hooks';
import { Target } from '../../../target/model'; import { Target } from '../../../target/model';
import { MAT_DIALOG_DATA } from '@angular/material'; import { MAT_DIALOG_DATA } from '@angular/material';
import { Infra } from '../../../infra/model'; import { Infra } from '../../../infra/model';
import { MetaCrawler } from '../../../meta/crawler/model/MetaCrawler';
@Component({ @Component({
@ -13,6 +14,7 @@ import { Infra } from '../../../infra/model';
export class SettingComponent implements OnInit, AfterContentInit { export class SettingComponent implements OnInit, AfterContentInit {
selectedTarget: Target = null; selectedTarget: Target = null;
selectedCrawler: MetaCrawler = null;
step = 1; step = 1;
constructor( constructor(
@ -46,4 +48,7 @@ export class SettingComponent implements OnInit, AfterContentInit {
handleTargetSelection(t: Target) { handleTargetSelection(t: Target) {
this.selectedTarget = t; this.selectedTarget = t;
} }
handleCrawlerSelection(c: MetaCrawler) {
this.selectedCrawler = c;
}
} }

View File

@ -11,6 +11,7 @@ import { SettingComponent } from './component/setting/setting.component';
import { TreeModule } from 'angular-tree-component'; import { TreeModule } from 'angular-tree-component';
import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar'; import { PerfectScrollbarModule } from 'ngx-perfect-scrollbar';
import { MetaCrawlerModule } from '../meta/crawler/crawler.module'; import { MetaCrawlerModule } from '../meta/crawler/crawler.module';
import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-input.module';
@NgModule({ @NgModule({
imports: [ imports: [
@ -20,7 +21,8 @@ import { MetaCrawlerModule } from '../meta/crawler/crawler.module';
SensorStoreModule, SensorStoreModule,
TreeModule, TreeModule,
PerfectScrollbarModule, PerfectScrollbarModule,
MetaCrawlerModule MetaCrawlerModule,
MetaCrawlerInputItemModule
], ],
declarations: [ declarations: [
COMPONENTS, COMPONENTS,