diff --git a/assets/sass/darkmeyer.sass b/assets/sass/darkmeyer.sass index 8ad5a73..6d7b3b4 100644 --- a/assets/sass/darkmeyer.sass +++ b/assets/sass/darkmeyer.sass @@ -74,7 +74,8 @@ input[type="submit"].button-primary #main-wrapper margin-top: 25px -#ticket-form +#ticket-form, +#comment-form textarea max-width: 100% height: 250px @@ -139,3 +140,17 @@ input[type="submit"].button-primary i margin-right: 5px font-size: 2rem + +#comment-form + textarea + height: 150px + +.comments-list + list-style: none + margin: 0 + + .comment + &:not(:last-child) + border-bottom: 1px solid #666 + p:last-child + margin-bottom: 5px diff --git a/db/migrations/20221122032232_add_comments_table.php b/db/migrations/20221122032232_add_comments_table.php new file mode 100644 index 0000000..5a912c3 --- /dev/null +++ b/db/migrations/20221122032232_add_comments_table.php @@ -0,0 +1,29 @@ +table('comments'); + $table->addColumn('body', 'text', ['null' => false]) + ->addColumn('ticket_id', 'integer', ['null' => false]) + ->addTimestamps() + ->addForeignKey('ticket_id', 'tickets', 'id', ['delete' => 'CASCADE', 'update' => 'CASCADE']) + ->addIndex(['body']) + ->create(); + } +} diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php new file mode 100644 index 0000000..7be2497 --- /dev/null +++ b/src/Controllers/CommentController.php @@ -0,0 +1,29 @@ +getParsedBody(); + + $comment = new Comment; + $comment->body = $params['comment_body']; + $comment->ticket_id = $params['ticket_id']; + + $comment->save(); + + // redirect the user back to the home page + $routeContext = RouteContext::fromRequest($request); + $routeParser = $routeContext->getRouteParser(); + return $response + ->withHeader('Location', $routeParser->urlFor('ticket.view', ['ticket_id' => $comment->ticket->id])) + ->withStatus(302); + } + +} diff --git a/src/Controllers/TicketController.php b/src/Controllers/TicketController.php index fd47f53..89d3c10 100644 --- a/src/Controllers/TicketController.php +++ b/src/Controllers/TicketController.php @@ -11,11 +11,11 @@ use BitGoblin\Goliath\Models\Ticket; class TicketController extends Controller { public function getView(Request $request, Response $response, array $args): Response { - $ticket = Ticket::where('id', $args['ticket_id'])->get(); + $ticket = Ticket::where('id', $args['ticket_id'])->get()[0]; $view = Twig::fromRequest($request); return $view->render($response, 'ticket/view.twig', [ - 'ticket' => $ticket[0], + 'ticket' => $ticket, ]); } diff --git a/src/Models/Comment.php b/src/Models/Comment.php new file mode 100644 index 0000000..9f9a644 --- /dev/null +++ b/src/Models/Comment.php @@ -0,0 +1,28 @@ + 'strip', + 'allow_unsafe_links' => false, + ]); + + return $converter->convert($this->body); + } + + public function ticket() { + return $this->belongsTo(Ticket::class); + } + +} diff --git a/src/Models/Ticket.php b/src/Models/Ticket.php index 8c56819..43199ee 100644 --- a/src/Models/Ticket.php +++ b/src/Models/Ticket.php @@ -23,4 +23,8 @@ class Ticket extends Model { return $converter->convert($this->body); } + public function comments() { + return $this->hasMany(Comment::class); + } + } diff --git a/src/routes.php b/src/routes.php index 6daddd2..ed253a9 100644 --- a/src/routes.php +++ b/src/routes.php @@ -17,3 +17,6 @@ $app->post('/ticket/{ticket_id}/edit', '\\BitGoblin\\Goliath\\Controllers\\Ticke // /ticket/id route - displays ticket info to user $app->get('/ticket/{ticket_id}', '\\BitGoblin\\Goliath\\Controllers\\TicketController:getView')->setName('ticket.view'); + +// add a comment to a ticket +$app->post('/comment/add', '\\BitGoblin\\Goliath\\Controllers\\CommentController:postAdd')->setName('comment.add'); diff --git a/views/ticket/view.twig b/views/ticket/view.twig index 87e301e..9870a48 100644 --- a/views/ticket/view.twig +++ b/views/ticket/view.twig @@ -48,7 +48,31 @@

Ticket comments/Updates

-

There are no comments to display at this time.

+ {% if ticket.comments | length > 0 %} + + {% else %} +

There are no comments to display at this time.

+ {% endif %} +
+
+ +
+ + +
+
+
+ + + + + + +
{% endblock %}