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

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