Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
Add feedback summary
Browse files Browse the repository at this point in the history
  • Loading branch information
bartkozal committed Dec 26, 2016
1 parent 17f8b7e commit 3d5e837
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/controllers/admin/dashboards_controller.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AdminController < ApplicationController
before_action :require_login, :require_admin

ADMINS = %w([email protected] [email protected])

private

def require_admin
raise ApplicationController::NotAuthorized unless ADMINS.any? { |email| current_user.email == email }
end
end
2 changes: 1 addition & 1 deletion app/mailers/feedback_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class FeedbackMailer < ApplicationMailer
def notify(feedback)
@feedback = feedback

mail to: "[email protected]",
mail to: "[email protected] [email protected]",
subject: %(New feedback on Jottings)
end
end
39 changes: 39 additions & 0 deletions app/views/admin/dashboards/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="container margin-top">
<div class="grid grid-pair">
<div class="grid-item 4/5">
<% @feedback_comments&.each do |feedback| %>
<div class="margin-bottom">
<div>
<span class="text-lead"><%= feedback %></span>
<span class="text-muted text-small"><%= time_ago_in_words(feedback.created_at) %> ago</span>
</div>

<%= feedback.comment %>
</div>
<% end %>
</div>

<div class="grid-item 1/5">
<ul class="list-inline margin-bottom">
<li>
<div class="text-muted text-small">Users</div>
<div class="text-lead"><%= User.count %></div>
</li>

<li class="margin-left">
<div class="text-muted text-small">Documents</div>
<div class="text-lead"><%= Document.count %></div>
</li>
</ul>

<ul class="list-reset">
<% @feedback_answers&.each do |answer, count| %>
<li>
<span class="text-muted text-small"><%= answer.titleize %> - </span>
<%= count %>
</li>
<% end %>
</ul>
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d5e837

Please sign in to comment.