admin views roughed in

This commit is contained in:
Mark Moser 2016-08-18 18:22:57 -05:00
parent 430097b6ef
commit 63701c8247
29 changed files with 316 additions and 104 deletions

View File

@ -15,6 +15,20 @@
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
guard 'livereload' do
watch(%r{app/assets/.+\.(scss|css|js|erb)})
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/controllers/.+\.rb})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(scss|css|js|erb|html|png|jpg))).*}) do |m|
"/assets/#{m[3]}"
end
end
guard :minitest, spring: true, all_after_pass: true, all_on_start: false do
watch(%r{^test/test_helper\.rb$}) { 'test' }
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
@ -32,20 +46,6 @@ guard :minitest, spring: true, all_after_pass: true, all_on_start: false do
watch(%r{^app/views/(.*_mailer/)?([^/]+)\.erb$}) { ["test/mailers", "test/integration"] }
end
guard 'livereload' do
watch(%r{app/assets/.+\.(scss|css|js|erb)})
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/controllers/.+\.rb})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(scss|css|js|erb|html|png|jpg))).*}) do |m|
"/assets/#{m[3]}"
end
end
guard :rubocop do
watch(/.+\.rb$/)
watch(/Rakefile/)

View File

@ -42,7 +42,7 @@ module Admin
private
def quiz_params
params.require(:quiz).permit(:dept, :unit)
params.require(:quiz).permit(:name, :dept, :unit)
end
end
end

View File

@ -1,7 +1,10 @@
class AdminController < ApplicationController
layout 'admin'
before_action :authorize_admin
def dashboard
@quizzes = Quiz.includes(:questions).all
@users = User.order(:role, :name)
end
def current_admin

View File

@ -9,4 +9,12 @@ module ApplicationHelper
["15+ Years", "15+"]
], disabled: "-", selected: (val.blank? ? '' : val))
end
def admin_role_options val
options_for_select([
%w(Reviewer reviewer),
%w(Recruiter recruiter),
%w(Admin admin)
], disabled: "-", selected: (val.blank? ? '' : val))
end
end

View File

@ -2,6 +2,7 @@ class Quiz < ApplicationRecord
has_many :questions, -> { order(:sort) }
has_many :candidates
validates_presence_of :name
validates_presence_of :dept
validates_presence_of :unit
end

View File

@ -1,2 +1,21 @@
<h1>Admin::Auth#login</h1>
<p>Find me in app/views/admin/auth/login.html.erb</p>
<main class="intro_tpl">
<h1>Admin Login</h1>
<% if flash[:error].present? %>
<div class="error"><%= flash[:error] %></div>
<% end %>
<%= form_for :auth, url: admin_login_path do |form| %>
<div class="form-group">
<%= form.label :email %>
<%= form.email_field :email %>
</div>
<div class="form-group">
<%= form.label :password %>
<%= form.password_field :password %>
</div>
<%= submit_tag "Log in" %>
<% end %>
</main>

View File

@ -1,2 +0,0 @@
<h1>Admin::Auth#logout</h1>
<p>Find me in app/views/admin/auth/logout.html.erb</p>

View File

@ -1 +1,18 @@
huzzah! dashboard
<%
content_for :section_title, "Admin Dashboard"
%>
<main class="summary_tpl">
<section>
<h1>Quizzes</h1>
<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %>
<%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
</section>
<section>
<h1>Users</h1>
<%= render partial: 'admin/user/table_list', locals: { users: @users } %>
<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %>
</section>
</main>

View File

@ -1,2 +0,0 @@
<h1>Admin::Questions#index</h1>
<p>Find me in app/views/admin/questions/index.html.erb</p>

View File

@ -1,6 +1,29 @@
<%= form_for quiz, url: action do |f| %>
<p>Unit: <%= f.text_field :unit %></p>
<p>Dept: <%= f.text_field :dept %></p>
<%= f.submit %>
<% if flash[:error].present? %>
<div class="error">
<%= flash[:error] %>
<p>
<% quiz.errors.messages.each do |k,v| %>
<%= "#{k.to_s} #{v.join(' and ')}" %><br />
<% end %>
</p>
</div>
<% end %>
<%= form_for quiz, url: action do |form| %>
<div class="form-group">
<%= form.label :name, "Quiz Description" %>
<%= form.text_field :name %>
</div>
<div class="form-group">
<%= form.label :dept, 'Department' %>
<%= form.text_field :dept %>
</div>
<div class="form-group">
<%= form.label :unit, 'Unit' %>
<%= form.text_field :unit %>
</div>
<%= form.submit %>
<% end %>

