This commit is contained in:
2022-02-17 14:01:07 +01:00
commit d13bee1395
30 changed files with 11302 additions and 0 deletions

15
pages/_app.js Normal file
View File

@@ -0,0 +1,15 @@
import '../styles/globals.css'
import { SessionProvider } from "next-auth/react"
function MyApp({
Component,
pageProps: { session, ...pageProps },
}) {
return (
<SessionProvider session={session}>
<Component {...pageProps} />
</SessionProvider>
)
}
export default MyApp

24
pages/api/contact.js Normal file
View File

@@ -0,0 +1,24 @@
export default function (req, res) {
let nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
port: 465,
host: "",
auth: {
user: "",
pass: "",
},
secure: true,
});
const mailData = {
from: "",
to: "",
subject: `Message From ${req.body.name}`,
text: req.body.message,
html: <div>{req.body.message}</div>,
};
transporter.sendMail(mailData, function (err, info) {
if (err) console.log(err);
else console.log(info);
});
console.log(req.body);
}

22
pages/api/hello.js Normal file
View File

@@ -0,0 +1,22 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
let len = 123; //
let przekroj = 35; //
let threephase = 2; //
let resistance = len / (przekroj * 35);
let moc = threephase * 7;
let wsp = 0.59; ///
let kom = 0;
let wspplus = moc * wsp + kom;
let Uodc = (wspplus / (3 * 230)) * 1000;
let spadek = Uodc * resistance;
console.log(spadek);
let a = [
1, 0.59, 0.45, 0.38, 0.34, 0.31, 0.29, 0.27, 0.26, 0.25, 0.232, 0.217, 0.208,
0.193, 0.183, 0.175, 0.168, 0.161, 0.155, 0.15, 0.145, 0.141, 0.137, 0.133,
0.13, 0.127, 0.124, 0.121, 0.119, 0.117, 0.115, 0.113, 0.111, 0.109, 0.107,
0.105, 0.104, 0.103, 0.101, 0.1, 0.1,
];

38
pages/api/spawn.js Normal file
View File

@@ -0,0 +1,38 @@
import { spawn } from "child_process";
export default function (req, res) {
console.log("spawnin");
//console.log(req.body);
//file
let textData = req.body.profil;
let replacedData = textData.replace("<22>", "o").replace("<22>", "e");
console.log(replacedData);
var fs = require("fs");
fs.writeFile("P.txt", replacedData, function (err) {
if (err) {
return console.error(err);
}
});
//py
const python = spawn("python3", ["a.py"]);
let dataToSend;
python.stdout.on("data", function (data) {
console.log("Pipe data from python script ...");
dataToSend = data.toString();
//console.log(dataToSend)
});
python.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
// in close event we are sure that stream from child process is closed
python.on("close", (code) => {
console.log(`child process close all stdio with code ${code}`);
// send data to browser
console.log(dataToSend);
console.log("done");
res.send("dataToSend");
});
}

97
pages/index.js Normal file
View File

@@ -0,0 +1,97 @@
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 { useState } from "react";
import { useSession, signIn, signOut } from "next-auth/react";
export default function Home() {
const { data: session } = useSession();
const [profil, setProfil] = useState();
const py = (e, profil) => {
e.preventDefault();
fetch("/api/spawn", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify({ profil: profil }),
}).then((res) => {
console.log("data from api: ", res);
document.getElementById("down").click();
});
};
if (session) {
return (
<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="p-2 bg-slate-200 rounded-md place-self-end"
>
Wyloguj
</button>
</div>
</div>
<main className={styles.main}>
<Header />
<textarea
id="profil"
className="bg-gray-100 h-96 w-96"
onChange={(e) => {
console.log(e.target.value);
setProfil(e.target.value);
}}
></textarea>
<button
onClick={(e) => {
py(e, profil);
}}
>
Generuj
</button>
<a href="test.dxf" download="test.dxf" id="down">
{" "}
</a>
</main>
<Footer />
</div>
);
}
return (
<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 justify-center">
<h2 className="p-2">Nie zalogowano</h2>
<br></br>
<button
onClick={() => signIn()}
className="p-2 bg-slate-200 rounded-md"
>
Zaloguj
</button>
</div>
</div>
);
}

74
pages/kontakt.js Normal file
View File

