From 6a3f652dd78cf304d78c73f5b1dfcc79785fb9b4 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Wed, 17 Aug 2016 17:49:09 -0500 Subject: [PATCH 01/10] admin interface generation --- app/controllers/admin/auth_controller.rb | 12 +++++++ app/controllers/admin/question_controller.rb | 21 +++++++++++ app/controllers/admin/quiz_controller.rb | 21 +++++++++++ app/controllers/admin/user_controller.rb | 21 +++++++++++ app/controllers/admin_controller.rb | 2 ++ app/views/admin/auth/login.html.erb | 2 ++ app/views/admin/auth/logout.html.erb | 2 ++ app/views/admin/question/edit.html.erb | 2 ++ app/views/admin/question/index.html.erb | 2 ++ app/views/admin/question/new.html.erb | 2 ++ app/views/admin/question/view.html.erb | 2 ++ app/views/admin/quiz/edit.html.erb | 2 ++ app/views/admin/quiz/index.html.erb | 2 ++ app/views/admin/quiz/new.html.erb | 2 ++ app/views/admin/quiz/view.html.erb | 2 ++ app/views/admin/user/edit.html.erb | 2 ++ app/views/admin/user/index.html.erb | 2 ++ app/views/admin/user/new.html.erb | 2 ++ app/views/admin/user/view.html.erb | 2 ++ config/application.rb | 6 ++++ config/routes.rb | 27 ++++++++++++++ .../controllers/admin/auth_controller_test.rb | 21 +++++++++++ .../admin/question_controller_test.rb | 35 +++++++++++++++++++ .../controllers/admin/quiz_controller_test.rb | 35 +++++++++++++++++++ .../controllers/admin/user_controller_test.rb | 35 +++++++++++++++++++ test/controllers/admin_controller_test.rb | 4 +++ 26 files changed, 268 insertions(+) create mode 100644 app/controllers/admin/auth_controller.rb create mode 100644 app/controllers/admin/question_controller.rb create mode 100644 app/controllers/admin/quiz_controller.rb create mode 100644 app/controllers/admin/user_controller.rb create mode 100644 app/controllers/admin_controller.rb create mode 100644 app/views/admin/auth/login.html.erb create mode 100644 app/views/admin/auth/logout.html.erb create mode 100644 app/views/admin/question/edit.html.erb create mode 100644 app/views/admin/question/index.html.erb create mode 100644 app/views/admin/question/new.html.erb create mode 100644 app/views/admin/question/view.html.erb create mode 100644 app/views/admin/quiz/edit.html.erb create mode 100644 app/views/admin/quiz/index.html.erb create mode 100644 app/views/admin/quiz/new.html.erb create mode 100644 app/views/admin/quiz/view.html.erb create mode 100644 app/views/admin/user/edit.html.erb create mode 100644 app/views/admin/user/index.html.erb create mode 100644 app/views/admin/user/new.html.erb create mode 100644 app/views/admin/user/view.html.erb create mode 100644 test/controllers/admin/auth_controller_test.rb create mode 100644 test/controllers/admin/question_controller_test.rb create mode 100644 test/controllers/admin/quiz_controller_test.rb create mode 100644 test/controllers/admin/user_controller_test.rb create mode 100644 test/controllers/admin_controller_test.rb diff --git a/app/controllers/admin/auth_controller.rb b/app/controllers/admin/auth_controller.rb new file mode 100644 index 0000000..983a370 --- /dev/null +++ b/app/controllers/admin/auth_controller.rb @@ -0,0 +1,12 @@ +module Admin + class AuthController < AdminController + def login + end + + def auth + end + + def logout + end + end +end diff --git a/app/controllers/admin/question_controller.rb b/app/controllers/admin/question_controller.rb new file mode 100644 index 0000000..2d49a92 --- /dev/null +++ b/app/controllers/admin/question_controller.rb @@ -0,0 +1,21 @@ +module Admin + class QuestionController < AdminController + def index + end + + def new + end + + def create + end + + def view + end + + def edit + end + + def update + end + end +end diff --git a/app/controllers/admin/quiz_controller.rb b/app/controllers/admin/quiz_controller.rb new file mode 100644 index 0000000..350a543 --- /dev/null +++ b/app/controllers/admin/quiz_controller.rb @@ -0,0 +1,21 @@ +module Admin + class QuizController < AdminController + def index + end + + def new + end + + def create + end + + def view + end + + def edit + end + + def update + end + end +end diff --git a/app/controllers/admin/user_controller.rb b/app/controllers/admin/user_controller.rb new file mode 100644 index 0000000..59cd2e7 --- /dev/null +++ b/app/controllers/admin/user_controller.rb @@ -0,0 +1,21 @@ +module Admin + class UserController < AdminController + def index + end + + def new + end + + def create + end + + def view + end + + def edit + end + + def update + end + end +end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb new file mode 100644 index 0000000..69655f9 --- /dev/null +++ b/app/controllers/admin_controller.rb @@ -0,0 +1,2 @@ +class AdminController < ApplicationController +end diff --git a/app/views/admin/auth/login.html.erb b/app/views/admin/auth/login.html.erb new file mode 100644 index 0000000..1aae790 --- /dev/null +++ b/app/views/admin/auth/login.html.erb @@ -0,0 +1,2 @@ +

Admin::Auth#login

+

Find me in app/views/admin/auth/login.html.erb

diff --git a/app/views/admin/auth/logout.html.erb b/app/views/admin/auth/logout.html.erb new file mode 100644 index 0000000..666b438 --- /dev/null +++ b/app/views/admin/auth/logout.html.erb @@ -0,0 +1,2 @@ +

Admin::Auth#logout

+

Find me in app/views/admin/auth/logout.html.erb

diff --git a/app/views/admin/question/edit.html.erb b/app/views/admin/question/edit.html.erb new file mode 100644 index 0000000..34ed55e --- /dev/null +++ b/app/views/admin/question/edit.html.erb @@ -0,0 +1,2 @@ +

Admin::Questions#edit

+

Find me in app/views/admin/questions/edit.html.erb

diff --git a/app/views/admin/question/index.html.erb b/app/views/admin/question/index.html.erb new file mode 100644 index 0000000..dcbca37 --- /dev/null +++ b/app/views/admin/question/index.html.erb @@ -0,0 +1,2 @@ +

Admin::Questions#index

+

Find me in app/views/admin/questions/index.html.erb

diff --git a/app/views/admin/question/new.html.erb b/app/views/admin/question/new.html.erb new file mode 100644 index 0000000..f4507f7 --- /dev/null +++ b/app/views/admin/question/new.html.erb @@ -0,0 +1,2 @@ +

Admin::Questions#new

+

Find me in app/views/admin/questions/new.html.erb

diff --git a/app/views/admin/question/view.html.erb b/app/views/admin/question/view.html.erb new file mode 100644 index 0000000..fea4846 --- /dev/null +++ b/app/views/admin/question/view.html.erb @@ -0,0 +1,2 @@ +

Admin::Questions#view

+

Find me in app/views/admin/questions/view.html.erb

diff --git a/app/views/admin/quiz/edit.html.erb b/app/views/admin/quiz/edit.html.erb new file mode 100644 index 0000000..fc5109e --- /dev/null +++ b/app/views/admin/quiz/edit.html.erb @@ -0,0 +1,2 @@ +

Admin::Quizes#edit

+

Find me in app/views/admin/quizes/edit.html.erb

diff --git a/app/views/admin/quiz/index.html.erb b/app/views/admin/quiz/index.html.erb new file mode 100644 index 0000000..458399a --- /dev/null +++ b/app/views/admin/quiz/index.html.erb @@ -0,0 +1,2 @@ +

Admin::Quizes#index

+

Find me in app/views/admin/quizes/index.html.erb

