diff --git a/package-lock.json b/package-lock.json index dd96ee2..e472ca4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,7 @@ "next-auth": "^4.2.1", "nodemailer": "^6.7.2", "react": "17.0.2", - "react-dom": "17.0.2", - "three": "^0.137.5" + "react-dom": "17.0.2" }, "devDependencies": { "autoprefixer": "^10.4.0", @@ -4733,11 +4732,6 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, - "node_modules/three": { - "version": "0.137.5", - "resolved": "https://registry.npmjs.org/three/-/three-0.137.5.tgz", - "integrity": "sha512-rTyr+HDFxjnN8+N/guZjDgfVxgHptZQpf6xfL/Mo7a5JYIFwK6tAq3bzxYYB4Ae0RosDZlDuP+X5aXDXz+XnHQ==" - }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -8436,11 +8430,6 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, - "three": { - "version": "0.137.5", - "resolved": "https://registry.npmjs.org/three/-/three-0.137.5.tgz", - "integrity": "sha512-rTyr+HDFxjnN8+N/guZjDgfVxgHptZQpf6xfL/Mo7a5JYIFwK6tAq3bzxYYB4Ae0RosDZlDuP+X5aXDXz+XnHQ==" - }, "through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", diff --git a/package.json b/package.json index 7b05832..c15b2e2 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "build": "next build", "export": "next build && next export", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "deploy": "git pull && next build && pm2 restart kroj" }, "dependencies": { "@supercharge/request-ip": "^1.1.2", @@ -17,8 +18,7 @@ "next-auth": "^4.2.1", "nodemailer": "^6.7.2", "react": "17.0.2", - "react-dom": "17.0.2", - "three": "^0.137.5" + "react-dom": "17.0.2" }, "devDependencies": { "autoprefixer": "^10.4.0", diff --git a/pages/_app.js b/pages/_app.js index df27e64..82c9fef 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -1,5 +1,6 @@ import '../styles/globals.css' import { SessionProvider } from "next-auth/react" +import Head from "next/head"; function MyApp({ Component, @@ -7,6 +8,10 @@ function MyApp({ }) { return ( + + + + ) diff --git a/pages/index.js b/pages/index.js index 6aaaa4f..a1b9416 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,10 +1,10 @@ import Head from "next/head"; import styles from "../styles/Home.module.css"; -import Header from "./templates/header"; -import Generator from "./templates/generator"; -import Nav from "./templates/nav"; -import Content from "./templates/content"; -import Footer from "./templates/footer"; +import Header from "../templates/header"; +import Generator from "../templates/generator"; +import Nav from "../templates/nav"; +import UserTop from "../templates/userTop"; +import Footer from "../templates/footer"; import { useState } from "react"; import { useSession, signIn, signOut } from "next-auth/react"; import { Button } from "evergreen-ui"; @@ -17,26 +17,18 @@ export default function Home() {
Wastpol - - +
-
+
-
); } @@ -45,8 +37,6 @@ export default function Home() {
Wastpol - -

Nie zalogowano

diff --git a/pages/kontakt.js b/pages/kontakt.js index 21dd413..9a1ff54 100644 --- a/pages/kontakt.js +++ b/pages/kontakt.js @@ -1,9 +1,9 @@ import Head from "next/head"; import styles from "../styles/Home.module.css"; -import Header from "./templates/header"; -import Nav from "./templates/nav"; -import Content from "./templates/content"; -import Footer from "./templates/footer"; +import Header from "../templates/header"; +import Nav from "../templates/nav"; +import Content from "../templates/content"; +import Footer from "../templates/footer"; import { useState } from "react"; diff --git a/pages/onas.js b/pages/onas.js index b83e666..e2b5881 100644 --- a/pages/onas.js +++ b/pages/onas.js @@ -1,9 +1,9 @@ import Head from "next/head"; import styles from "../styles/Home.module.css"; -import Header from "./templates/header"; -import Nav from "./templates/nav"; -import Content from "./templates/content"; -import Footer from "./templates/footer"; +import Header from "../templates/header"; +import Nav from "../templates/nav"; +import Content from "../templates/content"; +import Footer from "../templates/footer"; export default function Onas() { return ( @@ -15,6 +15,7 @@ export default function Onas() {
); } diff --git a/pages/templates/footer.js b/pages/templates/footer.js deleted file mode 100644 index 1046793..0000000 --- a/pages/templates/footer.js +++ /dev/null @@ -1,9 +0,0 @@ -import styles from "../../styles/Home.module.css"; - -export default function Footer() { - return ( -
-

-
- ); -} diff --git a/pages/templates/generator.js b/pages/templates/generator.js deleted file mode 100644 index b33c5d2..0000000 --- a/pages/templates/generator.js +++ /dev/null @@ -1,95 +0,0 @@ -import { useState } from "react"; -import { - Pane, - TextInputField, - TextareaField, - Button, - BuildIcon, - toaster, - Alert, -} from "evergreen-ui"; -import axios from "axios"; - -export default function Generator() { - const [profil, setProfil] = useState(); - const [args, setArgs] = useState({ scale: 200 }); - - const parsePreview = (e) => { - // console.log(dxf); - }; - - const py = (e, profil, args) => { - e.preventDefault(); - - axios - .post("/api/spawn", { - profil: profil, - arguments: args, - }) - .then(function (response) { - console.log(response); - if (response.data.toString().startsWith("Py Error")) { - toaster.danger(response.data); - return; - } - toaster.warning(response.data.data); - document.getElementById("down").download = - response.data.filename.toString() + ".dxf"; - document.getElementById("down").click(); - }) - .catch(function (error) { - console.log(error); - }); - }; - return ( -
- - { - console.log(e.target.value); - setProfil(e.target.value); - parsePreview(e); - }} - /> - - { - console.log(e.target.value); - setArgs({ ...args, scale: e.target.value }); - }} - /> - - - - - {" "} - -
- ); -} diff --git a/pages/templates/content.js b/templates/content.js similarity index 92% rename from pages/templates/content.js rename to templates/content.js index c49e1f9..a0e3372 100644 --- a/pages/templates/content.js +++ b/templates/content.js @@ -1,4 +1,4 @@ -import styles from "../../styles/Home.module.css"; +import styles from "../styles/Home.module.css"; export default function Content() { return ( diff --git a/templates/footer.js b/templates/footer.js new file mode 100644 index 0000000..1274275 --- /dev/null +++ b/templates/footer.js @@ -0,0 +1,111 @@ +export default function Footer({ path }) { + const getPath = (e, path) => { + let newLines = []; + + for (let line of path.split("\n")) { + if (line[0] == "P") continue; + if (line[0] == "S") continue; + if (line[0] == "X") continue; + + newLines.push(line); + } + let xs = []; + let ys = []; + let zs = []; + let toti = 0; + let al = 0; + for (let line of newLines) { + al +=1; + let theLine = line.split(","); + //console.log(theLine) + if ( + xs && + parseFloat(theLine[0]) == xs[-1] && + parseFloat(theLine[1]) == ys[-1] + ) + continue; + + if (al > 2) { + let dist = ((xs[xs.length-1] - xs[xs.length-2]) ** 2 + (ys[ys.length-1] - ys[ys.length-2]) ** 2) ** 0.5; + toti += Math.round(dist); + } + xs.push(parseFloat(theLine[0])); + ys.push(parseFloat(theLine[1])); + zs.push(parseFloat(theLine[2])); + } + let prevLine = ["0", "0", "0"]; + let scaleFactor = 100000 / 2000; + const canvas = document.getElementById("canvas"); + + if (!canvas.getContext) { + console.log("canvas err"); + return; + } + + const ctx = canvas.getContext("2d"); + + // set line stroke and line width + ctx.strokeStyle = "red"; + ctx.lineWidth = 2; + let totalH = Math.max(...zs); + let minH = Math.min(...zs); + for (let line = 0; line < xs.length - 1; line++) { + let theLine = [xs[line], ys[line], zs[line]]; + let x = parseFloat(theLine[0]) - parseFloat(prevLine[0]); + let y = parseFloat(theLine[1]) - parseFloat(prevLine[1]); + let x1 = line * scaleFactor; + let y1 = zs[line]; + let x2 = (line + 1) * scaleFactor; + let y2 = zs[line + 1]; + //console.log(x1, y1, x2, y2); + let b0 = 0; + let b1 = 500; + let z1 = b0 + (b1 - b0) * ((y1 - totalH) / (minH - totalH)); + let z2 = b0 + (b1 - b0) * ((y2 - totalH) / (minH - totalH)); + + //b0 + (b1 - b0) * ((x1-0)/(toti*scaleFactor-0)); + let x12 = b0 + (b1 - b0) * ((x1 - 0) / (toti*scaleFactor)); + let x22 = b0 + (b1 - b0) * ((x2 - 0) / (toti*scaleFactor)); + console.log(x12); + + ctx.beginPath(); + ctx.moveTo(x12, z1); + ctx.lineTo(x22, z2); + ctx.stroke(); + } + }; + const draw = (e) => { + //getPath(path); + const canvas = document.getElementById("canvas"); + + if (!canvas.getContext) { + return; + } + + const ctx = canvas.getContext("2d"); + + // set line stroke and line width + ctx.strokeStyle = "red"; + ctx.lineWidth = 2; + + // draw a red line + ctx.beginPath(); + ctx.moveTo(234, 100); + ctx.lineTo(234, 105); + ctx.stroke(); + }; + //draw() + return ( + <> + + + + ); +} diff --git a/templates/generator.js b/templates/generator.js new file mode 100644 index 0000000..81e1c10 --- /dev/null +++ b/templates/generator.js @@ -0,0 +1,183 @@ +import { useState } from "react"; +import { + Pane, + TextInputField, + TextareaField, + Button, + BuildIcon, + toaster, + Alert, +} from "evergreen-ui"; +import axios from "axios"; +import Footer from "./footer"; + +export default function Generator() { + const [profil, setProfil] = useState(); + const [args, setArgs] = useState({ scale: 200 }); + + const getPath = (e, path) => { + let newLines = []; + + for (let line of path.split("\n")) { + if (line[0] == "P") continue; + if (line[0] == "S") continue; + if (line[0] == "X") continue; + + newLines.push(line); + } + let xs = []; + let ys = []; + let zs = []; + let toti = 0; + let al = 0; + for (let line of newLines) { + al += 1; + let theLine = line.split(","); + //console.log(theLine) + if ( + xs && + parseFloat(theLine[0]) == xs[-1] && + parseFloat(theLine[1]) == ys[-1] + ) + continue; + + if (al > 2) { + let dist = + ((xs[xs.length - 1] - xs[xs.length - 2]) ** 2 + + (ys[ys.length - 1] - ys[ys.length - 2]) ** 2) ** + 0.5; + toti += Math.round(dist); + } + xs.push(parseFloat(theLine[0])); + ys.push(parseFloat(theLine[1])); + zs.push(parseFloat(theLine[2])); + } + let prevLine = ["0", "0", "0"]; + let scaleFactor = 100000 / 2000; + const canvas = document.getElementById("canvas"); + + if (!canvas.getContext) { + console.log("canvas err"); + toaster.warning("canvas err"); + return; + } + + const ctx = canvas.getContext("2d"); + ctx.clearRect(0, 0, 600, 600); + + // set line stroke and line width + ctx.strokeStyle = "red"; + ctx.lineWidth = 2; + let totalH = Math.max(...zs); + let minH = Math.min(...zs); + for (let line = 0; line < xs.length - 1; line++) { + let theLine = [xs[line], ys[line], zs[line]]; + let x = parseFloat(theLine[0]) - parseFloat(prevLine[0]); + let y = parseFloat(theLine[1]) - parseFloat(prevLine[1]); + let x1 = line * scaleFactor; + let y1 = zs[line]; + let x2 = (line + 1) * scaleFactor; + let y2 = zs[line + 1]; + //console.log(x1, y1, x2, y2); + let b0 = 0; + let b1 = 500; + let z1 = b0 + (b1 - b0) * ((y1 - totalH) / (minH - totalH)); + let z2 = b0 + (b1 - b0) * ((y2 - totalH) / (minH - totalH)); + + //b0 + (b1 - b0) * ((x1-0)/(toti*scaleFactor-0)); + let x12 = b0 + (b1 - b0) * ((x1 - 0) / (toti * scaleFactor)); + let x22 = b0 + (b1 - b0) * ((x2 - 0) / (toti * scaleFactor)); + //console.log(x12); + + ctx.beginPath(); + ctx.moveTo(x12, z1); + ctx.lineTo(x22, z2); + ctx.stroke(); + } + }; + + const parsePreview = (e) => { + // console.log(dxf); + }; + + const py = (e, profil, args) => { + e.preventDefault(); + + axios + .post("/api/spawn", { + profil: profil, + arguments: args, + }) + .then(function (response) { + console.log(response); + if (response.data.toString().startsWith("Py Error")) { + toaster.danger(response.data); + return; + } + toaster.warning(response.data.data); + document.getElementById("down").download = + response.data.filename.toString() + ".dxf"; + document.getElementById("down").click(); + }) + .catch(function (error) { + console.log(error); + }); + }; + return ( +
+
+ + { + //console.log(e.target.value); + setProfil(e.target.value); + parsePreview(e); + getPath(e, e.target.value); + }} + /> + + { + console.log(e.target.value); + setArgs({ ...args, scale: e.target.value }); + }} + /> + + + + + {" "} + +
+ + + +
+ ); +} diff --git a/pages/templates/header.js b/templates/header.js similarity index 80% rename from pages/templates/header.js rename to templates/header.js index fba2117..24d29cb 100644 --- a/pages/templates/header.js +++ b/templates/header.js @@ -1,4 +1,3 @@ -import styles from "../../styles/Home.module.css"; import { Pane, Heading } from "evergreen-ui"; export default function Header() { diff --git a/pages/templates/nav.js b/templates/nav.js similarity index 100% rename from pages/templates/nav.js rename to templates/nav.js diff --git a/templates/userTop.js b/templates/userTop.js new file mode 100644 index 0000000..341104d --- /dev/null +++ b/templates/userTop.js @@ -0,0 +1,15 @@ +import { Pane, Button } from "evergreen-ui"; +import { signOut } from "next-auth/react"; + +export default function UserTop({session}) { + return ( + +

+ Zalogowano jako {session.user.email} +

+ +
+ ); +}