forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-turbo-various-minor-tweaks.diff
544 lines (529 loc) · 21 KB
/
pre-turbo-various-minor-tweaks.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
diff --git a/assets/styles/app.css b/assets/styles/app.css
index 5621c51..49945ae 100644
--- a/assets/styles/app.css
+++ b/assets/styles/app.css
@@ -153,7 +153,7 @@ h1 {
}
.fade-enter-active, .fade-leave-active {
- transition: opacity 2000ms;
+ transition: opacity 300ms;
}
.fade-enter-from, .fade-leave-to {
opacity: 0;
diff --git a/config/packages/security.yaml b/config/packages/security.yaml
index ac75763..d7645dc 100644
--- a/config/packages/security.yaml
+++ b/config/packages/security.yaml
@@ -5,6 +5,10 @@ security:
App\Entity\User:
algorithm: auto
+ role_hierarchy:
+ # everyone is an admin!
+ ROLE_USER: [ROLE_ADMIN]
+
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
# used to reload user from session & other features (e.g. switch_user)
diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml
index 14e0cc1..6923b00 100644
--- a/config/packages/twig.yaml
+++ b/config/packages/twig.yaml
@@ -1,4 +1,4 @@
twig:
default_path: '%kernel.project_dir%/templates'
form_themes:
- - bootstrap_4_layout.html.twig
+ - bootstrap_5_layout.html.twig
diff --git a/src/Controller/ProductAdminController.php b/src/Controller/ProductAdminController.php
index f3ae653..fbc0ba2 100644
--- a/src/Controller/ProductAdminController.php
+++ b/src/Controller/ProductAdminController.php
@@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Product;
use App\Form\ProductType;
use App\Repository\ProductRepository;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -12,6 +13,7 @@ use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin/product")
+ * @IsGranted("ROLE_ADMIN")
*/
class ProductAdminController extends AbstractController
{
@@ -59,16 +61,6 @@ class ProductAdminController extends AbstractController
));
}
- /**
- * @Route("/{id}", name="product_admin_show", methods={"GET"})
- */
- public function show(Product $product): Response
- {
- return $this->render('product_admin/show.html.twig', [
- 'product' => $product,
- ]);
- }
-
/**
* @Route("/{id}/edit", name="product_admin_edit", methods={"GET","POST"})
*/
diff --git a/templates/base.html.twig b/templates/base.html.twig
index 0e06935..e8212ec 100644
--- a/templates/base.html.twig
+++ b/templates/base.html.twig
@@ -17,9 +17,10 @@
<nav class="navbar navbar-expand-lg navbar-dark justify-content-between">
<a class="navbar-brand" href="/">
<img src="{{ asset('images/mvp-logo-light.png' ) }}"
- width="50"
- height="50"
- alt="MVP Office Supplies Logo"
+ width="50"
+ height="50"
+ alt="MVP Office Supplies Logo"
+ id="logo-img"
>
<span class="p-3">MVP Office Supplies</span>
@@ -32,6 +33,13 @@
Log out
</a>
</li>
+ {% if is_granted('ROLE_ADMIN') %}
+ <li class="nav-item">
+ <a class="nav-link" href="{{ path('product_admin_index') }}">
+ Admin
+ </a>
+ </li>
+ {% endif %}
{% else %}
<li class="nav-item">
<a class="nav-link" href="{{ path('app_login') }}">
@@ -54,9 +62,13 @@
</header>
{% for flash in app.session.flashBag.get('success') %}
- <div class="alert alert-success">
+ <div class="alert alert-success alert-dismissible fade show" role="alert">
{{ flash }}
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
+ <span aria-hidden="true"></span>
+ </button>
</div>
+
{% endfor %}
</div>
diff --git a/templates/product/_categoriesSidebar.html.twig b/templates/product/_categoriesSidebar.html.twig
index acc26f2..cc430c4 100644
--- a/templates/product/_categoriesSidebar.html.twig
+++ b/templates/product/_categoriesSidebar.html.twig
@@ -19,11 +19,4 @@
</li>
{% endfor %}
</ul>
- <hr>
-
- <div class="d-flex justify-content-end">
- <button class="btn btn-secondary btn-sm">
- Collapse
- </button>
- </div>
</div>
diff --git a/templates/product/index.html.twig b/templates/product/index.html.twig
index 6184ce8..1771dda 100644
--- a/templates/product/index.html.twig
+++ b/templates/product/index.html.twig
@@ -1,116 +1,105 @@
-{% extends 'base.html.twig' %}
+{% extends 'product/productBase.html.twig' %}
-{% block body %}
- <div class="container-fluid mt-4">
- <div class="row">
- <aside class="col-xs-12 col-3">
- {{ include('product/_categoriesSidebar.html.twig') }}
- </aside>
+{% block productBody %}
+ <div data-controller="counter">
+ <button
+ data-action="counter#increment"
+ class="btn btn-primary btn-sm"
+ >
+ Click me!
+ </button>
- <div class="col-xs-12 col-9">
+ <br>
- <div data-controller="counter">
- <button
- data-action="counter#increment"
- class="btn btn-primary btn-sm"
- >
- Click me!
- </button>
+ I have been clicked
+ <span data-counter-target="count">0</span>
+ times!
+ </div>
- <br>
+ <div class="row">
+ <div class="col-3">
+ <h1>
+ {% if currentCategory %}
+ {{ currentCategory.name }}
+ {% else %}
+ All Products
+ {% endif %}
+ </h1>
+ </div>
+ <div class="col-9">
+ <form>
+ <div
+ class="input-group"
+ {{ stimulus_controller({
+ 'autocomplete': {
+ url: path('app_homepage', { preview: 1 }),
+ skipHiddenProperty: true
+ },
+ 'autocomplete-transition': {}
+ }) }}
+ data-action="toggle->autocomplete-transition#toggle"
+ >
+ <input
+ name="q"
+ value="{{ searchTerm }}"
+ placeholder="Search products..."
+ type="search"
+ class="form-control"
+ data-autocomplete-target="input"
+ >
- I have been clicked
- <span data-counter-target="count">0</span>
- times!
+ <div
+ class="search-preview"
+ data-autocomplete-target="results"
+ data-autocomplete-transition-target="results"
+ ></div>
</div>
-
- <div class="row">
- <div class="col-3">
- <h1>
- {% if currentCategory %}
- {{ currentCategory.name }}
- {% else %}
- All Products
- {% endif %}
- </h1>
- </div>
- <div class="col-9">
- <form>
- <div
- class="input-group"
- {{ stimulus_controller({
- 'autocomplete': {
- url: path('app_homepage', { preview: 1 }),
- skipHiddenProperty: true
- },
- 'autocomplete-transition': {}
- }) }}
- data-action="toggle->autocomplete-transition#toggle"
+ </form>
+ </div>
+ </div>
+ <div class="row mt-4">
+ {% for product in products %}
+ <div class="col-xs-12 col-6 mb-2 pb-2">
+ <div class="component-light">
+ <div class="product-image">
+ <a href="{{ path('app_product', { id: product.id }) }}">
+ <img
+ alt="{{ product.name }}"
+ src="{{ asset('/uploads/products/'~product.imageFilename) }}"
+ class="d-block mb-2"
>
- <input
- name="q"
- value="{{ searchTerm }}"
- placeholder="Search products..."
- type="search"
- class="form-control"
- data-autocomplete-target="input"
- >
-
- <div
- class="search-preview"
- data-autocomplete-target="results"
- data-autocomplete-transition-target="results"
- ></div>
- </div>
- </form>
+ </a>
+ <h3 class="font-weight-bold mb-2 px-2">
+ <a href="{{ path('app_product', { id: product.id }) }}">
+ {{ product.name }}
+ </a>
+ </h3>
+ </div>
+ <div
+ class="p-2 my-3 d-md-flex justify-content-between">
+ <p class="p-0 d-inline">
+ <strong>{{ product.priceString|format_currency('USD') }}</strong>
+ </p>
+ <a href="{{ path('app_product', { id: product.id }) }}" class="btn btn-info">View Product</a>
</div>
</div>
- <div class="row mt-4">
- {% for product in products %}
- <div class="col-xs-12 col-6 mb-2 pb-2">
- <div class="component-light">
- <div class="product-image">
- <a href="{{ path('app_product', { id: product.id }) }}">
- <img
- alt="{{ product.name }}"
- src="{{ asset('/uploads/products/'~product.imageFilename) }}"
- class="d-block mb-2"
- >
- </a>
- <h3 class="font-weight-bold mb-2 px-2">
- <a href="{{ path('app_product', { id: product.id }) }}">
- {{ product.name }}
- </a>
- </h3>
- </div>
- <div
- class="p-2 my-3 d-md-flex justify-content-between">
- <p class="p-0 d-inline">
- <strong>{{ product.priceString|format_currency('USD') }}</strong>
- </p>
- <a href="{{ path('app_product', { id: product.id }) }}" class="btn btn-info">View Product</a>
- </div>
- </div>
- <hr>
- <div class="px-2 pb-2">
- <small>brought to you by {{ product.brand }}</small>
- </div>
- </div>
- {% else %}
- <div class="col-12">
- <h5 class="ml-4 mt-4" >
- Whoopsie Daisy, no products found!
- </h5>
- </div>
- {% endfor %}
- </div>
-
- <div class="row">
- <span class="p-3">
- Shipping takes 10-13 weeks, and products probably won't work
- </span>
+ <hr>
+ <div class="px-2 pb-2">
+ <small>brought to you by {{ product.brand }}</small>
</div>
</div>
- </div>
+ {% else %}
+ <div class="col-12">
+ <h5 class="ml-4 mt-4" >
+ Whoopsie Daisy, no products found!
+ </h5>
+ </div>
+ {% endfor %}
+ </div>
+
+ <div class="row">
+ <span class="p-3">
+ Shipping takes 10-13 weeks, and products probably won't work
+ </span>
</div>
{% endblock %}
diff --git a/templates/product/productBase.html.twig b/templates/product/productBase.html.twig
new file mode 100644
index 0000000..82d3cc2
--- /dev/null
+++ b/templates/product/productBase.html.twig
@@ -0,0 +1,15 @@
+{% extends 'base.html.twig' %}
+
+{% block body %}
+ <div class="container-fluid mt-4">
+ <div class="row">
+ <aside class="col-xs-12 col-3">
+ {{ include('product/_categoriesSidebar.html.twig') }}
+ </aside>
+
+ <div class="col-xs-12 col-9">
+ {% block productBody %}{% endblock %}
+ </div>
+ </div>
+ </div>
+{% endblock %}
diff --git a/templates/product/show.html.twig b/templates/product/show.html.twig
index 537282c..138999b 100644
--- a/templates/product/show.html.twig
+++ b/templates/product/show.html.twig
@@ -1,39 +1,29 @@
-{% extends 'base.html.twig' %}
+{% extends 'product/productBase.html.twig' %}
-{% block body %}
- <div class="container-fluid mt-4">
- <div class="row">
- <aside class="col-xs-12 col-3">
- {{ include('product/_categoriesSidebar.html.twig') }}
- </aside>
-
- <div class="col-xs-12 col-9 product-show">
- <h1>{{ product.name }}</h1>
- <div class="row component-light">
- <div class="col-4 pt-3">
- <img
- alt="{{ product.name }}"
- src="{{ asset('/uploads/products/'~product.imageFilename) }}"
- class="d-block"
- >
- <div class="p-2">
- <small>brought to you by </small>
- <small class="d-inline">{{ product.brand }}</small>
- </div>
- </div>
- <div class="col-8 p-3">
- <div>
- {{ product.description }}
- </div>
- <div class="row mt-4 align-items-center">
- <div class="col-3">
- Price: <strong>{{ product.priceString|format_currency('USD') }}</strong>
- </div>
- <div class="col-9 p-3">
- {{ include('product/_cart_add_controls.html.twig') }}
- </div>
- </div>
- </div>
+{% block productBody %}
+ <h1>{{ product.name }}</h1>
+ <div class="row component-light product-show">
+ <div class="col-4 pt-3">
+ <img
+ alt="{{ product.name }}"
+ src="{{ asset('/uploads/products/'~product.imageFilename) }}"
+ class="d-block"
+ >
+ <div class="p-2">
+ <small>brought to you by </small>
+ <small class="d-inline">{{ product.brand }}</small>
+ </div>
+ </div>
+ <div class="col-8 p-3">
+ <div>
+ {{ product.description }}
+ </div>
+ <div class="row mt-4 align-items-center">
+ <div class="col-3">
+ Price: <strong>{{ product.priceString|format_currency('USD') }}</strong>
+ </div>
+ <div class="col-9 p-3">
+ {{ include('product/_cart_add_controls.html.twig') }}
</div>
</div>
</div>
diff --git a/templates/product_admin/_form.html.twig b/templates/product_admin/_form.html.twig
index bf20b98..eec6f04 100644
--- a/templates/product_admin/_form.html.twig
+++ b/templates/product_admin/_form.html.twig
@@ -1,4 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
- <button class="btn">{{ button_label|default('Save') }}</button>
+ <button class="btn btn-primary" formnovalidate>{{ button_label|default('Save') }}</button>
{{ form_end(form) }}
diff --git a/templates/product_admin/_list.html.twig b/templates/product_admin/_list.html.twig
index b03c9c3..9745a66 100644
--- a/templates/product_admin/_list.html.twig
+++ b/templates/product_admin/_list.html.twig
@@ -24,7 +24,7 @@
<td>{{ product.stockQuantity }}</td>
<td>{{ product.imageFilename }}</td>
<td>
- <a href="{{ path('product_admin_show', {'id': product.id}) }}">show</a>
+ <a href="{{ path('app_product', {'id': product.id}) }}">show</a>
<a href="{{ path('product_admin_edit', {'id': product.id}) }}">edit</a>
</td>
</tr>
diff --git a/templates/product_admin/show.html.twig b/templates/product_admin/show.html.twig
deleted file mode 100644
index 79dd56f..0000000
--- a/templates/product_admin/show.html.twig
+++ /dev/null
@@ -1,52 +0,0 @@
-{% extends 'base.html.twig' %}
-
-{% block title %}Product{% endblock %}
-
-{% block body %}
-<div class="container-fluid mt-4">
- <h1>Product</h1>
-
- <table class="table">
- <tbody>
- <tr>
- <th>Id</th>
- <td>{{ product.id }}</td>
- </tr>
- <tr>
- <th>Name</th>
- <td>{{ product.name }}</td>
- </tr>
- <tr>
- <th>Description</th>
- <td>{{ product.description }}</td>
- </tr>
- <tr>
- <th>Brand</th>
- <td>{{ product.brand }}</td>
- </tr>
- <tr>
- <th>Weight</th>
- <td>{{ product.weight }}</td>
- </tr>
- <tr>
- <th>Price</th>
- <td>{{ product.price }}</td>
- </tr>
- <tr>
- <th>StockQuantity</th>
- <td>{{ product.stockQuantity }}</td>
- </tr>
- <tr>
- <th>ImageFilename</th>
- <td>{{ product.imageFilename }}</td>
- </tr>
- </tbody>
- </table>
-
- <a href="{{ path('product_admin_index') }}">back to list</a>
-
- <a href="{{ path('product_admin_edit', {'id': product.id}) }}">edit</a>
-
- {{ include('product_admin/_delete_form.html.twig') }}
-</div>
-{% endblock %}
diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig
index 9133359..86e1835 100644
--- a/templates/security/login.html.twig
+++ b/templates/security/login.html.twig
@@ -21,11 +21,17 @@
<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="inputEmail">Email</label>
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" required autofocus>
+ <small class="form-text text-muted">
+ (try email <code>[email protected]</code>)
+ </small>
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" required>
+ <small class="form-text text-muted">
+ (try password <code>buy</code>)
+ </small>
</div>
<input type="hidden" name="_csrf_token"