diff --git a/app/views/admin/quiz/new.html.erb b/app/views/admin/quiz/new.html.erb new file mode 100644 index 0000000..d5bf9bb --- /dev/null +++ b/app/views/admin/quiz/new.html.erb @@ -0,0 +1,2 @@ +

Admin::Quizes#new

+

Find me in app/views/admin/quizes/new.html.erb

diff --git a/app/views/admin/quiz/view.html.erb b/app/views/admin/quiz/view.html.erb new file mode 100644 index 0000000..3df2d04 --- /dev/null +++ b/app/views/admin/quiz/view.html.erb @@ -0,0 +1,2 @@ +

Admin::Quizes#view

+

Find me in app/views/admin/quizes/view.html.erb

diff --git a/app/views/admin/user/edit.html.erb b/app/views/admin/user/edit.html.erb new file mode 100644 index 0000000..363be95 --- /dev/null +++ b/app/views/admin/user/edit.html.erb @@ -0,0 +1,2 @@ +

Admin::Users#edit

+

Find me in app/views/admin/users/edit.html.erb

diff --git a/app/views/admin/user/index.html.erb b/app/views/admin/user/index.html.erb new file mode 100644 index 0000000..30c6fab --- /dev/null +++ b/app/views/admin/user/index.html.erb @@ -0,0 +1,2 @@ +

Admin::Users#index

+

Find me in app/views/admin/users/index.html.erb

diff --git a/app/views/admin/user/new.html.erb b/app/views/admin/user/new.html.erb new file mode 100644 index 0000000..d380347 --- /dev/null +++ b/app/views/admin/user/new.html.erb @@ -0,0 +1,2 @@ +

Admin::Users#new

+

Find me in app/views/admin/users/new.html.erb

diff --git a/app/views/admin/user/view.html.erb b/app/views/admin/user/view.html.erb new file mode 100644 index 0000000..f5453b2 --- /dev/null +++ b/app/views/admin/user/view.html.erb @@ -0,0 +1,2 @@ +

Admin::Users#view

+

Find me in app/views/admin/users/view.html.erb

diff --git a/config/application.rb b/config/application.rb index 4bbbd91..d04f3ab 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,5 +23,11 @@ module SkillAssessmentApp config.action_mailer.delivery_method = :mailjet config.action_mailer.default_url_options = { host: ENV['full_app_url'] } + + config.generators do |g| + g.assets false + g.helper false + g.routes false + end end end diff --git a/config/routes.rb b/config/routes.rb index b245523..c19ff37 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,31 @@ Rails.application.routes.draw do + post "/admin/login", to: "admin/auth#auth", as: :admin_auth + get "/admin/logout", to: "admin/auth#logout", as: :admin_logout + get "/admin", to: "admin/auth#login", 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/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/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 + + ######################################################################################### + post "/validate", to: "candidate#validate", as: :validate_candidate get "/login(/:test_id)", to: "candidate#login", as: :login get "/welcome", to: "candidate#welcome", as: :welcome diff --git a/test/controllers/admin/auth_controller_test.rb b/test/controllers/admin/auth_controller_test.rb new file mode 100644 index 0000000..af50302 --- /dev/null +++ b/test/controllers/admin/auth_controller_test.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +module Admin + class AuthControllerTest < ActionDispatch::IntegrationTest + test "should get login" do + get admin_url + assert_response :success + assert_template 'admin/auth/login' + end + + test "should get auth" do + post admin_auth_url + assert_response :success + end + + test "should get logout" do + get admin_logout_url + assert_response :success + end + end +end diff --git a/test/controllers/admin/question_controller_test.rb b/test/controllers/admin/question_controller_test.rb new file mode 100644 index 0000000..00c2673 --- /dev/null +++ b/test/controllers/admin/question_controller_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' + +module Admin + class QuestionControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get admin_questions_url + assert_response :success + end + + test "should get new" do + get admin_new_question_url + assert_response :success + end + + test "should post create" do + post admin_create_question_url + assert_response :success + end + + test "should get view" do + get admin_question_url questions(:fed5).to_i + assert_response :success + end + + test "should get edit" do + get admin_edit_question_url questions(:fed5).to_i + assert_response :success + end + + test "should post update question" do + post admin_update_question_url questions(:fed5).to_i + assert_response :success + end + end +end diff --git a/test/controllers/admin/quiz_controller_test.rb b/test/controllers/admin/quiz_controller_test.rb new file mode 100644 index 0000000..7fee204 --- /dev/null +++ b/test/controllers/admin/quiz_controller_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' + +module Admin + class QuizControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get admin_quizzes_url + assert_response :success + end + + test "should get new" do + get admin_new_quiz_url + assert_response :success + end + + test "should post create" do + post admin_create_quiz_url + assert_response :success + end + + test "should get view" do + get admin_quiz_url quizzes(:fed).to_i + assert_response :success + end + + test "should get edit" do + get admin_edit_quiz_url quizzes(:fed).to_i + assert_response :success + end + + test "should post update quiz" do + post admin_update_quiz_url quizzes(:fed).to_i + assert_response :success + end + end +end diff --git a/test/controllers/admin/user_controller_test.rb b/test/controllers/admin/user_controller_test.rb new file mode 100644 index 0000000..c4773a5 --- /dev/null +++ b/test/controllers/admin/user_controller_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' + +module Admin + class UserControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get admin_users_url + assert_response :success + end + + test "should get new" do + get admin_new_user_url + assert_response :success + end + + test "should post create" do + post admin_create_user_url + assert_response :success + end + + test "should get view" do + get admin_user_url users(:recruiter).to_i + assert_response :success + end + + test "should get edit" do + get admin_edit_user_url users(:recruiter).to_i + assert_response :success + end + + test "should post update user" do + post admin_update_user_url users(:recruiter).to_i + assert_response :success + end + end +end diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb new file mode 100644 index 0000000..46d1e7b --- /dev/null +++ b/test/controllers/admin_controller_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class AdminControllerTest < ActionDispatch::IntegrationTest +end From 430097b6eff3a6fdff19402d75cd35e2bb9ba8ee Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 18 Aug 2016 15:35:17 -0500 Subject: [PATCH 02/10] admin controller tests, sans question --- app/controllers/admin/auth_controller.rb | 13 ++++ app/controllers/admin/quiz_controller.rb | 27 +++++++ app/controllers/admin/user_controller.rb | 29 ++++++++ app/controllers/admin_controller.rb | 16 +++++ app/models/quiz.rb | 3 + app/models/user.rb | 4 ++ app/views/admin/dashboard.html.erb | 1 + app/views/admin/quiz/_form.html.erb | 6 ++ app/views/admin/quiz/edit.html.erb | 2 + app/views/admin/quiz/new.html.erb | 2 + app/views/admin/quiz/view.html.erb | 5 ++ app/views/admin/user/_form.html.erb | 7 ++ app/views/admin/user/edit.html.erb | 2 + app/views/admin/user/new.html.erb | 2 + app/views/admin/user/view.html.erb | 4 ++ config/routes.rb | 4 +- .../controllers/admin/auth_controller_test.rb | 33 +++++++-- .../admin/question_controller_test.rb | 70 +++++++++---------- .../controllers/admin/quiz_controller_test.rb | 44 ++++++++++-- .../controllers/admin/user_controller_test.rb | 45 ++++++++++-- test/controllers/admin_controller_test.rb | 11 +++ 21 files changed, 275 insertions(+), 55 deletions(-) create mode 100644 app/views/admin/dashboard.html.erb create mode 100644 app/views/admin/quiz/_form.html.erb create mode 100644 app/views/admin/user/_form.html.erb diff --git a/app/controllers/admin/auth_controller.rb b/app/controllers/admin/auth_controller.rb index 983a370..a6db502 100644 --- a/app/controllers/admin/auth_controller.rb +++ b/app/controllers/admin/auth_controller.rb @@ -1,12 +1,25 @@ module Admin class AuthController < AdminController + skip_before_action :authorize_admin + def login end def auth + admin = User.find_by(email: auth_params[:email], role: 'admin') + + if admin && admin.authenticate(auth_params[:password]) + session[:user] = admin.to_i + redirect_to admin_path + else + redirect_to admin_login_path, + flash: { error: "Sorry, incorrect email or password. Please try again." } + end end def logout + reset_session + redirect_to admin_login_path end end end diff --git a/app/controllers/admin/quiz_controller.rb b/app/controllers/admin/quiz_controller.rb index 350a543..da05856 100644 --- a/app/controllers/admin/quiz_controller.rb +++ b/app/controllers/admin/quiz_controller.rb @@ -1,21 +1,48 @@ module Admin class QuizController < AdminController def index + @quizzes = Quiz.all end def new + @quiz = Quiz.new end def create + @quiz = Quiz.create(quiz_params) + + if @quiz.persisted? + redirect_to admin_quizzes_path, flash: { notice: "Sucessfully created quiz" } + else + flash[:error] = "Failed to save quiz." + render :new + end end def view + @quiz = Quiz.find(params[:quiz_id]) end def edit + @quiz = Quiz.find(params[:quiz_id]) end def update + @quiz = Quiz.find(params[:quiz_id]) + + if @quiz.update_attributes(quiz_params) + redirect_to admin_quiz_path(@quiz.to_i), + flash: { notice: "Sucessfully updated quiz" } + else + flash[:error] = "Failed to update quiz." + render :edit + end end + + private + + def quiz_params + params.require(:quiz).permit(:dept, :unit) + end end end diff --git a/app/controllers/admin/user_controller.rb b/app/controllers/admin/user_controller.rb index 59cd2e7..23c11dd 100644 --- a/app/controllers/admin/user_controller.rb +++ b/app/controllers/admin/user_controller.rb @@ -1,21 +1,50 @@ module Admin class UserController < AdminController def index + @users = User.order(:name) end def new + @user = User.new end def create + default_passwd = SecureRandom.urlsafe_base64(12) + @user = User.create({ password: default_passwd }.merge(user_params.to_h)) + + if @user.persisted? + # TODO: UserMailer.welcome(@user, default_passwd).deliver_now + redirect_to admin_users_path, flash: { notice: "Sucessfully created user #{@user.name}" } + else + flash[:error] = "Failed to save user." + render :new + end end def view + @user = User.find(params[:user_id]) end def edit + @user = User.find(params[:user_id]) end def update + @user = User.find(params[:user_id]) + + if @user.update_attributes(user_params) + redirect_to admin_user_path(@user.to_i), + flash: { notice: "Sucessfully updated #{@user.name}" } + else + flash[:error] = "Failed to update user." + render :edit + end end + + private + + def user_params + params.require(:user).permit(:name, :email, :role, :password) + end end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 69655f9..55b4a93 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,2 +1,18 @@ class AdminController < ApplicationController + before_action :authorize_admin + + def dashboard + end + + def current_admin + user_args = { id: session[:user], role: 'admin' } + @current_admin ||= User.find_by(user_args) if session[:user] + end + helper_method :current_admin + + private + + def authorize_admin + redirect_to admin_login_path unless current_admin + end end diff --git a/app/models/quiz.rb b/app/models/quiz.rb index b92a063..2f27521 100644 --- a/app/models/quiz.rb +++ b/app/models/quiz.rb @@ -1,4 +1,7 @@ class Quiz < ApplicationRecord has_many :questions, -> { order(:sort) } has_many :candidates + + validates_presence_of :dept + validates_presence_of :unit end diff --git a/app/models/user.rb b/app/models/user.rb index e1b1ee7..1da0679 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,8 @@ class User < ApplicationRecord has_secure_password has_many :candidates, foreign_key: "recruiter_id" + + validates_presence_of :email + validates_presence_of :name + validates_presence_of :role end diff --git a/app/views/admin/dashboard.html.erb b/app/views/admin/dashboard.html.erb new file mode 100644 index 0000000..4f3e250 --- /dev/null +++ b/app/views/admin/dashboard.html.erb @@ -0,0 +1 @@ +huzzah! dashboard diff --git a/app/views/admin/quiz/_form.html.erb b/app/views/admin/quiz/_form.html.erb new file mode 100644 index 0000000..2cc7e08 --- /dev/null +++ b/app/views/admin/quiz/_form.html.erb @@ -0,0 +1,6 @@ +<%= form_for quiz, url: action do |f| %> +

