mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
URL updates
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
"@mui/icons-material": "^6.1.1",
|
||||
"@mui/material": "^6.1.1",
|
||||
"@table-library/react-table-library": "4.1.7",
|
||||
"alova": "3.0.16",
|
||||
"alova": "3.0.17",
|
||||
"async-validator": "^4.2.5",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"mime-types": "^2.1.35",
|
||||
@@ -47,8 +47,8 @@
|
||||
"@preact/preset-vite": "^2.9.1",
|
||||
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
||||
"@types/formidable": "^3",
|
||||
"@types/node": "^22.7.3",
|
||||
"@types/react": "^18.3.9",
|
||||
"@types/node": "^22.7.4",
|
||||
"@types/react": "^18.3.10",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"concurrently": "^9.0.1",
|
||||
@@ -57,7 +57,7 @@
|
||||
"formidable": "^3.5.1",
|
||||
"prettier": "^3.3.3",
|
||||
"rollup-plugin-visualizer": "^5.12.0",
|
||||
"terser": "^5.34.0",
|
||||
"terser": "^5.34.1",
|
||||
"typescript-eslint": "8.7.0",
|
||||
"vite": "^5.4.8",
|
||||
"vite-plugin-imagemin": "^0.6.1",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { alovaInstance } from 'api/endpoints';
|
||||
|
||||
import type {
|
||||
APIcall,
|
||||
Action,
|
||||
Activity,
|
||||
CoreData,
|
||||
DeviceData,
|
||||
@@ -52,9 +53,9 @@ export const readActivity = () => alovaInstance.Get<Activity>('/rest/activity');
|
||||
// API
|
||||
export const API = (apiCall: APIcall) => alovaInstance.Post('/api', apiCall);
|
||||
|
||||
// DownloadUpload
|
||||
export const exportData = (type: string) =>
|
||||
alovaInstance.Get('/rest/exportData', { params: { type } });
|
||||
// Generic action
|
||||
export const callAction = (action: Action) =>
|
||||
alovaInstance.Post('/rest/action', action);
|
||||
|
||||
// SettingsCustomization
|
||||
export const readDeviceEntities = (id: number) =>
|
||||
@@ -118,7 +119,7 @@ export const writeModules = (data: {
|
||||
license: string;
|
||||
}) => alovaInstance.Post('/rest/modules', data);
|
||||
|
||||
// SettingsEntities
|
||||
// CustomEntities
|
||||
export const readCustomEntities = () =>
|
||||
alovaInstance.Get<EntityItem[]>('/rest/customEntities', {
|
||||
transform(data) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useContext } from 'react';
|
||||
import { useContext, useState } from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
import CommentIcon from '@mui/icons-material/CommentTwoTone';
|
||||
@@ -16,18 +16,17 @@ import {
|
||||
ListItemAvatar,
|
||||
ListItemButton,
|
||||
ListItemText,
|
||||
Paper,
|
||||
Stack,
|
||||
Typography,
|
||||
styled
|
||||
Typography
|
||||
} from '@mui/material';
|
||||
|
||||
import { useRequest } from 'alova/client';
|
||||
import { SectionContent, useLayoutTitle } from 'components';
|
||||
import { AuthenticatedContext } from 'contexts/authentication';
|
||||
import { useI18nContext } from 'i18n/i18n-react';
|
||||
import { saveFile } from 'utils/file';
|
||||
|
||||
import { API } from '../../api/app';
|
||||
import { API, callAction } from '../../api/app';
|
||||
import type { APIcall } from './types';
|
||||
|
||||
const Help = () => {
|
||||
@@ -36,33 +35,79 @@ const Help = () => {
|
||||
|
||||
const { me } = useContext(AuthenticatedContext);
|
||||
|
||||
const { send: sendAPI } = useRequest((data: APIcall) => API(data), {
|
||||
immediate: false
|
||||
}).onSuccess((event) => {
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = URL.createObjectURL(
|
||||
new Blob([JSON.stringify(event.data, null, 2)], {
|
||||
type: 'text/plain'
|
||||
})
|
||||
);
|
||||
const [customSupportIMG, setCustomSupportIMG] = useState<string | null>(null);
|
||||
const [customSupportHTML, setCustomSupportHTML] = useState<string | null>(null);
|
||||
|
||||
anchor.download =
|
||||
'emsesp_' + event.args[0].device + '_' + event.args[0].entity + '.txt';
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(anchor.href);
|
||||
toast.info(LL.DOWNLOAD_SUCCESSFUL());
|
||||
});
|
||||
useRequest(() => callAction({ action: 'customSupport' })).onSuccess(
|
||||
(event: { data: { img_url: string; html: string[] } }) => {
|
||||
if (event.data) {
|
||||
setCustomSupportIMG(event.data.img_url);
|
||||
setCustomSupportHTML(event.data.html.join('<br/>'));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const callAPI = async (device: string, cmd: string) => {
|
||||
await sendAPI({ device, cmd, id: 0 }).catch((error: Error) => {
|
||||
const { send: sendExportAllValues } = useRequest(
|
||||
() => callAction({ action: 'export', param: 'allvalues' }),
|
||||
{
|
||||
immediate: false
|
||||
}
|
||||
)
|
||||
.onSuccess((event) => {
|
||||
saveFile(event.data, 'allvalues', '.txt');
|
||||
toast.info(LL.DOWNLOAD_SUCCESSFUL());
|
||||
})
|
||||
.onError((error) => {
|
||||
toast.error(error.message);
|
||||
});
|
||||
|
||||
const { send: sendAPI } = useRequest((data: APIcall) => API(data), {
|
||||
immediate: false
|
||||
})
|
||||
.onSuccess((event) => {
|
||||
saveFile(event.data, 'system_info', '.json');
|
||||
toast.info(LL.DOWNLOAD_SUCCESSFUL());
|
||||
})
|
||||
.onError((error) => {
|
||||
toast.error(error.message);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SectionContent>
|
||||
{me.admin ? (
|
||||
<Stack
|
||||
padding={1}
|
||||
mb={2}
|
||||
direction="row"
|
||||
divider={<Divider orientation="vertical" flexItem />}
|
||||
sx={{
|
||||
borderRadius: 3,
|
||||
border: '2px solid grey',
|
||||
justifyContent: 'space-evenly',
|
||||
alignItems: 'center'
|
||||
}}
|
||||
>
|
||||
<Typography variant="subtitle1">
|
||||
{customSupportHTML ? (
|
||||
<div dangerouslySetInnerHTML={{ __html: customSupportHTML }} />
|
||||
) : (
|
||||
LL.HELP_INFORMATION_5()
|
||||
)}
|
||||
</Typography>
|
||||
<Box
|
||||
component="img"
|
||||
sx={{
|
||||
maxHeight: 250
|
||||
}}
|
||||
src={
|
||||
customSupportIMG
|
||||
? customSupportIMG
|
||||
: 'https://emsesp.org/_media/images/installer.jpeg'
|
||||
}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
{me.admin && (
|
||||
<List sx={{ borderRadius: 3, border: '2px solid grey' }}>
|
||||
<ListItem>
|
||||
<ListItemButton component="a" href="https://emsesp.org">
|
||||
@@ -100,31 +145,6 @@ const Help = () => {
|
||||
</ListItemButton>
|
||||
</ListItem>
|
||||
</List>
|
||||
) : (
|
||||
<Stack
|
||||
spacing={1}
|
||||
padding={1}
|
||||
direction="row"
|
||||
divider={<Divider orientation="vertical" flexItem />}
|
||||
sx={{
|
||||
borderRadius: 3,
|
||||
border: '2px solid grey',
|
||||
justifyContent: 'space-around',
|
||||
alignItems: 'center'
|
||||
}}
|
||||
>
|
||||
<Typography border="red" variant="subtitle1">
|
||||
{LL.HELP_INFORMATION_5()}
|
||||
</Typography>
|
||||
<Box
|
||||
padding={1}
|
||||
component="img"
|
||||
sx={{
|
||||
maxHeight: { xs: 100, md: 250 }
|
||||
}}
|
||||
src="https://emsesp.org/_media/images/installer.jpeg"
|
||||
/>
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
<Box p={2} color="warning.main">
|
||||
@@ -135,7 +155,7 @@ const Help = () => {
|
||||
startIcon={<DownloadIcon />}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={() => callAPI('system', 'info')}
|
||||
onClick={() => sendAPI({ device: 'system', cmd: 'info', id: 0 })}
|
||||
>
|
||||
{LL.DOWNLOAD(1)} {LL.SUPPORT_INFORMATION(0)}
|
||||
</Button>
|
||||
@@ -146,7 +166,7 @@ const Help = () => {
|
||||
startIcon={<DownloadIcon />}
|
||||
variant="outlined"
|
||||
color="primary"
|
||||
onClick={() => callAPI('system', 'allvalues')}
|
||||
onClick={() => sendExportAllValues()}
|
||||
>
|
||||
{LL.DOWNLOAD(1)} {LL.ALLVALUES()}
|
||||
</Button>
|
||||
|
||||
@@ -265,6 +265,12 @@ export interface APIcall {
|
||||
cmd: string;
|
||||
id: number;
|
||||
}
|
||||
|
||||
export interface Action {
|
||||
action: string;
|
||||
param?: string; // optional
|
||||
}
|
||||
|
||||
export interface WriteAnalogSensor {
|
||||
id: number;
|
||||
gpio: number;
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
import Grid from '@mui/material/Grid2';
|
||||
|
||||
import * as SystemApi from 'api/system';
|
||||
import { API, exportData } from 'api/app';
|
||||
import { API, callAction } from 'api/app';
|
||||
import {
|
||||
checkUpgrade,
|
||||
getDevVersion,
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
useLayoutTitle
|
||||
} from 'components';
|
||||
import { useI18nContext } from 'i18n/i18n-react';
|
||||
import { saveFile } from 'utils/file';
|
||||
|
||||
const DownloadUpload = () => {
|
||||
const { LL } = useI18nContext();
|
||||
@@ -46,11 +47,23 @@ const DownloadUpload = () => {
|
||||
const [useDev, setUseDev] = useState<boolean>(false);
|
||||
const [upgradeAvailable, setUpgradeAvailable] = useState<boolean>(false);
|
||||
|
||||
const { send: sendExportData } = useRequest((type: string) => exportData(type), {
|
||||
immediate: false
|
||||
})
|
||||
const { send: sendCheckUpgrade } = useRequest(
|
||||
(version: string) => callAction({ action: 'checkUpgrade', param: version }),
|
||||
{
|
||||
immediate: false
|
||||
}
|
||||
).onSuccess((event) => {
|
||||
setUpgradeAvailable((event.data as { upgradeable: boolean }).upgradeable);
|
||||
});
|
||||
|
||||
const { send: sendExportData } = useRequest(
|
||||
(type: string) => callAction({ action: 'export', param: type }),
|
||||
{
|
||||
immediate: false
|
||||
}
|
||||
)
|
||||
.onSuccess((event) => {
|
||||
saveFile(event.data, event.args[0]);
|
||||
saveFile(event.data, event.args[0], '.json');
|
||||
toast.info(LL.DOWNLOAD_SUCCESSFUL());
|
||||
})
|
||||
.onError((error) => {
|
||||
@@ -83,12 +96,6 @@ const DownloadUpload = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const { send: sendCheckUpgrade } = useRequest(checkUpgrade, {
|
||||
immediate: false
|
||||
}).onSuccess((event) => {
|
||||
setUpgradeAvailable(event.data.upgradeable);
|
||||
});
|
||||
|
||||
// called immediately to get the latest version, on page load
|
||||
const { data: latestVersion } = useRequest(getStableVersion, {
|
||||
// uncomment next 2 lines for testing, uses https://github.com/emsesp/EMS-ESP32/releases/download/v3.6.5/EMS-ESP-3_6_5-ESP32-16MB+.bin
|
||||
@@ -102,7 +109,7 @@ const DownloadUpload = () => {
|
||||
// immediate: false,
|
||||
// initialData: '3.7.0-dev.32'
|
||||
}).onSuccess((event) => {
|
||||
void sendCheckUpgrade({ version: event.data });
|
||||
void sendCheckUpgrade(event.data);
|
||||
});
|
||||
|
||||
const STABLE_URL = 'https://github.com/emsesp/EMS-ESP32/releases/download/';
|
||||
@@ -142,18 +149,6 @@ const DownloadUpload = () => {
|
||||
setRestarting(true);
|
||||
};
|
||||
|
||||
const saveFile = (json: unknown, filename: string) => {
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = URL.createObjectURL(
|
||||
new Blob([JSON.stringify(json, null, 2)], {
|
||||
type: 'text/plain'
|
||||
})
|
||||
);
|
||||
anchor.download = 'emsesp_' + filename + '.json';
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(anchor.href);
|
||||
};
|
||||
|
||||
useLayoutTitle(LL.DOWNLOAD_UPLOAD());
|
||||
|
||||
const internet_live =
|
||||
|
||||
11
interface/src/utils/file.ts
Normal file
11
interface/src/utils/file.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const saveFile = (json: unknown, filename: string, extension: string) => {
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = URL.createObjectURL(
|
||||
new Blob([JSON.stringify(json, null, 2)], {
|
||||
type: 'text/plain'
|
||||
})
|
||||
);
|
||||
anchor.download = 'emsesp_' + filename + extension;
|
||||
anchor.click();
|
||||
URL.revokeObjectURL(anchor.href);
|
||||
};
|
||||
@@ -1446,12 +1446,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:^22.7.3":
|
||||
version: 22.7.3
|
||||
resolution: "@types/node@npm:22.7.3"
|
||||
"@types/node@npm:^22.7.4":
|
||||
version: 22.7.4
|
||||
resolution: "@types/node@npm:22.7.4"
|
||||
dependencies:
|
||||
undici-types: "npm:~6.19.2"
|
||||
checksum: 10c0/0e579813528b0370454337a952f43b792cd12731e10fdca0fdb627158e980c1219bba99e9048c134b6a19325d817016059afe016ccd372326c838a1b85a51574
|
||||
checksum: 10c0/c22bf54515c78ff3170142c1e718b90e2a0003419dc2d55f79c9c9362edd590a6ab1450deb09ff6e1b32d1b4698da407930b16285e8be3a009ea6cd2695cac01
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1518,13 +1518,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/react@npm:^18.3.9":
|
||||
version: 18.3.9
|
||||
resolution: "@types/react@npm:18.3.9"
|
||||
"@types/react@npm:^18.3.10":
|
||||
version: 18.3.10
|
||||
resolution: "@types/react@npm:18.3.10"
|
||||
dependencies:
|
||||
"@types/prop-types": "npm:*"
|
||||
csstype: "npm:^3.0.2"
|
||||
checksum: 10c0/a92b8e061d0c833e096254782c56a802316593f4a907fb834b557cabe848a0829b9eb6056404ea239eb4d5ec5ac7b7724309761516c0a7a277916fa04dd4f805
|
||||
checksum: 10c0/f5be1de1b0331c1fdb33d577f4cf7f1b949d4bded5347b2351a537f03c51dade5be115e21b161dcf1b37061954d320f6a0bdf8d7b70e24eda51071fdd614383d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1678,11 +1678,11 @@ __metadata:
|
||||
"@table-library/react-table-library": "npm:4.1.7"
|
||||
"@trivago/prettier-plugin-sort-imports": "npm:^4.3.0"
|
||||
"@types/formidable": "npm:^3"
|
||||
"@types/node": "npm:^22.7.3"
|
||||
"@types/react": "npm:^18.3.9"
|
||||
"@types/node": "npm:^22.7.4"
|
||||
"@types/react": "npm:^18.3.10"
|
||||
"@types/react-dom": "npm:^18.3.0"
|
||||
"@types/react-router-dom": "npm:^5.3.3"
|
||||
alova: "npm:3.0.16"
|
||||
alova: "npm:3.0.17"
|
||||
async-validator: "npm:^4.2.5"
|
||||
concurrently: "npm:^9.0.1"
|
||||
eslint: "npm:^9.11.1"
|
||||
@@ -1698,7 +1698,7 @@ __metadata:
|
||||
react-router-dom: "npm:^6.26.2"
|
||||
react-toastify: "npm:^10.0.5"
|
||||
rollup-plugin-visualizer: "npm:^5.12.0"
|
||||
terser: "npm:^5.34.0"
|
||||
terser: "npm:^5.34.1"
|
||||
typesafe-i18n: "npm:^5.26.2"
|
||||
typescript: "npm:^5.6.2"
|
||||
typescript-eslint: "npm:8.7.0"
|
||||
@@ -1764,13 +1764,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"alova@npm:3.0.16":
|
||||
version: 3.0.16
|
||||
resolution: "alova@npm:3.0.16"
|
||||
"alova@npm:3.0.17":
|
||||
version: 3.0.17
|
||||
resolution: "alova@npm:3.0.17"
|
||||
dependencies:
|
||||
"@alova/shared": "npm:^1.0.5"
|
||||
rate-limiter-flexible: "npm:^5.0.3"
|
||||
checksum: 10c0/66cb597f4f00feda04b7619dd852fde92bc920cc97b018be70791240c8e8c64677a998a02a684f3aace5997322236a677264f25afe6bcaf4ec856ae42be859a8
|
||||
checksum: 10c0/e8a2ae885a3ff44dafec230d9388dc22b6445bb0cf8511fc9855b5a98ad9961941b0d33a7da874df23db4af0dba75872a470e3edebbdcc5ead8aecbc7fcc3d6b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -6654,9 +6654,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"terser@npm:^5.34.0":
|
||||
version: 5.34.0
|
||||
resolution: "terser@npm:5.34.0"
|
||||
"terser@npm:^5.34.1":
|
||||
version: 5.34.1
|
||||
resolution: "terser@npm:5.34.1"
|
||||
dependencies:
|
||||
"@jridgewell/source-map": "npm:^0.3.3"
|
||||
acorn: "npm:^8.8.2"
|
||||
@@ -6664,7 +6664,7 @@ __metadata:
|
||||
source-map-support: "npm:~0.5.20"
|
||||
bin:
|
||||
terser: bin/terser
|
||||
checksum: 10c0/74e8ef4e565e5600415cd9377a90eed419b8076465d453c0c76aef4053c45371512d2de76c34d01e004cdd49ea5a749d77eeb343f7e665b2d172158ca08ba23e
|
||||
checksum: 10c0/51c7d704c5c4ae88bf937124112c9972aed4e1fd29d805cc2d86e0f54cd631ecd4e69db5bb3c1e3b450c741c86e2313328bea0fde925329e8a31a07a7941723c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user