View File

@ -0,0 +1,19 @@
<table cellspacing="0" cellpadding="0">
<tr>
<th>Name</th>
<th>Dept</th>
<th>Unit</th>
<th>Questions</th>
<th></th>
</tr>
<% quizzes.each do |quiz| %>
<tr>
<td><%= link_to quiz.name, admin_quiz_path(quiz.to_i) %></td>
<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>
</tr>
<% end %>
</table>

View File

@ -1,4 +1,7 @@
<h1>Admin::Quizes#edit</h1>
<p>Find me in app/views/admin/quizes/edit.html.erb</p>
<%
content_for :section_title, "Edit: #{@quiz.name}"
%>
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %>
<main class="summary_tpl">
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %>
</main>

View File

@ -1,2 +1,8 @@
<h1>Admin::Quizes#index</h1>
<p>Find me in app/views/admin/quizes/index.html.erb</p>
<%
content_for :section_title, "Quizzes"
%>
<main class="summary_tpl">
<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %>
<%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
</main>

View File

@ -1,4 +1,7 @@
<h1>Admin::Quizes#new</h1>
<p>Find me in app/views/admin/quizes/new.html.erb</p>
<%
content_for :section_title, "New Quiz"
%>
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %>
<main class="summary_tpl">
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %>
</main>

View File

@ -1,7 +1,10 @@
<h1>Admin::Quizes#view</h1>
<p>Find me in app/views/admin/quizes/view.html.erb</p>
<%
content_for :section_title, "#{@quiz.name}"
%>
<main>
<main class="summary_tpl">
<p><%= @quiz.name %></p>
<p><%= @quiz.dept %></p>
<p><%= @quiz.unit %></p>
<%= link_to('Edit', admin_edit_quiz_path(@quiz.to_i), { class: 'btn' }) %>
</main>

View File

@ -1,7 +1,29 @@
<%= form_for user, url: action do |f| %>
<p>Name: <%= f.text_field :name %></p>
<p>eMail: <%= f.email_field :email %></p>
<p>Role: <%= f.text_field :role %></p>
<%= f.submit %>
<% if flash[:error].present? %>
<div class="error">
<%= flash[:error] %>
<p>
<% user.errors.messages.each do |k,v| %>
<%= "#{k.to_s} #{v.join(' and ')}" %><br />
<% end %>
</p>
</div>
<% end %>
<%= form_for user, url: action do |form| %>
<div class="form-group">
<%= form.label :name, "Full Name" %>
<%= form.text_field :name %>
</div>
<div class="form-group">
<%= form.label :email, "eMail" %>
<%= form.email_field :email %>
</div>
<div class="form-group">
<%= form.label :role, "Role" %>
<%= form.select :role, admin_role_options(user.role), include_blank: false %>
</div>
<%= form.submit %>
<% end %>

View File

@ -0,0 +1,17 @@
<table cellspacing="0" cellpadding="0">
<tr>
<th>User</th>
<th>Email</th>
<th>Role</th>
<th></th>
</tr>
<% users.each do |user| %>
<tr>
<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>
</tr>
<% end %>
</table>

View File

@ -1,4 +1,7 @@
<h1>Admin::Users#edit</h1>
<p>Find me in app/views/admin/users/edit.html.erb</p>
<%
content_for :section_title, "Edit: #{@user.name}"
%>
<%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %>
<main class="summary_tpl">
<%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %>
</main>

View File

@ -1,2 +1,9 @@
<h1>Admin::Users#index</h1>
<p>Find me in app/views/admin/users/index.html.erb</p>
<%
content_for :section_title, "Users"
%>
<main class="summary_tpl">
<h1>Users</h1>
<%= render partial: 'admin/user/table_list', locals: { users: @users } %>
<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %>
</main>

View File

@ -1,4 +1,7 @@
<h1>Admin::Users#new</h1>
<p>Find me in app/views/admin/users/new.html.erb</p>
<%
content_for :section_title, "New User"
%>
<%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %>
<main class="summary_tpl">
<%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %>
</main>

View File

@ -1,6 +1,10 @@
<h1>Admin::Users#view</h1>
<p>Find me in app/views/admin/users/view.html.erb</p>
<%
content_for :section_title, "#{@user.name}"
%>
<main>
<%= @user.name %>
<main class="summary_tpl">
<p><%= @user.name %></p>
<p><%= mail_to(@user.email) %></p>
<p><%= @user.role %></p>
<%= link_to('Edit', admin_edit_user_path(@user.to_i), { class: 'btn' }) %>
</main>