Unit: <%= f.text_field :unit %>

+

Dept: <%= f.text_field :dept %>

+ + <%= f.submit %> +<% end %> diff --git a/app/views/admin/quiz/edit.html.erb b/app/views/admin/quiz/edit.html.erb index fc5109e..bdea931 100644 --- a/app/views/admin/quiz/edit.html.erb +++ b/app/views/admin/quiz/edit.html.erb @@ -1,2 +1,4 @@

Admin::Quizes#edit

Find me in app/views/admin/quizes/edit.html.erb

+ +<%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %> diff --git a/app/views/admin/quiz/new.html.erb b/app/views/admin/quiz/new.html.erb index d5bf9bb..bac3d40 100644 --- a/app/views/admin/quiz/new.html.erb +++ b/app/views/admin/quiz/new.html.erb @@ -1,2 +1,4 @@

Admin::Quizes#new

Find me in app/views/admin/quizes/new.html.erb

+ +<%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %> diff --git a/app/views/admin/quiz/view.html.erb b/app/views/admin/quiz/view.html.erb index 3df2d04..24ec89b 100644 --- a/app/views/admin/quiz/view.html.erb +++ b/app/views/admin/quiz/view.html.erb @@ -1,2 +1,7 @@

Admin::Quizes#view

Find me in app/views/admin/quizes/view.html.erb

+ +
+

<%= @quiz.dept %>

+

<%= @quiz.unit %>

+
diff --git a/app/views/admin/user/_form.html.erb b/app/views/admin/user/_form.html.erb new file mode 100644 index 0000000..164f74e --- /dev/null +++ b/app/views/admin/user/_form.html.erb @@ -0,0 +1,7 @@ +<%= form_for user, url: action do |f| %> +

Name: <%= f.text_field :name %>

+

eMail: <%= f.email_field :email %>

+

Role: <%= f.text_field :role %>

+ + <%= f.submit %> +<% end %> diff --git a/app/views/admin/user/edit.html.erb b/app/views/admin/user/edit.html.erb index 363be95..b438098 100644 --- a/app/views/admin/user/edit.html.erb +++ b/app/views/admin/user/edit.html.erb @@ -1,2 +1,4 @@

Admin::Users#edit

Find me in app/views/admin/users/edit.html.erb

+ +<%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %> diff --git a/app/views/admin/user/new.html.erb b/app/views/admin/user/new.html.erb index d380347..f076758 100644 --- a/app/views/admin/user/new.html.erb +++ b/app/views/admin/user/new.html.erb @@ -1,2 +1,4 @@

Admin::Users#new

Find me in app/views/admin/users/new.html.erb

+ +<%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %> diff --git a/app/views/admin/user/view.html.erb b/app/views/admin/user/view.html.erb index f5453b2..ca68938 100644 --- a/app/views/admin/user/view.html.erb +++ b/app/views/admin/user/view.html.erb @@ -1,2 +1,6 @@

Admin::Users#view

Find me in app/views/admin/users/view.html.erb

