Add save button as POC

This commit is contained in:
Luc
2022-06-12 16:51:25 +08:00
parent 59fbed205c
commit 2441efcbfc
4 changed files with 115 additions and 81 deletions

76
package-lock.json generated
View File

@@ -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",

View File

@@ -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

View File

@@ -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

View File

@@ -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 (
<div id="generate">
<h4 class="title">{T("generate")}</h4>
TBD
<pre>{configurationFile}</pre>
<ButtonImg
m2
icon={<Save />}
label={T("Save")}
onclick={() => {
exportFile(configurationFile, "configuration.h")
}}
/>
<br />
</div>
)