Added functionality to update the ticket's last updated time when changing the ticket status or severity

This commit is contained in:
Gregory Ballantine 2022-12-04 17:15:17 -05:00
parent 77c8605b49
commit ab2c87ce3a
4 changed files with 26 additions and 7 deletions

View File

@ -19,9 +19,11 @@ handleSeverityClick = (e, msg = 'Set ticket severity:') ->
url: editLink,
data:
severity: newSeverity,
success: (data) ->
dataType: 'json',
success: (result) ->
newSeverity = newSeverity.charAt(0).toUpperCase() + newSeverity.slice(1)
$('.ticket-severity > span').text(newSeverity)
updateTicketModified(result.updated_at)
console.log('Ticket updated successfully.')
})
else
@ -39,16 +41,22 @@ handleStatusClick = (e, msg = 'Set ticket status:') ->
console.log('Setting status to ' + newStatus)
editLink = $('#ticketEditLink').attr('href') + '/status'
console.log('Sending data to ' + editLink)
$.ajax({
$.ajax(
type: "POST",
url: editLink,
data:
status: newStatus,
success: (data) ->
dataType: 'json',
success: (result) ->
newStatus = newStatus.charAt(0).toUpperCase() + newStatus.slice(1)
$('.ticket-status > span').text(newStatus)
updateTicketModified(result.updated_at)
console.log('Ticket updated successfully.')
})
)
else
console.log('Invalid status entered')
handleStatusClick(e, 'Invalid status; valid values are open, closed, and parked.')
updateTicketModified = (date) ->
$('.ticket-updated > span').text(date)
console.log('Ticket update time is ' + date)

View File

@ -82,7 +82,10 @@ class TicketController extends Controller {
$ticket->save();
// return a response
$response->getBody()->write(json_encode(['status' => 'success']));
$response->getBody()->write(json_encode([
'result' => 'success',
'updated_at' => $ticket->formatUpdatedAt(),
]));
return $response;
}

View File

@ -27,4 +27,12 @@ class Ticket extends Model {
return $this->hasMany(Comment::class);
}
public function formatCreatedAt(): string {
return date_format(date_create($this->created_at), "F jS\\, Y \\a\\t g:i:s a");
}
public function formatUpdatedAt(): string {
return date_format(date_create($this->updated_at), "F jS\\, Y \\a\\t g:i:s a");
}
}

View File

@ -9,8 +9,8 @@
<div id="ticket-header" class="row">
<div class="columns twelve">
<h1 class="ticket-title">{{ ticket.title }}</h1>
<h4 class="ticket-created">Created at {{ ticket.created_at }}</h4>
<h4 class="ticket-updated">Last updated at {{ ticket.updated_at }}</h4>
<h4 class="ticket-created">Created at: <span>{{ ticket.formatCreatedAt() }}</span></h4>
<h4 class="ticket-updated">Last updated at: <span>{{ ticket.formatUpdatedAt() }}</span></h4>
</div>
</div>