From 2441efcbfc8a80dcadd18d8d2fa4e84fd382b67d Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Sun, 12 Jun 2022 16:51:25 +0800 Subject: [PATCH] Add save button as POC --- package-lock.json | 76 ++----------------------------------- src/tabs/generate/footer.js | 25 ++++++++++++ src/tabs/generate/header.js | 47 +++++++++++++++++++++++ src/tabs/generate/index.js | 48 ++++++++++++++++++----- 4 files changed, 115 insertions(+), 81 deletions(-) create mode 100644 src/tabs/generate/footer.js create mode 100644 src/tabs/generate/header.js diff --git a/package-lock.json b/package-lock.json index 300740d..5d67b58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,16 @@ { - "name": "ESP3D-WEBUI", - "version": "3.0.0", + "name": "ESP3D-Configurator", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "ESP3D-WEBUI", - "version": "3.0.0", + "name": "ESP3D-Configurator", + "version": "1.0.0", "license": "ISC", "dependencies": { "preact": "^10.6.6", "preact-feather": "^4.2.1", - "smoothie": "^1.35.0", "spectre.css": "luc-github/spectre" }, "devDependencies": { @@ -31,7 +30,6 @@ "express": "^4.17.1", "express-fileupload": "^1.2.1", "express-static-gzip": "^2.1.1", - "express-ws": "^4.0.0", "gzipper": "^6.0.0", "html-inline-css-webpack-plugin": "^1.11.1", "html-inline-script-webpack-plugin": "^1.1.4", @@ -3659,12 +3657,6 @@ "lodash": "^4.17.14" } }, - "node_modules/async-limiter": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", - "dev": true - }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -5463,30 +5455,6 @@ "serve-static": "^1.14.1" } }, - "node_modules/express-ws": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/express-ws/-/express-ws-4.0.0.tgz", - "integrity": "sha512-KEyUw8AwRET2iFjFsI1EJQrJ/fHeGiJtgpYgEWG3yDv4l/To/m3a2GaYfeGyB3lsWdvbesjF5XCMx+SVBgAAYw==", - "dev": true, - "dependencies": { - "ws": "^5.2.0" - }, - "engines": { - "node": ">=4.5.0" - }, - "peerDependencies": { - "express": "^4.0.0 || ^5.0.0-alpha.1" - } - }, - "node_modules/express-ws/node_modules/ws": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.3.tgz", - "integrity": "sha512-jZArVERrMsKUatIdnLzqvcfydI85dvd/Fp1u/VOpfdDWQ4c9qWXe+VIeAbQ5FrDwciAkr+lzofXLz3Kuf26AOA==", - "dev": true, - "dependencies": { - "async-limiter": "~1.0.0" - } - }, "node_modules/express/node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", @@ -9389,11 +9357,6 @@ "node": ">=8" } }, - "node_modules/smoothie": { - "version": "1.35.0", - "resolved": "https://registry.npmjs.org/smoothie/-/smoothie-1.35.0.tgz", - "integrity": "sha512-tA+p9hDOeLOkETO6HyTgo3ZzGF2mHOGS+Vbc9d9M/iHMlSIsQvVJYuOBIYW21naaAi+eU1NxvVDQ8V9UM56hvQ==" - }, "node_modules/sockjs": { "version": "0.3.24", "resolved": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.24.tgz", @@ -13916,12 +13879,6 @@ "lodash": "^4.17.14" } }, - "async-limiter": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", - "dev": true - }, "available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -15330,26 +15287,6 @@ "serve-static": "^1.14.1" } }, - "express-ws": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/express-ws/-/express-ws-4.0.0.tgz", - "integrity": "sha512-KEyUw8AwRET2iFjFsI1EJQrJ/fHeGiJtgpYgEWG3yDv4l/To/m3a2GaYfeGyB3lsWdvbesjF5XCMx+SVBgAAYw==", - "dev": true, - "requires": { - "ws": "^5.2.0" - }, - "dependencies": { - "ws": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.3.tgz", - "integrity": "sha512-jZArVERrMsKUatIdnLzqvcfydI85dvd/Fp1u/VOpfdDWQ4c9qWXe+VIeAbQ5FrDwciAkr+lzofXLz3Kuf26AOA==", - "dev": true, - "requires": { - "async-limiter": "~1.0.0" - } - } - } - }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -18239,11 +18176,6 @@ "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true }, - "smoothie": { - "version": "1.35.0", - "resolved": "https://registry.npmjs.org/smoothie/-/smoothie-1.35.0.tgz", - "integrity": "sha512-tA+p9hDOeLOkETO6HyTgo3ZzGF2mHOGS+Vbc9d9M/iHMlSIsQvVJYuOBIYW21naaAi+eU1NxvVDQ8V9UM56hvQ==" - }, "sockjs": { "version": "0.3.24", "resolved": "https://registry.npmjs.org/sockjs/-/sockjs-0.3.24.tgz", diff --git a/src/tabs/generate/footer.js b/src/tabs/generate/footer.js new file mode 100644 index 0000000..435265d --- /dev/null +++ b/src/tabs/generate/footer.js @@ -0,0 +1,25 @@ +/* + index.js - ESP3D WebUI navigation tab file + + Copyright (c) 2020 Luc Lebosse. All rights reserved. + + This code is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with This code; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +import { h } from "preact" +const footer = "\n\ +\n\ +#endif //_CONFIGURATION_H\n" + +export default footer diff --git a/src/tabs/generate/header.js b/src/tabs/generate/header.js new file mode 100644 index 0000000..a1d84f0 --- /dev/null +++ b/src/tabs/generate/header.js @@ -0,0 +1,47 @@ +/* + index.js - ESP3D WebUI navigation tab file + + Copyright (c) 2020 Luc Lebosse. All rights reserved. + + This code is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with This code; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +import { h } from "preact" +const header = + "\n\ +/*\n\ + configuration.h - ESP3D configuration file\n\ +\n\ + Copyright (c) 2014 Luc Lebosse. All rights reserved.\n\ +\n\ + This code is free software; you can redistribute it and/or\n\ + modify it under the terms of the GNU Lesser General Public\n\ + License as published by the Free Software Foundation; either\n\ + version 2.1 of the License, or (at your option) any later version.\n\ +\n\ + This code is distributed in the hope that it will be useful,\n\ + but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n\ + Lesser General Public License for more details.\n\ +\n\ + You should have received a copy of the GNU Lesser General Public\n\ + License along with This code; if not, write to the Free Software\n\ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n\ +*/\n\ +#ifndef _CONFIGURATION_H\n\ +#define _CONFIGURATION_H\n\ +\n\ +" + +export default header diff --git a/src/tabs/generate/index.js b/src/tabs/generate/index.js index 65bb430..1e1ef4d 100644 --- a/src/tabs/generate/index.js +++ b/src/tabs/generate/index.js @@ -20,21 +20,51 @@ import { Fragment, h } from "preact" import { T } from "../../components/Translations" -import { - useUiContext, -} from "../../contexts" +import { ButtonImg } from "../../components/Controls" +import { Save } from "preact-feather" +import { useDatasContext, useUiContext } from "../../contexts" +import header from "./header" +import footer from "./footer" + +const configurationFile = header + "Configuration file" + footer + +const exportFile = (filecontent, filename) => { + const file = new Blob([filecontent], { + type: "application/txt", + }) + if (window.navigator.msSaveOrOpenBlob) + // IE10+ + window.navigator.msSaveOrOpenBlob(file, filename) + else { + // Others + const a = document.createElement("a") + const url = URL.createObjectURL(file) + a.href = url + a.download = filename + document.body.appendChild(a) + a.click() + setTimeout(function () { + document.body.removeChild(a) + window.URL.revokeObjectURL(url) + }, 0) + } +} const GenerateTab = () => { - - - console.log("generate") + return (
- -

{T("generate")}

- TBD +
{configurationFile}
+ } + label={T("Save")} + onclick={() => { + exportFile(configurationFile, "configuration.h") + }} + />
)