@@ -0,0 +1,74 @@
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 { useState } from "react";
export default function Kontakt() {
const [name, setName] = useState("");
const [email, setEmail] = useState("");
const [message, setMessage] = useState("");
const [submitted, setSubmitted] = useState(false);
const handleSubmit = (e) => {
e.preventDefault()
console.log('Sending')
let data = {
name,
email,
message
}
fetch('/api/contact', {
method: 'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then((res) => {
console.log('Response received')
if (res.status === 200) {
console.log('Response succeeded!')
setSubmitted(true)
setName('')
setEmail('')
setBody('')
}
})
}
return (
<div className={styles.container}>
<Head>
<title>Wastpol</title>
<meta name="description" content="Wastpol" />
<link rel="icon" href="/icon.png" />
</Head>
<Nav />
<main className={styles.main}>
<div className={styles.container}>
<form className={styles.main}>
<formGroup className={styles.inputGroup}>
<label htmlFor="name">Imię</label>
<input type="text" name="name" onChange={(e)=>{setName(e.target.value)}} className={styles.inputField} />
</formGroup>
<formGroup className={styles.inputGroup}>
<label htmlFor="email">Email</label>
<input type="email" name="email" onChange={(e)=>{setEmail(e.target.value)}} className={styles.inputField} />
</formGroup>
<formGroup className={styles.inputGroup}>
<label htmlFor="message">Wiadomość</label>
<input type="text" name="message" onChange={(e)=>{setMessage(e.target.value)}} className={styles.inputField} />
</formGroup>
<input type="submit" onClick={(e)=>{handleSubmit(e)}} />
</form>
</div>
</main>
<Footer />
</div>
);
}

35
pages/onas.js Normal file
View File

@@ -0,0 +1,35 @@
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";
export default function Onas() {
return (
<div className={styles.container}>
<Head>
<title>Wastpol</title>
<meta name="description" content="Wastpol" />
<link rel="icon" href="/icon.png" />
</Head>
<Nav />
<main className={styles.main}>
<p className="font-bold">
Głównym profilem działalności firmy jest projektowanie instalacji
elektrycznych oraz nadzór. Świadczymy również usługi w zakresie
audytów instalacji elektrycznych, umożliwiających wskazanie
konkretnych rozwiązań technicznych.
</p>
<p>
Jako projektanci posiadający wieloletnie doświadczenie, potwierdzone
odpowiednimi uprawnieniami, możemy Państwu zapewnić wykonywanie
projektów na najwyższym poziomie technicznym i w zadowalających
terminach realizacji.
</p>
</main>
<Footer />
</div>
);
}

View File

@@ -0,0 +1,33 @@
import styles from "../../styles/Home.module.css";
export default function Content() {
return (
<div>
<p className={styles.description}>
Lokalizacja
<br />
<b>Nowy Sącz, Aleje Wolności 6</b>
</p>
<p className={styles.description}>
Telefon kontaktowy
<br />
<b>
<a href="tel:+48504066513">+48 504 066 513</a>
</b>
<br />
<b>
<a href="tel:184420244">18 442 02 44</a>
</b>
</p>
<p className={styles.description}>
Adres email
<br />
<b>
<a href="mailto:biuro@wastpol.pl">biuro@wastpol.pl</a>
</b>
</p>
</div>
);
}

View File

@@ -0,0 +1,9 @@
import styles from "../../styles/Home.module.css";
export default function Footer() {
return (
<div>
<p></p>
</div>
);
}

View File

@@ -0,0 +1,9 @@
import styles from "../../styles/Home.module.css";
export default function Header() {
return (
<div>
<h1 className="text-3xl p-6">Generuj profil przekroju terenu</h1>
</div>
);
}

19
pages/templates/nav.js Normal file
View File

@@ -0,0 +1,19 @@
import Link from "next/link";
export default function Nav() {
return (
<div className="flex">
<Link href="/">
<h2 className="px-2 place-self-center">
<img src="logo.png" className="h-12" />
</h2>
</Link>
<Link href="/onas">
<h3 className="px-3 py-2 place-self-end">O nas</h3>
</Link>
<Link href="/kontakt">
<h3 className="px-3 py-2 place-self-end">Kontakt</h3>
</Link>
</div>
);
}