- {statOptions.interfaceList.map((data) => {
- const options = {
- data,
- options: {
- ...statOptions.settings,
- title: {
- text: capitalizeFirstLetter(data[0].titleName),
- align: 'left',
- style: {
- fontSize: '25px',
+ {section !== 'memory' && !loading && getInterface()}
+ {section === 'memory' &&
+ !loading &&
+ statOptions.memory.map((data) => {
+ const options = {
+ data,
+ options: {
+ ...statOptions.memoryOptions,
+ title: {
+ text: capitalizeFirstLetter(data[0].titleName),
+ align: 'left',
+ style: {
+ fontSize: '25px',
+ },
},
},
- },
- };
- return (
-
-
-
- );
- })}
+ };
+ return (
+
+
+
+ );
+ })}
);
};
+StatisticsChartList.propTypes = {
+ setOptions: PropTypes.func.isRequired,
+ section: PropTypes.string.isRequired,
+ time: PropTypes.instanceOf(Object).isRequired,
+ setStart: PropTypes.func.isRequired,
+ setEnd: PropTypes.func.isRequired,
+};
+
export default React.memo(StatisticsChartList);
diff --git a/src/components/InterfaceStatistics/index.js b/src/components/InterfaceStatistics/index.js
index 6a0b709..6a06ec5 100644
--- a/src/components/InterfaceStatistics/index.js
+++ b/src/components/InterfaceStatistics/index.js
@@ -1,9 +1,18 @@
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
-import { CCard, CCardHeader, CCardBody, CPopover, CButton } from '@coreui/react';
+import { v4 as createUuid } from 'uuid';
+import {
+ CCard,
+ CCardHeader,
+ CCardBody,
+ CPopover,
+ CButton,
+ CSelect,
+ CFormText,
+} from '@coreui/react';
+import DatePicker from 'react-widgets/DatePicker';
import { cilSync } from '@coreui/icons';
import CIcon from '@coreui/icons-react';
-import eventBus from 'utils/eventBus';
import LifetimeStatsmodal from 'components/LifetimeStatsModal';
import StatisticsChartList from './StatisticsChartList';
import LatestStatisticsmodal from './LatestStatisticsModal';
@@ -12,6 +21,13 @@ const DeviceStatisticsCard = () => {
const { t } = useTranslation();
const [showLatestModal, setShowLatestModal] = useState(false);
const [showLifetimeModal, setShowLifetimeModal] = useState(false);
+ const [options, setOptions] = useState([]);
+ const [section, setSection] = useState('');
+ const [start, setStart] = useState(null);
+ const [startError, setStartError] = useState(false);
+ const [end, setEnd] = useState(null);
+ const [endError, setEndError] = useState(false);
+ const [time, setTime] = useState({ refreshId: '0', start: null, end: null });
const toggleLatestModal = () => {
setShowLatestModal(!showLatestModal);
@@ -21,10 +37,36 @@ const DeviceStatisticsCard = () => {
setShowLifetimeModal(!showLifetimeModal);
};
- const refresh = () => {
- eventBus.dispatch('refreshInterfaceStatistics', { message: 'Refresh interface statistics' });
+ const modifyStart = (value) => {
+ try {
+ new Date(value).toISOString();
+ setStartError(false);
+ setStart(value);
+ } catch (e) {
+ setStart('');
+ setStartError(true);
+ }
};
+ const modifyEnd = (value) => {
+ try {
+ new Date(value).toISOString();
+ setEndError(false);
+ setEnd(value);
+ } catch (e) {
+ setEnd('');
+ setEndError(true);
+ }
+ };
+
+ const refresh = () => {
+ setTime({ refreshId: createUuid(), start, end });
+ };
+
+ useEffect(() => {
+ if (section === '' && options.length > 0) setSection(options[0].value);
+ }, [options]);
+
return (
@@ -32,12 +74,34 @@ const DeviceStatisticsCard = () => {
-
+
+ modifyEnd(date)}
+ value={end ? new Date(end) : undefined}
+ />
+
+ {t('common.invalid_date_explanation')}
+
+
+ To:
+
+ modifyStart(date)}
+ value={start ? new Date(start) : undefined}
+ />
+
+ {t('common.invalid_date_explanation')}
+
+
+ From:
+
Lifetime Statistics
@@ -47,10 +111,30 @@ const DeviceStatisticsCard = () => {
{t('statistics.show_latest')}
+
+ setSection(e.target.value)}
+ >
+ {options.map((opt) => (
+
+ ))}
+
+
-
+
diff --git a/src/pages/DevicePage/DeviceStatusCard/index.js b/src/pages/DevicePage/DeviceStatusCard/index.js
index 25135aa..13e97f9 100644
--- a/src/pages/DevicePage/DeviceStatusCard/index.js
+++ b/src/pages/DevicePage/DeviceStatusCard/index.js
@@ -2,13 +2,13 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
+ CAlert,
CCard,
CCardHeader,
CRow,
CCol,
CCardBody,
CBadge,
- CAlert,
CPopover,
CButton,
CSpinner,
@@ -16,8 +16,7 @@ import {
} from '@coreui/react';
import CIcon from '@coreui/icons-react';
import { cilSync } from '@coreui/icons';
-import { prettyDate, compactSecondsToDetailed } from 'utils/helper';
-import MemoryBar from './MemoryBar';
+import { prettyDate, compactSecondsToDetailed, cleanBytesString } from 'utils/helper';
import styles from './index.module.scss';
@@ -27,6 +26,20 @@ const errorField = (t) => (
);
+const getMemoryColor = (memTotal, memFree) => {
+ let memoryUsed = 0;
+ if (memTotal > 0) memoryUsed = Math.floor(((memTotal - memFree) / memTotal) * 100);
+
+ if (memoryUsed < 60) return 'success';
+ if (memoryUsed <= 85) return 'warning';
+ return 'danger';
+};
+
+const getMemoryPercentage = (memTotal, memFree) => {
+ if (memTotal <= 0) return `0%`;
+ return `${Math.floor(((memTotal - memFree) / memTotal) * 100)}%`;
+};
+
const DeviceStatusCard = ({
t,
loading,
@@ -156,6 +169,12 @@ const DeviceStatusCard = ({
)}
+