added authcrawler

This commit is contained in:
snoop 2017-08-30 19:53:10 +09:00
parent 1eae013724
commit 9319ddfa8e
13 changed files with 175 additions and 13 deletions

View File

@ -0,0 +1,14 @@
import MetaCrawler from '@overflow/meta/api/model/MetaCrawler';
import Target from '@overflow/target/api/model/Target';
interface AuthCrawler {
id?: number;
crawler?: MetaCrawler;
target?: Target;
authJson?: string;
createDate?: Date;
}
export default AuthCrawler;

View File

@ -0,0 +1,7 @@
export type REQUEST = '@overflow/auth/check_auth_crawler/REQUEST';
export type REQUEST_SUCCESS = '@overflow/auth/check_auth_crawler/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/auth/check_auth_crawler/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/auth/check_auth_crawler/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/auth/check_auth_crawler/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/auth/check_auth_crawler/REQUEST/FAILURE';

View File

@ -0,0 +1,7 @@
export type REQUEST = '@overflow/auth/regist/REQUEST';
export type REQUEST_SUCCESS = '@overflow/auth/regist/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/auth/regist/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/auth/regist/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/auth/regist/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/auth/regist/REQUEST/FAILURE';

View File

@ -0,0 +1,25 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import * as CheckAuthCrawlerActionTypes from '../action/check_auth_crawler';
import CheckAuthCrawlerState, { defaultState as CheckAuthCrawlerDefaultState } from '../state/CheckAuthCrawler';
const reducer: ReducersMapObject = {
[CheckAuthCrawlerActionTypes.REQUEST_SUCCESS]: (state: CheckAuthCrawlerState = CheckAuthCrawlerDefaultState,
action: Action<boolean>): CheckAuthCrawlerState => {
return {
...state,
isSuccessCheckAuthCrawler: action.payload,
};
},
[CheckAuthCrawlerActionTypes.REQUEST_FAILURE]: (state: CheckAuthCrawlerState = CheckAuthCrawlerDefaultState,
action: Action<Error>): CheckAuthCrawlerState => {
return {
...state,
error: action.error,
};
},
};
export default reducer;

View File

@ -0,0 +1,27 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import * as RegistActionTypes from '../action/regist';
import RegistState, { defaultState as RegistDefaultState } from '../state/Regist';
import AuthCrawler from '../../api/model/AuthCrawler';
const reducer: ReducersMapObject = {
[RegistActionTypes.REQUEST_SUCCESS]: (state: RegistState = RegistDefaultState,
action: Action<AuthCrawler>): RegistState => {
return {
...state,
authCrawler: action.payload,
};
},
[RegistActionTypes.REQUEST_FAILURE]: (state: RegistState = RegistDefaultState,
action: Action<AuthCrawler>): RegistState => {
return {
...state,
error: action.error,
};
},
};
export default reducer;

View File

@ -0,0 +1,12 @@
export interface State {
readonly isSuccessCheckAuthCrawler: boolean;
readonly error?: Error;
}
export const defaultState: State = {
isSuccessCheckAuthCrawler: undefined,
error: undefined,
};
export default State;

View File

@ -0,0 +1,14 @@
import AuthCrawler from '../../api/model/AuthCrawler';
export interface State {
readonly authCrawler: AuthCrawler;
readonly error?: Error;
}
export const defaultState: State = {
authCrawler: undefined,
error: undefined,
};
export default State;

View File