View File

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en" class="no-js">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= csrf_meta_tags %>
<title><%= yield(:title) %></title>
<!--[if ! lte IE 8]><!-->
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<!--<![endif]-->
<!--[if lt IE 9]>
<%= javascript_include_tag 'ie9' %>
<![endif]-->
</head>
<body>
<div class="layout">
<header class="no-progressbar">
<div class="page-title slash-left">
<% if content_for?(:section_title) %>
<div><%= yield(:section_title) %></div>
<% else %>
<div>Skills Assessment Admin</div>
<% end %>
</div>
</header>
<%= yield %>
</div>
<footer>
<div class="pd_logo"><%= image_tag("perficientdigital.png", alt:"Perficient Digital") %></div>
<div class="footer_yellow-bar slantleft slantright">&nbsp;</div>
</footer>
<!--[if ! lte IE 8]><!-->
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<!--<![endif]-->
</body>
</html>

View File

@ -1,2 +0,0 @@
<h1>Recruiter#create</h1>
<p>Find me in app/views/recruiter/create.html.erb</p>

View File

@ -1,58 +1,61 @@
Rails.application.routes.draw do
post "/admin/login", to: "admin/auth#auth", as: :admin_auth
get "/admin/login", to: "admin/auth#login", as: :admin_login
get "/admin/logout", to: "admin/auth#logout", as: :admin_logout
get "/admin/login", to: "admin/auth#login", as: :admin_login
get "/admin/logout", to: "admin/auth#logout", as: :admin_logout
get "/admin", to: "admin#dashboard", as: :admin
get "/admin", to: "admin#dashboard", as: :admin
get "/admin/quizzes", to: "admin/quiz#index", as: :admin_quizzes
get "/admin/quiz/new", to: "admin/quiz#new", as: :admin_new_quiz
post "/admin/quiz/create", to: "admin/quiz#create", as: :admin_create_quiz
get "/admin/quiz/:quiz_id", to: "admin/quiz#view", as: :admin_quiz
get "/admin/quiz/:quiz_id/edit", to: "admin/quiz#edit", as: :admin_edit_quiz
post "/admin/quiz/:quiz_id/update", to: "admin/quiz#update", as: :admin_update_quiz
get "/admin/quizzes", to: "admin/quiz#index", as: :admin_quizzes
get "/admin/quiz/new", to: "admin/quiz#new", as: :admin_new_quiz
post "/admin/quiz/new", to: "admin/quiz#create", as: :admin_create_quiz
get "/admin/quiz/:quiz_id", to: "admin/quiz#view", as: :admin_quiz
get "/admin/quiz/:quiz_id/edit", to: "admin/quiz#edit", as: :admin_edit_quiz
post "/admin/quiz/:quiz_id/edit", to: "admin/quiz#update", as: :admin_update_quiz
patch "/admin/quiz/:quiz_id/edit", to: "admin/quiz#update"
get "/admin/users", to: "admin/user#index", as: :admin_users
get "/admin/user/new", to: "admin/user#new", as: :admin_new_user
post "/admin/user/create", to: "admin/user#create", as: :admin_create_user
get "/admin/user/:user_id", to: "admin/user#view", as: :admin_user
get "/admin/user/:user_id/edit", to: "admin/user#edit", as: :admin_edit_user
post "/admin/user/:user_id/update", to: "admin/user#update", as: :admin_update_user
get "/admin/users", to: "admin/user#index", as: :admin_users
get "/admin/user/new", to: "admin/user#new", as: :admin_new_user
post "/admin/user/new", to: "admin/user#create", as: :admin_create_user
get "/admin/user/:user_id", to: "admin/user#view", as: :admin_user
get "/admin/user/:user_id/edit", to: "admin/user#edit", as: :admin_edit_user
post "/admin/user/:user_id/edit", to: "admin/user#update", as: :admin_update_user
patch "/admin/user/:user_id/edit", to: "admin/user#update"
get "/admin/questions", to: "admin/question#index", as: :admin_questions
get "/admin/question/new", to: "admin/question#new", as: :admin_new_question
post "/admin/question/create", to: "admin/question#create", as: :admin_create_question
get "/admin/question/:question_id", to: "admin/question#view", as: :admin_question
get "/admin/question/:question_id/edit", to: "admin/question#edit", as: :admin_edit_question
post "/admin/question/:question_id/update", to: "admin/question#update", as: :admin_update_question
get "/admin/questions", to: "admin/question#index", as: :admin_questions
get "/admin/question/new", to: "admin/question#new", as: :admin_new_question
post "/admin/question/new", to: "admin/question#create", as: :admin_create_question
get "/admin/question/:question_id", to: "admin/question#view", as: :admin_question
get "/admin/question/:question_id/edit", to: "admin/question#edit", as: :admin_edit_question
post "/admin/question/:question_id/edit", to: "admin/question#update", as: :admin_update_question
patch "/admin/question/:question_id/edit", to: "admin/question#update"
#########################################################################################
post "/validate", to: "candidate#validate", as: :validate_candidate
get "/login(/:test_id)", to: "candidate#login", as: :login
get "/welcome", to: "candidate#welcome", as: :welcome
get "/saved", to: "candidate#saved", as: :saved
get "/thankyou", to: "candidate#thankyou", as: :thankyou
post "/validate", to: "candidate#validate", as: :validate_candidate
get "/login(/:test_id)", to: "candidate#login", as: :login
get "/welcome", to: "candidate#welcome", as: :welcome
get "/saved", to: "candidate#saved", as: :saved
get "/thankyou", to: "candidate#thankyou", as: :thankyou
get "/oops", to: "candidate#oops", as: :oops
get "/oops", to: "candidate#oops", as: :oops
post "/question(/:answer_id)", to: "quiz#update_answer", as: :post_answer
get "/question(/:question_id)", to: "quiz#question", as: :question
post "/summary", to: "quiz#submit_summary", as: :post_summary
get "/summary", to: "quiz#summary", as: :summary
post "/question(/:answer_id)", to: "quiz#update_answer", as: :post_answer
get "/question(/:question_id)", to: "quiz#question", as: :question
post "/summary", to: "quiz#submit_summary", as: :post_summary
get "/summary", to: "quiz#summary", as: :summary
get "/review/logout", to: "review#logout", as: :review_logout
post "/review/login", to: "review#auth", as: :review_auth
get "/review/login", to: "review#login", as: :review_login
get "/review", to: "review#index", as: :review
get "/review/:test_hash", to: "review#view", as: :review_test
get "/review/logout", to: "review#logout", as: :review_logout
post "/review/login", to: "review#auth", as: :review_auth
get "/review/login", to: "review#login", as: :review_login
get "/review", to: "review#index", as: :review
get "/review/:test_hash", to: "review#view", as: :review_test
get "/recruiter", to: "recruiter#index", as: :recruiter
get "/recruiter/new-candidate", to: "recruiter#new", as: :new_candidate
post "/recruiter/new-candidate", to: "recruiter#create", as: :create_candidate
get "/recruiter/logout", to: "recruiter#logout", as: :recruiter_logout
get "/recruiter/login", to: "recruiter#login", as: :recruiter_login
post "/recruiter/login", to: "recruiter#auth", as: :recruiter_auth
get "/recruiter", to: "recruiter#index", as: :recruiter
get "/recruiter/new-candidate", to: "recruiter#new", as: :new_candidate
post "/recruiter/new-candidate", to: "recruiter#create", as: :create_candidate
get "/recruiter/logout", to: "recruiter#logout", as: :recruiter_logout
get "/recruiter/login", to: "recruiter#login", as: :recruiter_login
post "/recruiter/login", to: "recruiter#auth", as: :recruiter_auth
root to: "candidate#login"

