-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #29 -- Add CRUD controllers for Groups and Poster Types.
- Loading branch information
1 parent
9dd3385
commit 4c81ee8
Showing
13 changed files
with
504 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
backend/src/Controller/Dashboard/Admin/GroupsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Controller\Dashboard\Admin; | ||
|
||
use App\Controller\Dashboard\AbstractCrudController; | ||
use App\Http\ServerRequest; | ||
use Doctrine\DBAL\Connection; | ||
|
||
final class GroupsController extends AbstractCrudController | ||
{ | ||
public function __construct( | ||
Connection $db | ||
) { | ||
parent::__construct( | ||
$db, | ||
'Group', | ||
'dashboard:admin:groups', | ||
'dashboard/admin/groups/list', | ||
'dashboard/admin/groups/edit', | ||
'web_groups' | ||
); | ||
} | ||
|
||
protected function modifyFromRequest(ServerRequest $request, array $row = [], bool $isEditMode = false): array | ||
{ | ||
$postData = $request->getParsedBody(); | ||
|
||
if (!$isEditMode) { | ||
$row['id'] = $postData['id'] ?? null; | ||
if (empty($row['id'])) { | ||
throw new \InvalidArgumentException('ID is required.'); | ||
} | ||
} | ||
|
||
$row['name'] = $postData['name'] ?? null; | ||
|
||
if (empty($row['name'])) { | ||
throw new \InvalidArgumentException('Name is required.'); | ||
} | ||
|
||
return $row; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
backend/src/Controller/Dashboard/Admin/PosterTypesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Controller\Dashboard\Admin; | ||
|
||
use App\Controller\Dashboard\AbstractCrudController; | ||
use App\Http\ServerRequest; | ||
use Doctrine\DBAL\Connection; | ||
|
||
final class PosterTypesController extends AbstractCrudController | ||
{ | ||
public function __construct( | ||
Connection $db | ||
) { | ||
parent::__construct( | ||
$db, | ||
'Poster Type', | ||
'dashboard:admin:poster_types', | ||
'dashboard/admin/poster_types/list', | ||
'dashboard/admin/poster_types/edit', | ||
'web_poster_types' | ||
); | ||
} | ||
|
||
protected function modifyFromRequest(ServerRequest $request, array $row = [], bool $isEditMode = false): array | ||
{ | ||
$postData = $request->getParsedBody(); | ||
|
||
if (!$isEditMode) { | ||
$row['id'] = $postData['id'] ?? null; | ||
if (empty($row['id'])) { | ||
throw new \InvalidArgumentException('ID is required.'); | ||
} | ||
} | ||
|
||
$row['name'] = $postData['name'] ?? null; | ||
|
||
if (empty($row['name'])) { | ||
throw new \InvalidArgumentException('Name is required.'); | ||
} | ||
|
||
return $row; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{% extends "layouts/dashboard.twig" %} | ||
|
||
{% import "macros/breadcrumbs.twig" as breadcrumbs %} | ||
|
||
{% block content %} | ||
{{ breadcrumbs.body( | ||
{ | ||
'dashboard': 'My Dashboard', | ||
'dashboard:admin:groups': 'Manage Groups' | ||
}, | ||
(isEditMode) ? 'Edit Group' : 'Create Group' | ||
) }} | ||
|
||
<h1>Manage Groups</h1> | ||
|
||
<div class="card"> | ||
<h2 class="card-header"> | ||
{% if isEditMode %} | ||
Edit Group | ||
{% else %} | ||
Create Group | ||
{% endif %} | ||
</h2> | ||
<div class="card-body"> | ||
{% if error %} | ||
<div class="alert alert-danger"> | ||
<b>Error:</b> {{ error }} | ||
</div> | ||
{% endif %} | ||
|
||
<form action="" method="POST"> | ||
<div class="row mb-3"> | ||
<div class="col-md-8"> | ||
{% if not isEditMode %} | ||
<div class="control-group mb-3"> | ||
<label for="id" class="form-label">Group ID:</label> | ||
<input type="text" name="id" id="id" | ||
value="{{ row.id|default('')|e('html_attr') }}" | ||
class="form-control form-control-lg" required maxlength="50"> | ||
|
||
<p class="form-text"> | ||
The programmatic ID of the group. Should be only letters, numbers and underscores | ||
(i.e. <code>my_group_1</code>). | ||
</p> | ||
</div> | ||
{% endif %} | ||
|
||
<div class="control-group"> | ||
<label for="name" class="form-label">Group Name:</label> | ||
<input type="text" name="name" id="name" | ||
value="{{ row.name|default('')|e('html_attr') }}" | ||
class="form-control form-control-lg" required maxlength="255"> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="buttons"> | ||
<button type="submit" class="btn btn-lg btn-primary">Save Changes</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{% extends "layouts/dashboard.twig" %} | ||
|
||
{% import "macros/breadcrumbs.twig" as breadcrumbs %} | ||
|
||
{% block head %} | ||
{{ parent() }} | ||
|
||
{{ renderAssets('frontend/dataTable.js') }} | ||
|
||
<script> | ||
ready(() => { | ||
let dataTable = new DataTable('#data_table'); | ||
}); | ||
</script> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{{ breadcrumbs.body( | ||
{ | ||
'dashboard': 'My Dashboard' | ||
}, | ||
'Manage Groups' | ||
) }} | ||
|
||
<h1>Manage Groups</h1> | ||
|
||
<div class="card"> | ||
<h2 class="card-header">View Groups</h2> | ||
<div class="card-body"> | ||
<div class="buttons mb-3"> | ||
<a class="btn btn-lg btn-success" | ||
href="{{ urlFor('dashboard:admin:groups:create') }}"> | ||
<i class="bi-plus-circle-fill" aria-hidden="true"></i> Add Group | ||
</a> | ||
</div> | ||
|
||
<table class="table table-striped table-bordered table-hover align-middle" id="data_table"> | ||
<thead> | ||
<tr> | ||
<th>Group ID</th> | ||
<th>Group Name</th> | ||
<th data-dt-order="disable" style="width:15%">Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for row in records %} | ||
<tr> | ||
<td><code>{{ row.id }}</code></td> | ||
<th scope="col">{{ row.name }}</th> | ||
<td class="text-nowrap"> | ||
<a class="btn btn-sm btn-warning" | ||
href="{{ urlFor('dashboard:admin:groups:edit', {id: row.id}) }}"> | ||
<i class="bi-pencil-fill" aria-hidden="true"></i> Edit | ||
</a> | ||
<a class="btn btn-sm btn-danger" | ||
href="{{ urlFor('dashboard:admin:groups:delete', {id: row.id}) }}" | ||
data-confirm-delete="Remove group? This will affect posters uploaded to this group as well." | ||
> | ||
<i class="bi-trash" aria-hidden="true"></i> Delete | ||
</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{% extends "layouts/dashboard.twig" %} | ||
|
||
{% import "macros/breadcrumbs.twig" as breadcrumbs %} | ||
|
||
{% block content %} | ||
{{ breadcrumbs.body( | ||
{ | ||
'dashboard': 'My Dashboard', | ||
'dashboard:admin:poster_types': 'Manage Poster Types' | ||
}, | ||
(isEditMode) ? 'Edit Poster Type' : 'Create Poster Type' | ||
) }} | ||
|
||
<h1>Manage Poster Types</h1> | ||
|
||
<div class="card"> | ||
<h2 class="card-header"> | ||
{% if isEditMode %} | ||
Edit Poster Type | ||
{% else %} | ||
Create Poster Type | ||
{% endif %} | ||
</h2> | ||
<div class="card-body"> | ||
{% if error %} | ||
<div class="alert alert-danger"> | ||
<b>Error:</b> {{ error }} | ||
</div> | ||
{% endif %} | ||
|
||
<form action="" method="POST"> | ||
<div class="row mb-3"> | ||
<div class="col-md-8"> | ||
{% if not isEditMode %} | ||
<div class="control-group mb-3"> | ||
<label for="id" class="form-label">Poster Type ID:</label> | ||
<input type="text" name="id" id="id" | ||
value="{{ row.id|default('')|e('html_attr') }}" | ||
class="form-control form-control-lg" required maxlength="50"> | ||
|
||
<p class="form-text"> | ||
The programmatic ID of the poster type. Should be only letters, numbers and | ||
underscores (i.e. <code>my_poster_type_1</code>). | ||
</p> | ||
</div> | ||
{% endif %} | ||
|
||
<div class="control-group"> | ||
<label for="name" class="form-label">Type Name:</label> | ||
<input type="text" name="name" id="name" | ||
value="{{ row.name|default('')|e('html_attr') }}" | ||
class="form-control form-control-lg" required maxlength="255"> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="buttons"> | ||
<button type="submit" class="btn btn-lg btn-primary">Save Changes</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.