@ -6,11 +6,12 @@ import {
} from './components/CrawlerAuthInputs'; } from './components/CrawlerAuthInputs';
// import State from '../redux/state/ReadAllByTarget'; // import State from '../redux/state/ReadAllByTarget';
import Crawler from '@overflow/meta/api/model/MetaCrawler'; import MetaCrawler from '@overflow/meta/api/model/MetaCrawler';
// import Sensor from '@overflow/sensor/api/model/Sensor'; import Infra from '@overflow/infra/api/model/Infra';
// import MetaSensorItem from '@overflow/meta/api/model/MetaSensorItem'; import AuthCrawler from '@overflow/auth/api/model/AuthCrawler';
import * as CrawlerAuthInputsActions from '@overflow/meta/redux/action/crawler_auth_inputs'; import * as CheckAuthCrawlerActions from '@overflow/auth/redux/action/check_auth_crawler';
import * as RegistActions from '@overflow/auth/redux/action/regist';
// import * as SensorItemReadAllActions from '@overflow/meta/redux/action/sensor_item_read_all'; // import * as SensorItemReadAllActions from '@overflow/meta/redux/action/sensor_item_read_all';
// import * as CrawlerReadAllByTargetActions from '../redux/action/crawler_read_all_by_target'; // import * as CrawlerReadAllByTargetActions from '../redux/action/crawler_read_all_by_target';
@ -21,12 +22,20 @@ import * as asyncRequestActions from '@overflow/commons/redux/action/asyncReques
export function mapStateToProps(state: any, props: any): CrawlerAuthInputsStateProps { export function mapStateToProps(state: any, props: any): CrawlerAuthInputsStateProps {
return { return {
// crawler: props.crawler, // crawler: props.crawler,
metaCrawlerInputItemList:props.metaCrawlerInputItemList, metaCrawlerInputItemList: props.metaCrawlerInputItemList,
}; };
} }
export function mapDispatchToProps(dispatch: Dispatch<any>): CrawlerAuthInputsDispatchProps { export function mapDispatchToProps(dispatch: Dispatch<any>): CrawlerAuthInputsDispatchProps {
return { return {
onVerifyCrawler: (infraId: number, crawler: MetaCrawler, authJson: String) => {
dispatch(asyncRequestActions.request('AuthCrawlerService', 'checkAuthCrawler', CheckAuthCrawlerActions.REQUEST,
JSON.stringify(infraId), JSON.stringify(crawler), authJson));
},
onRegistAuthCrawler: (authCrawler: AuthCrawler) => {
dispatch(asyncRequestActions.request('AuthCrawlerService', 'regist', RegistActions.REQUEST,
JSON.stringify(authCrawler)));
},
// onCrawlerReadAllByMetaCrawler: (crawler: Crawler) => { // onCrawlerReadAllByMetaCrawler: (crawler: Crawler) => {
// dispatch(asyncRequestActions.request('MetaCrawlerInputItemService', // dispatch(asyncRequestActions.request('MetaCrawlerInputItemService',
// 'readAllByMetaCrawler', CrawlerAuthInputsActions.REQUEST, JSON.stringify(crawler))); // 'readAllByMetaCrawler', CrawlerAuthInputsActions.REQUEST, JSON.stringify(crawler)));

View File

@ -1,20 +1,28 @@
import * as React from 'react'; import * as React from 'react';
import * as _ from 'lodash';
import { Icon, Step, Button, Table, Radio, Form, Container, Checkbox } from 'semantic-ui-react'; import { Icon, Step, Button, Table, Radio, Form, Container, Checkbox } from 'semantic-ui-react';
import { Grid, Image, Label, Segment, Dropdown, Input, List, Accordion, Loader } from 'semantic-ui-react'; import { Grid, Image, Label, Segment, Dropdown, Input, List, Accordion, Loader, InputOnChangeData, CheckboxProps } from 'semantic-ui-react';
import MetaCrawler from '@overflow/meta/api/model/MetaCrawler'; import MetaCrawler from '@overflow/meta/api/model/MetaCrawler';
import MetaCrawlerInputItem from '@overflow/meta/api/model/MetaCrawlerInputItem'; import MetaCrawlerInputItem from '@overflow/meta/api/model/MetaCrawlerInputItem';
import SensorItemTree from '@overflow/meta/react/SensorItemTree'; import SensorItemTree from '@overflow/meta/react/SensorItemTree';
import SensorRegistInfo from '@overflow/sensor/api/model/SensorRegistInfo';
import Infra from '@overflow/infra/api/model/Infra';
import AuthCrawler from '@overflow/auth/api/model/AuthCrawler';
export interface CrawlerAuthInputsStateProps { export interface CrawlerAuthInputsStateProps {
crawlerId?: number; crawlerId?: number;
crawler?: MetaCrawler; crawler?: MetaCrawler;
metaCrawlerInputItemList?: MetaCrawlerInputItem[]; metaCrawlerInputItemList?: MetaCrawlerInputItem[];
setSensor?(data: SensorRegistInfo): void;
getSensor?(): SensorRegistInfo;
} }
export interface CrawlerAuthInputsDispatchProps { export interface CrawlerAuthInputsDispatchProps {
onVerifyCrawler?(infraId: number, crawler: MetaCrawler, authJson: String): void;
onRegistAuthCrawler?(authCrawler: AuthCrawler): void;
} }
export type CrawlerAuthInputsProps = CrawlerAuthInputsStateProps & CrawlerAuthInputsDispatchProps; export type CrawlerAuthInputsProps = CrawlerAuthInputsStateProps & CrawlerAuthInputsDispatchProps;
@ -23,6 +31,7 @@ export type CrawlerAuthInputsProps = CrawlerAuthInputsStateProps & CrawlerAuthIn
export interface CrawlerAuthInputsState { export interface CrawlerAuthInputsState {
isVerifying: boolean; isVerifying: boolean;
authJson: any;
} }
export class CrawlerAuthInputs extends React.Component<CrawlerAuthInputsProps, CrawlerAuthInputsState> { export class CrawlerAuthInputs extends React.Component<CrawlerAuthInputsProps, CrawlerAuthInputsState> {
@ -32,6 +41,7 @@ export class CrawlerAuthInputs extends React.Component<CrawlerAuthInputsProps, C
super(props, context); super(props, context);
this.state = { this.state = {
isVerifying: false, isVerifying: false,
authJson: {},
}; };
} }
@ -71,14 +81,39 @@ export class CrawlerAuthInputs extends React.Component<CrawlerAuthInputsProps, C
this.setState({ this.setState({
isVerifying: true, isVerifying: true,
}); });
let sd = this.props.getSensor();
sd.crawlerAuth = this.state.authJson;
this.props.setSensor(sd);
this.props.onVerifyCrawler(sd.infra.id, sd.crawler, sd.crawlerAuth);
let authCrawler: AuthCrawler = {
crawler: {id:sd.crawler.id},
target: {id:sd.infra.target.id},
authJson: JSON.stringify(sd.crawlerAuth),
};
this.props.onRegistAuthCrawler(authCrawler);
}
public onChangeAuth = (key: string, data: string) => {
let newJson: any = _.clone(this.state.authJson);
newJson[key] = data;
this.setState({ authJson: newJson });
} }
public renderRow(item: MetaCrawlerInputItem, index: number): JSX.Element { public renderRow(item: MetaCrawlerInputItem, index: number): JSX.Element {
let elem = new Array(); let elem = new Array();
if (item.inputType.name === 'TEXT_TYPE') { if (item.inputType.name === 'TEXT_TYPE') {
elem.push(<Input placeholder={item.defaultValue} key={0} />); elem.push(<Input label={item.name} placeholder={item.defaultValue} key={0} onChange={
(event: React.SyntheticEvent<HTMLInputElement>, data: InputOnChangeData) => {
this.onChangeAuth(item.name, data.value);
}} />);
} else if (item.inputType.name === 'PASSWORD_TYPE') { } else if (item.inputType.name === 'PASSWORD_TYPE') {
elem.push(<Input type='password' placeholder={item.defaultValue} key={0} />); elem.push(<Input label={item.name} type='password' placeholder={item.defaultValue} key={0} onChange={
(event: React.SyntheticEvent<HTMLInputElement>, data: InputOnChangeData) => {
this.onChangeAuth(item.name, data.value);
}} />);
} else if (item.inputType.name === 'Radio') { } else if (item.inputType.name === 'Radio') {
let itemValues = item.keyValue.split('|'); let itemValues = item.keyValue.split('|');
let idx = 0; let idx = 0;
@ -88,6 +123,11 @@ export class CrawlerAuthInputs extends React.Component<CrawlerAuthInputsProps, C
label={itemValue} label={itemValue}
name='radioGroup' name='radioGroup'
value={itemValue} value={itemValue}
onChange={
(event: React.FormEvent<HTMLInputElement>, data: CheckboxProps) => {
this.onChangeAuth(item.name, itemValue);
}
}
/>); />);
} }
} }
@ -145,6 +185,7 @@ export class CrawlerAuthInputs extends React.Component<CrawlerAuthInputsProps, C
<Table.Footer> <Table.Footer>
<Table.Row> <Table.Row>
<Table.HeaderCell colSpan='2'> <Table.HeaderCell colSpan='2'>
{/*loading={this.state.isVerifying}*/}
<Button primary floated={'right'} onClick={this.handleVerify.bind(this)} loading={this.state.isVerifying}>Verify</Button> <Button primary floated={'right'} onClick={this.handleVerify.bind(this)} loading={this.state.isVerifying}>Verify</Button>
</Table.HeaderCell> </Table.HeaderCell>
</Table.Row> </Table.Row>

