i think i fixed a bug...
This commit is contained in:
13
package-lock.json
generated
13
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 (
|
||||
<SessionProvider session={session}>
|
||||
<Head>
|
||||
<meta name="description" content="Wastpol" />
|
||||
<link rel="icon" href="/icon.png" />
|
||||
</Head>
|
||||
<Component {...pageProps} />
|
||||
</SessionProvider>
|
||||
)
|
||||
|
||||
@@ -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() {
|
||||
<div className={styles.container}>
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
<meta name="description" content="Wastpol" />
|
||||
<link rel="icon" href="/icon.png" />
|
||||
</Head>
|
||||
|
||||
<div className="flex justify-between">
|
||||
<Nav />
|
||||
<div className="flex">
|
||||
<h3 className="px-3 py-2 place-self-end">
|
||||
Zalogowano jako {session.user.email}
|
||||
</h3>
|
||||
<Button onClick={() => signOut()} className="place-self-end">
|
||||
Wyloguj
|
||||
</Button>
|
||||
</div>
|
||||
<UserTop session={session} />
|
||||
</div>
|
||||
|
||||
<main className={styles.main}>
|
||||
<main className="flex flex-1 flex-col justify-center items-center p-8 mx-auto mt-24 rounded-md shadow-md transition-all duration-500 hover:shadow-xl">
|
||||
<Header />
|
||||
<Generator />
|
||||
</main>
|
||||
<Footer />
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -45,8 +37,6 @@ export default function Home() {
|
||||
<div className="grid place-items-center h-screen">
|
||||
<Head>
|
||||
<title>Wastpol</title>
|
||||
<meta name="description" content="Wastpol" />
|
||||
<link rel="icon" href="/icon.png" />
|
||||
</Head>
|
||||
<div className="flex flex-col justify-center">
|
||||
<h2 className="p-2">Nie zalogowano</h2>
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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() {
|
||||
</Head>
|
||||
|
||||
<Nav />
|
||||
<Footer />
|
||||
<main className={styles.main}>
|
||||
<p className="font-bold">
|
||||
Głównym profilem działalności firmy jest projektowanie instalacji
|
||||
@@ -29,7 +30,7 @@ export default function Onas() {
|
||||
terminach realizacji.
|
||||
</p>
|
||||
</main>
|
||||
<Footer />
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import styles from "../../styles/Home.module.css";
|
||||
|
||||
export default function Footer() {
|
||||
return (
|
||||
<div>
|
||||
<p></p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="flex flex-col">
|
||||
<Pane width={480}>
|
||||
<TextareaField
|
||||
id="textarea-1"
|
||||
label="Dane z Geoportalu:"
|
||||
placeholder="Próbkowanie: 1 ..."
|
||||
onChange={(e) => {
|
||||
console.log(e.target.value);
|
||||
setProfil(e.target.value);
|
||||
parsePreview(e);
|
||||
}}
|
||||
/>
|
||||
|
||||
<TextInputField
|
||||
label="Skala:"
|
||||
placeholder="200"
|
||||
width={100}
|
||||
onChange={(e) => {
|
||||
console.log(e.target.value);
|
||||
setArgs({ ...args, scale: e.target.value });
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
marginY={8}
|
||||
marginRight={12}
|
||||
appearance="default"
|
||||
iconAfter={BuildIcon}
|
||||
onClick={(e) => {
|
||||
if (document.getElementById("textarea-1").value == "") {
|
||||
toaster.danger("Pole danych nie może być puste");
|
||||
} else if (
|
||||
!document
|
||||
.getElementById("textarea-1")
|
||||
.value.startsWith("Próbkowanie")
|
||||
) {
|
||||
toaster.danger("Błędne dane");
|
||||
} else {
|
||||
py(e, profil, args);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Generuj
|
||||
</Button>
|
||||
</Pane>
|
||||
|
||||
<a href="test.dxf" download="test.dxf" id="down">
|
||||
{" "}
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import styles from "../../styles/Home.module.css";
|
||||
import styles from "../styles/Home.module.css";
|
||||
|
||||
export default function Content() {
|
||||
return (
|
||||
111
templates/footer.js
Normal file
111
templates/footer.js
Normal file
@@ -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 (
|
||||
<>
|
||||
<canvas id="canvas" height="600" width="600"></canvas>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
//draw();
|
||||
getPath(e, path);
|
||||
}}
|
||||
>
|
||||
Rys
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
183
templates/generator.js
Normal file
183
templates/generator.js
Normal file
@@ -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 (
|
||||
<div className="flex">
|
||||
<div className="flex flex-col">
|
||||
<Pane width={480}>
|
||||
<TextareaField
|
||||
id="textarea-1"
|
||||
label="Dane z Geoportalu:"
|
||||
placeholder="Próbkowanie: 1 ..."
|
||||
onChange={(e) => {
|
||||
//console.log(e.target.value);
|
||||
setProfil(e.target.value);
|
||||
parsePreview(e);
|
||||
getPath(e, e.target.value);
|
||||
}}
|
||||
/>
|
||||
|
||||
<TextInputField
|
||||
label="Skala:"
|
||||
placeholder="200"
|
||||
width={100}
|
||||
onChange={(e) => {
|
||||
console.log(e.target.value);
|
||||
setArgs({ ...args, scale: e.target.value });
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
marginY={8}
|
||||
marginRight={12}
|
||||
appearance="default"
|
||||
iconAfter={BuildIcon}
|
||||
onClick={(e) => {
|
||||
if (document.getElementById("textarea-1").value == "") {
|
||||
toaster.danger("Pole danych nie może być puste");
|
||||
} else if (
|
||||
!document
|
||||
.getElementById("textarea-1")
|
||||
.value.startsWith("Próbkowanie")
|
||||
) {
|
||||
toaster.danger("Błędne dane");
|
||||
} else {
|
||||
py(e, profil, args);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Generuj
|
||||
</Button>
|
||||
</Pane>
|
||||
|
||||
<a href="test.dxf" download="test.dxf" id="down">
|
||||
{" "}
|
||||
</a>
|
||||
</div>
|
||||
<Pane className="mx-2 shadow-md rounded-md">
|
||||
<canvas className="mx-2" id="canvas" height="600" width="600"></canvas>
|
||||
</Pane>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import styles from "../../styles/Home.module.css";
|
||||
import { Pane, Heading } from "evergreen-ui";
|
||||
|
||||
export default function Header() {
|
||||
15
templates/userTop.js
Normal file
15
templates/userTop.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Pane, Button } from "evergreen-ui";
|
||||
import { signOut } from "next-auth/react";
|
||||
|
||||
export default function UserTop({session}) {
|
||||
return (
|
||||
<Pane display="flex">
|
||||
<h3 className="px-3 py-2 place-self-end">
|
||||
Zalogowano jako {session.user.email}
|
||||
</h3>
|
||||
<Button onClick={() => signOut()} className="place-self-end">
|
||||
Wyloguj
|
||||
</Button>
|
||||
</Pane>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user