From 5398a8ea8bc6b50b61695e82c2aa3809f41cb8e8 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 22 Sep 2016 16:29:19 -0500 Subject: [PATCH] admin global nav --- app/assets/stylesheets/molecules/_nav.scss | 17 +++++++++ app/assets/stylesheets/templates/_header.scss | 4 +++ app/controllers/admin/candidate_controller.rb | 4 +-- app/controllers/admin/dashboard_controller.rb | 21 +++++++++-- app/controllers/application_controller.rb | 18 ---------- app/views/admin/_nav.html.erb | 9 +++++ app/views/admin/candidate/index.html.erb | 7 ++-- app/views/admin/dashboard/show.html.erb | 35 ------------------- app/views/admin/quiz/_table_list.html.erb | 2 +- app/views/admin/result/index.html.erb | 5 +-- app/views/admin/user/_table_list.html.erb | 2 +- app/views/admin/user/index.html.erb | 2 +- app/views/layouts/admin.html.erb | 3 +- .../admin/dashboard_controller_test.rb | 2 +- 14 files changed, 64 insertions(+), 67 deletions(-) create mode 100644 app/assets/stylesheets/molecules/_nav.scss create mode 100644 app/views/admin/_nav.html.erb delete mode 100644 app/views/admin/dashboard/show.html.erb diff --git a/app/assets/stylesheets/molecules/_nav.scss b/app/assets/stylesheets/molecules/_nav.scss new file mode 100644 index 0000000..f27eb2f --- /dev/null +++ b/app/assets/stylesheets/molecules/_nav.scss @@ -0,0 +1,17 @@ +nav { + margin: 15px 0; + padding: 0; + text-align: right; + + a, + a:visited { + text-decoration: none; + padding: 15px; + margin: 0; + text-transform: uppercase; + + &:hover { + background-color: $gray-lighter; + } + } +} diff --git a/app/assets/stylesheets/templates/_header.scss b/app/assets/stylesheets/templates/_header.scss index b5f6734..c12384f 100644 --- a/app/assets/stylesheets/templates/_header.scss +++ b/app/assets/stylesheets/templates/_header.scss @@ -5,6 +5,10 @@ header { &.no-progressbar { padding-top: 52px; } + + &.no-progressbar.admin { + padding-top: 0; + } } .page-title { @include omega(); diff --git a/app/controllers/admin/candidate_controller.rb b/app/controllers/admin/candidate_controller.rb index 85f4d2b..5a95b68 100644 --- a/app/controllers/admin/candidate_controller.rb +++ b/app/controllers/admin/candidate_controller.rb @@ -4,7 +4,7 @@ module Admin before_action :collect_quizzes, except: [:login, :auth] def index - @candidates = policy_scope current_recruiter.candidates + @candidates = policy_scope Candidate.order(:name) end def new @@ -15,7 +15,7 @@ module Admin def create authorize Candidate - @candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id)) + @candidate = Candidate.create(candidate_params.merge(recruiter_id: current_user.id)) if @candidate.persisted? send_notifications @candidate diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 94c7f00..ea5492f 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -3,8 +3,25 @@ module Admin class DashboardController < AdminController def show authorize :dashboard - @quizzes = policy_scope Quiz.includes(:questions).all - @users = policy_scope User.order(:role, :name) + send "redirect_for_#{current_user.role}" end + + private + + def redirect_for_admin + redirect_to admin_users_url + end + + def redirect_for_manager + redirect_to admin_quizzes_url + end + + def redirect_for_reviewer + redirect_to admin_results_url + end + + def redirect_for_recruiter + redirect_to admin_candidates_url + end end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 37fe04f..c9b89a9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,16 +4,6 @@ class ApplicationController < ActionController::Base add_flash_types :warning, :success - def current_recruiter - user_parms = { id: session[:user], role: %w(admin recruiter) } - @current_recruiter ||= User.find_by(user_parms) if session[:user] - end - - def current_reviewer - user_parms = { id: session[:user], role: %w(admin reviewer) } - @current_reviewer ||= User.find_by(user_parms) if session[:user] - end - def current_candidate @current_candidate ||= Candidate.find_by(test_hash: session[:test_id]) if session[:test_id] end @@ -29,14 +19,6 @@ class ApplicationController < ActionController::Base params.require(:auth).permit(:email, :password) end - def authorize_recruiter - redirect_to recruiter_login_path unless current_recruiter - end - - def authorize_reviewer - redirect_to review_login_path unless current_reviewer - end - def authorize_candidate redirect_to login_path unless current_candidate end diff --git a/app/views/admin/_nav.html.erb b/app/views/admin/_nav.html.erb new file mode 100644 index 0000000..e81cb18 --- /dev/null +++ b/app/views/admin/_nav.html.erb @@ -0,0 +1,9 @@ + diff --git a/app/views/admin/candidate/index.html.erb b/app/views/admin/candidate/index.html.erb index e6095fc..0c29e2e 100644 --- a/app/views/admin/candidate/index.html.erb +++ b/app/views/admin/candidate/index.html.erb @@ -1,9 +1,10 @@ +<% + content_for :section_title, "Candidates" +%>
-

