fixed sensorItemTree repack
This commit is contained in:
parent
10b8d42b74
commit
ea6deee6b7
|
@ -65,22 +65,9 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
// fs.readFile('../../../../../dh.json', this.handlJSONFile);
|
||||
}
|
||||
|
||||
public sortItemMap(): void {
|
||||
|
||||
SensorJsonData.map((data: any, idx: number) => {
|
||||
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<SensorItemTreeProps, SensorI
|
|||
// this.state.itemState[key] = new Array(data.metaSensorItemList.length).fill(false);
|
||||
elems.push(
|
||||
<List.Item key={key} >
|
||||
<List.Icon name={this.state.categoryState[key] ? 'chevron up' : 'chevron down'} onClick={() => {
|
||||
let newCategoryState: Map<number, boolean> = _.clone(this.state.categoryState);
|
||||
newCategoryState[key] = !newCategoryState[key];
|
||||
this.setState({ categoryState: newCategoryState });
|
||||
|
||||
}} />
|
||||
<List.Icon name={this.state.categoryState[key] ? 'chevron up' : 'chevron down'}
|
||||
onClick={this.onTypeClick.bind(this, key)} />
|
||||
<List.Content>
|
||||
<List.Header> <Checkbox label={data.metaSensorItemType.name} checked={this.state.categoryCheckState[key]} onChange={
|
||||
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
|
||||
|
||||
this.state.categoryCheckState[key] = checkProps.checked;
|
||||
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 });
|
||||
this.onTypeCheckCBox(key, checkProps, data);
|
||||
}} /> </List.Header>
|
||||
<List.Description>Category</List.Description>
|
||||
{this.state.categoryState[key] ? this.ViewSensorItem(data.metaSensorItemList, key) : ''}
|
||||
|
@ -122,6 +93,8 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
return elems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ViewSensorItem(metaSensorItemList: MetaSensorItem[], parentKey: number): JSX.Element[] {
|
||||
let elems: JSX.Element[] = new Array();
|
||||
|
||||
|
@ -131,35 +104,13 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
|
||||
metaSensorItemList.map((item: MetaSensorItem, idx: number) => {
|
||||
elems.push(
|
||||
<List.List key={String(parentKey) + String(idx)} onClick={() => {
|
||||
|
||||
{/*let newPortState: Map<number, boolean> = new Map(this.state.portState);*/ }
|
||||
let newItemState: Map<number, Array<boolean>> = _.clone(this.state.itemState);
|
||||
newItemState[parentKey][idx] = !newItemState[parentKey][idx];
|
||||
this.setState({ itemState: newItemState });
|
||||
|
||||
}}>
|
||||
<List.List key={String(parentKey) + String(idx)} onClick={this.onItemClick.bind(this, parentKey, idx)}>
|
||||
<List.Item >
|
||||
<List.Icon name='file' />
|
||||
<List.Content>
|
||||
<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);
|
||||
}
|
||||
if (this.selectedItemMap[parentKey].length <= 0) {
|
||||
let newCheckState: Map<number, boolean> = _.clone(this.state.categoryCheckState);
|
||||
newCheckState[parentKey] = false;
|
||||
this.setState({ categoryCheckState: newCheckState });
|
||||
}
|
||||
}
|
||||
this.onItemCheckCBox(parentKey, checkProps, item);
|
||||
}} /></List.Header>
|
||||
<List.Description>Sensor Item</List.Description>
|
||||
</List.Content>
|
||||
|
@ -184,6 +135,69 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
|
|||
);
|
||||
}
|
||||
|
||||
private sortItemMap(): void {
|
||||
|
||||
SensorJsonData.map((data: any, idx: number) => {
|
||||
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<number, Array<boolean>> = _.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<number, boolean> = _.clone(this.state.categoryCheckState);
|
||||
newCheckState[parentKey] = false;
|
||||
this.setState({ categoryCheckState: newCheckState });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private onTypeClick = (key: number) => {
|
||||
let newCategoryState: Map<number, boolean> = _.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<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 });
|
||||
}
|
||||
|
||||
private checkUnCheckParent(metaSensorItemList: Array<MetaSensorItem>): boolean {
|
||||
if (metaSensorItemList.length <= 0) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user