crawler auth ing

This commit is contained in:
insanity 2018-03-22 19:02:32 +09:00
parent ab2757c1e7
commit b28e77fb26
20 changed files with 341 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import { Sensor } from './Sensor';
import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem'; import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem';
import { Sensor } from 'packages/sensor/model';
export interface SensorItem { export interface SensorItem {
id?: number; id?: number;

View File

@ -0,0 +1,8 @@
import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem';
import { MetaSensorItemKey } from '../../meta/sensor-item-key/model/MetaSensorItemKey';
export interface SensorItemDependency {
id?: number;
item?: MetaSensorDisplayItem;
sensorItem?: MetaSensorItemKey;
}

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 './sensor-item.constant';
@NgModule({
imports: [
StoreModule.forFeature(MODULE.name, REDUCERS),
EffectsModule.forFeature(EFFECTS),
],
})
export class SensorItemStoreModule { }

View File

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

View File

@ -2,12 +2,15 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { MaterialModule } from 'packages/commons/material/material.module'; import { MaterialModule } from 'packages/commons/material/material.module';
import { COMPONENTS } from './component'; import { COMPONENTS } from './component';
import { SensorItemStoreModule } from './sensor-item-store.module';
import { MetaSensorDisplayItemModule } from '../meta/sensor-display-item/sensor-display-item.module';
import { SERVICES } from './service';
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
MaterialModule, MaterialModule,
SensorItemStoreModule,
], ],
declarations: [ declarations: [
COMPONENTS, COMPONENTS,
@ -15,5 +18,8 @@ import { COMPONENTS } from './component';
exports: [ exports: [
COMPONENTS, COMPONENTS,
], ],
providers: [
SERVICES,
],
}) })
export class SensorItemModule { } export class SensorItemModule { }

View File

@ -0,0 +1,7 @@
import { SensorItemDependencyService } from './sensor-item-dependency.service';
import { SensorItemService } from './sensor-item.service';
export const SERVICES = [
SensorItemDependencyService,
SensorItemService
];

View File

@ -0,0 +1,29 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { RPCClient } from 'packages/core/rpc/client/RPCClient';
import { SensorItemDependency } from '../model/SensorItemDependency';
import { MetaSensorItemKey } from 'packages/meta/sensor-item-key/model/MetaSensorItemKey';
import { MetaSensorDisplayItem } from '../../meta/sensor-display-item/model/MetaSensorDisplayItem';
@Injectable()
export class SensorItemDependencyService {
public constructor(
private rpcClient: RPCClient,
) {
}
public regist(dependency: SensorItemDependency): Observable<SensorItemDependency> {
return this.rpcClient.call('SensorItemDependencyService.regist', dependency);
}
public readAllByDisplayItem(displayItem: MetaSensorDisplayItem): Observable<MetaSensorItemKey[]> {
return this.rpcClient.call('SensorItemDependencyService.readAllByDisplayItem', displayItem);
}
}

View File

@ -0,0 +1,22 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { RPCClient } from 'packages/core/rpc/client/RPCClient';
@Injectable()
export class SensorItemService {
public constructor(
private rpcClient: RPCClient,
) {
}
// public regist(dependency: SensorItemDependency): Observable<SensorItemDependency> {
// return this.rpcClient.call('SensorItemDependencyService.regist', dependency);
// }
}

View File

