From 5d5265ef38391b3fb986805151513de482a31483 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sun, 4 Dec 2022 15:00:26 -0500 Subject: [PATCH] Added ability to change the ticket status --- assets/coffee/slepe.coffee | 26 ++++++++++++++++++++++++++ assets/sass/darkmeyer.sass | 8 +++++++- src/Controllers/TicketController.php | 17 +++++++++++++++++ src/routes.php | 1 + views/ticket/view.twig | 8 ++++---- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/assets/coffee/slepe.coffee b/assets/coffee/slepe.coffee index 6654ba5..0511e69 100644 --- a/assets/coffee/slepe.coffee +++ b/assets/coffee/slepe.coffee @@ -1,2 +1,28 @@ $(document).ready -> 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') diff --git a/assets/sass/darkmeyer.sass b/assets/sass/darkmeyer.sass index 6d7b3b4..a1cc574 100644 --- a/assets/sass/darkmeyer.sass +++ b/assets/sass/darkmeyer.sass @@ -98,7 +98,7 @@ input[type="submit"].button-primary p:last-child margin-bottom: 5px -.ticket-status +.ticket-attributes list-style: none margin: 0 border: 1px solid #bbb @@ -141,6 +141,12 @@ input[type="submit"].button-primary margin-right: 5px font-size: 2rem + .ticket-status + transition: all 230ms ease-in-out + &:hover + background: rgba(0, 0, 0, .1) + cursor: pointer + #comment-form textarea height: 150px diff --git a/src/Controllers/TicketController.php b/src/Controllers/TicketController.php index 49b872b..8c3fec6 100644 --- a/src/Controllers/TicketController.php +++ b/src/Controllers/TicketController.php @@ -69,6 +69,23 @@ class TicketController extends Controller { ->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 { $ticket = Ticket::where('id', $args['ticket_id'])->first(); diff --git a/src/routes.php b/src/routes.php index ef66e1a..29f0d1c 100644 --- a/src/routes.php +++ b/src/routes.php @@ -14,6 +14,7 @@ $app->post('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketControlle // /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'); +$app->post('/ticket/{ticket_id}/edit/{attr}', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postEditAttr')->setName('ticket.edit.attr'); // ticket deletion route $app->get('/ticket/{ticket_id}/delete', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getDelete')->setName('ticket.delete'); diff --git a/views/ticket/view.twig b/views/ticket/view.twig index 4c231cc..8a7522c 100644 --- a/views/ticket/view.twig +++ b/views/ticket/view.twig @@ -23,17 +23,17 @@
-