View File

@ -128,7 +128,8 @@ export class CrawlerSelector extends React.Component<CrawlerSelectorProps, Crawl
<br /> <br />
</Grid.Column> </Grid.Column>
<Grid.Column> <Grid.Column>
<CrawlerAuthInputsContainer metaCrawlerInputItemList={this.props.metaCrawlerInputItemList} /> <CrawlerAuthInputsContainer metaCrawlerInputItemList={this.props.metaCrawlerInputItemList}
getSensor={this.props.getSensor} setSensor={this.props.setSensor}/>
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
); );

View File

@ -10,6 +10,7 @@ interface SensorRegistInfo {
interval: number; interval: number;
// type: string; // type: string;
infra: Infra; infra: Infra;
crawlerAuth: string;
} }
export default SensorRegistInfo; export default SensorRegistInfo;

View File

@ -29,9 +29,10 @@ export function mapStateToProps(state: any, props: any): SensorConfigStepperStat
export function mapDispatchToProps(dispatch: Dispatch<any>): SensorConfigStepperDispatchProps { export function mapDispatchToProps(dispatch: Dispatch<any>): SensorConfigStepperDispatchProps {
return { return {
onRegistSensorConfig: (sensor: Sensor, sensorItemList: SensorItem[]) => { onRegistSensorConfig: (sensor: Sensor, sensorItemList: SensorItem[], etc: any) => {
dispatch(asyncRequestActions.request('SensorService', 'registSensorConfig', RegistSensorConfigActions.REQUEST, dispatch(asyncRequestActions.request('SensorService', 'registSensorConfig', RegistSensorConfigActions.REQUEST,
JSON.stringify(sensor), JSON.stringify(sensorItemList))); JSON.stringify(sensor), JSON.stringify(sensorItemList),
JSON.stringify(etc)));
}, },
onMoveSensors: () => { onMoveSensors: () => {
dispatch(routerPush('/sensors')); dispatch(routerPush('/sensors'));

View File

@ -47,7 +47,7 @@ export interface SensorConfigStepperStateProps {
} }
export interface SensorConfigStepperDispatchProps { export interface SensorConfigStepperDispatchProps {
onRegistSensorConfig?(sensor: Sensor, sensorItemList: SensorItem[]): void; onRegistSensorConfig?(sensor: Sensor, sensorItemList: SensorItem[], etc: any): void;
onMoveSensors?(): void; onMoveSensors?(): void;
onMoveTargetSensors?(targetId: number): void; onMoveTargetSensors?(targetId: number): void;
} }
@ -182,6 +182,7 @@ export class SensorConfigStepper extends React.Component<SensorConfigStepperProp
public registSensor(): void { public registSensor(): void {
let sensorData = this.props.getSensor(); let sensorData = this.props.getSensor();
console.log(sensorData);
let sensor: Sensor = {}; let sensor: Sensor = {};
sensor.crawler = { id: sensorData.crawler.id }; sensor.crawler = { id: sensorData.crawler.id };
@ -202,7 +203,9 @@ export class SensorConfigStepper extends React.Component<SensorConfigStepperProp
console.log(sensor); console.log(sensor);
console.log(siList); console.log(siList);
this.props.onRegistSensorConfig(sensor, siList); let etc: any = {interval: sensorData.interval};
this.props.onRegistSensorConfig(sensor, siList, etc);
} }
public showContent(): any { public showContent(): any {