From 09f9cf9d483c9ac4e3ef3f8161a02590607facd0 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 24 Jul 2017 15:21:10 +0100 Subject: [PATCH] Feedback HTML views added and fixes made --- lib/Pear/LocalLoop.pm | 3 ++ .../LocalLoop/Controller/Admin/Feedback.pm | 29 +++++++++++++ lib/Pear/LocalLoop/Controller/Api/Feedback.pm | 1 - lib/Pear/LocalLoop/Schema/Result/Feedback.pm | 14 ++++-- templates/admin/feedback/index.html.ep | 25 +++++++++++ templates/admin/feedback/read.html.ep | 43 +++++++++++++++++++ 6 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 lib/Pear/LocalLoop/Controller/Admin/Feedback.pm create mode 100644 templates/admin/feedback/index.html.ep create mode 100644 templates/admin/feedback/read.html.ep diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index c05fafb..1c5efd6 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -177,6 +177,9 @@ sub startup { $admin_routes->get('/organisations/pending/:id')->to('admin-organisations#pending_read'); $admin_routes->get('/organisations/pending/:id/approve')->to('admin-organisations#pending_approve'); + $admin_routes->get('/feedback')->to('admin-feedback#index'); + $admin_routes->get('/feedback/:id')->to('admin-feedback#read'); + # my $user_routes = $r->under('/')->to('root#under'); # $user_routes->get('/home')->to('root#home'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Feedback.pm b/lib/Pear/LocalLoop/Controller/Admin/Feedback.pm new file mode 100644 index 0000000..f9063a4 --- /dev/null +++ b/lib/Pear/LocalLoop/Controller/Admin/Feedback.pm @@ -0,0 +1,29 @@ +package Pear::LocalLoop::Controller::Admin::Feedback; +use Mojo::Base 'Mojolicious::Controller'; + +has result_set => sub { + my $c = shift; + return $c->schema->resultset('Feedback'); +}; + +sub index { + my $c = shift; + + my $feedback_rs = $c->result_set; + $c->stash( feedbacks => [ $feedback_rs->all ] ); +} + +sub read { + my $c = shift; + + my $id = $c->param('id'); + + if ( my $feedback = $c->result_set->find($id) ) { + $c->stash( feedback => $feedback ); + } else { + $c->flash( error => 'No Feedback found' ); + $c->redirect_to( '/admin/feedback' ); + } +} + +1; diff --git a/lib/Pear/LocalLoop/Controller/Api/Feedback.pm b/lib/Pear/LocalLoop/Controller/Api/Feedback.pm index 34f1bf2..eafce88 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Feedback.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Feedback.pm @@ -45,7 +45,6 @@ sub post_feedback { my $user = $user_rs->find({'email' => $validation->param('email')}); $c->schema->resultset('Feedback')->create({ - email => $validation->param('email'), user => $user, feedbacktext => $validation->param('feedbacktext'), app_name => $validation->param('app_name'), diff --git a/lib/Pear/LocalLoop/Schema/Result/Feedback.pm b/lib/Pear/LocalLoop/Schema/Result/Feedback.pm index 60deba9..2d741ae 100644 --- a/lib/Pear/LocalLoop/Schema/Result/Feedback.pm +++ b/lib/Pear/LocalLoop/Schema/Result/Feedback.pm @@ -7,18 +7,24 @@ use base 'DBIx::Class::Core'; __PACKAGE__->table("feedback"); +__PACKAGE__->load_components(qw/ + InflateColumn::DateTime + TimeStamp +/); + __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "email" => { - data_type => "text", - is_nullable => 0, - }, "user_id" => { data_type => "integer", is_foreign_key => 1, is_nullable => 0, }, + "submitted_at" => { + data_type => "datetime", + is_nullable => 0, + set_on_create => 1, + }, "feedbacktext" => { data_type => "text", is_nullable => 0, diff --git a/templates/admin/feedback/index.html.ep b/templates/admin/feedback/index.html.ep new file mode 100644 index 0000000..375ed5a --- /dev/null +++ b/templates/admin/feedback/index.html.ep @@ -0,0 +1,25 @@ +% layout 'admin'; +% title 'Feedback'; +% content_for javascript => begin +% end +% if ( my $error = flash 'error' ) { + +% } elsif ( my $success = flash 'success' ) { + +% } +
+ % for my $feedback (@$feedbacks) { + +
+ %= $feedback->user->email +
+
+ %= $feedback->submitted_at +
+
+ % } +
diff --git a/templates/admin/feedback/read.html.ep b/templates/admin/feedback/read.html.ep new file mode 100644 index 0000000..6a5372b --- /dev/null +++ b/templates/admin/feedback/read.html.ep @@ -0,0 +1,43 @@ +% layout 'admin'; +% title 'Feedback'; +% content_for javascript => begin +% end +% if ( my $error = flash 'error' ) { + +% } elsif ( my $success = flash 'success' ) { + +% } +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+