mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev2
This commit is contained in:
@@ -59,7 +59,7 @@
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-autofix": "^1.1.0",
|
||||
"eslint-plugin-import": "^2.28.1",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-prettier": "alpha",
|
||||
"eslint-plugin-react": "^7.33.2",
|
||||
|
||||
@@ -295,49 +295,50 @@ const DashboardDevices: FC = () => {
|
||||
return sc;
|
||||
};
|
||||
|
||||
const makeCsvData = (columns: any, data: any) =>
|
||||
data.reduce(
|
||||
(csvString: any, rowItem: any) =>
|
||||
csvString + columns.map(({ accessor }: any) => escapeCsvCell(accessor(rowItem))).join(';') + '\r\n',
|
||||
columns.map(({ name }: any) => escapeCsvCell(name)).join(';') + '\r\n'
|
||||
);
|
||||
|
||||
const downloadAsCsv = (columns: any, data: any, filename: string) => {
|
||||
const csvData = makeCsvData(columns, data);
|
||||
const csvFile = new Blob([csvData], { type: 'text/csv;charset:utf-8' });
|
||||
const downloadLink = document.createElement('a');
|
||||
|
||||
downloadLink.download = filename;
|
||||
downloadLink.href = window.URL.createObjectURL(csvFile);
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
};
|
||||
|
||||
const hasMask = (id: string, mask: number) => (parseInt(id.slice(0, 2), 16) & mask) === mask;
|
||||
|
||||
const handleDownloadCsv = () => {
|
||||
const columns = [
|
||||
{ accessor: (dv: any) => dv.id.slice(2), name: LL.ENTITY_NAME(0) },
|
||||
{
|
||||
accessor: (dv: any) => (typeof dv.v === 'number' ? new Intl.NumberFormat().format(dv.v) : dv.v),
|
||||
name: LL.VALUE(0)
|
||||
},
|
||||
{ accessor: (dv: any) => DeviceValueUOM_s[dv.u], name: 'UoM' },
|
||||
{ accessor: (dv: any) => (dv.c ? '1' : '0'), name: 'writeable' }
|
||||
];
|
||||
|
||||
const deviceIndex = coreData.devices.findIndex((d) => d.id === device_select.state.id);
|
||||
if (deviceIndex === -1) {
|
||||
return;
|
||||
}
|
||||
const filename = coreData.devices[deviceIndex].tn + '_' + coreData.devices[deviceIndex].n;
|
||||
|
||||
downloadAsCsv(
|
||||
columns,
|
||||
onlyFav ? deviceData.data.filter((dv) => hasMask(dv.id, DeviceEntityMask.DV_FAVORITE)) : deviceData.data,
|
||||
filename
|
||||
const columns = [
|
||||
{ accessor: (dv: DeviceValue) => dv.id.slice(2), name: LL.ENTITY_NAME(0) },
|
||||
{
|
||||
accessor: (dv: DeviceValue) => (typeof dv.v === 'number' ? new Intl.NumberFormat().format(dv.v) : dv.v),
|
||||
name: LL.VALUE(1)
|
||||
},
|
||||
{ accessor: (dv: DeviceValue) => DeviceValueUOM_s[dv.u].replace(/[^a-zA-Z0-9]/g, ''), name: 'UoM' },
|
||||
{
|
||||
accessor: (dv: DeviceValue) => (dv.c && !hasMask(dv.id, DeviceEntityMask.DV_READONLY) ? 'yes' : 'no'),
|
||||
name: LL.WRITEABLE()
|
||||
},
|
||||
{
|
||||
accessor: (dv: DeviceValue) =>
|
||||
dv.h ? dv.h : dv.l ? dv.l.join(' | ') : dv.m !== undefined && dv.x !== undefined ? dv.m + ', ' + dv.x : '',
|
||||
name: 'Range'
|
||||
}
|
||||
];
|
||||
|
||||
const data = onlyFav
|
||||
? deviceData.data.filter((dv) => hasMask(dv.id, DeviceEntityMask.DV_FAVORITE))
|
||||
: deviceData.data;
|
||||
|
||||
const csvData = data.reduce(
|
||||
(csvString: any, rowItem: any) =>
|
||||
csvString + columns.map(({ accessor }: any) => escapeCsvCell(accessor(rowItem))).join(';') + '\r\n',
|
||||
columns.map(({ name }: any) => escapeCsvCell(name)).join(';') + '\r\n'
|
||||
);
|
||||
|
||||
const csvFile = new Blob([csvData], { type: 'text/csv;charset:utf-8' });
|
||||
const downloadLink = document.createElement('a');
|
||||
downloadLink.download = filename;
|
||||
downloadLink.href = window.URL.createObjectURL(csvFile);
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -1571,7 +1571,7 @@ __metadata:
|
||||
eslint-config-prettier: "npm:^9.0.0"
|
||||
eslint-import-resolver-typescript: "npm:^3.6.1"
|
||||
eslint-plugin-autofix: "npm:^1.1.0"
|
||||
eslint-plugin-import: "npm:^2.28.1"
|
||||
eslint-plugin-import: "npm:^2.29.0"
|
||||
eslint-plugin-jsx-a11y: "npm:^6.7.1"
|
||||
eslint-plugin-prettier: "npm:alpha"
|
||||
eslint-plugin-react: "npm:^7.33.2"
|
||||
@@ -1790,7 +1790,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array-includes@npm:^3.1.6":
|
||||
"array-includes@npm:^3.1.6, array-includes@npm:^3.1.7":
|
||||
version: 3.1.7
|
||||
resolution: "array-includes@npm:3.1.7"
|
||||
dependencies:
|
||||
@@ -1810,7 +1810,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array.prototype.findlastindex@npm:^1.2.2":
|
||||
"array.prototype.findlastindex@npm:^1.2.3":
|
||||
version: 1.2.3
|
||||
resolution: "array.prototype.findlastindex@npm:1.2.3"
|
||||
dependencies:
|
||||
@@ -1823,7 +1823,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array.prototype.flat@npm:^1.3.1":
|
||||
"array.prototype.flat@npm:^1.3.1, array.prototype.flat@npm:^1.3.2":
|
||||
version: 1.3.2
|
||||
resolution: "array.prototype.flat@npm:1.3.2"
|
||||
dependencies:
|
||||
@@ -1835,7 +1835,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"array.prototype.flatmap@npm:^1.3.1":
|
||||
"array.prototype.flatmap@npm:^1.3.1, array.prototype.flatmap@npm:^1.3.2":
|
||||
version: 1.3.2
|
||||
resolution: "array.prototype.flatmap@npm:1.3.2"
|
||||
dependencies:
|
||||
@@ -3465,7 +3465,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"eslint-import-resolver-node@npm:^0.3.7":
|
||||
"eslint-import-resolver-node@npm:^0.3.9":
|
||||
version: 0.3.9
|
||||
resolution: "eslint-import-resolver-node@npm:0.3.9"
|
||||
dependencies:
|
||||
@@ -3521,30 +3521,30 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"eslint-plugin-import@npm:^2.28.1":
|
||||
version: 2.28.1
|
||||
resolution: "eslint-plugin-import@npm:2.28.1"
|
||||
"eslint-plugin-import@npm:^2.29.0":
|
||||
version: 2.29.0
|
||||
resolution: "eslint-plugin-import@npm:2.29.0"
|
||||
dependencies:
|
||||
array-includes: "npm:^3.1.6"
|
||||
array.prototype.findlastindex: "npm:^1.2.2"
|
||||
array.prototype.flat: "npm:^1.3.1"
|
||||
array.prototype.flatmap: "npm:^1.3.1"
|
||||
array-includes: "npm:^3.1.7"
|
||||
array.prototype.findlastindex: "npm:^1.2.3"
|
||||
array.prototype.flat: "npm:^1.3.2"
|
||||
array.prototype.flatmap: "npm:^1.3.2"
|
||||
debug: "npm:^3.2.7"
|
||||
doctrine: "npm:^2.1.0"
|
||||
eslint-import-resolver-node: "npm:^0.3.7"
|
||||
eslint-import-resolver-node: "npm:^0.3.9"
|
||||
eslint-module-utils: "npm:^2.8.0"
|
||||
has: "npm:^1.0.3"
|
||||
is-core-module: "npm:^2.13.0"
|
||||
hasown: "npm:^2.0.0"
|
||||
is-core-module: "npm:^2.13.1"
|
||||
is-glob: "npm:^4.0.3"
|
||||
minimatch: "npm:^3.1.2"
|
||||
object.fromentries: "npm:^2.0.6"
|
||||
object.groupby: "npm:^1.0.0"
|
||||
object.values: "npm:^1.1.6"
|
||||
object.fromentries: "npm:^2.0.7"
|
||||
object.groupby: "npm:^1.0.1"
|
||||
object.values: "npm:^1.1.7"
|
||||
semver: "npm:^6.3.1"
|
||||
tsconfig-paths: "npm:^3.14.2"
|
||||
peerDependencies:
|
||||
eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8
|
||||
checksum: 707dc97f06b12b0f3f91d5248dcea91bcd6a72c1168249a3ba177dd1ab6f31de9d5db829705236207a6ae79ad99a7a03efdfddb4a703da3a85530f9cc7401b2f
|
||||
checksum: d6e8d016f38369892c85b866f762c03dee2b337d4f12031756e30d7490879261d1192a3c2f682fd7c4d2b923465f7a1e3d22cfdad5da1b1391c3bd39ea87af1a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -4198,7 +4198,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"function-bind@npm:^1.1.1":
|
||||
"function-bind@npm:^1.1.1, function-bind@npm:^1.1.2":
|
||||
version: 1.1.2
|
||||
resolution: "function-bind@npm:1.1.2"
|
||||
checksum: 185e20d20f10c8d661d59aac0f3b63b31132d492e1b11fcc2a93cb2c47257ebaee7407c38513efd2b35cafdf972d9beb2ea4593c1e0f3bf8f2744836928d7454
|
||||
@@ -4641,6 +4641,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"hasown@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "hasown@npm:2.0.0"
|
||||
dependencies:
|
||||
function-bind: "npm:^1.1.2"
|
||||
checksum: c330f8d93f9d23fe632c719d4db3d698ef7d7c367d51548b836069e06a90fa9151e868c8e67353cfe98d67865bf7354855db28fa36eb1b18fa5d4a3f4e7f1c90
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"history@npm:^5.3.0":
|
||||
version: 5.3.0
|
||||
resolution: "history@npm:5.3.0"
|
||||
@@ -5001,6 +5010,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"is-core-module@npm:^2.13.1":
|
||||
version: 2.13.1
|
||||
resolution: "is-core-module@npm:2.13.1"
|
||||
dependencies:
|
||||
hasown: "npm:^2.0.0"
|
||||
checksum: d53bd0cc24b0a0351fb4b206ee3908f71b9bbf1c47e9c9e14e5f06d292af1663704d2abd7e67700d6487b2b7864e0d0f6f10a1edf1892864bdffcb197d1845a2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"is-cwebp-readable@npm:^3.0.0":
|
||||
version: 3.0.0
|
||||
resolution: "is-cwebp-readable@npm:3.0.0"
|
||||
@@ -6207,7 +6225,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"object.fromentries@npm:^2.0.6":
|
||||
"object.fromentries@npm:^2.0.6, object.fromentries@npm:^2.0.7":
|
||||
version: 2.0.7
|
||||
resolution: "object.fromentries@npm:2.0.7"
|
||||
dependencies:
|
||||
@@ -6218,7 +6236,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"object.groupby@npm:^1.0.0":
|
||||
"object.groupby@npm:^1.0.1":
|
||||
version: 1.0.1
|
||||
resolution: "object.groupby@npm:1.0.1"
|
||||
dependencies:
|
||||
@@ -6240,7 +6258,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"object.values@npm:^1.1.6":
|
||||
"object.values@npm:^1.1.6, object.values@npm:^1.1.7":
|
||||
version: 1.1.7
|
||||
resolution: "object.values@npm:1.1.7"
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user