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 @@ -
Find me in app/views/admin/auth/login.html.erb
+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" +%> + +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? %> +
+ <% quiz.errors.messages.each do |k,v| %>
+ <%= "#{k.to_s} #{v.join(' and ')}" %>
+ <% end %>
+
Name | +Dept | +Unit | +Questions | ++ |
---|---|---|---|---|
<%= 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' } %> | +
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 } %> +Find me in app/views/admin/quizes/index.html.erb
+<% + content_for :section_title, "Quizzes" +%> + +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 } %> +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' }) %>Name: <%= f.text_field :name %>
-eMail: <%= f.email_field :email %>
-Role: <%= f.text_field :role %>
- - <%= f.submit %> +<% if flash[:error].present? %> +
+ <% user.errors.messages.each do |k,v| %>
+ <%= "#{k.to_s} #{v.join(' and ')}" %>
+ <% end %>
+
User | +Role | ++ | |
---|---|---|---|
<%= 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' } %> | +
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 } %> +Find me in app/views/admin/users/index.html.erb
+<% + content_for :section_title, "Users" +%> + +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 } %> +Find me in app/views/admin/users/view.html.erb
+<% + content_for :section_title, "#{@user.name}" +%> -<%= @user.name %>
+<%= mail_to(@user.email) %>
+<%= @user.role %>
+ <%= link_to('Edit', admin_edit_user_path(@user.to_i), { class: 'btn' }) %>