+ +
+ <%= @user.name %> +
diff --git a/config/routes.rb b/config/routes.rb index c19ff37..ca102d9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,9 @@ 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", to: "admin/auth#login", 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 diff --git a/test/controllers/admin/auth_controller_test.rb b/test/controllers/admin/auth_controller_test.rb index af50302..1c22fce 100644 --- a/test/controllers/admin/auth_controller_test.rb +++ b/test/controllers/admin/auth_controller_test.rb @@ -3,19 +3,38 @@ require 'test_helper' module Admin class AuthControllerTest < ActionDispatch::IntegrationTest test "should get login" do - get admin_url + get admin_login_url assert_response :success assert_template 'admin/auth/login' end - test "should get auth" do - post admin_auth_url - assert_response :success + test "should get logout" do + post admin_auth_url, params: { auth: + { email: 'alan.admin@mailinator.com', password: 'password' } } + + get admin_logout_url + assert_redirected_to admin_login_url + assert session[:user].nil? end - test "should get logout" do - get admin_logout_url - assert_response :success + test "should auth to dashboard" do + post admin_auth_url, params: { auth: + { email: 'alan.admin@mailinator.com', password: 'password' } } + assert_redirected_to admin_url + end + + test "recruiter should not admin auth" do + post admin_auth_url, params: { auth: + { email: 'pdr.recruiter@mailinator.com', password: 'password' } } + assert_redirected_to admin_login_url + assert_match(/incorrect.*email/, flash[:error]) + end + + test "reviewer should not admin auth" do + post admin_auth_url, params: { auth: + { email: 'fed.reviewer@mailinator.com', password: 'password' } } + assert_redirected_to admin_login_url + assert_match(/incorrect.*email/, flash[:error]) end end end diff --git a/test/controllers/admin/question_controller_test.rb b/test/controllers/admin/question_controller_test.rb index 00c2673..8872dd8 100644 --- a/test/controllers/admin/question_controller_test.rb +++ b/test/controllers/admin/question_controller_test.rb @@ -1,35 +1,35 @@ -require 'test_helper' - -module Admin - class QuestionControllerTest < ActionDispatch::IntegrationTest - test "should get index" do - get admin_questions_url - assert_response :success - end - - test "should get new" do - get admin_new_question_url - assert_response :success - end - - test "should post create" do - post admin_create_question_url - assert_response :success - end - - test "should get view" do - get admin_question_url questions(:fed5).to_i - assert_response :success - end - - test "should get edit" do - get admin_edit_question_url questions(:fed5).to_i - assert_response :success - end - - test "should post update question" do - post admin_update_question_url questions(:fed5).to_i - assert_response :success - end - end -end +# require 'test_helper' +# +# module Admin +# class QuestionControllerTest < ActionDispatch::IntegrationTest +# test "should get index" do +# get admin_questions_url +# assert_response :success +# end +# +# test "should get new" do +# get admin_new_question_url +# assert_response :success +# end +# +# test "should post create" do +# post admin_create_question_url +# assert_response :success +# end +# +# test "should get view" do +# get admin_question_url questions(:fed5).to_i +# assert_response :success +# end +# +# test "should get edit" do +# get admin_edit_question_url questions(:fed5).to_i +# assert_response :success +# end +# +# test "should post update question" do +# post admin_update_question_url questions(:fed5).to_i +# assert_response :success +# end +# end +# end diff --git a/test/controllers/admin/quiz_controller_test.rb b/test/controllers/admin/quiz_controller_test.rb index 7fee204..fd16e59 100644 --- a/test/controllers/admin/quiz_controller_test.rb +++ b/test/controllers/admin/quiz_controller_test.rb @@ -2,34 +2,66 @@ require 'test_helper' module Admin class QuizControllerTest < ActionDispatch::IntegrationTest + def setup + post admin_auth_url, params: { auth: + { email: 'alan.admin@mailinator.com', password: 'password' } } + end + test "should get index" do get admin_quizzes_url assert_response :success + assert assigns :quizzes end test "should get new" do get admin_new_quiz_url assert_response :success + assert assigns :quiz + end + + test "should fail create" do + assert_difference("Quiz.count", 0) do + post admin_create_quiz_url, params: { quiz: { dept: nil } } + end + assert :success + assert_match(/failed/i, session[:flash].values.join) end test "should post create" do - post admin_create_quiz_url - assert_response :success + assert_difference("Quiz.count", 1) do + post admin_create_quiz_url, params: { quiz: { unit: 'PDW', dept: 'MBL' } } + end + assert_redirected_to admin_quizzes_url end test "should get view" do - get admin_quiz_url quizzes(:fed).to_i + quiz = quizzes :fed + get admin_quiz_url quiz.to_i assert_response :success + assert_select 'p', quiz.dept end test "should get edit" do - get admin_edit_quiz_url quizzes(:fed).to_i + quiz = quizzes :fed + get admin_edit_quiz_url quiz.to_i assert_response :success + assert_select "[value=?]", quiz.dept end test "should post update quiz" do - post admin_update_quiz_url quizzes(:fed).to_i - assert_response :success + quiz = quizzes(:fed) + post admin_update_quiz_url(quiz.to_i), params: { quiz: { dept: 'new', unit: 'another' } } + assert_redirected_to admin_quiz_path(quiz.to_i) + + get admin_quiz_path quiz.to_i + assert_select 'p', 'another' + end + + test "should fail to update quiz" do + quiz = quizzes(:fed) + post admin_update_quiz_url(quiz.to_i), params: { quiz: { dept: nil } } + assert :success + assert_match(/failed/i, session[:flash].values.join) end end end diff --git a/test/controllers/admin/user_controller_test.rb b/test/controllers/admin/user_controller_test.rb index c4773a5..972ebf4 100644 --- a/test/controllers/admin/user_controller_test.rb +++ b/test/controllers/admin/user_controller_test.rb @@ -2,34 +2,67 @@ require 'test_helper' module Admin class UserControllerTest < ActionDispatch::IntegrationTest + def setup + post admin_auth_url, params: { auth: + { email: 'alan.admin@mailinator.com', password: 'password' } } + end + test "should get index" do get admin_users_url assert_response :success + assert assigns :users end test "should get new" do get admin_new_user_url assert_response :success + assert assigns :user + end + + test "should fail create" do + assert_difference("User.count", 0) do + post admin_create_user_url, params: { user: { name: 'New User' } } + end + assert :success + assert_match(/failed/i, session[:flash].values.join) end test "should post create" do - post admin_create_user_url - assert_response :success + assert_difference("User.count", 1) do + post admin_create_user_url, params: { user: + { email: 'new.user@mailinator.com', name: 'New User', role: 'reviewer' } } + end + assert_redirected_to admin_users_url end test "should get view" do - get admin_user_url users(:recruiter).to_i + user = users(:recruiter) + get admin_user_url user.to_i assert_response :success + assert_select 'main', user.name end test "should get edit" do - get admin_edit_user_url users(:recruiter).to_i + user = users(:recruiter) + get admin_edit_user_url user.to_i assert_response :success + assert_select "[value=?]", user.name end test "should post update user" do - post admin_update_user_url users(:recruiter).to_i - assert_response :success + user = users(:recruiter) + post admin_update_user_url(user.to_i), params: { user: { name: 'new name' } } + assert_redirected_to admin_user_path(user.to_i) + + get admin_user_url user.to_i + assert_select 'main', 'new name' + end + + test "should fail to update user" do + user = users(:recruiter) + post admin_update_user_url(user.to_i), params: { user: { name: nil } } + assert :success + assert_match(/failed/i, session[:flash].values.join) end end end diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb index 46d1e7b..0c0c0b1 100644 --- a/test/controllers/admin_controller_test.rb +++ b/test/controllers/admin_controller_test.rb @@ -1,4 +1,15 @@ require 'test_helper' class AdminControllerTest < ActionDispatch::IntegrationTest + test "dashboard should require auth" do + get admin_url + assert_redirected_to admin_login_url + end + + test "should get dashboard" do + post admin_auth_url, params: { auth: + { email: 'alan.admin@mailinator.com', password: 'password' } } + get admin_url + assert_response :success + end end From 63701c824723cf1055bdd699ea505df575c33928 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 18 Aug 2016 18:22:57 -0500 Subject: [PATCH 03/10] admin views roughed in --- Guardfile | 28 +++--- app/controllers/admin/quiz_controller.rb | 2 +- app/controllers/admin_controller.rb | 3 + app/helpers/application_helper.rb | 8 ++ app/models/quiz.rb | 1 + app/views/admin/auth/login.html.erb | 23 ++++- app/views/admin/auth/logout.html.erb | 2 - app/views/admin/dashboard.html.erb | 19 +++- app/views/admin/question/index.html.erb | 2 - app/views/admin/quiz/_form.html.erb | 33 +++++-- app/views/admin/quiz/_table_list.html.erb | 19 ++++ app/views/admin/quiz/edit.html.erb | 9 +- app/views/admin/quiz/index.html.erb | 10 ++- app/views/admin/quiz/new.html.erb | 9 +- app/views/admin/quiz/view.html.erb | 9 +- app/views/admin/user/_form.html.erb | 34 ++++++-- app/views/admin/user/_table_list.html.erb | 17 ++++ app/views/admin/user/edit.html.erb | 9 +- app/views/admin/user/index.html.erb | 11 ++- app/views/admin/user/new.html.erb | 9 +- app/views/admin/user/view.html.erb | 12 ++- app/views/layouts/admin.html.erb | 46 ++++++++++ app/views/recruiter/create.html.erb | 2 - config/routes.rb | 87 ++++++++++--------- db/migrate/20160818225721_add_name_to_quiz.rb | 5 ++ db/schema.rb | 3 +- .../controllers/admin/quiz_controller_test.rb | 3 +- .../controllers/admin/user_controller_test.rb | 4 +- test/fixtures/quizzes.yml | 1 + 29 files changed, 316 insertions(+), 104 deletions(-) delete mode 100644 app/views/admin/auth/logout.html.erb create mode 100644 app/views/admin/quiz/_table_list.html.erb create mode 100644 app/views/admin/user/_table_list.html.erb create mode 100644 app/views/layouts/admin.html.erb delete mode 100644 app/views/recruiter/create.html.erb create mode 100644 db/migrate/20160818225721_add_name_to_quiz.rb diff --git a/Guardfile b/Guardfile index e686215..a200919 100644 --- a/Guardfile +++ b/Guardfile @@ -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/) diff --git a/app/controllers/admin/quiz_controller.rb b/app/controllers/admin/quiz_controller.rb index da05856..82c2de4 100644 --- a/app/controllers/admin/quiz_controller.rb +++ b/app/controllers/admin/quiz_controller.rb @@ -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 diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 55b4a93..37a79b4 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index feaaee8..cd6c340 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/quiz.rb b/app/models/quiz.rb index 2f27521..bf967e4 100644 --- a/app/models/quiz.rb +++ b/app/models/quiz.rb @@ -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 diff --git a/app/views/admin/auth/login.html.erb b/app/views/admin/auth/login.html.erb index 1aae790..b54def1 100644 --- a/app/views/admin/auth/login.html.erb +++ b/app/views/admin/auth/login.html.erb @@ -1,2 +1,21 @@ -

