diff --git a/src/ts/@overflow/meta/react/components/SensorItemTree.tsx b/src/ts/@overflow/meta/react/components/SensorItemTree.tsx index 2ef7bae..22ececd 100644 --- a/src/ts/@overflow/meta/react/components/SensorItemTree.tsx +++ b/src/ts/@overflow/meta/react/components/SensorItemTree.tsx @@ -65,22 +65,9 @@ export class SensorItemTree extends React.Component { - let sensorItem: MetaSensorItem = data; - if (this.itemMap.has(sensorItem.metaSensorItemType.id)) { - this.itemMap.get(sensorItem.metaSensorItemType.id).metaSensorItemList.push(sensorItem); - } else { - let item: TreeItem = { metaSensorItemList: null, metaSensorItemType: null }; - item.metaSensorItemList = []; - item.metaSensorItemList.push(sensorItem); - item.metaSensorItemType = this.GetMetaSensorItemType(sensorItem.metaSensorItemType.id); - this.itemMap.set(sensorItem.metaSensorItemType.id, item); - } - }); - } + public ViewSensorItemType(): JSX.Element[] { let elems: JSX.Element[] = new Array(); @@ -89,28 +76,12 @@ export class SensorItemTree extends React.Component - { - let newCategoryState: Map = _.clone(this.state.categoryState); - newCategoryState[key] = !newCategoryState[key]; - this.setState({ categoryState: newCategoryState }); - - }} /> + , checkProps: CheckboxProps) => { - - this.state.categoryCheckState[key] = checkProps.checked; - let newItemState: Map> = _.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 }); + this.onTypeCheckCBox(key, checkProps, data); }} /> Category {this.state.categoryState[key] ? this.ViewSensorItem(data.metaSensorItemList, key) : ''} @@ -122,6 +93,8 @@ export class SensorItemTree extends React.Component { elems.push( - { - - {/*let newPortState: Map = new Map(this.state.portState);*/ } - let newItemState: Map> = _.clone(this.state.itemState); - newItemState[parentKey][idx] = !newItemState[parentKey][idx]; - this.setState({ itemState: newItemState }); - - }}> + , 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); - } - if (this.selectedItemMap[parentKey].length <= 0) { - let newCheckState: Map = _.clone(this.state.categoryCheckState); - newCheckState[parentKey] = false; - this.setState({ categoryCheckState: newCheckState }); - } - } + this.onItemCheckCBox(parentKey, checkProps, item); }} /> Sensor Item @@ -184,6 +135,69 @@ export class SensorItemTree extends React.Component { + let sensorItem: MetaSensorItem = data; + + if (this.itemMap.has(sensorItem.metaSensorItemType.id)) { + this.itemMap.get(sensorItem.metaSensorItemType.id).metaSensorItemList.push(sensorItem); + } else { + let item: TreeItem = { metaSensorItemList: null, metaSensorItemType: null }; + item.metaSensorItemList = []; + item.metaSensorItemList.push(sensorItem); + item.metaSensorItemType = this.GetMetaSensorItemType(sensorItem.metaSensorItemType.id); + this.itemMap.set(sensorItem.metaSensorItemType.id, item); + } + }); + } + + private onItemClick = (parentKey: number, idx: number) => { + let newItemState: Map> = _.clone(this.state.itemState); + newItemState[parentKey][idx] = !newItemState[parentKey][idx]; + this.setState({ itemState: newItemState }); + } + + private onItemCheckCBox = (parentKey: number, checkProps: CheckboxProps, item: MetaSensorItem) => { + 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); + } + if (this.selectedItemMap[parentKey].length <= 0) { + let newCheckState: Map = _.clone(this.state.categoryCheckState); + newCheckState[parentKey] = false; + this.setState({ categoryCheckState: newCheckState }); + } + } + } + + private onTypeClick = (key: number) => { + let newCategoryState: Map = _.clone(this.state.categoryState); + newCategoryState[key] = !newCategoryState[key]; + this.setState({ categoryState: newCategoryState }); + } + + private onTypeCheckCBox = (key: number, checkProps: CheckboxProps, data: TreeItem) => { + this.state.categoryCheckState[key] = checkProps.checked; + let newItemState: Map> = _.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 }); + } + private checkUnCheckParent(metaSensorItemList: Array): boolean { if (metaSensorItemList.length <= 0) { return true;