Added ticket edit action
This commit is contained in:
parent
c6d4c3df10
commit
17c2e36bb5
@ -4,6 +4,7 @@ namespace BitGoblin\Goliath\Controllers;
|
|||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
use Slim\Routing\RouteContext;
|
||||||
use Slim\Views\Twig;
|
use Slim\Views\Twig;
|
||||||
use BitGoblin\Goliath\Models\Ticket;
|
use BitGoblin\Goliath\Models\Ticket;
|
||||||
|
|
||||||
@ -40,4 +41,32 @@ class TicketController extends Controller {
|
|||||||
->withStatus(302);
|
->withStatus(302);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getEdit(Request $request, Response $response, array $args): Response {
|
||||||
|
$ticket = Ticket::where('id', $args['ticket_id'])->get();
|
||||||
|
|
||||||
|
$view = Twig::fromRequest($request);
|
||||||
|
return $view->render($response, 'ticket/edit.twig', [
|
||||||
|
'ticket' => $ticket[0],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postEdit(Request $request, Response $response, array $args): Response {
|
||||||
|
$ticket = Ticket::where('id', $args['ticket_id'])->first();
|
||||||
|
|
||||||
|
$params = (array)$request->getParsedBody();
|
||||||
|
$ticket->title = $params['ticket_title'];
|
||||||
|
$ticket->body = $params['ticket_body'];
|
||||||
|
$ticket->severity = $params['ticket_severity'];
|
||||||
|
$ticket->due_at = $params['ticket_due'];
|
||||||
|
|
||||||
|
$ticket->save();
|
||||||
|
|
||||||
|
// redirect the user back to the home page
|
||||||
|
$routeContext = RouteContext::fromRequest($request);
|
||||||
|
$routeParser = $routeContext->getRouteParser();
|
||||||
|
return $response
|
||||||
|
->withHeader('Location', $routeParser->urlFor('ticket.view', ['ticket_id' => $ticket->id]))
|
||||||
|
->withStatus(302);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,13 @@ use Slim\Views\Twig;
|
|||||||
// index GET route - this page should welcome the user and direct them to the available actions
|
// index GET route - this page should welcome the user and direct them to the available actions
|
||||||
$app->get('/', '\\BitGoblin\\Goliath\\Controllers\\HomeController:getIndex')->setName('index');
|
$app->get('/', '\\BitGoblin\\Goliath\\Controllers\\HomeController:getIndex')->setName('index');
|
||||||
|
|
||||||
// /ticket/create GET route - allows a user to fill out a form to create a ticket
|
// /ticket/create routes - allows a user to fill out a form to create a ticket
|
||||||
$app->get('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getCreate')->setName('ticket.create');
|
$app->get('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getCreate')->setName('ticket.create');
|
||||||
$app->post('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postCreate');
|
$app->post('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postCreate');
|
||||||
|
|
||||||
|
// /ticket/edit routes - update a ticket!
|
||||||
|
$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/id route - displays ticket info to user
|
// /ticket/id route - displays ticket info to user
|
||||||
$app->get('/ticket/{ticket_id}', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getView')->setName('ticket.view');
|
$app->get('/ticket/{ticket_id}', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getView')->setName('ticket.view');
|
||||||
|
@ -16,12 +16,16 @@
|
|||||||
<th>Title</th>
|
<th>Title</th>
|
||||||
<th>Severity</th>
|
<th>Severity</th>
|
||||||
<th>Due date</th>
|
<th>Due date</th>
|
||||||
|
<th>Actions</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for ticket in tickets %}
|
{% for ticket in tickets %}
|
||||||
<td><a href="{{ url_for('ticket.view', {ticket_id: ticket.id}) }}">{{ ticket.title }}</a></td>
|
<td><a href="{{ url_for('ticket.view', {ticket_id: ticket.id}) }}">{{ ticket.title }}</a></td>
|
||||||
<td>{{ ticket.severity }}</td>
|
<td>{{ ticket.severity }}</td>
|
||||||
<td>{{ ticket.due_at }}</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>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
41
views/ticket/edit.twig
Normal file
41
views/ticket/edit.twig
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
{% extends 'layout.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Create new ticket{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<h1>Editing "{{ ticket.title }}"</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="columns twelve">
|
||||||
|
<form action="{{ url_for('ticket.edit', {ticket_id: ticket.id}) }}" method="POST" class="u-full-width">
|
||||||
|
<div class="row">
|
||||||
|
<div class="six columns">
|
||||||
|
<label for="ticket_title">Title</label>
|
||||||
|
<input id="ticket_title" class="u-full-width" type="text" placeholder="My new ticket" name="ticket_title" value="{{ ticket.title }}">
|
||||||
|
</div>
|
||||||
|
<div class="columns three">
|
||||||
|
<label for="ticket_due">Due at</label>
|
||||||
|
<input id="ticket_due" class="u-full-width" type="datetime-local" name="ticket_due" value="{{ ticket.due_at }}">
|
||||||
|
</div>
|
||||||
|
<div class="three columns">
|
||||||
|
<label for="ticket_severity">Severity level</label>
|
||||||
|
<select id="ticket_severity" class="u-full-width" name="ticket_severity" value="{{ ticket.severity }}">
|
||||||
|
<option value="low">Low</option>
|
||||||
|
<option value="medium">Medium</option>
|
||||||
|
<option value="high">High</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label for="ticket_body">Ticket body</label>
|
||||||
|
<textarea id="ticket_body" class="u-full-width" placeholder="Explain what this ticket is about..." name="ticket_body">{{ ticket.body }}</textarea>
|
||||||
|
|
||||||
|
<input class="button-primary" type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user