Admin::Auth#login

-

Find me in app/views/admin/auth/login.html.erb

+
+

Admin Login

+ + <% if flash[:error].present? %> +
<%= flash[:error] %>
+ <% end %> + + <%= form_for :auth, url: admin_login_path do |form| %> +
+ <%= form.label :email %> + <%= form.email_field :email %> +
+ +
+ <%= form.label :password %> + <%= form.password_field :password %> +
+ + <%= submit_tag "Log in" %> + <% end %> +
diff --git a/app/views/admin/auth/logout.html.erb b/app/views/admin/auth/logout.html.erb deleted file mode 100644 index 666b438..0000000 --- a/app/views/admin/auth/logout.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Admin::Auth#logout

-

Find me in app/views/admin/auth/logout.html.erb

diff --git a/app/views/admin/dashboard.html.erb b/app/views/admin/dashboard.html.erb index 4f3e250..b69057c 100644 --- a/app/views/admin/dashboard.html.erb +++ b/app/views/admin/dashboard.html.erb @@ -1 +1,18 @@ -huzzah! dashboard +<% + content_for :section_title, "Admin Dashboard" +%> + +
+
+

Quizzes

+ <%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %> + <%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %> +
+ +
+

Users

+ <%= render partial: 'admin/user/table_list', locals: { users: @users } %> + <%= link_to('New User', admin_new_user_path, { class: 'btn' }) %> +
+ +
diff --git a/app/views/admin/question/index.html.erb b/app/views/admin/question/index.html.erb index dcbca37..e69de29 100644 --- a/app/views/admin/question/index.html.erb +++ b/app/views/admin/question/index.html.erb @@ -1,2 +0,0 @@ -

Admin::Questions#index

-

Find me in app/views/admin/questions/index.html.erb

diff --git a/app/views/admin/quiz/_form.html.erb b/app/views/admin/quiz/_form.html.erb index 2cc7e08..591a6f5 100644 --- a/app/views/admin/quiz/_form.html.erb +++ b/app/views/admin/quiz/_form.html.erb @@ -1,6 +1,29 @@ -<%= form_for quiz, url: action do |f| %> -

Unit: <%= f.text_field :unit %>

-

Dept: <%= f.text_field :dept %>

- - <%= f.submit %> +<% if flash[:error].present? %> +
+ <%= flash[:error] %> +

+ <% quiz.errors.messages.each do |k,v| %> + <%= "#{k.to_s} #{v.join(' and ')}" %>
+ <% end %> +

+
+<% end %> + +<%= form_for quiz, url: action do |form| %> +
+ <%= form.label :name, "Quiz Description" %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :dept, 'Department' %> + <%= form.text_field :dept %> +
+ +
+ <%= form.label :unit, 'Unit' %> + <%= form.text_field :unit %> +
+ + <%= form.submit %> <% end %> diff --git a/app/views/admin/quiz/_table_list.html.erb b/app/views/admin/quiz/_table_list.html.erb new file mode 100644 index 0000000..98fbd79 --- /dev/null +++ b/app/views/admin/quiz/_table_list.html.erb @@ -0,0 +1,19 @@ + + + + + + + + + + <% quizzes.each do |quiz| %> + + + + + + + + <% end %> +
NameDeptUnitQuestions
<%= link_to quiz.name, admin_quiz_path(quiz.to_i) %><%= quiz.dept %><%= quiz.unit %><%= quiz.questions.count %><%= link_to 'edit', admin_edit_quiz_path(quiz.to_i), { class: 'btn tertiary-btn' } %>
diff --git a/app/views/admin/quiz/edit.html.erb b/app/views/admin/quiz/edit.html.erb index bdea931..f0435b9 100644 --- a/app/views/admin/quiz/edit.html.erb +++ b/app/views/admin/quiz/edit.html.erb @@ -1,4 +1,7 @@ -

Admin::Quizes#edit

-

Find me in app/views/admin/quizes/edit.html.erb

+<% + content_for :section_title, "Edit: #{@quiz.name}" +%> -<%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %> +
+ <%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %> +
diff --git a/app/views/admin/quiz/index.html.erb b/app/views/admin/quiz/index.html.erb index 458399a..4b1af23 100644 --- a/app/views/admin/quiz/index.html.erb +++ b/app/views/admin/quiz/index.html.erb @@ -1,2 +1,8 @@ -

Admin::Quizes#index

-

Find me in app/views/admin/quizes/index.html.erb

+<% + content_for :section_title, "Quizzes" +%> + +
+ <%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %> + <%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %> +
diff --git a/app/views/admin/quiz/new.html.erb b/app/views/admin/quiz/new.html.erb index bac3d40..639e477 100644 --- a/app/views/admin/quiz/new.html.erb +++ b/app/views/admin/quiz/new.html.erb @@ -1,4 +1,7 @@ -

