From 3a5f5c5cfec5dc089b960fd7cac014f7fac077ee Mon Sep 17 00:00:00 2001 From: llis <2227043858@qq.com> Date: Mon, 19 Feb 2024 20:06:02 +0800 Subject: [PATCH 1/2] Fixed the warning message in the CombinedEquipmentCost.js file --- .../CombinedEquipmentCost.js | 1291 ++++++++++------- 1 file changed, 729 insertions(+), 562 deletions(-) diff --git a/myems-web/src/components/MyEMS/CombinedEquipment/CombinedEquipmentCost.js b/myems-web/src/components/MyEMS/CombinedEquipment/CombinedEquipmentCost.js index d8840c9f02..b859428168 100644 --- a/myems-web/src/components/MyEMS/CombinedEquipment/CombinedEquipmentCost.js +++ b/myems-web/src/components/MyEMS/CombinedEquipment/CombinedEquipmentCost.js @@ -31,7 +31,7 @@ import { APIBaseURL, settings } from '../../../config'; import { periodTypeOptions } from '../common/PeriodTypeOptions'; import { comparisonTypeOptions } from '../common/ComparisonTypeOptions'; import DateRangePickerWrapper from '../common/DateRangePickerWrapper'; -import { endOfDay} from 'date-fns'; +import { endOfDay } from 'date-fns'; import AppContext from '../../../context/Context'; import MultipleLineChart from '../common/MultipleLineChart'; @@ -46,7 +46,7 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { let user_display_name = getCookieValue('user_display_name'); let user_uuid = getCookieValue('user_uuid'); let token = getCookieValue('token'); - if (checkEmpty(is_logged_in) || checkEmpty(token)|| checkEmpty(user_uuid) || !is_logged_in) { + if (checkEmpty(is_logged_in) || checkEmpty(token) || checkEmpty(user_uuid) || !is_logged_in) { setRedirectUrl(`/authentication/basic/login`); setRedirect(true); } else { @@ -79,9 +79,25 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { const [comparisonType, setComparisonType] = useState('month-on-month'); const [periodType, setPeriodType] = useState('daily'); const [cascaderOptions, setCascaderOptions] = useState(undefined); - const [basePeriodDateRange, setBasePeriodDateRange] = useState([current_moment.clone().subtract(1, 'months').startOf('month').toDate(), current_moment.clone().subtract(1, 'months').toDate()]); + const [basePeriodDateRange, setBasePeriodDateRange] = useState([ + current_moment + .clone() + .subtract(1, 'months') + .startOf('month') + .toDate(), + current_moment + .clone() + .subtract(1, 'months') + .toDate() + ]); const [basePeriodDateRangePickerDisabled, setBasePeriodDateRangePickerDisabled] = useState(true); - const [reportingPeriodDateRange, setReportingPeriodDateRange] = useState([current_moment.clone().startOf('month').toDate(), current_moment.toDate()]); + const [reportingPeriodDateRange, setReportingPeriodDateRange] = useState([ + current_moment + .clone() + .startOf('month') + .toDate(), + current_moment.toDate() + ]); const dateRangePickerLocale = { sunday: t('sunday'), monday: t('monday'), @@ -99,7 +115,7 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { last7Days: t('last7Days'), formattedMonthPattern: 'yyyy-MM-dd' }; - const dateRangePickerStyle = { display: 'block', zIndex: 10}; + const dateRangePickerStyle = { display: 'block', zIndex: 10 }; const { language } = useContext(AppContext); // buttons @@ -113,18 +129,22 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { const [cardSummaryList, setCardSummaryList] = useState([]); - const [combinedEquipmentBaseAndReportingNames, setCombinedEquipmentBaseAndReportingNames] = useState({"a0":""}); - const [combinedEquipmentBaseAndReportingUnits, setCombinedEquipmentBaseAndReportingUnits] = useState({"a0":"()"}); + const [combinedEquipmentBaseAndReportingNames, setCombinedEquipmentBaseAndReportingNames] = useState({ a0: '' }); + const [combinedEquipmentBaseAndReportingUnits, setCombinedEquipmentBaseAndReportingUnits] = useState({ a0: '()' }); - const [combinedEquipmentBaseLabels, setCombinedEquipmentBaseLabels] = useState({"a0": []}); - const [combinedEquipmentBaseData, setCombinedEquipmentBaseData] = useState({"a0": []}); - const [combinedEquipmentBaseSubtotals, setCombinedEquipmentBaseSubtotals] = useState({"a0": (0).toFixed(2)}); + const [combinedEquipmentBaseLabels, setCombinedEquipmentBaseLabels] = useState({ a0: [] }); + const [combinedEquipmentBaseData, setCombinedEquipmentBaseData] = useState({ a0: [] }); + const [combinedEquipmentBaseSubtotals, setCombinedEquipmentBaseSubtotals] = useState({ + a0: (0).toFixed(2) + }); - const [combinedEquipmentReportingLabels, setCombinedEquipmentReportingLabels] = useState({"a0": []}); - const [combinedEquipmentReportingData, setCombinedEquipmentReportingData] = useState({"a0": []}); - const [combinedEquipmentReportingSubtotals, setCombinedEquipmentReportingSubtotals] = useState({"a0": (0).toFixed(2)}); + const [combinedEquipmentReportingLabels, setCombinedEquipmentReportingLabels] = useState({ a0: [] }); + const [combinedEquipmentReportingData, setCombinedEquipmentReportingData] = useState({ a0: [] }); + const [combinedEquipmentReportingSubtotals, setCombinedEquipmentReportingSubtotals] = useState({ + a0: (0).toFixed(2) + }); - const [combinedEquipmentReportingRates, setCombinedEquipmentReportingRates] = useState({"a0": []}); + const [combinedEquipmentReportingRates, setCombinedEquipmentReportingRates] = useState({ a0: [] }); const [combinedEquipmentReportingOptions, setCombinedEquipmentReportingOptions] = useState([]); const [parameterLineChartLabels, setParameterLineChartLabels] = useState([]); @@ -132,89 +152,102 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { const [parameterLineChartOptions, setParameterLineChartOptions] = useState([]); const [detailedDataTableData, setDetailedDataTableData] = useState([]); - const [detailedDataTableColumns, setDetailedDataTableColumns] = useState([{dataField: 'startdatetime', text: t('Datetime'), sort: true}]); + 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 [associatedEquipmentTableColumns, setAssociatedEquipmentTableColumns] = useState([ + { dataField: 'name', text: t('Associated Equipment'), sort: true } + ]); const [excelBytesBase64, setExcelBytesBase64] = useState(undefined); useEffect(() => { let isResponseOK = false; - fetch( - APIBaseURL + - '/spaces/tree', { + fetch(APIBaseURL + '/spaces/tree', { method: 'GET', headers: { 'Content-type': 'application/json', 'User-UUID': getCookieValue('user_uuid'), Token: getCookieValue('token') }, - body: null, - - }).then(response => { - console.log(response); - if (response.ok) { - isResponseOK = true; - } - return response.json(); - }).then(json => { - console.log(json); - if (isResponseOK) { - // rename keys - json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); - setCascaderOptions(json); - setSelectedSpaceName([json[0]].map(o => o.label)); - setSelectedSpaceID([json[0]].map(o => o.value)); - // get Combined Equipments by root Space ID - let isResponseOK = false; - fetch( - APIBaseURL + - '/spaces/' + - [json[0]].map(o => o.value) + - '/combinedequipments', { - method: 'GET', - headers: { - 'Content-type': 'application/json', - 'User-UUID': getCookieValue('user_uuid'), - Token: getCookieValue('token') - }, - body: null, - - }).then(response => { - if (response.ok) { - isResponseOK = true; - } - return response.json(); - }).then(json => { - if (isResponseOK) { - json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); - console.log(json); - setCombinedEquipmentList(json[0]); - if (json[0].length > 0) { - setSelectedCombinedEquipment(json[0][0].value); - // enable submit button - setSubmitButtonDisabled(false); - } else { - setSelectedCombinedEquipment(undefined); - // disable submit button - setSubmitButtonDisabled(true); - } - } else { - toast.error(t(json.description)) - } - }).catch(err => { - console.log(err); - }); - // end of get Combined Equipments by root Space ID - } else { - toast.error(t(json.description)); - } - }).catch(err => { - console.log(err); - }); - - }, [ ]); + body: null + }) + .then(response => { + console.log(response); + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }) + .then(json => { + console.log(json); + if (isResponseOK) { + // rename keys + json = JSON.parse( + JSON.stringify([json]) + .split('"id":') + .join('"value":') + .split('"name":') + .join('"label":') + ); + setCascaderOptions(json); + setSelectedSpaceName([json[0]].map(o => o.label)); + setSelectedSpaceID([json[0]].map(o => o.value)); + // get Combined Equipments by root Space ID + let isResponseOK = false; + fetch(APIBaseURL + '/spaces/' + [json[0]].map(o => o.value) + '/combinedequipments', { + method: 'GET', + headers: { + 'Content-type': 'application/json', + 'User-UUID': getCookieValue('user_uuid'), + Token: getCookieValue('token') + }, + body: null + }) + .then(response => { + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }) + .then(json => { + if (isResponseOK) { + json = JSON.parse( + JSON.stringify([json]) + .split('"id":') + .join('"value":') + .split('"name":') + .join('"label":') + ); + console.log(json); + setCombinedEquipmentList(json[0]); + if (json[0].length > 0) { + setSelectedCombinedEquipment(json[0][0].value); + // enable submit button + setSubmitButtonDisabled(false); + } else { + setSelectedCombinedEquipment(undefined); + // disable submit button + setSubmitButtonDisabled(true); + } + } else { + toast.error(t(json.description)); + } + }) + .catch(err => { + console.log(err); + }); + // end of get Combined Equipments by root Space ID + } else { + toast.error(t(json.description)); + } + }) + .catch(err => { + console.log(err); + }); + }, [t]); const labelClasses = 'ls text-uppercase text-600 font-weight-semi-bold mb-0'; @@ -223,44 +256,48 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { setSelectedSpaceID(value[value.length - 1]); let isResponseOK = false; - fetch( - APIBaseURL + - '/spaces/' + - value[value.length - 1] + - '/combinedequipments', { + fetch(APIBaseURL + '/spaces/' + value[value.length - 1] + '/combinedequipments', { method: 'GET', headers: { 'Content-type': 'application/json', 'User-UUID': getCookieValue('user_uuid'), Token: getCookieValue('token') }, - body: null, - - }).then(response => { - if (response.ok) { - isResponseOK = true; - } - return response.json(); - }).then(json => { - if (isResponseOK) { - json = JSON.parse(JSON.stringify([json]).split('"id":').join('"value":').split('"name":').join('"label":')); - console.log(json) - setCombinedEquipmentList(json[0]); - if (json[0].length > 0) { - setSelectedCombinedEquipment(json[0][0].value); - // enable submit button - setSubmitButtonDisabled(false); + body: null + }) + .then(response => { + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }) + .then(json => { + if (isResponseOK) { + json = JSON.parse( + JSON.stringify([json]) + .split('"id":') + .join('"value":') + .split('"name":') + .join('"label":') + ); + console.log(json); + setCombinedEquipmentList(json[0]); + if (json[0].length > 0) { + setSelectedCombinedEquipment(json[0][0].value); + // enable submit button + setSubmitButtonDisabled(false); + } else { + setSelectedCombinedEquipment(undefined); + // disable submit button + setSubmitButtonDisabled(true); + } } else { - setSelectedCombinedEquipment(undefined); - // disable submit button - setSubmitButtonDisabled(true); + toast.error(t(json.description)); } - } else { - toast.error(t(json.description)); - } - }).catch(err => { - console.log(err); - }); + }) + .catch(err => { + console.log(err); + }); }; let onComparisonTypeChange = ({ target }) => { @@ -268,16 +305,34 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { setComparisonType(target.value); if (target.value === 'year-over-year') { setBasePeriodDateRangePickerDisabled(true); - setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'years').toDate(), - moment(reportingPeriodDateRange[1]).subtract(1, 'years').toDate()]); + setBasePeriodDateRange([ + moment(reportingPeriodDateRange[0]) + .subtract(1, 'years') + .toDate(), + moment(reportingPeriodDateRange[1]) + .subtract(1, 'years') + .toDate() + ]); } else if (target.value === 'month-on-month') { setBasePeriodDateRangePickerDisabled(true); - setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'months').toDate(), - moment(reportingPeriodDateRange[1]).subtract(1, 'months').toDate()]); + setBasePeriodDateRange([ + moment(reportingPeriodDateRange[0]) + .subtract(1, 'months') + .toDate(), + moment(reportingPeriodDateRange[1]) + .subtract(1, 'months') + .toDate() + ]); } else if (target.value === 'free-comparison') { setBasePeriodDateRangePickerDisabled(false); - setBasePeriodDateRange([moment(reportingPeriodDateRange[0]).subtract(1, 'days').toDate(), - moment(reportingPeriodDateRange[1]).subtract(1, 'days').toDate()]); + setBasePeriodDateRange([ + moment(reportingPeriodDateRange[0]) + .subtract(1, 'days') + .toDate(), + moment(reportingPeriodDateRange[1]) + .subtract(1, 'days') + .toDate() + ]); } else if (target.value === 'none-comparison') { setBasePeriodDateRange([null, null]); setBasePeriodDateRangePickerDisabled(true); @@ -285,11 +340,11 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { }; // Callback fired when value changed - let onBasePeriodChange = (DateRange) => { - if(DateRange == null) { + let onBasePeriodChange = DateRange => { + if (DateRange == null) { setBasePeriodDateRange([null, null]); } else { - if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') { + if (moment(DateRange[1]).format('HH:mm:ss') === '00:00:00') { // if the user did not change time value, set the default time to the end of day DateRange[1] = endOfDay(DateRange[1]); } @@ -298,19 +353,37 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { }; // Callback fired when value changed - let onReportingPeriodChange = (DateRange) => { - if(DateRange == null) { + let onReportingPeriodChange = DateRange => { + if (DateRange == null) { setReportingPeriodDateRange([null, null]); } else { - if (moment(DateRange[1]).format('HH:mm:ss') == '00:00:00') { + if (moment(DateRange[1]).format('HH:mm:ss') === '00:00:00') { // if the user did not change time value, set the default time to the end of day DateRange[1] = endOfDay(DateRange[1]); } setReportingPeriodDateRange([DateRange[0], DateRange[1]]); if (comparisonType === 'year-over-year') { - setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'years').toDate(), moment(DateRange[1]).clone().subtract(1, 'years').toDate()]); + setBasePeriodDateRange([ + moment(DateRange[0]) + .clone() + .subtract(1, 'years') + .toDate(), + moment(DateRange[1]) + .clone() + .subtract(1, 'years') + .toDate() + ]); } else if (comparisonType === 'month-on-month') { - setBasePeriodDateRange([moment(DateRange[0]).clone().subtract(1, 'months').toDate(), moment(DateRange[1]).clone().subtract(1, 'months').toDate()]); + setBasePeriodDateRange([ + moment(DateRange[0]) + .clone() + .subtract(1, 'months') + .toDate(), + moment(DateRange[1]) + .clone() + .subtract(1, 'months') + .toDate() + ]); } } }; @@ -325,7 +398,7 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { setReportingPeriodDateRange([null, null]); }; - const isBasePeriodTimestampExists = (base_period_data) => { + const isBasePeriodTimestampExists = base_period_data => { const timestamps = base_period_data['timestamps']; if (timestamps.length === 0) { @@ -348,9 +421,9 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { console.log(selectedCombinedEquipment); console.log(comparisonType); console.log(periodType); - console.log(basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : null) - console.log(basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : null) - console.log(moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss')) + console.log(basePeriodDateRange[0] != null ? moment(basePeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss') : null); + console.log(basePeriodDateRange[1] != null ? moment(basePeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') : null); + console.log(moment(reportingPeriodDateRange[0]).format('YYYY-MM-DDTHH:mm:ss')); console.log(moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss')); // disable submit button @@ -358,7 +431,7 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { // show spinner setSpinnerHidden(false); // hide export button - setExportButtonHidden(true) + setExportButtonHidden(true); // Reinitialize tables setDetailedDataTableData([]); @@ -381,222 +454,239 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { '&reportingperiodenddatetime=' + moment(reportingPeriodDateRange[1]).format('YYYY-MM-DDTHH:mm:ss') + '&language=' + - language, { - method: 'GET', - headers: { - 'Content-type': 'application/json', - 'User-UUID': getCookieValue('user_uuid'), - Token: getCookieValue('token') - }, - body: null, - - }).then(response => { - if (response.ok) { - isResponseOK = true; - }; - return response.json(); - }).then(json => { - if (isResponseOK) { - console.log(json) - - let cardSummaryList = [] - json['reporting_period']['names'].forEach((currentValue, index) => { - let cardSummaryItem = {} - cardSummaryItem['name'] = json['reporting_period']['names'][index]; - cardSummaryItem['unit'] = json['reporting_period']['units'][index]; - cardSummaryItem['subtotal'] = json['reporting_period']['subtotals'][index]; - cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['increment_rates'][index] * 100).toFixed(2) + "%"; + language, + { + method: 'GET', + headers: { + 'Content-type': 'application/json', + 'User-UUID': getCookieValue('user_uuid'), + Token: getCookieValue('token') + }, + body: null + } + ) + .then(response => { + if (response.ok) { + isResponseOK = true; + } + return response.json(); + }) + .then(json => { + if (isResponseOK) { + console.log(json); + + let cardSummaryList = []; + json['reporting_period']['names'].forEach((currentValue, index) => { + let cardSummaryItem = {}; + cardSummaryItem['name'] = json['reporting_period']['names'][index]; + cardSummaryItem['unit'] = json['reporting_period']['units'][index]; + cardSummaryItem['subtotal'] = json['reporting_period']['subtotals'][index]; + cardSummaryItem['increment_rate'] = + parseFloat(json['reporting_period']['increment_rates'][index] * 100).toFixed(2) + '%'; + cardSummaryList.push(cardSummaryItem); + }); + let cardSummaryItem = {}; + cardSummaryItem['name'] = t('Total'); + cardSummaryItem['unit'] = json['reporting_period']['total_unit']; + cardSummaryItem['subtotal'] = json['reporting_period']['total']; + cardSummaryItem['increment_rate'] = + parseFloat(json['reporting_period']['total_increment_rate'] * 100).toFixed(2) + '%'; cardSummaryList.push(cardSummaryItem); - }); - let cardSummaryItem = {} - cardSummaryItem['name'] = t('Total'); - cardSummaryItem['unit'] = json['reporting_period']['total_unit']; - cardSummaryItem['subtotal'] = json['reporting_period']['total']; - cardSummaryItem['increment_rate'] = parseFloat(json['reporting_period']['total_increment_rate'] * 100).toFixed(2) + "%"; - cardSummaryList.push(cardSummaryItem); - setCardSummaryList(cardSummaryList); - - let timeOfUseArray = []; - json['reporting_period']['energy_category_ids'].forEach((currentValue, index) => { - if(currentValue === 1) { - // energy_category_id 1 electricity - let timeOfUseItem = {} - timeOfUseItem['id'] = 1; - timeOfUseItem['name'] = t('Top-Peak'); - timeOfUseItem['value'] = json['reporting_period']['toppeaks'][index]; - timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); - timeOfUseArray.push(timeOfUseItem); - - timeOfUseItem = {} - timeOfUseItem['id'] = 2; - timeOfUseItem['name'] = t('On-Peak'); - timeOfUseItem['value'] = json['reporting_period']['onpeaks'][index]; - timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); - timeOfUseArray.push(timeOfUseItem); - - timeOfUseItem = {} - timeOfUseItem['id'] = 3; - timeOfUseItem['name'] = t('Mid-Peak'); - timeOfUseItem['value'] = json['reporting_period']['midpeaks'][index]; - timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); - timeOfUseArray.push(timeOfUseItem); - - timeOfUseItem = {} - timeOfUseItem['id'] = 4; - timeOfUseItem['name'] = t('Off-Peak'); - timeOfUseItem['value'] = json['reporting_period']['offpeaks'][index]; - timeOfUseItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); - timeOfUseArray.push(timeOfUseItem); - } - }); - setTimeOfUseShareData(timeOfUseArray); - - let costDataArray = []; - json['reporting_period']['names'].forEach((currentValue, index) => { - let costDataItem = {} - costDataItem['id'] = index; - costDataItem['name'] = currentValue; - costDataItem['value'] = json['reporting_period']['subtotals'][index]; - costDataItem['color'] = "#"+((1<<24)*Math.random()|0).toString(16); - costDataArray.push(costDataItem); - }); - setCostShareData(costDataArray); - - let base_timestamps = {} - json['base_period']['timestamps'].forEach((currentValue, index) => { - base_timestamps['a' + index] = currentValue; - }); - setCombinedEquipmentBaseLabels(base_timestamps) - - let base_values = {} - json['base_period']['values'].forEach((currentValue, index) => { - base_values['a' + index] = currentValue; - }); - setCombinedEquipmentBaseData(base_values) - - /* - * Tip: - * base_names === reporting_names - * base_units === reporting_units - * */ - - let base_and_reporting_names = {} - json['reporting_period']['names'].forEach((currentValue, index) => { - base_and_reporting_names['a' + index] = currentValue; - }); - setCombinedEquipmentBaseAndReportingNames(base_and_reporting_names) - - let base_and_reporting_units = {} - json['reporting_period']['units'].forEach((currentValue, index) => { - base_and_reporting_units['a' + index] = "("+currentValue+")"; - }); - setCombinedEquipmentBaseAndReportingUnits(base_and_reporting_units) - - let base_subtotals = {} - json['base_period']['subtotals'].forEach((currentValue, index) => { - base_subtotals['a' + index] = currentValue.toFixed(2); - }); - setCombinedEquipmentBaseSubtotals(base_subtotals) - - let reporting_timestamps = {} - json['reporting_period']['timestamps'].forEach((currentValue, index) => { - reporting_timestamps['a' + index] = currentValue; - }); - setCombinedEquipmentReportingLabels(reporting_timestamps); - - let reporting_values = {} - json['reporting_period']['values'].forEach((currentValue, index) => { - reporting_values['a' + index] = currentValue; - }); - setCombinedEquipmentReportingData(reporting_values); - - let reporting_subtotals = {} - json['reporting_period']['subtotals'].forEach((currentValue, index) => { - reporting_subtotals['a' + index] = currentValue.toFixed(2); - }); - setCombinedEquipmentReportingSubtotals(reporting_subtotals); - - let rates = {} - json['reporting_period']['rates'].forEach((currentValue, index) => { - let currentRate = Array(); - currentValue.forEach((rate) => { - currentRate.push(rate ? parseFloat(rate * 100).toFixed(2) : '0.00'); + setCardSummaryList(cardSummaryList); + + let timeOfUseArray = []; + json['reporting_period']['energy_category_ids'].forEach((currentValue, index) => { + if (currentValue === 1) { + // energy_category_id 1 electricity + let timeOfUseItem = {}; + timeOfUseItem['id'] = 1; + timeOfUseItem['name'] = t('Top-Peak'); + timeOfUseItem['value'] = json['reporting_period']['toppeaks'][index]; + timeOfUseItem['color'] = '#' + (((1 << 24) * Math.random()) | 0).toString(16); + timeOfUseArray.push(timeOfUseItem); + + timeOfUseItem = {}; + timeOfUseItem['id'] = 2; + timeOfUseItem['name'] = t('On-Peak'); + timeOfUseItem['value'] = json['reporting_period']['onpeaks'][index]; + timeOfUseItem['color'] = '#' + (((1 << 24) * Math.random()) | 0).toString(16); + timeOfUseArray.push(timeOfUseItem); + + timeOfUseItem = {}; + timeOfUseItem['id'] = 3; + timeOfUseItem['name'] = t('Mid-Peak'); + timeOfUseItem['value'] = json['reporting_period']['midpeaks'][index]; + timeOfUseItem['color'] = '#' + (((1 << 24) * Math.random()) | 0).toString(16); + timeOfUseArray.push(timeOfUseItem); + + timeOfUseItem = {}; + timeOfUseItem['id'] = 4; + timeOfUseItem['name'] = t('Off-Peak'); + timeOfUseItem['value'] = json['reporting_period']['offpeaks'][index]; + timeOfUseItem['color'] = '#' + (((1 << 24) * Math.random()) | 0).toString(16); + timeOfUseArray.push(timeOfUseItem); + } }); - rates['a' + index] = currentRate; - }); - setCombinedEquipmentReportingRates(rates) - - let options = Array(); - json['reporting_period']['names'].forEach((currentValue, index) => { - let unit = json['reporting_period']['units'][index]; - options.push({ 'value': 'a' + index, 'label': currentValue + ' (' + unit + ')'}); - }); - setCombinedEquipmentReportingOptions(options); - - let timestamps = {} - json['parameters']['timestamps'].forEach((currentValue, index) => { - timestamps['a' + index] = currentValue; - }); - setParameterLineChartLabels(timestamps); - - let values = {} - json['parameters']['values'].forEach((currentValue, index) => { - values['a' + index] = currentValue; - }); - setParameterLineChartData(values); - - let names = Array(); - json['parameters']['names'].forEach((currentValue, index) => { - - names.push({ 'value': 'a' + index, 'label': currentValue }); - }); - setParameterLineChartOptions(names); - - if(!isBasePeriodTimestampExists(json['base_period'])) { - let detailed_value_list = []; - if (json['reporting_period']['timestamps'].length > 0) { - json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => { - let detailed_value = {}; - detailed_value['id'] = timestampIndex; - detailed_value['startdatetime'] = currentTimestamp; - let total_current_timstamp = 0.0; - json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { - detailed_value['a' + energyCategoryIndex] = json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; - total_current_timstamp += json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; - }); - detailed_value['total'] = total_current_timstamp; - detailed_value_list.push(detailed_value); - }); - } - ; + setTimeOfUseShareData(timeOfUseArray); + + let costDataArray = []; + json['reporting_period']['names'].forEach((currentValue, index) => { + let costDataItem = {}; + costDataItem['id'] = index; + costDataItem['name'] = currentValue; + costDataItem['value'] = json['reporting_period']['subtotals'][index]; + costDataItem['color'] = '#' + (((1 << 24) * Math.random()) | 0).toString(16); + costDataArray.push(costDataItem); + }); + setCostShareData(costDataArray); + + let base_timestamps = {}; + json['base_period']['timestamps'].forEach((currentValue, index) => { + base_timestamps['a' + index] = currentValue; + }); + setCombinedEquipmentBaseLabels(base_timestamps); - let detailed_value = {}; - detailed_value['id'] = detailed_value_list.length; - detailed_value['startdatetime'] = t('Subtotal'); - let total_of_subtotals = 0.0; + let base_values = {}; + json['base_period']['values'].forEach((currentValue, index) => { + base_values['a' + index] = currentValue; + }); + setCombinedEquipmentBaseData(base_values); + + /* + * Tip: + * base_names === reporting_names + * base_units === reporting_units + * */ + + let base_and_reporting_names = {}; + json['reporting_period']['names'].forEach((currentValue, index) => { + base_and_reporting_names['a' + index] = currentValue; + }); + setCombinedEquipmentBaseAndReportingNames(base_and_reporting_names); + + let base_and_reporting_units = {}; + json['reporting_period']['units'].forEach((currentValue, index) => { + base_and_reporting_units['a' + index] = '(' + currentValue + ')'; + }); + setCombinedEquipmentBaseAndReportingUnits(base_and_reporting_units); + + let base_subtotals = {}; + json['base_period']['subtotals'].forEach((currentValue, index) => { + base_subtotals['a' + index] = currentValue.toFixed(2); + }); + setCombinedEquipmentBaseSubtotals(base_subtotals); + + let reporting_timestamps = {}; + json['reporting_period']['timestamps'].forEach((currentValue, index) => { + reporting_timestamps['a' + index] = currentValue; + }); + setCombinedEquipmentReportingLabels(reporting_timestamps); + + let reporting_values = {}; + json['reporting_period']['values'].forEach((currentValue, index) => { + reporting_values['a' + index] = currentValue; + }); + setCombinedEquipmentReportingData(reporting_values); + + let reporting_subtotals = {}; json['reporting_period']['subtotals'].forEach((currentValue, index) => { - detailed_value['a' + index] = currentValue; - total_of_subtotals += currentValue + reporting_subtotals['a' + index] = currentValue.toFixed(2); }); - detailed_value['total'] = total_of_subtotals; - detailed_value_list.push(detailed_value); - setTimeout(() => { - setDetailedDataTableData(detailed_value_list); - }, 0) - - let detailed_column_list = []; - detailed_column_list.push({ - dataField: 'startdatetime', - text: t('Datetime'), - sort: true + setCombinedEquipmentReportingSubtotals(reporting_subtotals); + + let rates = {}; + json['reporting_period']['rates'].forEach((currentValue, index) => { + let currentRate = []; + currentValue.forEach(rate => { + currentRate.push(rate ? parseFloat(rate * 100).toFixed(2) : '0.00'); + }); + rates['a' + index] = currentRate; }); + setCombinedEquipmentReportingRates(rates); + + let options = []; json['reporting_period']['names'].forEach((currentValue, index) => { let unit = json['reporting_period']['units'][index]; + options.push({ value: 'a' + index, label: currentValue + ' (' + unit + ')' }); + }); + setCombinedEquipmentReportingOptions(options); + + let timestamps = {}; + json['parameters']['timestamps'].forEach((currentValue, index) => { + timestamps['a' + index] = currentValue; + }); + setParameterLineChartLabels(timestamps); + + let values = {}; + json['parameters']['values'].forEach((currentValue, index) => { + values['a' + index] = currentValue; + }); + setParameterLineChartData(values); + + let names = []; + json['parameters']['names'].forEach((currentValue, index) => { + names.push({ value: 'a' + index, label: currentValue }); + }); + setParameterLineChartOptions(names); + + if (!isBasePeriodTimestampExists(json['base_period'])) { + let detailed_value_list = []; + if (json['reporting_period']['timestamps'].length > 0) { + json['reporting_period']['timestamps'][0].forEach((currentTimestamp, timestampIndex) => { + let detailed_value = {}; + detailed_value['id'] = timestampIndex; + detailed_value['startdatetime'] = currentTimestamp; + let total_current_timstamp = 0.0; + json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { + detailed_value['a' + energyCategoryIndex] = + json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; + total_current_timstamp += json['reporting_period']['values'][energyCategoryIndex][timestampIndex]; + }); + detailed_value['total'] = total_current_timstamp; + detailed_value_list.push(detailed_value); + }); + } + + let detailed_value = {}; + detailed_value['id'] = detailed_value_list.length; + detailed_value['startdatetime'] = t('Subtotal'); + let total_of_subtotals = 0.0; + json['reporting_period']['subtotals'].forEach((currentValue, index) => { + detailed_value['a' + index] = currentValue; + total_of_subtotals += currentValue; + }); + detailed_value['total'] = total_of_subtotals; + detailed_value_list.push(detailed_value); + setTimeout(() => { + setDetailedDataTableData(detailed_value_list); + }, 0); + + let detailed_column_list = []; detailed_column_list.push({ - dataField: 'a' + index, - text: currentValue + ' (' + unit + ')', + dataField: 'startdatetime', + text: t('Datetime'), + sort: true + }); + json['reporting_period']['names'].forEach((currentValue, index) => { + let unit = json['reporting_period']['units'][index]; + detailed_column_list.push({ + dataField: 'a' + index, + text: currentValue + ' (' + unit + ')', + sort: true, + formatter: function(decimalValue) { + if (typeof decimalValue === 'number') { + return decimalValue.toFixed(2); + } else { + return null; + } + } + }); + }); + detailed_column_list.push({ + dataField: 'total', + text: t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', sort: true, - formatter: function (decimalValue) { + formatter: function(decimalValue) { if (typeof decimalValue === 'number') { return decimalValue.toFixed(2); } else { @@ -604,186 +694,203 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { } } }); - }); - detailed_column_list.push({ - dataField: 'total', - text: t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', - sort: true, - formatter: function (decimalValue) { - if (typeof decimalValue === 'number') { - return decimalValue.toFixed(2); - } else { - return null; - } - } - }); - setDetailedDataTableColumns(detailed_column_list); - }else { - /* - * Tip: - * json['base_period']['names'] === json['reporting_period']['names'] - * json['base_period']['units'] === json['reporting_period']['units'] - * */ - let detailed_column_list = []; - detailed_column_list.push({ - dataField: 'basePeriodDatetime', - text: t('Base Period') + ' - ' + t('Datetime'), - sort: true - }) + setDetailedDataTableColumns(detailed_column_list); + } else { + /* + * Tip: + * json['base_period']['names'] === json['reporting_period']['names'] + * json['base_period']['units'] === json['reporting_period']['units'] + * */ + let detailed_column_list = []; + detailed_column_list.push({ + dataField: 'basePeriodDatetime', + text: t('Base Period') + ' - ' + t('Datetime'), + sort: true + }); + + json['base_period']['names'].forEach((currentValue, index) => { + let unit = json['base_period']['units'][index]; + detailed_column_list.push({ + dataField: 'a' + index, + text: t('Base Period') + ' - ' + currentValue + ' (' + unit + ')', + sort: true, + formatter: function(decimalValue) { + if (typeof decimalValue === 'number') { + return decimalValue.toFixed(2); + } else { + return null; + } + } + }); + }); - json['base_period']['names'].forEach((currentValue, index) => { - let unit = json['base_period']['units'][index]; detailed_column_list.push({ - dataField: 'a' + index, - text: t('Base Period') + ' - ' + currentValue + ' (' + unit + ')', + dataField: 'basePeriodTotal', + text: t('Base Period') + ' - ' + t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', sort: true, - formatter: function (decimalValue) { + formatter: function(decimalValue) { if (typeof decimalValue === 'number') { return decimalValue.toFixed(2); } else { return null; } } - }) - }); + }); - detailed_column_list.push({ - dataField: 'basePeriodTotal', - text: t('Base Period') + ' - ' + t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', - sort: true, - formatter: function (decimalValue) { - if (typeof decimalValue === 'number') { - return decimalValue.toFixed(2); - } else { - return null; - } - } - }) + detailed_column_list.push({ + dataField: 'reportingPeriodDatetime', + text: t('Reporting Period') + ' - ' + t('Datetime'), + sort: true + }); - detailed_column_list.push({ - dataField: 'reportingPeriodDatetime', - text: t('Reporting Period') + ' - ' + t('Datetime'), - sort: true - }) + json['reporting_period']['names'].forEach((currentValue, index) => { + let unit = json['reporting_period']['units'][index]; + detailed_column_list.push({ + dataField: 'b' + index, + text: t('Reporting Period') + ' - ' + currentValue + ' (' + unit + ')', + sort: true, + formatter: function(decimalValue) { + if (typeof decimalValue === 'number') { + return decimalValue.toFixed(2); + } else { + return null; + } + } + }); + }); - json['reporting_period']['names'].forEach((currentValue, index) => { - let unit = json['reporting_period']['units'][index]; detailed_column_list.push({ - dataField: 'b' + index, - text: t('Reporting Period') + ' - ' + currentValue + ' (' + unit + ')', + dataField: 'reportingPeriodTotal', + text: t('Reporting Period') + ' - ' + t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', sort: true, - formatter: function (decimalValue) { + formatter: function(decimalValue) { if (typeof decimalValue === 'number') { return decimalValue.toFixed(2); } else { return null; } } - }) - }); + }); - detailed_column_list.push({ - dataField: 'reportingPeriodTotal', - text: t('Reporting Period') + ' - ' + t('Total') + ' (' + json['reporting_period']['total_unit'] + ')', - sort: true, - formatter: function (decimalValue) { - if (typeof decimalValue === 'number') { - return decimalValue.toFixed(2); - } else { - return null; + setDetailedDataTableColumns(detailed_column_list); + + let detailed_value_list = []; + if (json['base_period']['timestamps'].length > 0 || json['reporting_period']['timestamps'].length > 0) { + const max_timestamps_length = + json['base_period']['timestamps'][0].length >= json['reporting_period']['timestamps'][0].length + ? json['base_period']['timestamps'][0].length + : json['reporting_period']['timestamps'][0].length; + for (let index = 0; index < max_timestamps_length; index++) { + let detailed_value = {}; + detailed_value['id'] = index; + detailed_value['basePeriodDatetime'] = + index < json['base_period']['timestamps'][0].length + ? json['base_period']['timestamps'][0][index] + : null; + detailed_value['basePeriodTotal'] = 0.0; + if (detailed_value['basePeriodDatetime'] == null) { + detailed_value['basePeriodTotal'] = null; + } + json['base_period']['values'].forEach((currentValue, energyCategoryIndex) => { + detailed_value['a' + energyCategoryIndex] = + index < json['base_period']['values'][energyCategoryIndex].length + ? json['base_period']['values'][energyCategoryIndex][index] + : null; + if (detailed_value['a' + energyCategoryIndex] != null) { + detailed_value['basePeriodTotal'] += detailed_value['a' + energyCategoryIndex]; + } + }); + detailed_value['reportingPeriodDatetime'] = + index < json['reporting_period']['timestamps'][0].length + ? json['reporting_period']['timestamps'][0][index] + : null; + detailed_value['reportingPeriodTotal'] = 0.0; + if (detailed_value['reportingPeriodDatetime'] == null) { + detailed_value['reportingPeriodTotal'] = null; + } + json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { + detailed_value['b' + energyCategoryIndex] = + index < json['reporting_period']['values'][energyCategoryIndex].length + ? json['reporting_period']['values'][energyCategoryIndex][index] + : null; + if (detailed_value['b' + energyCategoryIndex] != null) { + detailed_value['reportingPeriodTotal'] += detailed_value['b' + energyCategoryIndex]; + } + }); + detailed_value_list.push(detailed_value); } - } - }) - setDetailedDataTableColumns(detailed_column_list); - - let detailed_value_list = []; - if (json['base_period']['timestamps'].length > 0 || json['reporting_period']['timestamps'].length > 0) { - const max_timestamps_length = json['base_period']['timestamps'][0].length >= json['reporting_period']['timestamps'][0].length? - json['base_period']['timestamps'][0].length : json['reporting_period']['timestamps'][0].length; - for (let index = 0; index < max_timestamps_length; index++) { let detailed_value = {}; - detailed_value['id'] = index; - detailed_value['basePeriodDatetime'] = index < json['base_period']['timestamps'][0].length? json['base_period']['timestamps'][0][index] : null; - detailed_value['basePeriodTotal'] = 0.0; - if (detailed_value['basePeriodDatetime'] == null) { - detailed_value['basePeriodTotal'] = null; - } - json['base_period']['values'].forEach((currentValue, energyCategoryIndex) => { - detailed_value['a' + energyCategoryIndex] = index < json['base_period']['values'][energyCategoryIndex].length? json['base_period']['values'][energyCategoryIndex][index] : null; - if(detailed_value['a' + energyCategoryIndex] != null) { - detailed_value['basePeriodTotal'] += detailed_value['a' + energyCategoryIndex]; - } + detailed_value['id'] = detailed_value_list.length; + detailed_value['basePeriodDatetime'] = t('Subtotal'); + let total_of_subtotals_from_base_period = 0.0; + json['base_period']['subtotals'].forEach((currentValue, index) => { + detailed_value['a' + index] = currentValue; + total_of_subtotals_from_base_period += detailed_value['a' + index]; }); - detailed_value['reportingPeriodDatetime'] = index < json['reporting_period']['timestamps'][0].length? json['reporting_period']['timestamps'][0][index] : null; - detailed_value['reportingPeriodTotal'] = 0.0; - if (detailed_value['reportingPeriodDatetime'] == null) { - detailed_value['reportingPeriodTotal'] = null; - } - json['reporting_period']['values'].forEach((currentValue, energyCategoryIndex) => { - detailed_value['b' + energyCategoryIndex] = index < json['reporting_period']['values'][energyCategoryIndex].length? json['reporting_period']['values'][energyCategoryIndex][index] : null; - if(detailed_value['b' + energyCategoryIndex] != null) { - detailed_value['reportingPeriodTotal'] += detailed_value['b' + energyCategoryIndex]; - } + detailed_value['basePeriodTotal'] = total_of_subtotals_from_base_period; + + let total_of_subtotals_from_reporting_period = 0.0; + detailed_value['reportingPeriodDatetime'] = t('Subtotal'); + json['reporting_period']['subtotals'].forEach((currentValue, index) => { + detailed_value['b' + index] = currentValue; + total_of_subtotals_from_reporting_period += detailed_value['b' + index]; }); + detailed_value['reportingPeriodTotal'] = total_of_subtotals_from_reporting_period; detailed_value_list.push(detailed_value); + setTimeout(() => { + setDetailedDataTableData(detailed_value_list); + }, 0); } + } - let detailed_value = {}; - detailed_value['id'] = detailed_value_list.length; - detailed_value['basePeriodDatetime'] = t('Subtotal'); - let total_of_subtotals_from_base_period = 0.0 - json['base_period']['subtotals'].forEach((currentValue, index) => { - detailed_value['a' + index] = currentValue; - total_of_subtotals_from_base_period += detailed_value['a' + index]; - }); - detailed_value['basePeriodTotal'] = total_of_subtotals_from_base_period; - - let total_of_subtotals_from_reporting_period = 0.0 - detailed_value['reportingPeriodDatetime'] = t('Subtotal'); - json['reporting_period']['subtotals'].forEach((currentValue, index) => { - detailed_value['b' + index] = currentValue; - total_of_subtotals_from_reporting_period += detailed_value['b' + index]; - }); - detailed_value['reportingPeriodTotal'] = total_of_subtotals_from_reporting_period; - detailed_value_list.push(detailed_value); - setTimeout( () => { - setDetailedDataTableData(detailed_value_list); - }, 0) + 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; + let total = 0.0; + json['associated_equipment']['energy_category_names'].forEach((currentValue, energyCategoryIndex) => { + associated_equipment_value['a' + energyCategoryIndex] = + json['associated_equipment']['subtotals_array'][energyCategoryIndex][equipmentIndex]; + total += json['associated_equipment']['subtotals_array'][energyCategoryIndex][equipmentIndex]; + }); + associated_equipment_value['total'] = total; + associated_equipment_value_list.push(associated_equipment_value); + } + ); } - } - 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; - let total = 0.0; - json['associated_equipment']['energy_category_names'].forEach((currentValue, energyCategoryIndex) => { - associated_equipment_value['a' + energyCategoryIndex] = json['associated_equipment']['subtotals_array'][energyCategoryIndex][equipmentIndex]; - total += json['associated_equipment']['subtotals_array'][energyCategoryIndex][equipmentIndex] + 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_category_names'].forEach((currentValue, index) => { + let unit = json['associated_equipment']['units'][index]; + associated_equipment_column_list.push({ + dataField: 'a' + index, + text: currentValue + ' (' + unit + ')', + sort: true, + formatter: function(decimalValue) { + if (typeof decimalValue === 'number') { + return decimalValue.toFixed(2); + } else { + return null; + } + } }); - associated_equipment_value['total'] = total; - 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_category_names'].forEach((currentValue, index) => { - let unit = json['associated_equipment']['units'][index]; associated_equipment_column_list.push({ - dataField: 'a' + index, - text: currentValue + ' (' + unit + ')', + dataField: 'total', + text: t('Total') + ' (' + json['associated_equipment']['total_unit'] + ')', sort: true, - formatter: function (decimalValue) { + formatter: function(decimalValue) { if (typeof decimalValue === 'number') { return decimalValue.toFixed(2); } else { @@ -791,60 +898,49 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { } } }); - }); - associated_equipment_column_list.push({ - dataField: 'total', - text: t('Total') + ' (' + json['associated_equipment']['total_unit'] + ')', - sort: true, - formatter: function (decimalValue) { - if (typeof decimalValue === 'number') { - return decimalValue.toFixed(2); - } else { - return null; - } - } - }); - setAssociatedEquipmentTableColumns(associated_equipment_column_list); + setAssociatedEquipmentTableColumns(associated_equipment_column_list); - setExcelBytesBase64(json['excel_bytes_base64']); + setExcelBytesBase64(json['excel_bytes_base64']); - // enable submit button - setSubmitButtonDisabled(false); - // hide spinner - setSpinnerHidden(true); - // show export button - setExportButtonHidden(false); - } else { - toast.error(t(json.description)) - } - }).catch(err => { - console.log(err); - }); + // enable submit button + setSubmitButtonDisabled(false); + // hide spinner + setSpinnerHidden(true); + // show export button + setExportButtonHidden(false); + } else { + toast.error(t(json.description)); + } + }) + .catch(err => { + console.log(err); + }); }; const handleExport = e => { e.preventDefault(); - const mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' - const fileName = 'combinedequipmentcost.xlsx' - var fileUrl = "data:" + mimeType + ";base64," + excelBytesBase64; + const mimeType = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + const fileName = 'combinedequipmentcost.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); - }); + .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 (
- {t('Combined Equipment Data')}{t('Cost')} + {t('Combined Equipment Data')} + {t('Cost')}
@@ -857,10 +953,12 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { {t('Space')}
- + expandTrigger="hover" + > @@ -870,7 +968,11 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { - setSelectedCombinedEquipment(target.value)} + setSelectedCombinedEquipment(target.value)} > {combinedEquipmentList.map((combinedEquipment, index) => (
{cardSummaryList.map(cardSummaryItem => ( - - {cardSummaryItem['subtotal'] && } + title={t('Reporting Period Costs CATEGORY UNIT', { + CATEGORY: cardSummaryItem['name'], + UNIT: '(' + cardSummaryItem['unit'] + ')' + })} + color="success" + > + {cardSummaryItem['subtotal'] && ( + + )} ))}
@@ -991,32 +1126,64 @@ const CombinedEquipmentCost = ({ setRedirect, setRedirectUrl, t }) => { - - + options={combinedEquipmentReportingOptions} + /> - - + options={parameterLineChartOptions} + />
- - +
- - - +
); }; From bd0e290d62219874908809c5ec275437df87fe91 Mon Sep 17 00:00:00 2001 From: nengyuanzhang <13011132526@163.com> Date: Mon, 19 Feb 2024 20:25:19 +0800 Subject: [PATCH 2/2] fixed warnings in myems-web --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d22ea825a..38a736caf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - ### Fixed - fixed chart issues in myems-web - +- fixed warnings in myems-web +- ### Removed - None