Compare commits

..

2 Commits

5 changed files with 84 additions and 7 deletions

View File

@ -1,2 +1,54 @@
$(document).ready -> $(document).ready ->
console.log('Hello, world!') console.log('Hello, world!')
$('.ticket-severity').on('click', handleSeverityClick)
$('.ticket-status').on('click', handleStatusClick)
handleSeverityClick = (e, msg = 'Set ticket severity:') ->
validSeverity = ['low', 'medium', 'high']
newSeverity = prompt(msg, $('.ticket-severity > span').text())
newSeverity = newSeverity.toLowerCase()
if (newSeverity != null) and (newSeverity != '')
if (newSeverity in validSeverity)
console.log('Setting severity to ' + newSeverity)
editLink = $('#ticketEditLink').attr('href') + '/severity'
console.log('Sending data to ' + editLink)
$.ajax({
type: "POST",
url: editLink,
data:
severity: newSeverity,
success: (data) ->
newSeverity = newSeverity.charAt(0).toUpperCase() + newSeverity.slice(1)
$('.ticket-severity > span').text(newSeverity)
console.log('Ticket updated successfully.')
})
else
console.log('Invalid severity entered')
handleSeverityClick(e, 'Invalid severity; valid values are low, medium, and high.')
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,13 @@ input[type="submit"].button-primary
margin-right: 5px margin-right: 5px
font-size: 2rem font-size: 2rem
.ticket-severity,
.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 class="ticket-severity">
Severity {{ ticket.severity | capitalize }} Severity: <span>{{ ticket.severity | capitalize }}</span>
</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