Admin::Quizes#new

-

Find me in app/views/admin/quizes/new.html.erb

+<% + content_for :section_title, "New Quiz" +%> -<%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %> +
+ <%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %> +
diff --git a/app/views/admin/quiz/view.html.erb b/app/views/admin/quiz/view.html.erb index 24ec89b..7047ca1 100644 --- a/app/views/admin/quiz/view.html.erb +++ b/app/views/admin/quiz/view.html.erb @@ -1,7 +1,10 @@ -

Admin::Quizes#view

-

Find me in app/views/admin/quizes/view.html.erb

+<% + content_for :section_title, "#{@quiz.name}" +%> -
+
+

<%= @quiz.name %>

<%= @quiz.dept %>

<%= @quiz.unit %>

+ <%= link_to('Edit', admin_edit_quiz_path(@quiz.to_i), { class: 'btn' }) %>
diff --git a/app/views/admin/user/_form.html.erb b/app/views/admin/user/_form.html.erb index 164f74e..4edf982 100644 --- a/app/views/admin/user/_form.html.erb +++ b/app/views/admin/user/_form.html.erb @@ -1,7 +1,29 @@ -<%= form_for user, url: action do |f| %> -

Name: <%= f.text_field :name %>

-

eMail: <%= f.email_field :email %>

-

Role: <%= f.text_field :role %>

- - <%= f.submit %> +<% if flash[:error].present? %> +
+ <%= flash[:error] %> +

+ <% user.errors.messages.each do |k,v| %> + <%= "#{k.to_s} #{v.join(' and ')}" %>
+ <% end %> +

+
+<% end %> + +<%= form_for user, url: action do |form| %> +
+ <%= form.label :name, "Full Name" %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :email, "eMail" %> + <%= form.email_field :email %> +
+ +
+ <%= form.label :role, "Role" %> + <%= form.select :role, admin_role_options(user.role), include_blank: false %> +
+ + <%= form.submit %> <% end %> diff --git a/app/views/admin/user/_table_list.html.erb b/app/views/admin/user/_table_list.html.erb new file mode 100644 index 0000000..bcce061 --- /dev/null +++ b/app/views/admin/user/_table_list.html.erb @@ -0,0 +1,17 @@ + + + + + + + + + <% users.each do |user| %> + + + + + + + <% end %> +
UserEmailRole
<%= 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' } %>
diff --git a/app/views/admin/user/edit.html.erb b/app/views/admin/user/edit.html.erb index b438098..7d30c1a 100644 --- a/app/views/admin/user/edit.html.erb +++ b/app/views/admin/user/edit.html.erb @@ -1,4 +1,7 @@ -

Admin::Users#edit

-

Find me in app/views/admin/users/edit.html.erb

+<% + content_for :section_title, "Edit: #{@user.name}" +%> -<%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %> +
+ <%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %> +
diff --git a/app/views/admin/user/index.html.erb b/app/views/admin/user/index.html.erb index 30c6fab..0d25eb9 100644 --- a/app/views/admin/user/index.html.erb +++ b/app/views/admin/user/index.html.erb @@ -1,2 +1,9 @@ -

Admin::Users#index

-

Find me in app/views/admin/users/index.html.erb

+<% + content_for :section_title, "Users" +%> + +
+

Users

+ <%= render partial: 'admin/user/table_list', locals: { users: @users } %> + <%= link_to('New User', admin_new_user_path, { class: 'btn' }) %> +
diff --git a/app/views/admin/user/new.html.erb b/app/views/admin/user/new.html.erb index f076758..16906ea 100644 --- a/app/views/admin/user/new.html.erb +++ b/app/views/admin/user/new.html.erb @@ -1,4 +1,7 @@ -

Admin::Users#new

-

Find me in app/views/admin/users/new.html.erb

+<% + content_for :section_title, "New User" +%> -<%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %> +
+ <%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %> +
diff --git a/app/views/admin/user/view.html.erb b/app/views/admin/user/view.html.erb index ca68938..3890172 100644 --- a/app/views/admin/user/view.html.erb +++ b/app/views/admin/user/view.html.erb @@ -1,6 +1,10 @@ -

Admin::Users#view

-

Find me in app/views/admin/users/view.html.erb

+<% + content_for :section_title, "#{@user.name}" +%> -
- <%= @user.name %> +
+

<%= @user.name %>

+

<%= mail_to(@user.email) %>

+

<%= @user.role %>

+ <%= link_to('Edit', admin_edit_user_path(@user.to_i), { class: 'btn' }) %>
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb new file mode 100644 index 0000000..05fa14f --- /dev/null +++ b/app/views/layouts/admin.html.erb @@ -0,0 +1,46 @@ + + + + + + <%= csrf_meta_tags %> + + <%= yield(:title) %> + + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + + + + + + + +
+ +
+
+ <% if content_for?(:section_title) %> +
<%= yield(:section_title) %>
+ <% else %> +
Skills Assessment Admin
+ <% end %> +
+
+ + <%= yield %> + +
+ +
+ + +
+ + + <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + + diff --git a/app/views/recruiter/create.html.erb b/app/views/recruiter/create.html.erb deleted file mode 100644 index abf096a..0000000 --- a/app/views/recruiter/create.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Recruiter#create

-

Find me in app/views/recruiter/create.html.erb

