Merge branch 'develop'
commit
4808bbad27
|
@ -27,6 +27,7 @@ import { getCookieValue, createCookie } from '../../../helpers/utils';
|
||||||
import withRedirect from '../../../hoc/withRedirect';
|
import withRedirect from '../../../hoc/withRedirect';
|
||||||
import { withTranslation } from 'react-i18next';
|
import { withTranslation } from 'react-i18next';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
import ButtonIcon from '../../common/ButtonIcon';
|
||||||
import { APIBaseURL } from '../../../config';
|
import { APIBaseURL } from '../../../config';
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,6 +57,8 @@ const EquipmentTracking = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
const [cascaderOptions, setCascaderOptions] = useState(undefined);
|
const [cascaderOptions, setCascaderOptions] = useState(undefined);
|
||||||
const [equipmentList, setEquipmentList] = useState([]);
|
const [equipmentList, setEquipmentList] = useState([]);
|
||||||
const [spinnerHidden, setSpinnerHidden] = useState(false);
|
const [spinnerHidden, setSpinnerHidden] = useState(false);
|
||||||
|
const [exportButtonHidden, setExportButtonHidden] = useState(true);
|
||||||
|
const [excelBytesBase64, setExcelBytesBase64] = useState(undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let isResponseOK = false;
|
let isResponseOK = false;
|
||||||
|
@ -114,7 +117,10 @@ const EquipmentTracking = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
'description': currentValue['description']});
|
'description': currentValue['description']});
|
||||||
});
|
});
|
||||||
setEquipmentList(equipments);
|
setEquipmentList(equipments);
|
||||||
|
// hide spinner
|
||||||
setSpinnerHidden(true);
|
setSpinnerHidden(true);
|
||||||
|
// show export buttion
|
||||||
|
setExportButtonHidden(false);
|
||||||
} else {
|
} else {
|
||||||
toast.error(json.description)
|
toast.error(json.description)
|
||||||
}
|
}
|
||||||
|
@ -204,7 +210,10 @@ const EquipmentTracking = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
let onSpaceCascaderChange = (value, selectedOptions) => {
|
let onSpaceCascaderChange = (value, selectedOptions) => {
|
||||||
setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
|
setSelectedSpaceName(selectedOptions.map(o => o.label).join('/'));
|
||||||
let selectedSpaceID = value[value.length - 1];
|
let selectedSpaceID = value[value.length - 1];
|
||||||
|
// show spinner
|
||||||
setSpinnerHidden(false);
|
setSpinnerHidden(false);
|
||||||
|
// hide export buttion
|
||||||
|
setExportButtonHidden(true)
|
||||||
// begin of getting equipment list
|
// begin of getting equipment list
|
||||||
let isResponseOK = false;
|
let isResponseOK = false;
|
||||||
fetch(APIBaseURL + '/reports/equipmenttracking?' +
|
fetch(APIBaseURL + '/reports/equipmenttracking?' +
|
||||||
|
@ -224,10 +233,10 @@ const EquipmentTracking = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
return response.json();
|
return response.json();
|
||||||
}).then(json => {
|
}).then(json => {
|
||||||
if (isResponseOK) {
|
if (isResponseOK) {
|
||||||
json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":'));
|
let json_equipments = JSON.parse(JSON.stringify([json['equipments']]).split('"id":').join('"value":').split('"name":').join('"label":'));
|
||||||
console.log(json)
|
console.log(json)
|
||||||
let equipments = [];
|
let equipments = [];
|
||||||
json[0].forEach((currentValue, index) => {
|
json_equipments[0].forEach((currentValue, index) => {
|
||||||
equipments.push({
|
equipments.push({
|
||||||
'key': index,
|
'key': index,
|
||||||
'id': currentValue['id'],
|
'id': currentValue['id'],
|
||||||
|
@ -237,7 +246,13 @@ const EquipmentTracking = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
'description': currentValue['description']});
|
'description': currentValue['description']});
|
||||||
});
|
});
|
||||||
setEquipmentList(equipments);
|
setEquipmentList(equipments);
|
||||||
|
|
||||||
|
setExcelBytesBase64(json['excel_bytes_base64']);
|
||||||
|
|
||||||
|
// hide spinner
|
||||||
setSpinnerHidden(true);
|
setSpinnerHidden(true);
|
||||||
|
// show export buttion
|
||||||
|
setExportButtonHidden(false);
|
||||||
} else {
|
} else {
|
||||||
toast.error(json.description)
|
toast.error(json.description)
|
||||||
}
|
}
|
||||||
|
@ -247,6 +262,24 @@ const EquipmentTracking = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
// end of getting equipment list
|
// end of getting equipment list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const handleExport = e => {
|
||||||
|
e.preventDefault();
|
||||||
|
const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
|
const fileName = 'equipmenttracking.xlsx'
|
||||||
|
var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64;
|
||||||
|
fetch(fileUrl)
|
||||||
|
.then(response => response.blob())
|
||||||
|
.then(blob => {
|
||||||
|
var link = window.document.createElement("a");
|
||||||
|
link.href = window.URL.createObjectURL(blob, { type: mimeType });
|
||||||
|
link.download = fileName;
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div>
|
<div>
|
||||||
|
@ -277,7 +310,15 @@ const EquipmentTracking = ({ setRedirect, setRedirectUrl, t }) => {
|
||||||
<br></br>
|
<br></br>
|
||||||
<Spinner color="primary" hidden={spinnerHidden} />
|
<Spinner color="primary" hidden={spinnerHidden} />
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
|
<Col xs="auto">
|
||||||
|
<br></br>
|
||||||
|
<ButtonIcon icon="external-link-alt" transform="shrink-3 down-2" color="falcon-default"
|
||||||
|
hidden={exportButtonHidden}
|
||||||
|
onClick={handleExport} >
|
||||||
|
{t('Export')}
|
||||||
|
</ButtonIcon>
|
||||||
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</Form>
|
</Form>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
|
|
Loading…
Reference in New Issue