View File

@ -0,0 +1,5 @@
class AddNameToQuiz < ActiveRecord::Migration[5.0]
def change
add_column :quizzes, :name, :string, after: :id
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160803003932) do
ActiveRecord::Schema.define(version: 20160818225721) do
create_table "answers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.integer "candidate_id"
@ -62,6 +62,7 @@ ActiveRecord::Schema.define(version: 20160803003932) do
t.string "dept"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
end
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|

View File

@ -29,7 +29,8 @@ module Admin
test "should post create" do
assert_difference("Quiz.count", 1) do
post admin_create_quiz_url, params: { quiz: { unit: 'PDW', dept: 'MBL' } }
post admin_create_quiz_url, params: { quiz:
{ name: 'PDW Mobile team screening', unit: 'PDW', dept: 'MBL' } }
end
assert_redirected_to admin_quizzes_url
end

View File

@ -39,7 +39,7 @@ module Admin
user = users(:recruiter)
get admin_user_url user.to_i
assert_response :success
assert_select 'main', user.name
assert_select 'p', user.name
end
test "should get edit" do
@ -55,7 +55,7 @@ module Admin
assert_redirected_to admin_user_path(user.to_i)
get admin_user_url user.to_i
assert_select 'main', 'new name'
assert_select 'p', 'new name'
end
test "should fail to update user" do

View File

@ -1,5 +1,6 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
fed:
name: PDR Standard FED Screening
unit: PDR
dept: FED