diff --git a/config/routes.rb b/config/routes.rb index ca102d9..7f0cb37 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/db/migrate/20160818225721_add_name_to_quiz.rb b/db/migrate/20160818225721_add_name_to_quiz.rb new file mode 100644 index 0000000..a8ecd97 --- /dev/null +++ b/db/migrate/20160818225721_add_name_to_quiz.rb @@ -0,0 +1,5 @@ +class AddNameToQuiz < ActiveRecord::Migration[5.0] + def change + add_column :quizzes, :name, :string, after: :id + end +end diff --git a/db/schema.rb b/db/schema.rb index 61aa979..2085033 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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| diff --git a/test/controllers/admin/quiz_controller_test.rb b/test/controllers/admin/quiz_controller_test.rb index fd16e59..b638661 100644 --- a/test/controllers/admin/quiz_controller_test.rb +++ b/test/controllers/admin/quiz_controller_test.rb @@ -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 diff --git a/test/controllers/admin/user_controller_test.rb b/test/controllers/admin/user_controller_test.rb index 972ebf4..8416cc8 100644 --- a/test/controllers/admin/user_controller_test.rb +++ b/test/controllers/admin/user_controller_test.rb @@ -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 diff --git a/test/fixtures/quizzes.yml b/test/fixtures/quizzes.yml index 87dc32d..daf1e5d 100644 --- a/test/fixtures/quizzes.yml +++ b/test/fixtures/quizzes.yml @@ -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 From 6bbbaf4580cc4ec20cad714fa45f5e7c2a1f5113 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Fri, 19 Aug 2016 16:02:18 -0500 Subject: [PATCH 04/10] admin questions work --- app/assets/javascripts/admin.js | 10 ++ app/assets/javascripts/application.js | 3 + app/controllers/admin/question_controller.rb | 31 +++++ app/helpers/application_helper.rb | 9 ++ app/models/question.rb | 5 + app/views/admin/dashboard.html.erb | 2 +- app/views/admin/question/_checkbox.html.erb | 18 +++ app/views/admin/question/_form.html.erb | 49 ++++++++ app/views/admin/question/_live_code.html.erb | 29 +++++ app/views/admin/question/_radio.html.erb | 18 +++ app/views/admin/question/_table_list.html.erb | 21 ++++ app/views/admin/question/_text.html.erb | 0 app/views/admin/question/edit.html.erb | 11 +- app/views/admin/question/index.html.erb | 12 ++ app/views/admin/question/new.html.erb | 9 +- app/views/admin/question/view.html.erb | 38 +++++- app/views/admin/quiz/edit.html.erb | 2 +- app/views/admin/quiz/index.html.erb | 2 +- app/views/admin/quiz/new.html.erb | 2 +- app/views/admin/quiz/view.html.erb | 7 +- app/views/admin/user/edit.html.erb | 2 +- app/views/admin/user/index.html.erb | 2 +- app/views/admin/user/new.html.erb | 2 +- app/views/admin/user/view.html.erb | 2 +- app/views/layouts/admin.html.erb | 1 + app/views/quiz/_live_code.html.erb | 2 +- .../admin/question_controller_test.rb | 111 ++++++++++++------ 27 files changed, 349 insertions(+), 51 deletions(-) create mode 100644 app/assets/javascripts/admin.js create mode 100644 app/views/admin/question/_checkbox.html.erb create mode 100644 app/views/admin/question/_form.html.erb create mode 100644 app/views/admin/question/_live_code.html.erb create mode 100644 app/views/admin/question/_radio.html.erb create mode 100644 app/views/admin/question/_table_list.html.erb create mode 100644 app/views/admin/question/_text.html.erb diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js new file mode 100644 index 0000000..de154bc --- /dev/null +++ b/app/assets/javascripts/admin.js @@ -0,0 +1,10 @@ +$(function(){ + + $("[data-id=input_option_adder]").on('click', function(){ + var $new_li = $(this).siblings('li').clone(); + $new_li.attr('style', ''); + $("[data-id=input_option_list]").append($new_li); + $new_li.find('input').focus(); + }); + +}); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e716f6f..3cfbc1b 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,3 +21,6 @@ //= require summary-edit //= require textarea-limit //= require live-coder + + +//= require admin diff --git a/app/controllers/admin/question_controller.rb b/app/controllers/admin/question_controller.rb index 2d49a92..33ecdd1 100644 --- a/app/controllers/admin/question_controller.rb +++ b/app/controllers/admin/question_controller.rb @@ -1,21 +1,52 @@ module Admin class QuestionController < AdminController def index + @questions = Question.includes(:quiz).order("quizzes.name", { active: :desc }, :sort) end def new + @question = Question.new(active: true) + @quizzes = Quiz.all end def create + @quizzes = Quiz.all + @question = Question.create(question_params) + + if @question.persisted? + redirect_to admin_questions_path, flash: { notice: "Sucessfully created question" } + else + flash[:error] = "Failed to save question." + render :new + end end def view + @question = Question.includes(:quiz).find(params[:question_id]) end def edit + @quizzes = Quiz.all + @question = Question.includes(:quiz).find(params[:question_id]) end def update + @quizzes = Quiz.all + @question = Question.find(params[:question_id]) + + if @question.update_attributes(question_params) + redirect_to admin_question_path(@question.to_i), + flash: { notice: "Sucessfully updated question" } + else + flash[:error] = "Failed to update question." + render :edit + end end + + private + + def question_params + params.require(:question).permit(:quiz_id, :question, :category, :input_type, :input_options, :sort) + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cd6c340..876a05c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -17,4 +17,13 @@ module ApplicationHelper %w(Admin admin) ], disabled: "-", selected: (val.blank? ? '' : val)) end + + def question_type_options val + options_for_select([ + %w(Text text), + %w(Radio radio), + %w(Checkbox checkbox), + %w(Coder live_code) + ], selected: (val.blank? ? '' : val)) + end end diff --git a/app/models/question.rb b/app/models/question.rb index 3abd437..9258649 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -3,4 +3,9 @@ class Question < ApplicationRecord has_many :answers belongs_to :quiz + + validates_presence_of :quiz_id + validates_presence_of :question + validates_presence_of :category + validates_presence_of :input_type end diff --git a/app/views/admin/dashboard.html.erb b/app/views/admin/dashboard.html.erb index b69057c..c19052d 100644 --- a/app/views/admin/dashboard.html.erb +++ b/app/views/admin/dashboard.html.erb @@ -2,7 +2,7 @@ content_for :section_title, "Admin Dashboard" %> -
+

Quizzes

<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %> diff --git a/app/views/admin/question/_checkbox.html.erb b/app/views/admin/question/_checkbox.html.erb new file mode 100644 index 0000000..7c3db76 --- /dev/null +++ b/app/views/admin/question/_checkbox.html.erb @@ -0,0 +1,18 @@ +Checkbox Options + +
    + <% question.input_options.each do | option | %> +
  • + <%= text_field_tag 'question[input_options][]', option, { disabled: (disable ||= false), data: { last: option } } %> +
  • + <% end %> +
