import React, {Component} from 'react'; import {Box, List, ListItem, ListItemText} from '@material-ui/core'; import {FormButton, restController, RestControllerProps, RestFormLoader, SectionContent} from '../components'; import {ENDPOINT_ROOT} from "../api"; import {GeneralInformaitonState} from "./types"; import RefreshIcon from "@material-ui/icons/Refresh"; // define api endpoint export const GENERALINFORMATION_SETTINGS_ENDPOINT = ENDPOINT_ROOT + "generalinfo"; type GeneralInformationRestControllerProps = RestControllerProps; class GeneralInformation extends Component { intervalhandler: number | undefined; componentDidMount() { this.props.loadData(); } componentWillUnmount() { clearInterval(this.intervalhandler); } render() { return ( ( <> } variant="contained" color="secondary" onClick={this.props.loadData}> Refresh Version: {props.data.version} )} /> ); } /** * stringify seconds to a pretty format * @param sec number of seconds */ private stringifyTime(sec: number): string { if (sec >= 86400) { // display days return (Math.trunc(sec / 86400) + "d " + Math.trunc((sec % 86400) / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec"); } else if (sec >= 3600) { // display hours return (Math.trunc(sec / 3600) + "h " + Math.trunc((sec % 3600) / 60) + "min " + sec % 60 + "sec"); } else if (sec >= 60) { // only seconds and minutes return (Math.trunc(sec / 60) + "min " + sec % 60 + "sec"); } else { // only seconds return (sec + "sec"); } } private getRealTimeString(runtime: number): string { const timestamp = Date.now(); const a = new Date(timestamp - (runtime * 1000)); const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; const year = a.getFullYear(); const month = months[a.getMonth()]; const date = a.getDate(); const hour = a.getHours(); const min = "0" + a.getMinutes(); const sec = "0" + a.getSeconds(); return '[' + date + ' ' + month + ' ' + year + ' ' + hour + ':' + min.substr(-2) + ':' + sec.substr(-2) + ']'; } } export default restController(GENERALINFORMATION_SETTINGS_ENDPOINT, GeneralInformation);