diff --git a/assets/coffee/slepe.coffee b/assets/coffee/slepe.coffee index d871794..29113a7 100644 --- a/assets/coffee/slepe.coffee +++ b/assets/coffee/slepe.coffee @@ -1,12 +1,41 @@ $(document).ready -> - console.log('Hello, world!') - - $('.ticket-severity').on('click', handleAttributeClick('severity')) - $('.ticket-status').on('click', handleAttributeClick('status')) + $('.ticket-queue').on('click', (e) -> + handleQueueClick(e) + ) + $('.ticket-severity').on('click', (e) -> + handleAttributeClick(e, 'severity') + ) + $('.ticket-status').on('click', (e) -> + handleAttributeClick(e, 'status') + ) validOptions = - 'severity' = ['low', 'medium', 'high'], - 'status' = ['open', 'closed', 'parked'] + 'severity': ['low', 'medium', 'high'], + 'status': ['open', 'closed', 'parked'] + +handleQueueClick = (e, fail = false) -> + newQueueId = prompt('Set queue ID:', $('.ticket-queue').data('id')) + + if (newQueueId != null) and (newQueueId != '') + if (true) + console.log('Setting queue ID to ' + newQueueId) + editLink = $('#ticketEditLink').attr('href') + '/queue_id' + console.log('Sending data to ' + editLink) + $.ajax({ + type: "POST", + url: editLink, + data: + 'queue_id': newQueueId, + dataType: 'json', + success: (result) -> + $('.ticket-queue').data('id', newQueueId) + $('.ticket-queue > span').text(result.queue_name) + updateTicketModified(result.updated_at) + console.log('Ticket updated successfully.') + }) + else + console.log('Invalid queue ID entered') + handleQueueClick(e, 'Invalid queue ID entered; you must enter a number.') handleAttributeClick = (e, attr, fail = false) -> newValue = prompt('Set ticket ' + attr + ':', $('.ticket-' + attr + ' > span').text()) @@ -16,12 +45,13 @@ handleAttributeClick = (e, attr, fail = false) -> if (newValue in validOptions[attr]) console.log('Setting ' + attr + ' to ' + newValue) editLink = $('#ticketEditLink').attr('href') + '/' + attr + postData = {} + postData[attr] = newValue console.log('Sending data to ' + editLink) $.ajax({ type: "POST", url: editLink, - data: - attr: newValue, + data: postData, dataType: 'json', success: (result) -> newValue = newValue.charAt(0).toUpperCase() + newValue.slice(1) diff --git a/assets/sass/darkmeyer.sass b/assets/sass/darkmeyer.sass index bc61237..f94986f 100644 --- a/assets/sass/darkmeyer.sass +++ b/assets/sass/darkmeyer.sass @@ -81,12 +81,16 @@ input[type="submit"].button-primary height: 250px min-height: 100px +#queue-header, #ticket-header margin-bottom: 15px + .queue-title, .ticket-title margin-bottom: 5px + .queue-created, + .queue-updated, .ticket-created, .ticket-updated margin-bottom: 3px @@ -94,6 +98,7 @@ input[type="submit"].button-primary font-size: 1.5rem font-style: italic +#queue-description, #ticket-body p:last-child margin-bottom: 5px @@ -141,6 +146,7 @@ input[type="submit"].button-primary margin-right: 5px font-size: 2rem + .ticket-queue, .ticket-severity, .ticket-status transition: all 230ms ease-in-out diff --git a/db/migrations/20221204223428_add_queue_table.php b/db/migrations/20221204223428_add_queue_table.php new file mode 100644 index 0000000..9b98d98 --- /dev/null +++ b/db/migrations/20221204223428_add_queue_table.php @@ -0,0 +1,35 @@ +table('queues'); + $table->addColumn('title', 'string', ['null' => false]) + ->addColumn('description', 'text', ['null' => false]) + ->addTimestamps() + ->addIndex(['title']) + ->create(); + + // Update tickets table to have a Queue ID field + $tickets = $this->table('tickets') + ->addColumn('queue_id', 'integer', ['null' => false]) + ->addForeignKey('queue_id', 'queues', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) + ->update(); + } +} diff --git a/src/Controllers/QueueController.php b/src/Controllers/QueueController.php new file mode 100644 index 0000000..254f706 --- /dev/null +++ b/src/Controllers/QueueController.php @@ -0,0 +1,44 @@ +first(); + + $view = Twig::fromRequest($request); + return $view->render($response, 'queue/view.twig', [ + 'queue' => $queue, + ]); + } + + public function getCreate(Request $request, Response $response): Response { + $view = Twig::fromRequest($request); + return $view->render($response, 'queue/create.twig'); + } + + public function postCreate(Request $request, Response $response): Response { + $params = (array)$request->getParsedBody(); + + $queue = new Queue; + $queue->title = $params['queue_title']; + $queue->description = $params['queue_description']; + + $queue->save(); + + // redirect the user back to the home page + $routeContext = RouteContext::fromRequest($request); + $routeParser = $routeContext->getRouteParser(); + return $response + ->withHeader('Location', $routeParser->urlFor('queue.view', ['queue_id' => $queue->id])) + ->withStatus(302); + } + +} diff --git a/src/Controllers/TicketController.php b/src/Controllers/TicketController.php index df32ed5..0e69a82 100644 --- a/src/Controllers/TicketController.php +++ b/src/Controllers/TicketController.php @@ -81,11 +81,17 @@ class TicketController extends Controller { // save updated ticket $ticket->save(); - // return a response - $response->getBody()->write(json_encode([ + // build JSON response + $jsonResponse = [ 'result' => 'success', 'updated_at' => $ticket->formatUpdatedAt(), - ])); + ]; + if ($attr == 'queue_id') { + $jsonResponse['queue_name'] = $ticket->queue->title; + } + + // return a response + $response->getBody()->write(json_encode($jsonResponse)); return $response; } diff --git a/src/Models/Queue.php b/src/Models/Queue.php new file mode 100644 index 0000000..684433e --- /dev/null +++ b/src/Models/Queue.php @@ -0,0 +1,36 @@ +hasMany(Ticket::class); + } + + public function render(): string { + $converter = new CommonMarkConverter([ + 'html_input' => 'strip', + 'allow_unsafe_links' => false, + ]); + + return $converter->convert($this->description); + } + + 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"); + } + +} diff --git a/src/Models/Ticket.php b/src/Models/Ticket.php index 94a71cb..2fbe9cb 100644 --- a/src/Models/Ticket.php +++ b/src/Models/Ticket.php @@ -14,6 +14,14 @@ class Ticket extends Model { 'due_at', ]; + public function queue() { + return $this->belongsTo(Queue::class); + } + + public function comments() { + return $this->hasMany(Comment::class); + } + public function render(): string { $converter = new CommonMarkConverter([ 'html_input' => 'strip', @@ -23,10 +31,6 @@ class Ticket extends Model { return $converter->convert($this->body); } - public function comments() { - 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"); } diff --git a/src/routes.php b/src/routes.php index 29f0d1c..f82a165 100644 --- a/src/routes.php +++ b/src/routes.php @@ -7,6 +7,13 @@ use Slim\Views\Twig; // 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'); +// /queue/create routes - allows a user to fill out a form to create a new queue +$app->get('/queue/create', '\\BitGoblin\\Goliath\\Controllers\\QueueController:getCreate')->setName('queue.create'); +$app->post('/queue/create', '\\BitGoblin\\Goliath\\Controllers\\QueueController:postCreate'); + +// /queue/id route - displays queue info to user +$app->get('/queue/{queue_id}', '\\BitGoblin\\Goliath\\Controllers\QueueController:getView')->setName('queue.view'); + // /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->post('/ticket/create', '\\BitGoblin\\Goliath\\Controllers\\TicketController:postCreate'); diff --git a/views/layout.twig b/views/layout.twig index 07d2709..bc2ff86 100644 --- a/views/layout.twig +++ b/views/layout.twig @@ -16,7 +16,8 @@ diff --git a/views/queue/create.twig b/views/queue/create.twig new file mode 100644 index 0000000..21ece85 --- /dev/null +++ b/views/queue/create.twig @@ -0,0 +1,29 @@ +{% extends 'layout.twig' %} + +{% block title %}Create New Queue{% endblock %} + +{% block content %} +
+
+

Create new queue

+
+
+ +
+
+
+
+
+ + +
+
+ + + + + +
+
+
+{% endblock %} diff --git a/views/queue/view.twig b/views/queue/view.twig new file mode 100644 index 0000000..5691812 --- /dev/null +++ b/views/queue/view.twig @@ -0,0 +1,44 @@ +{% extends 'layout.twig' %} + +{% block title %}Ticket Queue: {{ queue.title }}{% endblock %} + +{% block content %} + +
+
+
+
+

{{ queue.title }}

+

Created at: {{ queue.formatCreatedAt() }}

+

Last updated at: {{ queue.formatUpdatedAt() }}

+
+
+ +
+
+ {{ queue.render() | raw }} +
+
+
+
+ +
+ + +
+
+ +
+
+{% endblock %} diff --git a/views/ticket/view.twig b/views/ticket/view.twig index 9f6fd92..f809c7f 100644 --- a/views/ticket/view.twig +++ b/views/ticket/view.twig @@ -29,6 +29,9 @@
  • Edit
  • Delete
  • +
  • + Queue: {{ ticket.queue.title }} +
  • Severity: {{ ticket.severity | capitalize }}