Added ability to change the ticket status

This commit is contained in:
Gregory Ballantine 2022-12-04 15:00:26 -05:00
parent f3ac8a6965
commit 5d5265ef38
5 changed files with 55 additions and 5 deletions

View File

@ -1,2 +1,28 @@
$(document).ready -> $(document).ready ->
console.log('Hello, world!') console.log('Hello, world!')
$('.ticket-status').on('click', handleStatusClick)
handleStatusClick = (e, msg = 'Set ticket status:') ->
validStatus = ['open', 'closed', 'parked']
newStatus = prompt(msg, $('.ticket-status > span').text())
newStatus = newStatus.toLowerCase()
if (newStatus != null) and (newStatus != '')
if (newStatus in validStatus)
console.log('Setting status to ' + newStatus)
editLink = $('#ticketEditLink').attr('href') + '/status'
console.log('Sending data to ' + editLink)
$.ajax({
type: "POST",
url: editLink,
data:
status: newStatus,
success: (data) ->
newStatus = newStatus.charAt(0).toUpperCase() + newStatus.slice(1)
$('.ticket-status > span').text(newStatus)
console.log('Ticket updated successfully.')
})
else
console.log('Invalid status entered')
handleStatusClick(e, 'Invalid status; valid values are open, closed, and parked')

View File

@ -98,7 +98,7 @@ input[type="submit"].button-primary
p:last-child p:last-child
margin-bottom: 5px margin-bottom: 5px
.ticket-status .ticket-attributes
list-style: none list-style: none
margin: 0 margin: 0
border: 1px solid #bbb border: 1px solid #bbb
@ -141,6 +141,12 @@ input[type="submit"].button-primary
margin-right: 5px margin-right: 5px
font-size: 2rem font-size: 2rem
.ticket-status
transition: all 230ms ease-in-out
&:hover
background: rgba(0, 0, 0, .1)
cursor: pointer
#comment-form #comment-form
textarea textarea
height: 150px height: 150px

View File

@ -69,6 +69,23 @@ class TicketController extends Controller {
->withStatus(302); ->withStatus(302);
} }
public function postEditAttr(Request $request, Response $response, array $args): Response {
// grab ticket from database
$ticket = Ticket::where('id', $args['ticket_id'])->first();
// edit the specified attribute
$params = (array)$request->getParsedBody();
$attr = $args['attr'];
$ticket->$attr = $params[$attr];
// save updated ticket
$ticket->save();
// return a response
$response->getBody()->write(json_encode(['status' => 'success']));
return $response;
}
public function getDelete(Request $request, Response $response, array $args): Response { public function getDelete(Request $request, Response $response, array $args): Response {
$ticket = Ticket::where('id', $args['ticket_id'])->first(); $ticket = Ticket::where('id', $args['ticket_id'])->first();

View File

@ -14,6 +14,7 @@ $app->post('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketControlle
// /ticket/edit routes - update a ticket! // /ticket/edit routes - update a ticket!
$app->get('/ticket/{ticket_id}/edit', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getEdit')->setName('ticket.edit'); $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'); $app->post('/ticket/{ticket_id}/edit', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postEdit')->setName('ticket.edit');
$app->post('/ticket/{ticket_id}/edit/{attr}', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postEditAttr')->setName('ticket.edit.attr');
// ticket deletion route // ticket deletion route
$app->get('/ticket/{ticket_id}/delete', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getDelete')->setName('ticket.delete'); $app->get('/ticket/{ticket_id}/delete', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getDelete')->setName('ticket.delete');

View File

@ -23,17 +23,17 @@
<!-- ticket status column --> <!-- ticket status column -->
<div class="three columns"> <div class="three columns">
<ul class="ticket-status"> <ul class="ticket-attributes">
<li class="ticket-actions"> <li class="ticket-actions">
<ul> <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.delete', {ticket_id: ticket.id}) }}"><i class="fa-solid fa-trash"></i>Delete</a></li> <li><a id="ticketEditLink" 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> </ul>
</li> </li>
<li> <li>
Severity {{ ticket.severity | capitalize }} Severity {{ ticket.severity | capitalize }}
</li> </li>
<li> <li class="ticket-status">
Status: {{ ticket.status | capitalize }} Status: <span>{{ ticket.status | capitalize }}</span>
</li> </li>
<li> <li>
Assignee(s): N/a Assignee(s): N/a