Added ticket deletion; fixed some small issues with the ticket list on the home page

This commit is contained in:
Gregory Ballantine 2022-11-21 23:55:19 -05:00
parent 5683c0bc8b
commit f3ac8a6965
5 changed files with 26 additions and 10 deletions

View File

@ -11,7 +11,7 @@ use BitGoblin\Goliath\Models\Ticket;
class TicketController extends Controller {
public function getView(Request $request, Response $response, array $args): Response {
$ticket = Ticket::where('id', $args['ticket_id'])->get()[0];
$ticket = Ticket::where('id', $args['ticket_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'ticket/view.twig', [
@ -69,4 +69,14 @@ class TicketController extends Controller {
->withStatus(302);
}
public function getDelete(Request $request, Response $response, array $args): Response {
$ticket = Ticket::where('id', $args['ticket_id'])->first();
$ticket->delete();
return $response
->withHeader('Location', '/')
->withStatus(302);
}
}

View File

@ -15,6 +15,9 @@ $app->post('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketControlle
$app->get('/ticket/{ticket_id}/edit', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getEdit')->setName('ticket.edit');
$app->post('/ticket/{ticket_id}/edit', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postEdit')->setName('ticket.edit');
// ticket deletion route
$app->get('/ticket/{ticket_id}/delete', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getDelete')->setName('ticket.delete');
// /ticket/id route - displays ticket info to user
$app->get('/ticket/{ticket_id}', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getView')->setName('ticket.view');

View File

@ -20,12 +20,15 @@
</thead>
<tbody>
{% for ticket in tickets %}
<td><a href="{{ url_for('ticket.view', {ticket_id: ticket.id}) }}">{{ ticket.title }}</a></td>
<td>{{ ticket.severity }}</td>
<td>{{ ticket.due_at }}</td>
<td>
<a href="{{ url_for('ticket.edit', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-pen-to-square"></i></a>
</td>
<tr>
<td><a href="{{ url_for('ticket.view', {ticket_id: ticket.id}) }}">{{ ticket.title }}</a></td>
<td>{{ ticket.severity }}</td>
<td>{{ ticket.due_at ? ticket.due_at : 'N/a' }}</td>
<td>
<a href="{{ url_for('ticket.edit', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-pen-to-square"></i></a>
<a href="{{ url_for('ticket.delete', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-trash"></i></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -1,6 +1,6 @@
{% extends 'layout.twig' %}
{% block title %}Create new ticket{% endblock %}
{% block title %}Editing ticket{% endblock %}
{% block content %}
<div class="row">

View File

@ -1,6 +1,6 @@
{% extends 'layout.twig' %}
{% block title %}Home{% endblock %}
{% block title %}{{ ticket.title }}{% endblock %}
{% block content %}
<div class="row">
@ -26,7 +26,7 @@
<ul class="ticket-status">
<li class="ticket-actions">
<ul>
<li><a href="{{ url_for('ticket.edit', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-pen-to-square"></i>Edit</a></li><li><a href="{{ url_for('ticket.edit', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-trash"></i>Delete</a></li>
<li><a href="{{ url_for('ticket.edit', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-pen-to-square"></i>Edit</a></li><li><a href="{{ url_for('ticket.delete', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-trash"></i>Delete</a></li>
</ul>
</li>
<li>