diff --git a/interface/src/framework/system/UploadFileForm.tsx b/interface/src/framework/system/UploadFileForm.tsx index 3a22eb540..f60e3539b 100644 --- a/interface/src/framework/system/UploadFileForm.tsx +++ b/interface/src/framework/system/UploadFileForm.tsx @@ -28,7 +28,7 @@ const UploadFileForm: FC = () => { const { send: getSchedule, onSuccess: onSuccessGetSchedule } = useRequest(EMSESP.getSchedule(), { immediate: false }); - const { send: getInfo, onSuccess: onSuccessGetInfo } = useRequest((data) => EMSESP.API(data), { + const { send: getAPI, onSuccess: onGetAPI } = useRequest((data) => EMSESP.API(data), { immediate: false }); @@ -89,8 +89,9 @@ const UploadFileForm: FC = () => { onSuccessGetSchedule((event) => { saveFile(event.data, 'schedule'); }); - onSuccessGetInfo((event) => { - saveFile(event.data, 'info'); + onGetAPI((event) => { + const filename = event.sendArgs[0].device + '_' + event.sendArgs[0].entity; + saveFile(event.data, filename); }); const downloadSettings = async () => { @@ -112,13 +113,17 @@ const UploadFileForm: FC = () => { }; const downloadSchedule = async () => { - await getSchedule().catch((error) => { - toast.error(error.message); - }); + await getSchedule() + .catch((error) => { + toast.error(error.message); + }) + .finally(() => { + toast.info(LL.DOWNLOAD_SUCCESSFUL()); + }); }; - const downloadInfo = async () => { - await getInfo({ device: 'system', entity: 'info', id: 0 }).catch((error) => { + const callAPI = async (device: string, entity: string) => { + await getAPI({ device, entity, id: 0 }).catch((error) => { toast.error(error.message); }); }; @@ -143,8 +148,34 @@ const UploadFileForm: FC = () => { {!isUploading && ( <> - - {LL.DOWNLOAD(0)} + + {LL.DOWNLOAD(0)} {LL.SUPPORT_INFORMATION()} + + + + {LL.HELP_INFORMATION_4()} + + + + + + + {LL.DOWNLOAD(0)} {LL.SETTINGS()} @@ -179,14 +210,6 @@ const UploadFileForm: FC = () => { - - - {LL.DOWNLOAD(0)} {LL.SUPPORT_INFORMATION()} - - - )} diff --git a/interface/src/project/Help.tsx b/interface/src/project/Help.tsx index 555a44c63..b6278fa38 100644 --- a/interface/src/project/Help.tsx +++ b/interface/src/project/Help.tsx @@ -1,17 +1,40 @@ import CommentIcon from '@mui/icons-material/CommentTwoTone'; import EastIcon from '@mui/icons-material/East'; +import DownloadIcon from '@mui/icons-material/GetApp'; import GitHubIcon from '@mui/icons-material/GitHub'; import MenuBookIcon from '@mui/icons-material/MenuBookTwoTone'; -import { Box, List, ListItem, ListItemAvatar, ListItemText, Link, Typography } from '@mui/material'; +import { Box, List, ListItem, ListItemAvatar, ListItemText, Link, Typography, Button } from '@mui/material'; +import { useRequest } from 'alova'; +import { toast } from 'react-toastify'; import type { FC } from 'react'; import { SectionContent, useLayoutTitle } from 'components'; import { useI18nContext } from 'i18n/i18n-react'; +import * as EMSESP from 'project/api'; const Help: FC = () => { const { LL } = useI18nContext(); useLayoutTitle(LL.HELP_OF('')); - const uploadURL = window.location.origin + '/system/upload'; + const { send: getAPI, onSuccess: onGetAPI } = useRequest((data) => EMSESP.API(data), { + immediate: false + }); + onGetAPI((event) => { + const anchor = document.createElement('a'); + anchor.href = URL.createObjectURL( + new Blob([JSON.stringify(event.data, null, 2)], { + type: 'text/plain' + }) + ); + anchor.download = 'emsesp_' + event.sendArgs[0].device + '_' + event.sendArgs[0].entity + '.json'; + anchor.click(); + URL.revokeObjectURL(anchor.href); + toast.info(LL.DOWNLOAD_SUCCESSFUL()); + }); + const callAPI = async (device: string, entity: string) => { + await getAPI({ device, entity, id: 0 }).catch((error) => { + toast.error(error.message); + }); + }; return ( @@ -55,16 +78,28 @@ const Help: FC = () => { {LL.CLICK_HERE()}
- ({LL.HELP_INFORMATION_4()}  - - - {LL.UPLOAD_DOWNLOAD()} - - ) + + + {LL.HELP_INFORMATION_4()} + + + + + {LL.HELP_INFORMATION_5()}