admin global nav

This commit is contained in:
Mark Moser 2016-09-22 16:29:19 -05:00
parent aeef75bf8b
commit 5398a8ea8b
14 changed files with 64 additions and 67 deletions

View File

@ -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;
}
}
}

View File

@ -5,6 +5,10 @@ header {
&.no-progressbar {
padding-top: 52px;
}
&.no-progressbar.admin {
padding-top: 0;
}
}
.page-title {
@include omega();

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,9 @@
<nav>
<%= link_to("Users", admin_users_url) if policy(User).index? %>
<% #= link_to("Departments", admin_departments_url) if policy(Department).index? %>
<%= link_to("Quizzes", admin_quizzes_url) if policy(Quiz).index? %>
<%= link_to("Candidates", admin_candidates_url) if policy(Candidate).index? %>
<%= link_to("Results", admin_results_url) if policy(Quiz).index? %>
<%= link_to("Profile", admin_profile_url) %>
<%= link_to("Logout", admin_logout_url) %>
</nav>

View File

@ -1,9 +1,10 @@
<%
content_for :section_title, "Candidates"
%>
<main class="summary_tpl">
<h1>Candidates</h1>
<%= link_to(admin_new_candidate_path, { class: 'secondary-btn' }) do %>
<button>Create New Candidate</button>
<% end %>
<% end if policy(User).create? %>
<table cellspacing="0" cellpadding="0">
<tr>

View File

@ -1,35 +0,0 @@
<%
content_for :section_title, "Admin Dashboard"
%>
<pre>
## Admin
Users | Dept/Unit | Quizzes | Candidates | Results | Profile | Logout
## Manager
Quizzes | Results | Profile | Logout
## Recruiter
Results | Profile | Logout
## Reviewer
Candidates | Profile | Logout
</pre>
<% if policy(Quiz).index? %>
<section>
<h1>Quizzes</h1>
<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %>
<%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
</section>
<% end %>
<% if policy(User).index? %>
<section>
<h1>Users</h1>
<%= render partial: 'admin/user/table_list', locals: { users: @users } %>
<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %>
</section>
<% end %>

View File

@ -13,7 +13,7 @@
<td><%= quiz.dept %></td>
<td><%= quiz.unit %></td>
<td><%= quiz.questions.count %></td>
<td><%= link_to 'edit', admin_edit_quiz_path(quiz.to_i), { class: 'btn tertiary-btn' } %></td>
<td><%= link_to 'edit', admin_edit_quiz_path(quiz.to_i), { class: 'btn tertiary-btn' } if policy(quiz).edit? %></td>
</tr>
<% end %>
</table>

View File

@ -1,6 +1,7 @@
<%
content_for :section_title, "Completed Tests"
%>
<main class="summary_tpl">
<h1>Completed Tests</h1>
<table cellspacing="0" cellpadding="0">
<tr>
<th>Test ID</th>

View File

@ -11,7 +11,7 @@
<td><%= link_to user.name, admin_user_path(user.to_i) %></td>
<td><%= mail_to(user.email) %></td>
<td><%= user.role %></td>
<td><%= link_to 'edit', admin_edit_user_path(user.to_i), { class: 'btn tertiary-btn' } %></td>
<td><%= link_to 'edit', admin_edit_user_path(user.to_i), { class: 'btn tertiary-btn' } if policy(user).edit? %></td>
</tr>
<% end %>
</table>

View File

@ -4,4 +4,4 @@
<h1>Users</h1>
<%= 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? %>

View File

@ -20,7 +20,8 @@
<body>
<div class="layout">
<header class="no-progressbar">
<header class="no-progressbar admin">
<%= render partial: "admin/nav" if current_user %>
<div class="page-title slash-left">
<% if content_for?(:section_title) %>
<div><%= yield(:section_title) %></div>

View File

@ -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