mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
download button for log
This commit is contained in:
@@ -4,6 +4,7 @@ export const PROJECT_PATH = process.env.REACT_APP_PROJECT_PATH!;
|
|||||||
export const ENDPOINT_ROOT = calculateEndpointRoot('/rest/');
|
export const ENDPOINT_ROOT = calculateEndpointRoot('/rest/');
|
||||||
export const WEB_SOCKET_ROOT = calculateWebSocketRoot('/ws/');
|
export const WEB_SOCKET_ROOT = calculateWebSocketRoot('/ws/');
|
||||||
export const EVENT_SOURCE_ROOT = calculateEndpointRoot('/es/');
|
export const EVENT_SOURCE_ROOT = calculateEndpointRoot('/es/');
|
||||||
|
export const API_ENDPOINT_ROOT = calculateEndpointRoot('/api/');
|
||||||
|
|
||||||
function calculateEndpointRoot(endpointPath: string) {
|
function calculateEndpointRoot(endpointPath: string) {
|
||||||
const httpRoot = process.env.REACT_APP_HTTP_ROOT;
|
const httpRoot = process.env.REACT_APP_HTTP_ROOT;
|
||||||
|
|||||||
@@ -12,21 +12,29 @@ import {
|
|||||||
SelectValidator
|
SelectValidator
|
||||||
} from 'react-material-ui-form-validator';
|
} from 'react-material-ui-form-validator';
|
||||||
|
|
||||||
import { Grid, Slider, FormLabel, Checkbox, MenuItem } from '@material-ui/core';
|
import {
|
||||||
|
Grid,
|
||||||
|
Slider,
|
||||||
|
FormLabel,
|
||||||
|
Checkbox,
|
||||||
|
MenuItem,
|
||||||
|
Button
|
||||||
|
} from '@material-ui/core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addAccessTokenParameter,
|
addAccessTokenParameter,
|
||||||
redirectingAuthorizedFetch
|
redirectingAuthorizedFetch
|
||||||
} from '../authentication';
|
} from '../authentication';
|
||||||
|
|
||||||
|
import DownloadIcon from '@material-ui/icons/GetApp';
|
||||||
|
|
||||||
import { ENDPOINT_ROOT, EVENT_SOURCE_ROOT } from '../api';
|
import { ENDPOINT_ROOT, EVENT_SOURCE_ROOT } from '../api';
|
||||||
export const FETCH_LOG_ENDPOINT = ENDPOINT_ROOT + 'fetchLog';
|
export const FETCH_LOG_ENDPOINT = ENDPOINT_ROOT + 'fetchLog';
|
||||||
export const LOG_SETTINGS_ENDPOINT = ENDPOINT_ROOT + 'logSettings';
|
export const LOG_SETTINGS_ENDPOINT = ENDPOINT_ROOT + 'logSettings';
|
||||||
export const LOG_EVENT_EVENT_SOURCE_URL = EVENT_SOURCE_ROOT + 'log';
|
export const LOG_EVENT_EVENT_SOURCE_URL = EVENT_SOURCE_ROOT + 'log';
|
||||||
|
|
||||||
import LogEventConsole from './LogEventConsole';
|
import LogEventConsole from './LogEventConsole';
|
||||||
|
import { LogEvent, LogSettings, LogLevel } from './types';
|
||||||
import { LogEvent, LogSettings } from './types';
|
|
||||||
|
|
||||||
import { Decoder } from '@msgpack/msgpack';
|
import { Decoder } from '@msgpack/msgpack';
|
||||||
const decoder = new Decoder();
|
const decoder = new Decoder();
|
||||||
@@ -185,6 +193,54 @@ class LogEventController extends Component<
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
levelLabel = (level: LogLevel) => {
|
||||||
|
switch (level) {
|
||||||
|
case LogLevel.ERROR:
|
||||||
|
return 'E';
|
||||||
|
case LogLevel.WARNING:
|
||||||
|
return 'W';
|
||||||
|
case LogLevel.NOTICE:
|
||||||
|
return 'N';
|
||||||
|
case LogLevel.INFO:
|
||||||
|
return 'I';
|
||||||
|
case LogLevel.DEBUG:
|
||||||
|
return 'D';
|
||||||
|
case LogLevel.TRACE:
|
||||||
|
return 'TRACE';
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onDownload = () => {
|
||||||
|
const { events, level } = this.state;
|
||||||
|
let result = '';
|
||||||
|
for (const i in events) {
|
||||||
|
if (events[i].l <= level) {
|
||||||
|
result +=
|
||||||
|
events[i].t +
|
||||||
|
' ' +
|
||||||
|
this.levelLabel(events[i].l) +
|
||||||
|
' ' +
|
||||||
|
events[i].i +
|
||||||
|
': [' +
|
||||||
|
events[i].n +
|
||||||
|
'] ' +
|
||||||
|
events[i].m +
|
||||||
|
'\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.setAttribute(
|
||||||
|
'href',
|
||||||
|
'data:text/plain;charset=utf-8,' + encodeURIComponent(result)
|
||||||
|
);
|
||||||
|
a.setAttribute('download', 'log.txt');
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { saveData } = this.props;
|
const { saveData } = this.props;
|
||||||
return (
|
return (
|
||||||
@@ -244,6 +300,16 @@ class LogEventController extends Component<
|
|||||||
label="Compact Layout"
|
label="Compact Layout"
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item md>
|
||||||
|
<Button
|
||||||
|
startIcon={<DownloadIcon />}
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={this.onDownload}
|
||||||
|
>
|
||||||
|
Download
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</ValidatorForm>
|
</ValidatorForm>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user