@ -0,0 +1,30 @@
import {
createSelector,
createFeatureSelector,
ActionReducerMap,
} from '@ngrx/store';
import { StateSelector } from 'packages/core/ngrx/store';
import * as ListStore from './key-list';
import { MODULE } from '../sensor-item.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 ReadSensorItemKeySelector = 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 { MetaSensorItemKey } from 'packages/meta/sensor-item-key/model/MetaSensorItemKey';
import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem';
export enum ActionType {
ReadAllByDisplayItem = '[meta.sensor-display-key-list] ReadAllByDisplayItem',
ReadAllByDisplayItemSuccess = '[meta.sensor-display-key-list] ReadAllByDisplayItemSuccess',
ReadAllByDisplayItemFailure = '[meta.sensor-display-key-list] ReadAllByDisplayItemFailure',
}
export class ReadAllByDisplayItem implements Action {
readonly type = ActionType.ReadAllByDisplayItem;
constructor(public payload: MetaSensorDisplayItem) {}
}
export class ReadAllByDisplayItemSuccess implements Action {
readonly type = ActionType.ReadAllByDisplayItemSuccess;
constructor(public payload: MetaSensorItemKey[]) {}
}
export class ReadAllByDisplayItemFailure implements Action {
readonly type = ActionType.ReadAllByDisplayItemFailure;
constructor(public payload: RPCError) {}
}
export type Actions =
| ReadAllByDisplayItem
| ReadAllByDisplayItemSuccess
| ReadAllByDisplayItemFailure
;

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 {
ReadAllByDisplayItem,
ReadAllByDisplayItemSuccess,
ReadAllByDisplayItemFailure,
ActionType,
} from './list.action';
import { SensorItemDependencyService } from '../../service/sensor-item-dependency.service';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private service: SensorItemDependencyService,
private router: Router
) { }
@Effect()
readAllByDisplayItem$: Observable<Action> = this.actions$
.ofType(ActionType.ReadAllByDisplayItem)
.map((action: ReadAllByDisplayItem) => action.payload)
.switchMap(payload => this.service.readAllByDisplayItem(payload))
.map(list => {
return new ReadAllByDisplayItemSuccess(list);
})
.catch((error: RPCError) => {
return of(new ReadAllByDisplayItemFailure(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.ReadAllByDisplayItem: {
return {
...state,
error: null,
pending: true,
};
}
case ActionType.ReadAllByDisplayItemSuccess: {
return {
...state,
error: null,
pending: false,
list: action.payload
};
}
case ActionType.ReadAllByDisplayItemFailure: {
return {
...state,
error: action.payload,
pending: false,
list: null,
};
}
default: {
return state;
}
}
}

View File

@ -0,0 +1,15 @@
import { RPCError } from 'packages/core/rpc/error';
import { MetaSensorItemKey } from 'packages/meta/sensor-item-key/model/MetaSensorItemKey';
export interface State {
error: RPCError | null;
pending: boolean;
list: MetaSensorItemKey[] | null;
}
export const initialState: State = {
error: null,
pending: false,
list: null,
};

View File

@ -8,6 +8,12 @@
<mat-card-content> <mat-card-content>
<perfect-scrollbar style="height: 150px"> <perfect-scrollbar style="height: 150px">
크롤러 인증해야 됨 크롤러 인증해야 됨
<div *ngFor="let inputItem of inputItems">
<mat-form-field>
<input *ngIf="inputItem.inputType.id == 1" matInput type="text" placeholder={{inputItem.name}}>
<input *ngIf="inputItem.inputType.id == 2" matInput type="password" placeholder={{inputItem.name}}>
</mat-form-field>
</div>
</perfect-scrollbar> </perfect-scrollbar>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>

View File

@ -1,10 +1,15 @@
import { Component, OnInit, Input, Inject, DoCheck } from '@angular/core'; import { Component, OnInit, Input, Inject, DoCheck } from '@angular/core';
import { Target } from '../../../target/model'; import { Target } from '../../../target/model';
import { MAT_DIALOG_DATA } from '@angular/material'; import { MAT_DIALOG_DATA, MatSnackBar } from '@angular/material';
import { Infra } from '../../../infra/model'; import { Infra } from '../../../infra/model';
import { MetaCrawler } from '../../../meta/crawler/model/MetaCrawler'; import { MetaCrawler } from '../../../meta/crawler/model/MetaCrawler';
import { MetaSensorDisplayItem } from '../../../meta/sensor-display-item/model/MetaSensorDisplayItem'; import { MetaSensorDisplayItem } from '../../../meta/sensor-display-item/model/MetaSensorDisplayItem';
import { Store, select } from '@ngrx/store';
import { RPCError } from 'packages/core/rpc/error';
import * as SensorItemKeyListStore from 'packages/sensor-item/store/key-list';
import { ReadSensorItemKeySelector } from 'packages/sensor-item/store';
import { MetaSensorItemKey } from '../../../meta/sensor-item-key/model/MetaSensorItemKey';
@Component({ @Component({
selector: 'of-sensor-setting', selector: 'of-sensor-setting',
@ -19,8 +24,12 @@ export class SettingComponent implements OnInit, DoCheck {
step = 1; step = 1;
nextable = false; nextable = false;
sensorItemKeys$ = this.keyListStore.pipe(select(ReadSensorItemKeySelector.select('list')));
constructor( constructor(
@Inject(MAT_DIALOG_DATA) public data: any @Inject(MAT_DIALOG_DATA) public data: any,
public snackBar: MatSnackBar,
private keyListStore: Store<SensorItemKeyListStore.State>,
) { ) {
if (data !== null) { if (data !== null) {
this.selectedTarget = data.infra.target; this.selectedTarget = data.infra.target;
@ -28,6 +37,18 @@ export class SettingComponent implements OnInit, DoCheck {
} }
ngOnInit() { ngOnInit() {
this.sensorItemKeys$.subscribe(
(list: MetaSensorItemKey[]) => {
if (list !== null) {
console.log('#############################');
console.log(list);
console.log('#############################');
}
},
(error: RPCError) => {
console.log(error.response.message);
}
);
} }
ngDoCheck() { ngDoCheck() {
@ -52,7 +73,19 @@ export class SettingComponent implements OnInit, DoCheck {
} }
onDone() { onDone() {
// SensorService.registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson) this.openSnackBar('센서 등록해야되는데 아직 못함');
// List<MetaSensorItemKey> SensorItemDependencyService.readAllByDisplayItem(MetaSensorDisplayItem displayItem)
for (const displayItem of Array.from(this.selectedSensorDisplayItems)) {
this.keyListStore.dispatch(new SensorItemKeyListStore.ReadAllByDisplayItem(displayItem));
}
// Sensor SensorService.registSensorConfig(Sensor sensor, List<SensorItem> sensorItemList, String etcJson)
}
openSnackBar(message: string) {
this.snackBar.open(message, 'OK', {
duration: 2000,
});
} }
handleTargetSelection(t: Target) { handleTargetSelection(t: Target) {

View File

@ -1,3 +1,2 @@
export * from './Sensor'; export * from './Sensor';
export * from './SensorItem';
export * from './SensorRegistInfo'; export * from './SensorRegistInfo';

View File

@ -14,6 +14,7 @@ import { MetaCrawlerModule } from '../meta/crawler/crawler.module';
import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-input.module'; import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-input.module';
import { MetaSensorDisplayItemModule } from '../meta/sensor-display-item/sensor-display-item.module'; import { MetaSensorDisplayItemModule } from '../meta/sensor-display-item/sensor-display-item.module';
import { InfoTableModule } from '../commons/component/info-table/info-table.module'; import { InfoTableModule } from '../commons/component/info-table/info-table.module';
import { SensorItemModule } from '../sensor-item/sensor-item.module';
@NgModule({ @NgModule({
imports: [ imports: [
@ -26,7 +27,8 @@ import { InfoTableModule } from '../commons/component/info-table/info-table.modu
PerfectScrollbarModule, PerfectScrollbarModule,
MetaCrawlerModule, MetaCrawlerModule,
MetaCrawlerInputItemModule, MetaCrawlerInputItemModule,
MetaSensorDisplayItemModule MetaSensorDisplayItemModule,
SensorItemModule
], ],
declarations: [ declarations: [
COMPONENTS, COMPONENTS,

View File

@ -19,10 +19,6 @@ export class SensorService {
} }
public readAllByDomain(domain: Domain): Observable<Sensor[]> { public readAllByDomain(domain: Domain): Observable<Sensor[]> {
const body = {
domain: domain,
};
return this.rpcClient.call('SensorService.readAllByDomain', domain); return this.rpcClient.call('SensorService.readAllByDomain', domain);
} }