+ +<% unless (disable ||= false) %> +
+
Add option
+
  • + <%= text_field_tag 'question[input_options][]', nil, { disabled: (disable ||= false), data: { last: nil } } %> +
  • +
    +<% end %> diff --git a/app/views/admin/question/_form.html.erb b/app/views/admin/question/_form.html.erb new file mode 100644 index 0000000..a3afa87 --- /dev/null +++ b/app/views/admin/question/_form.html.erb @@ -0,0 +1,49 @@ +<% if flash[:error].present? %> +
    + <%= flash[:error] %> +

    + <% question.errors.messages.each do |k,v| %> + <%= "#{k.to_s} #{v.join(' and ')}" %>
    + <% end %> +

    +
    +<% end %> + +<%= form_for question, url: action do |form| %> +
    + <%= form.label :quiz_id, 'Quiz' %> + <%= form.select :quiz_id, options_for_select(@quizzes.map{ |q| [q.name, q.id] }, question.quiz_id), include_blank: (@quizzes.size > 1) %> +
    + +
    + <%= form.label :category, 'Category' %> + <%= form.text_field :category %> +
    + +
    + <%= form.label :sort, 'Sort' %> + <%= form.text_field :sort %> +
    + +
    + <%= form.check_box :active %> + <%= form.label :active, 'Active' %> +
    + +
    + <%= form.label :question, "Question" %> + <%= form.text_area :question %> +
    + +
    + <%= form.label :input_type, 'Input Type' %> + <%= form.select :input_type, question_type_options(question.input_type), include_blank: false %> +
    + + <%= fields_for @question do |fields| %> + <% partial = question.input_type.blank? ? 'admin/question/text' : "admin/question/#{question.input_type}" %> + <%= render partial: partial, locals: {question: question, fields: fields } %> + <% end %> + + <%= form.submit %> +<% end %> diff --git a/app/views/admin/question/_live_code.html.erb b/app/views/admin/question/_live_code.html.erb new file mode 100644 index 0000000..e2820f8 --- /dev/null +++ b/app/views/admin/question/_live_code.html.erb @@ -0,0 +1,29 @@ +<% + + return nil + + # don't load this partial yet. Will finish in issue #16 + # https://gitlab.perficientxd.com/pdr/skill-assessment-app/issues/16 + options = { 'text' => '', 'html' => '', 'css' => '', 'js' => '' } +%> + + +
    +
    + + <%= text_area_tag 'question[input_options][html]', options['html'], { data: {id: 'code-html', last: options['html']}, class: 'code-answer code-html' } %> +
    + +
    + + <%= text_area_tag 'question[input_options][css]', options['css'], { data: {id: 'code-css', last: options['css']}, class: 'code-answer code-css' } %> +
    + +
    + + <%= text_area_tag 'question[input_options][js]', options['js'], { data: {id: 'code-js', last: options['js']}, class: 'code-answer code-js' } %> +
    + +
    +
    + diff --git a/app/views/admin/question/_radio.html.erb b/app/views/admin/question/_radio.html.erb new file mode 100644 index 0000000..6343cdc --- /dev/null +++ b/app/views/admin/question/_radio.html.erb @@ -0,0 +1,18 @@ +Radio Options + +
      + <% question.input_options.each do | option | %> +
    • + <%= text_field_tag 'question[input_options][]', option, { disabled: (disable ||= false), data: { last: option } } %> +
    • + <% end %> +
    + +<% unless (disable ||= false) %> +
    +
    Add option
    +
  • + <%= text_field_tag 'question[input_options][]', nil, { disabled: (disable ||= false), data: { last: nil } } %> +
  • +
    +<% end %> diff --git a/app/views/admin/question/_table_list.html.erb b/app/views/admin/question/_table_list.html.erb new file mode 100644 index 0000000..1ce0359 --- /dev/null +++ b/app/views/admin/question/_table_list.html.erb @@ -0,0 +1,21 @@ + + + + + + + + + + + <% questions.each do |question| %> + + + + + + + + + <% end %> +
    SortQuestionTypeCategoryActive
    <%= question.sort %><%= question.question %><%= question.input_type %><%= question.category %><%= question.active unless question.active? %><%= link_to 'Edit', admin_edit_question_path(question.to_i), { class: 'btn tertiary-btn' } %>
    diff --git a/app/views/admin/question/_text.html.erb b/app/views/admin/question/_text.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/admin/question/edit.html.erb b/app/views/admin/question/edit.html.erb index 34ed55e..baea6e8 100644 --- a/app/views/admin/question/edit.html.erb +++ b/app/views/admin/question/edit.html.erb @@ -1,2 +1,9 @@ -

    Admin::Questions#edit

    -

    Find me in app/views/admin/questions/edit.html.erb

    +<% + content_for :section_title, "Questions" +%> + +
    +

    <%= @question.quiz.name %>

    + + <%= render partial: 'form', locals: {question: @question, action: admin_update_question_path } %> +
    diff --git a/app/views/admin/question/index.html.erb b/app/views/admin/question/index.html.erb index e69de29..8ec115b 100644 --- a/app/views/admin/question/index.html.erb +++ b/app/views/admin/question/index.html.erb @@ -0,0 +1,12 @@ +<% + content_for :section_title, "Questions" +%> + +
    + <% quizzes = @questions.group_by{ |q| q.quiz.name } %> + <% quizzes.each do |quiz, questions| %> +

    <%= quiz %>

    + <%= render partial: 'admin/question/table_list', locals: { questions: questions } %> + <%= link_to('Edit Quiz', admin_quiz_path(questions.first.quiz.to_i), { class: 'btn' }) %> + <% end %> +
    diff --git a/app/views/admin/question/new.html.erb b/app/views/admin/question/new.html.erb index f4507f7..8bc7a68 100644 --- a/app/views/admin/question/new.html.erb +++ b/app/views/admin/question/new.html.erb @@ -1,2 +1,7 @@ -

    Admin::Questions#new

    -

    Find me in app/views/admin/questions/new.html.erb

    +<% + content_for :section_title, "New Question" +%> + +
    + <%= render partial: 'form', locals: {question: @question, action: admin_create_question_path } %> +
    diff --git a/app/views/admin/question/view.html.erb b/app/views/admin/question/view.html.erb index fea4846..8cfce12 100644 --- a/app/views/admin/question/view.html.erb +++ b/app/views/admin/question/view.html.erb @@ -1,2 +1,36 @@ -

    Admin::Questions#view

    -

    Find me in app/views/admin/questions/view.html.erb

    +<% + content_for :section_title, "Question for #{@question.quiz.name}" +%> + +
    + + + + + + + + + + + + + + + + + +
    Category<%= @question.category %>
    Type<%= @question.input_type %>
    Sort<%= @question.sort %>
    + <%= check_box_tag 'question_active', nil, @question.active?, {disabled: true} %> + <%= label_tag 'question_active', 'Active' %> +
    + + Question +

    <%= @question.question %>

    + + <%= fields_for @question do |fields| %> + <%= render partial: "admin/question/#{@question.input_type}", locals: {question: @question, disable: true, fields: fields } %> + <% end %> + + <%= link_to('Edit', admin_edit_question_path(@question.to_i), { class: 'btn' }) %> +
    diff --git a/app/views/admin/quiz/edit.html.erb b/app/views/admin/quiz/edit.html.erb index f0435b9..a67e234 100644 --- a/app/views/admin/quiz/edit.html.erb +++ b/app/views/admin/quiz/edit.html.erb @@ -2,6 +2,6 @@ content_for :section_title, "Edit: #{@quiz.name}" %> -
    +
    <%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %>
    diff --git a/app/views/admin/quiz/index.html.erb b/app/views/admin/quiz/index.html.erb index 4b1af23..70b8cf2 100644 --- a/app/views/admin/quiz/index.html.erb +++ b/app/views/admin/quiz/index.html.erb @@ -2,7 +2,7 @@ content_for :section_title, "Quizzes" %> -
    +
    <%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %> <%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
    diff --git a/app/views/admin/quiz/new.html.erb b/app/views/admin/quiz/new.html.erb index 639e477..2d0dd11 100644 --- a/app/views/admin/quiz/new.html.erb +++ b/app/views/admin/quiz/new.html.erb @@ -2,6 +2,6 @@ content_for :section_title, "New Quiz" %> -
    +
    <%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %>
    diff --git a/app/views/admin/quiz/view.html.erb b/app/views/admin/quiz/view.html.erb index 7047ca1..21eb321 100644 --- a/app/views/admin/quiz/view.html.erb +++ b/app/views/admin/quiz/view.html.erb @@ -2,9 +2,14 @@ content_for :section_title, "#{@quiz.name}" %> -
    +

    <%= @quiz.name %>

    <%= @quiz.dept %>

    <%= @quiz.unit %>

    <%= link_to('Edit', admin_edit_quiz_path(@quiz.to_i), { class: 'btn' }) %>
    + +
    + <%= render partial: 'admin/question/table_list', locals: { questions: @quiz.questions, disable: true } %> + <%= link_to('New Question', admin_new_question_path, { class: 'btn' }) %> +
    diff --git a/app/views/admin/user/edit.html.erb b/app/views/admin/user/edit.html.erb index 7d30c1a..0ccc724 100644 --- a/app/views/admin/user/edit.html.erb +++ b/app/views/admin/user/edit.html.erb @@ -2,6 +2,6 @@ content_for :section_title, "Edit: #{@user.name}" %> -
    +
    <%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %>
    diff --git a/app/views/admin/user/index.html.erb b/app/views/admin/user/index.html.erb index 0d25eb9..3092e28 100644 --- a/app/views/admin/user/index.html.erb +++ b/app/views/admin/user/index.html.erb @@ -2,7 +2,7 @@ content_for :section_title, "Users" %> -
    +

    Users

    <%= render partial: 'admin/user/table_list', locals: { users: @users } %> <%= link_to('New User', admin_new_user_path, { class: 'btn' }) %> diff --git a/app/views/admin/user/new.html.erb b/app/views/admin/user/new.html.erb index 16906ea..dc70d47 100644 --- a/app/views/admin/user/new.html.erb +++ b/app/views/admin/user/new.html.erb @@ -2,6 +2,6 @@ content_for :section_title, "New User" %> -
    +
    <%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %>
    diff --git a/app/views/admin/user/view.html.erb b/app/views/admin/user/view.html.erb index 3890172..caf2c25 100644 --- a/app/views/admin/user/view.html.erb +++ b/app/views/admin/user/view.html.erb @@ -2,7 +2,7 @@ content_for :section_title, "#{@user.name}" %> -
    +

    <%= @user.name %>

    <%= mail_to(@user.email) %>

    <%= @user.role %>

    diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 05fa14f..0beec5b 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -35,6 +35,7 @@
    +
    diff --git a/app/views/quiz/_live_code.html.erb b/app/views/quiz/_live_code.html.erb index 5e76e3a..9a3a344 100644 --- a/app/views/quiz/_live_code.html.erb +++ b/app/views/quiz/_live_code.html.erb @@ -37,7 +37,7 @@