added AssociatedEquipmentTable to CombinedEquipmentEnergyItem Report in web UI
parent
fca523a616
commit
6ee35da206
|
|
@ -33,6 +33,7 @@ import ButtonIcon from '../../common/ButtonIcon';
|
|||
import { APIBaseURL } from '../../../config';
|
||||
|
||||
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
|
||||
const AssociatedEquipmentTable = loadable(() => import('../common/AssociatedEquipmentTable'));
|
||||
|
||||
const CombinedEquipmentEnergyItem = ({ setRedirect, setRedirectUrl, t }) => {
|
||||
let current_moment = moment();
|
||||
|
|
@ -88,6 +89,10 @@ const CombinedEquipmentEnergyItem = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
|
||||
const [detailedDataTableData, setDetailedDataTableData] = useState([]);
|
||||
const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]);
|
||||
|
||||
const [associatedEquipmentTableData, setAssociatedEquipmentTableData] = useState([]);
|
||||
const [associatedEquipmentTableColumns, setAssociatedEquipmentTableColumns] = useState([{dataField: 'name', text: t('Associated Equipment'), sort: true }]);
|
||||
|
||||
const [excelBytesBase64, setExcelBytesBase64] = useState(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -291,6 +296,7 @@ const CombinedEquipmentEnergyItem = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
|
||||
// Reinitialize tables
|
||||
setDetailedDataTableData([]);
|
||||
setAssociatedEquipmentTableData([]);
|
||||
|
||||
let isResponseOK = false;
|
||||
fetch(APIBaseURL + '/reports/combinedequipmentenergyitem?' +
|
||||
|
|
@ -443,6 +449,38 @@ const CombinedEquipmentEnergyItem = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
});
|
||||
setDetailedDataTableColumns(detailed_column_list);
|
||||
|
||||
let associated_equipment_value_list = [];
|
||||
if (json['associated_equipment']['associated_equipment_names_array'].length > 0) {
|
||||
json['associated_equipment']['associated_equipment_names_array'][0].forEach((currentEquipmentName, equipmentIndex) => {
|
||||
let associated_equipment_value = {};
|
||||
associated_equipment_value['id'] = equipmentIndex;
|
||||
associated_equipment_value['name'] = currentEquipmentName;
|
||||
json['associated_equipment']['energy_item_names'].forEach((currentValue, energyItemIndex) => {
|
||||
associated_equipment_value['a' + energyItemIndex] = json['associated_equipment']['subtotals_array'][energyItemIndex][equipmentIndex].toFixed(2);
|
||||
});
|
||||
associated_equipment_value_list.push(associated_equipment_value);
|
||||
});
|
||||
};
|
||||
|
||||
setAssociatedEquipmentTableData(associated_equipment_value_list);
|
||||
|
||||
let associated_equipment_column_list = [];
|
||||
associated_equipment_column_list.push({
|
||||
dataField: 'name',
|
||||
text: t('Associated Equipment'),
|
||||
sort: true
|
||||
});
|
||||
json['associated_equipment']['energy_item_names'].forEach((currentValue, index) => {
|
||||
let unit = json['associated_equipment']['units'][index];
|
||||
associated_equipment_column_list.push({
|
||||
dataField: 'a' + index,
|
||||
text: currentValue + ' (' + unit + ')',
|
||||
sort: true
|
||||
});
|
||||
});
|
||||
|
||||
setAssociatedEquipmentTableColumns(associated_equipment_column_list);
|
||||
|
||||
setExcelBytesBase64(json['excel_bytes_base64']);
|
||||
|
||||
// enable submit button
|
||||
|
|
@ -662,6 +700,9 @@ const CombinedEquipmentEnergyItem = ({ setRedirect, setRedirectUrl, t }) => {
|
|||
<br />
|
||||
<DetailedDataTable data={detailedDataTableData} title={t('Detailed Data')} columns={detailedDataTableColumns} pagesize={50} >
|
||||
</DetailedDataTable>
|
||||
<br />
|
||||
<AssociatedEquipmentTable data={associatedEquipmentTableData} title={t('Associated Equipment Data')} columns={associatedEquipmentTableColumns}>
|
||||
</AssociatedEquipmentTable>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import React, { Fragment } from 'react';
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import FalconCardHeader from '../../common/FalconCardHeader';
|
||||
import ButtonIcon from '../../common/ButtonIcon';
|
||||
import { Card, CardBody, CardHeader, Row, Col } from 'reactstrap';
|
||||
import { withTranslation } from 'react-i18next';
|
||||
|
||||
|
||||
const defaultSorted = [{
|
||||
dataField: 'name',
|
||||
order: 'asc'
|
||||
}];
|
||||
|
||||
const AssociatedEquipmentTable = ({ title, data, columns, t }) => {
|
||||
return (
|
||||
<Fragment>
|
||||
<Card>
|
||||
<FalconCardHeader title={title} className="bg-light">
|
||||
|
||||
</FalconCardHeader>
|
||||
<CardBody>
|
||||
<Row>
|
||||
<Col>
|
||||
<BootstrapTable
|
||||
bootstrap4
|
||||
keyField="id"
|
||||
data={data}
|
||||
columns={columns}
|
||||
defaultSorted={defaultSorted}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</CardBody>
|
||||
</Card>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
export default withTranslation()(AssociatedEquipmentTable);
|
||||
Loading…
Reference in New Issue