Merge remote-tracking branch 'origin/master'

This commit is contained in:
geek 2017-07-26 15:23:18 +09:00
commit f02e3e99e6
4 changed files with 179 additions and 38 deletions

View File

@ -2,7 +2,16 @@ import * as React from 'react';
import * as _ from 'lodash'; import * as _ from 'lodash';
// import update from 'immutability-helper'; // import update from 'immutability-helper';
import { Checkbox, Container, Label, Accordion, Icon, List, ListItemProps } from 'semantic-ui-react'; import {
Checkbox,
Container,
Label,
Accordion,
Icon,
List, Button,
ListItemProps,
CheckboxProps,
} from 'semantic-ui-react';
import MetaSensorItemType from '../../api/model/MetaSensorItemType'; import MetaSensorItemType from '../../api/model/MetaSensorItemType';
@ -26,22 +35,24 @@ export type SensorItemTreeProps = SensorItemTreeStateProps & SensorItemTreeDispa
export interface SensorItemTreeState { export interface SensorItemTreeState {
categoryState: Map<number, boolean>; categoryState: Map<number, boolean>;
itemState: Map<number, boolean[]>; itemState: Map<number, Array<boolean>>;
} }
interface TreeItem { interface TreeItem {
metaSensorItemList: MetaSensorItem[]; metaSensorItemList: Array<MetaSensorItem>;
metaSensorItemType: MetaSensorItemType; metaSensorItemType: MetaSensorItemType;
} }
export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorItemTreeState> { export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorItemTreeState> {
private itemMap: Map<number, TreeItem>; private itemMap: Map<number, TreeItem>;
private selectedItemMap: Map<number, Array<MetaSensorItem>>;
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.itemMap = new Map; this.itemMap = new Map;
this.selectedItemMap = new Map,
this.state = { this.state = {
categoryState: new Map(), categoryState: new Map(),
@ -64,27 +75,41 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
item.metaSensorItemList = []; item.metaSensorItemList = [];
item.metaSensorItemList.push(sensorItem); item.metaSensorItemList.push(sensorItem);
item.metaSensorItemType = this.GetMetaSensorItemType(sensorItem.metaSensorItemType.id); item.metaSensorItemType = this.GetMetaSensorItemType(sensorItem.metaSensorItemType.id);
this.itemMap.set(sensorItem.id, item); this.itemMap.set(sensorItem.metaSensorItemType.id, item);
} }
}); });
} }
public ViewSensorItemType(): JSX.Element[] { public ViewSensorItemType(): JSX.Element[] {
let elems: JSX.Element[] = new Array(); let elems: JSX.Element[] = new Array();
this.itemMap.forEach((data: TreeItem, key: number) => { this.itemMap.forEach((data: TreeItem, key: number) => {
// this.state.portState[key] = false; // this.state.itemState[key] = new Array(data.metaSensorItemList.length).fill(false);
elems.push( elems.push(
<List.Item key={key} > <List.Item key={key + 1} >
<List.Icon name={this.state.categoryState[key] ? 'chevron up' : 'chevron down'} onClick={() => { <List.Icon name={this.state.categoryState[key] ? 'chevron up' : 'chevron down'} onClick={() => {
{/*let newPortState: Map<number, boolean> = new Map(this.state.portState);*/ } {/*let newPortState: Map<number, boolean> = new Map(this.state.portState);*/ }
let newCategoryState: Map<number, boolean> = _.cloneDeep(this.state.categoryState); let newCategoryState: Map<number, boolean> = _.clone(this.state.categoryState);
newCategoryState[key] = !newCategoryState[key]; newCategoryState[key] = !newCategoryState[key];
this.setState({ categoryState: newCategoryState }); this.setState({ categoryState: newCategoryState });
}} /> }} />
<List.Content> <List.Content>
<List.Header> <Checkbox label={data.metaSensorItemType.name} /> </List.Header> <List.Header> <Checkbox label={data.metaSensorItemType.name} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
let newItemState: Map<number, Array<boolean>> = _.clone(this.state.itemState);
if (newItemState[key] === undefined) {
newItemState[key] = new Array(data.metaSensorItemList.length).fill(false);
}
newItemState[key].fill(checkProps.checked);
if (checkProps.checked) {
this.selectedItemMap[key] = _.clone(data.metaSensorItemList);
} else {
this.selectedItemMap[key].length = 0;
}
this.setState({ itemState: newItemState });
}} /> </List.Header>
<List.Description>Category</List.Description> <List.Description>Category</List.Description>
{this.state.categoryState[key] ? this.ViewSensorItem(data.metaSensorItemList, key) : ''} {this.state.categoryState[key] ? this.ViewSensorItem(data.metaSensorItemList, key) : ''}
</List.Content> </List.Content>
@ -97,21 +122,38 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
public ViewSensorItem(metaSensorItemList: MetaSensorItem[], parentKey: number): JSX.Element[] { public ViewSensorItem(metaSensorItemList: MetaSensorItem[], parentKey: number): JSX.Element[] {
let elems: JSX.Element[] = new Array(); let elems: JSX.Element[] = new Array();
if (this.state.itemState[parentKey] === undefined) {
this.state.itemState[parentKey] = new Array(metaSensorItemList.length).fill(false);
}
metaSensorItemList.map((item: MetaSensorItem, idx: number) => { metaSensorItemList.map((item: MetaSensorItem, idx: number) => {
let checkList: boolean[] = this.state.itemState[parentKey];
elems.push( elems.push(
<List.List key={String(parentKey) + String(idx)} onClick={() => { <List.List key={String(parentKey) + String(idx)} onClick={() => {
{/*let newPortState: Map<number, boolean> = new Map(this.state.portState);*/ } {/*let newPortState: Map<number, boolean> = new Map(this.state.portState);*/ }
let newItemState: Map<number, boolean[]> = _.cloneDeep(this.state.itemState[parentKey]); let newItemState: Map<number, Array<boolean>> = _.clone(this.state.itemState);
newItemState[idx] = !newItemState[idx]; newItemState[parentKey][idx] = !newItemState[parentKey][idx];
this.setState({ itemState: newItemState }); this.setState({ itemState: newItemState });
}}> }}>
<List.Item > <List.Item >
<List.Icon name='file' /> <List.Icon name='file' />
<List.Content> <List.Content>
<List.Header> <Checkbox label={item.name} checked={checkList[idx]} /></List.Header> <List.Header> <Checkbox label={item.name} checked={this.state.itemState[parentKey][idx]} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
if(this.selectedItemMap[parentKey] === undefined) {
this.selectedItemMap[parentKey] = [];
}
if (checkProps.checked) {
this.selectedItemMap[parentKey].push(item);
} else {
let index: number = this.selectedItemMap[parentKey].indexOf(item);
if(index >= 0) {
this.selectedItemMap[parentKey].splice(index, 1);
}
}
}} /></List.Header>
<List.Description>Sensor Item</List.Description> <List.Description>Sensor Item</List.Description>
</List.Content> </List.Content>
</List.Item> </List.Item>
@ -128,6 +170,9 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
<List selection> <List selection>
{this.ViewSensorItemType()} {this.ViewSensorItemType()}
</List> </List>
<Button label='test' onClick={() => {
console.log(this.selectedItemMap);
}} />
</Container> </Container>
); );
} }

View File

@ -4,8 +4,8 @@ import {
Menu, Menu,
Segment, Segment,
MenuItemProps, MenuItemProps,
Header,
Container, Container,
Icon,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
export interface StateProps { export interface StateProps {
@ -19,45 +19,84 @@ export interface DispatchProps {
export type Props = StateProps & DispatchProps; export type Props = StateProps & DispatchProps;
export interface State { export interface State {
activeItem: string[]; activeItem: string;
} }
const osNames = ['Windows', 'Debian', 'Ubuntu', 'Fedora', 'CentOS']; const osNames = [
{
'name': 'Windows',
'icon': 'windows',
},
{
'name': 'Ubuntu',
'icon': 'linux',
},
{
'name': 'Fedora',
'icon': 'linux',
},
{
'name': 'CentOS',
'icon': 'linux',
},
];
export class ProbeDown extends React.Component<any, any> { export class ProbeDown extends React.Component<any, any> {
constructor(props: Props, context: State) { constructor(props: Props, context: State) {
super(props, context); super(props, context);
this.state = {
this.state = { activeItem: osNames[0] }; activeItem: '',
};
} }
public handleItemClick = (event: React.SyntheticEvent<HTMLAnchorElement>, data: MenuItemProps): void => { public handleItemClick = (event: React.SyntheticEvent<HTMLAnchorElement>, data: MenuItemProps): void => {
this.setState({ activeItem: data.name }); this.setState({ activeItem: data.name });
}
console.log(data.name); public ShowContent = (): JSX.Element => {
let os = this.state.activeItem;
if(os === '') {
return <div>Instruction page.</div>;
}
switch (os) {
case 'Windows': {
return <Windows />;
}
case 'Ubuntu': {
return <Ubuntu />;
}
case 'Fedora': {
return <Fedora />;
}
case 'CentOS': {
return <CentOS />;
}
default:
break;
}
return null;
} }
public render(): JSX.Element { public render(): JSX.Element {
const { activeItem } = this.state.activeItem;
return ( return (
<Container fluid> <Container fluid>
<Header as='h3' dividing>Probe Download</Header>
<Grid> <Grid>
<Grid.Column width={4}> <Grid.Column width={4}>
<Menu fluid vertical tabular> <Menu fluid vertical icon='labeled' pointing>
{osNames.map((os: string) => { {osNames.map((item: any, index: number) => {
return ( return (
<Menu.Item name={os} active={activeItem === os} onClick={this.handleItemClick} /> <Menu.Item key={index} name={item.name} active={this.state.activeItem === item.name} onClick={this.handleItemClick} >
<Icon name={item.icon} />
{item.name}
</Menu.Item>
); );
})} })}
</Menu> </Menu>
</Grid.Column> </Grid.Column>
<Grid.Column stretched width={12}> <Grid.Column stretched width={12}>
<Segment vertical> <Segment>
{this.state.activeItem} Download Page {this.ShowContent()}
</Segment> </Segment>
</Grid.Column> </Grid.Column>
</Grid> </Grid>
@ -66,3 +105,58 @@ export class ProbeDown extends React.Component<any, any> {
} }
} }
export class Windows extends React.Component<any, any> {
constructor(props: Props, context: State) {
super(props, context);
}
public render(): JSX.Element {
return (
<div>
Windows Download Page
</div>
);
}
}
export class Ubuntu extends React.Component<any, any> {
constructor(props: Props, context: State) {
super(props, context);
}
public render(): JSX.Element {
return (
<Container fluid>
Ubuntu Download Page
</Container>
);
}
}
export class Fedora extends React.Component<any, any> {
constructor(props: Props, context: State) {
super(props, context);
}
public render(): JSX.Element {
return (
<Container fluid>
Fedora Download Page
</Container>
);
}
}
export class CentOS extends React.Component<any, any> {
constructor(props: Props, context: State) {
super(props, context);
}
public render(): JSX.Element {
return (
<Container fluid>
CentOS Download Page
</Container>
);
}
}

View File

@ -1,4 +1,6 @@
import { connect, Dispatch } from 'react-redux'; import { connect, Dispatch } from 'react-redux';
import { push as routerPush } from 'react-router-redux';
import { import {
SensorList, SensorList,
StateProps as SensorListStateProps, StateProps as SensorListStateProps,
@ -6,6 +8,7 @@ import {
} from './components/SensorList'; } from './components/SensorList';
import State from '../redux/state/ReadAllByTarget'; import State from '../redux/state/ReadAllByTarget';
import * as ReadAllByTargetActions from '../redux/action/read_all_by_target'; import * as ReadAllByTargetActions from '../redux/action/read_all_by_target';
import * as ReadAllByProbeActions from '../redux/action/read_all_by_probe'; import * as ReadAllByProbeActions from '../redux/action/read_all_by_probe';
import * as ReadAllByDomainActions from '../redux/action/read_all_by_domain'; import * as ReadAllByDomainActions from '../redux/action/read_all_by_domain';
@ -30,6 +33,9 @@ export function mapDispatchToProps(dispatch: Dispatch<any>): SensorListDispatchP
onReadAllByDomain: (domain: Domain) => { onReadAllByDomain: (domain: Domain) => {
dispatch(ReadAllByDomainActions.request(domain)); dispatch(ReadAllByDomainActions.request(domain));
}, },
onSensorSelect: (id: number) => {
dispatch(routerPush('/sensor/' + String(id)));
},
}; };
} }

View File

@ -16,12 +16,12 @@ export interface DispatchProps {
onReadAllByTarget?(target: Target): void; onReadAllByTarget?(target: Target): void;
onReadAllByProbe?(probe: Probe): void; onReadAllByProbe?(probe: Probe): void;
onReadAllByDomain?(domain: Domain): void; onReadAllByDomain?(domain: Domain): void;
onSensorSelect?(id: number): void;
} }
export type SensorListProps = StateProps & DispatchProps; export type SensorListProps = StateProps & DispatchProps;
export interface SensorListState { export interface SensorListState {
isDetail: boolean;
selected: Sensor; selected: Sensor;
} }
@ -34,7 +34,6 @@ export class SensorList extends React.Component<SensorListProps, SensorListState
super(props, context); super(props, context);
this.state = { this.state = {
selected: null, selected: null,
isDetail: false, // temp
}; };
} }
@ -92,8 +91,9 @@ export class SensorList extends React.Component<SensorListProps, SensorListState
public handleSelect(selectedSensor: Sensor): void { public handleSelect(selectedSensor: Sensor): void {
this.setState({ this.setState({
selected: selectedSensor, selected: selectedSensor,
isDetail: true,
}); });
this.props.onSensorSelect(selectedSensor.id);
} }
public checkCellStatus(status: any): boolean { public checkCellStatus(status: any): boolean {
@ -119,10 +119,6 @@ export class SensorList extends React.Component<SensorListProps, SensorListState
} }
public render(): JSX.Element { public render(): JSX.Element {
if (this.state.isDetail) {
// return (<SensorDetailContainer sensor={this.state.selected} />);
return (<SensorDetailContainer />);
}
return ( return (
<Container fluid> <Container fluid>
<Header as='h3' dividing>Sensors</Header> <Header as='h3' dividing>Sensors</Header>