From f210466cb17d8797818bf4d494fa174572e258ad Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 29 Jul 2021 16:54:08 +0200 Subject: [PATCH] download buttons for settings --- interface/src/project/EMSESPHelp.tsx | 89 +++++++++++++++++----------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/interface/src/project/EMSESPHelp.tsx b/interface/src/project/EMSESPHelp.tsx index 46905d542..363eb94c1 100644 --- a/interface/src/project/EMSESPHelp.tsx +++ b/interface/src/project/EMSESPHelp.tsx @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import { Component } from 'react'; import { Typography, Box, @@ -14,14 +14,40 @@ import CommentIcon from '@material-ui/icons/CommentTwoTone'; import MenuBookIcon from '@material-ui/icons/MenuBookTwoTone'; import GitHubIcon from '@material-ui/icons/GitHub'; import StarIcon from '@material-ui/icons/Star'; -import ImportExportIcon from '@material-ui/icons/ImportExport'; -import BugReportIcon from '@material-ui/icons/BugReportTwoTone'; +import DownloadIcon from '@material-ui/icons/GetApp'; -export const WebAPISystemSettings = - window.location.origin + '/api/system/settings'; -export const WebAPISystemInfo = window.location.origin + '/api/system/info'; +import { FormButton } from '../components'; + +import { API_ENDPOINT_ROOT } from '../api'; + +import { redirectingAuthorizedFetch } from '../authentication'; class EMSESPHelp extends Component { + onDownload = (endpoint: string) => { + redirectingAuthorizedFetch(API_ENDPOINT_ROOT + 'system/' + endpoint) + .then((response) => { + if (response.status === 200) { + return response.json(); + } + throw Error( + 'Device returned unexpected response code: ' + response.status + ); + }) + .then((json) => { + const a = document.createElement('a'); + const filename = 'emsesp_system_' + endpoint + '.txt'; + a.href = URL.createObjectURL( + new Blob([JSON.stringify(json, null, 2)], { + type: 'text/plain' + }) + ); + a.setAttribute('download', filename); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + }); + }; + render() { return ( @@ -31,9 +57,9 @@ class EMSESPHelp extends Component { - For the latest news and updates go to the{' '} + For help and information on the latest updates visit the{' '} - {'official documentation'} website + {'online documentation'} @@ -55,41 +81,36 @@ class EMSESPHelp extends Component { - To report an issue or feature request go to{' '} + To report an issue or request a feature go to{' '} - {'click here'} - - - - - - - - - - To export your system settings{' '} - - {'click here'} - - - - - - - - - - To export the current status of EMS-ESP{' '} - - {'click here'} + {'GitHub'} + + } + variant="contained" + color="primary" + onClick={() => this.onDownload('info')} + > + download system info + + } + variant="contained" + color="primary" + onClick={() => this.onDownload('settings')} + > + download all settings + + + EMS-ESP is free and open-source.