Candidates

- <%= link_to(admin_new_candidate_path, { class: 'secondary-btn' }) do %> - <% end %> + <% end if policy(User).create? %> diff --git a/app/views/admin/dashboard/show.html.erb b/app/views/admin/dashboard/show.html.erb deleted file mode 100644 index ee1284a..0000000 --- a/app/views/admin/dashboard/show.html.erb +++ /dev/null @@ -1,35 +0,0 @@ -<% - content_for :section_title, "Admin Dashboard" -%> - -
-## Admin
-Users | Dept/Unit | Quizzes | Candidates | Results | Profile | Logout
-
-## Manager
-Quizzes | Results | Profile | Logout
-
-## Recruiter
-Results | Profile | Logout
-
-## Reviewer
-Candidates | Profile | Logout
-
- -<% if policy(Quiz).index? %> -
-

Quizzes

- <%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %> - <%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %> -
-<% end %> - -<% if policy(User).index? %> -
-

Users

- <%= render partial: 'admin/user/table_list', locals: { users: @users } %> - <%= link_to('New User', admin_new_user_path, { class: 'btn' }) %> -
-<% end %> - - diff --git a/app/views/admin/quiz/_table_list.html.erb b/app/views/admin/quiz/_table_list.html.erb index 98fbd79..8ba51bc 100644 --- a/app/views/admin/quiz/_table_list.html.erb +++ b/app/views/admin/quiz/_table_list.html.erb @@ -13,7 +13,7 @@ - + <% end %>
<%= quiz.dept %> <%= quiz.unit %> <%= quiz.questions.count %><%= link_to 'edit', admin_edit_quiz_path(quiz.to_i), { class: 'btn tertiary-btn' } %><%= link_to 'edit', admin_edit_quiz_path(quiz.to_i), { class: 'btn tertiary-btn' } if policy(quiz).edit? %>
diff --git a/app/views/admin/result/index.html.erb b/app/views/admin/result/index.html.erb index 158605e..3c1373c 100644 --- a/app/views/admin/result/index.html.erb +++ b/app/views/admin/result/index.html.erb @@ -1,6 +1,7 @@ +<% + content_for :section_title, "Completed Tests" +%>
-

Completed Tests

- diff --git a/app/views/admin/user/_table_list.html.erb b/app/views/admin/user/_table_list.html.erb index bcce061..9b8ef8f 100644 --- a/app/views/admin/user/_table_list.html.erb +++ b/app/views/admin/user/_table_list.html.erb @@ -11,7 +11,7 @@ - + <% end %>
Test ID<%= link_to user.name, admin_user_path(user.to_i) %> <%= mail_to(user.email) %> <%= user.role %><%= link_to 'edit', admin_edit_user_path(user.to_i), { class: 'btn tertiary-btn' } %><%= link_to 'edit', admin_edit_user_path(user.to_i), { class: 'btn tertiary-btn' } if policy(user).edit? %>
diff --git a/app/views/admin/user/index.html.erb b/app/views/admin/user/index.html.erb index 2598812..303aa62 100644 --- a/app/views/admin/user/index.html.erb +++ b/app/views/admin/user/index.html.erb @@ -4,4 +4,4 @@

Users

<%= render partial: 'admin/user/table_list', locals: { users: @users } %> -<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %> +<%= link_to('New User', admin_new_user_path, { class: 'btn' }) if policy(User).create? %> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 79672e3..dae9069 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -20,7 +20,8 @@
-
+
+ <%= render partial: "admin/nav" if current_user %>
<% if content_for?(:section_title) %>
<%= yield(:section_title) %>
diff --git a/test/controllers/admin/dashboard_controller_test.rb b/test/controllers/admin/dashboard_controller_test.rb index 9b36041..10a1474 100644 --- a/test/controllers/admin/dashboard_controller_test.rb +++ b/test/controllers/admin/dashboard_controller_test.rb @@ -11,7 +11,7 @@ module Admin test "should get dashboard" do post admin_auth_url, params: { auth: { email: 'alan.admin@mailinator.com', password: 'password' } } - get admin_url + get admin_users_url assert_response :success end end