From 3d5e837e66705a72d95560b617e7994d976db41f Mon Sep 17 00:00:00 2001 From: Bartlomiej Kozal Date: Mon, 26 Dec 2016 20:32:33 +0100 Subject: [PATCH] Add feedback summary --- .../admin/dashboards_controller.rb | 10 +++++ app/controllers/admin_controller.rb | 11 ++++++ app/mailers/feedback_mailer.rb | 2 +- app/views/admin/dashboards/show.html.erb | 39 +++++++++++++++++++ config/routes.rb | 4 ++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 app/controllers/admin/dashboards_controller.rb create mode 100644 app/controllers/admin_controller.rb create mode 100644 app/views/admin/dashboards/show.html.erb diff --git a/app/controllers/admin/dashboards_controller.rb b/app/controllers/admin/dashboards_controller.rb new file mode 100644 index 0000000..43d56c3 --- /dev/null +++ b/app/controllers/admin/dashboards_controller.rb @@ -0,0 +1,10 @@ +class Admin::DashboardsController < AdminController + def show + @feedback_comments = Feedback.where.not(comment: "").order(created_at: :desc) + @feedback_answers = Feedback.all.map(&:answers).inject do |mem, hash| + mem.merge(hash) do |_, old_value, new_value| + old_value.to_i + new_value.to_i + end + end + end +end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb new file mode 100644 index 0000000..356e20b --- /dev/null +++ b/app/controllers/admin_controller.rb @@ -0,0 +1,11 @@ +class AdminController < ApplicationController + before_action :require_login, :require_admin + + ADMINS = %w(bkzl@me.com mackozal@me.com) + + private + + def require_admin + raise ApplicationController::NotAuthorized unless ADMINS.any? { |email| current_user.email == email } + end +end diff --git a/app/mailers/feedback_mailer.rb b/app/mailers/feedback_mailer.rb index 4e3e7c6..2f261d3 100644 --- a/app/mailers/feedback_mailer.rb +++ b/app/mailers/feedback_mailer.rb @@ -2,7 +2,7 @@ class FeedbackMailer < ApplicationMailer def notify(feedback) @feedback = feedback - mail to: "bkzl@me.com", + mail to: "bkzl@me.com mackozal@me.com", subject: %(New feedback on Jottings) end end diff --git a/app/views/admin/dashboards/show.html.erb b/app/views/admin/dashboards/show.html.erb new file mode 100644 index 0000000..a4f2489 --- /dev/null +++ b/app/views/admin/dashboards/show.html.erb @@ -0,0 +1,39 @@ +
+
+
+ <% @feedback_comments&.each do |feedback| %> +
+
+ <%= feedback %> + <%= time_ago_in_words(feedback.created_at) %> ago +
+ + <%= feedback.comment %> +
+ <% end %> +
+ +
+
    +
  • +
    Users
    +
    <%= User.count %>
    +
  • + +
  • +
    Documents
    +
    <%= Document.count %>
    +
  • +
+ +
    + <% @feedback_answers&.each do |answer, count| %> +
  • + <%= answer.titleize %> - + <%= count %> +
  • + <% end %> +
+
+
+
diff --git a/config/routes.rb b/config/routes.rb index 2008159..c3463f7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,6 +24,10 @@ get "/:page" => "static_pages#show", page: :page, as: :page end + namespace :admin do + resource :dashboard, only: [:show] + end + constraints Clearance::Constraints::SignedIn.new do root to: "editor/documents#index" end