csv-header and online time translation

This commit is contained in:
MichaelDvP
2022-09-06 19:43:42 +02:00
parent c2ccb4edda
commit 70f94322ee
2 changed files with 20 additions and 3 deletions

View File

@@ -328,10 +328,10 @@ const DashboardData: FC = () => {
const handleDownloadCsv = () => { const handleDownloadCsv = () => {
const columns = [ const columns = [
{ accessor: (dv: any) => dv.id.slice(2), name: 'Entity' }, { accessor: (dv: any) => dv.id.slice(2), name: LL.ENTITY_NAME() },
{ {
accessor: (dv: any) => (typeof dv.v === 'number' ? new Intl.NumberFormat().format(dv.v) : dv.v), accessor: (dv: any) => (typeof dv.v === 'number' ? new Intl.NumberFormat().format(dv.v) : dv.v),
name: 'Value' name: LL.VALUE()
}, },
{ accessor: (dv: any) => DeviceValueUOM_s[dv.u], name: 'UoM' } { accessor: (dv: any) => DeviceValueUOM_s[dv.u], name: 'UoM' }
]; ];

View File

@@ -32,12 +32,13 @@ import { ButtonRow, FormLoader, SectionContent } from '../components';
import { Status, busConnectionStatus, Stat } from './types'; import { Status, busConnectionStatus, Stat } from './types';
import { formatDurationSec, extractErrorMessage, useRest } from '../utils'; import { extractErrorMessage, useRest } from '../utils';
import * as EMSESP from './api'; import * as EMSESP from './api';
import type { Translation } from '../i18n/i18n-types'; import type { Translation } from '../i18n/i18n-types';
import { useI18nContext } from '../i18n/i18n-react'; import { useI18nContext } from '../i18n/i18n-react';
import parseMilliseconds from 'parse-ms';
export const isConnected = ({ status }: Status) => status !== busConnectionStatus.BUS_STATUS_OFFLINE; export const isConnected = ({ status }: Status) => status !== busConnectionStatus.BUS_STATUS_OFFLINE;
@@ -155,6 +156,22 @@ const DashboardStatus: FC = () => {
} }
}; };
const formatDurationSec = (duration_sec: number) => {
const { days, hours, minutes, seconds } = parseMilliseconds(duration_sec * 1000);
let formatted = ' ';
if (days) {
formatted += LL.NUM_DAYS({ num: days }) + ' ';
}
if (hours) {
formatted += LL.NUM_HOURS({ num: hours }) + ' ';
}
if (minutes) {
formatted += LL.NUM_MINUTES({ num: minutes }) + ' ';
}
formatted += LL.NUM_SECONDS({ num: seconds });
return formatted;
};
const renderScanDialog = () => ( const renderScanDialog = () => (
<Dialog open={confirmScan} onClose={() => setConfirmScan(false)}> <Dialog open={confirmScan} onClose={() => setConfirmScan(false)}>
<DialogTitle>{LL.SCAN_DEVICES()}</DialogTitle> <DialogTitle>{LL.SCAN_DEVICES()}</DialogTitle>