Skip to content

Commit 177caa6

Browse files
committed
Add wood document generation
1 parent 0f48901 commit 177caa6

File tree

9 files changed

+261
-14
lines changed

9 files changed

+261
-14
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"symfony/validator": "^6.3"
2020
},
2121
"require-dev": {
22-
"symfony/var-dumper": "^6.2",
22+
"symfony/var-dumper": "^6.4",
2323
"friendsofphp/php-cs-fixer": "^3.16",
2424
"phpunit/phpunit": "^10.3",
2525
"mockery/mockery": "^1.6"

composer.lock

+13-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/css/main-23-09-11.css public/assets/css/main-24-09-08.css

+16
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,19 @@ a:hover {
151151
text-align: center;
152152
opacity: 0.6;
153153
}
154+
155+
.wood-form {
156+
width: 100%;
157+
border: 1px dashed gray;
158+
border-radius: 7px;
159+
border-collapse: separate !important;
160+
margin-bottom: 1.5rem;
161+
}
162+
163+
.wood-form td {
164+
padding: 0.8rem;
165+
}
166+
167+
.wood-form .btn-danger {
168+
width: 100%;
169+
}

public/index.php

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exan\Landviz\Controllers\ErrorController;
66
use Exan\Landviz\Controllers\FuckController;
77
use Exan\Landviz\Controllers\HomeController;
8+
use Exan\Landviz\Controllers\WoodController;
89
use HttpSoft\Emitter\SapiEmitter;
910
use HttpSoft\ServerRequest\ServerRequestCreator;
1011
use League\Route\Router;
@@ -29,6 +30,9 @@
2930

3031
$router->map('GET', '/dependencies', [DependencyController::class, 'index']);
3132

33+
$router->map('GET', '/wood', [WoodController::class, 'form']);
34+
$router->map('GET', '/wood/document', [WoodController::class, 'document']);
35+
3236
$request = ServerRequestCreator::createFromGlobals();
3337

3438
try {

src/Controllers/WoodController.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Exan\Landviz\Controllers;
4+
5+
use Exan\Config\Config;
6+
use Exan\Landviz\ResponseBuilder;
7+
use Psr\Http\Message\RequestInterface;
8+
use Psr\Http\Message\ResponseInterface;
9+
10+
class WoodController extends Controller
11+
{
12+
public function __construct(
13+
private readonly ResponseBuilder $responseBuilder,
14+
private readonly Config $config,
15+
) {
16+
}
17+
18+
public function form(RequestInterface $request): ResponseInterface
19+
{
20+
return $this->responseBuilder->build($request, 'pages/wood/form', [], false);
21+
}
22+
23+
public function document(RequestInterface $request)
24+
{
25+
$parts = array_map(fn (string $name, string $width, string $height, string $thickness, string $amount) => [
26+
'name' => $name,
27+
'width' => $width,
28+
'height' => $height,
29+
'thickness' => $thickness,
30+
'amount' => $amount,
31+
], $_GET['n'], $_GET['w'], $_GET['h'], $_GET['t'], $_GET['a']);
32+
33+
return $this->responseBuilder->build($request, 'pages/wood/document', ['parts' => $parts], false);
34+
}
35+
}

templates/base.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
1616

17-
<link rel="stylesheet" href="public/assets/css/main-23-09-11.css">
17+
<link rel="stylesheet" href="public/assets/css/main-24-09-08.css">
1818

1919
<link rel="icon" type="image/x-icon" href="public/assets/img/favicon.ico">
2020

templates/pages/wood/document.php

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
/**
4+
* @var \League\Plates\Template\Template $this
5+
*/
6+
7+
?>
8+
9+
<!DOCTYPE html>
10+
<html lang="en">
11+
12+
<head>
13+
<meta charset="UTF-8">
14+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
15+
<title>Document</title>
16+
<style>
17+
html {
18+
font-size: 5px;
19+
}
20+
21+
span {
22+
margin-bottom: 20px;
23+
}
24+
25+
div {
26+
font-size: 15px;
27+
}
28+
29+
table th {
30+
text-align: right;
31+
padding-right: 10px;
32+
padding-left: 20px;
33+
}
34+
35+
.wood {
36+
background: repeating-linear-gradient(45deg,
37+
/* Angle of the stripes */
38+
lightgray,
39+
/* Color of the stripes */
40+
lightgray 10px,
41+
/* End of the stripe */
42+
#ffffff 10px,
43+
/* Start of the space between stripes */
44+
#ffffff 20px
45+
/* End of the space between stripes */
46+
);
47+
48+
border: 1px solid black;
49+
}
50+
</style>
51+
</head>
52+
53+
<body>
54+
<div>
55+
<table>
56+
<?php foreach ($parts as $part) : ?>
57+
<tr>
58+
<td colspan="2"><b><?= $part['name'] ?></b></td>
59+
</tr>
60+
<tr>
61+
<td>
62+
<div class="wood" style="height: <?= $part['height'] ?>rem; width: <?= $part['width'] ?>rem;">
63+
</div>
64+
</td>
65+
<td>
66+
<table>
67+
<tr>
68+
<th>
69+
Height
70+
</th>
71+
<td>
72+
<?= $part['height'] ?>cm
73+
</td>
74+
</tr>
75+
<tr>
76+
<th>
77+
Width
78+
</th>
79+
<td>
80+
<?= $part['width'] ?>cm
81+
</td>
82+
</tr>
83+
<tr>
84+
<th>
85+
Thickness
86+
</th>
87+
<td>
88+
<?= $part['thickness'] ?>mm
89+
</td>
90+
</tr>
91+
<tr>
92+
<td colspan="2">&nbsp;</td>
93+
</tr>
94+
<tr>
95+
<th>
96+
Amount
97+
</th>
98+
<td>
99+
<?= $part['amount'] ?>
100+
</td>
101+
</tr>
102+
</table>
103+
</td>
104+
</tr>
105+
<tr>
106+
<td colspan="2">&nbsp;</td>
107+
</tr>
108+
<?php endforeach ?>
109+
</table>
110+
</div>
111+
</body>
112+
113+
</html>

templates/pages/wood/form.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* @var \League\Plates\Template\Template $this
5+
*/
6+
7+
?>
8+
9+
<?php $this->layout('content-page') ?>
10+
11+
<?php $this->start('main') ?>
12+
13+
<div class="px-md-5 mb-5">
14+
<div class="container px-md-5 text-center">
15+
<h1>Wood cutting list</h1>
16+
<p>
17+
Input dimensions of your parts.
18+
Height and width should be in CM, thickness should be in MM.
19+
</p>
20+
21+
<button id="add-input" class="btn btn-success">
22+
Add part
23+
</button>
24+
25+
<p>
26+
<form action="/wood/document">
27+
<div id="wood-form">
28+
<?= $this->insert('pages/wood/part-input') ?>
29+
</div>
30+
31+
<button class="btn btn-primary">
32+
Submit
33+
</button>
34+
</form>
35+
</p>
36+
</div>
37+
</div>
38+
39+
<div id="part-input" class="d-none">
40+
<?= $this->insert('pages/wood/part-input') ?>
41+
</div>
42+
43+
<script>
44+
const form = document.getElementById('wood-form');
45+
const inputTemplate = document.getElementById('part-input').innerHTML;
46+
47+
document.getElementById('add-input').onclick = () => {
48+
form.innerHTML += inputTemplate;
49+
};
50+
</script>
51+
52+
<?php $this->stop() ?>

templates/pages/wood/part-input.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<table class="wood-form">
2+
<tbody>
3+
<tr>
4+
<td>Name:</td>
5+
<td colspan="2">
6+
<input class="form-control" type="name" name="n[]">
7+
</td>
8+
</tr>
9+
<tr>
10+
<td>Width: <input class="form-control" type="number" name="w[]" min="0" value="<?= $w ?? '' ?>"></td>
11+
<td>Height: <input class="form-control" type="number" name="h[]" min="0" value="<?= $w ?? '' ?>"></td>
12+
<td>Thickness: <input class="form-control" type="number" name="t[]" min="0" value="<?= $w ?? '' ?>"></td>
13+
</tr>
14+
<tr>
15+
<td>
16+
Amount:
17+
<input class="form-control" type="number" name="a[]" min="0" step="1" value="<?= $w ?? 1 ?>">
18+
</td>
19+
<td></td>
20+
<td>
21+
&nbsp;<br>
22+
<button class="btn btn-danger" onclick="this.parentNode.parentNode.parentNode.parentNode.remove()" href="#">&cross;</button>
23+
</td>
24+
</tr>
25+
</tbody>
26+
</table>

0 commit comments

Comments
 (0)