diff --git a/app/assets/javascripts/ajax-links.js b/app/assets/javascripts/ajax-links.js index 1dd5fac..55ee365 100644 --- a/app/assets/javascripts/ajax-links.js +++ b/app/assets/javascripts/ajax-links.js @@ -1,7 +1,8 @@ -function handleAjaxResponse($el) { +function handleAjaxResponse($el, callback) { var $header = $('header'); $el.on("ajax:success", function(e, data){ $header.after('
' + data.message + '
'); + callback(data); }).on("ajax:error", function(e, xhr) { if (xhr.status === 400){ $header.after('
' + xhr.responseJSON.join('
') + '
'); @@ -11,6 +12,25 @@ function handleAjaxResponse($el) { }); } +function updateVotes(data){ + $("[data-id=up-votes]").html(data.upCount); + $("[data-id=down-votes]").html(data.downCount); + $("[data-id=my-vote]").html(data.myVote); +} + +function updateVeto(data){ + $("[data-id=interview-request]").html(data.requestCopy); + $("[data-id=interview-decline]").html(data.declineCopy); +} + $(document).ready(function() { $('[data-id=ajax-action]').each(function(){ handleAjaxResponse($(this)); }); }); + +$(document).ready(function() { + $('[data-id=vote-count]').each(function(){ handleAjaxResponse($(this), updateVotes); }); +}); + +$(document).ready(function() { + $('[data-id=veto-status]').each(function(){ handleAjaxResponse($(this), updateVeto); }); +}); diff --git a/app/controllers/admin/vote_controller.rb b/app/controllers/admin/vote_controller.rb index 63a2fdc..5ef1ded 100644 --- a/app/controllers/admin/vote_controller.rb +++ b/app/controllers/admin/vote_controller.rb @@ -7,9 +7,10 @@ module Admin current_user.cast_yea_on(@candidate) results = { - message: "Vote tallied!", + message: "Vote Counted", upCount: @candidate.votes.yea.count, - downCount: @candidate.votes.nay.count + downCount: @candidate.votes.nay.count, + myVote: "yea" } render json: results.to_json end @@ -20,9 +21,10 @@ module Admin current_user.cast_nay_on(@candidate) results = { - message: "Vote tallied!", + message: "Vote Counted", upCount: @candidate.votes.yea.count, - downCount: @candidate.votes.nay.count + downCount: @candidate.votes.nay.count, + myVote: "nay" } render json: results.to_json end @@ -32,7 +34,11 @@ module Admin @candidate = Candidate.find_by(test_hash: params[:test_hash]) current_user.approve_candidate(@candidate) - results = { message: "Interview requested!" } + results = { + message: "Interview requested!", + requestCopy: "Requested", + declineCopy: "Decline Interview" + } render json: results.to_json end @@ -41,7 +47,11 @@ module Admin @candidate = Candidate.find_by(test_hash: params[:test_hash]) current_user.decline_candidate(@candidate) - results = { message: "Interview declined." } + results = { + message: "Interview declined.", + requestCopy: "Request Interview", + declineCopy: "Declined" + } render json: results.to_json end end diff --git a/app/models/candidate.rb b/app/models/candidate.rb index dac22db..74c2f47 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -17,7 +17,7 @@ class Candidate < ApplicationRecord validates :test_hash, uniqueness: true, presence: true enum review_status: { - # pending: 0, + pending: 0, approved: 1, declined: 2 } diff --git a/app/models/user.rb b/app/models/user.rb index a563182..ec0a298 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,6 +47,13 @@ class User < ApplicationRecord candidate.update_attribute(:review_status, :declined) if vote.save end + def my_vote candidate + candidate = Candidate.find(candidate.to_i) + + my_votes = votes.find_by(candidate_id: candidate.id) + my_votes.nil? ? "undecided" : my_votes.votes + end + # Roles def admin? 'admin' == role diff --git a/app/views/admin/result/view.html.erb b/app/views/admin/result/view.html.erb index 10f1458..8892276 100644 --- a/app/views/admin/result/view.html.erb +++ b/app/views/admin/result/view.html.erb @@ -8,24 +8,33 @@ Recruiter Email: <%= mail_to @candidate.recruiter.name, @candidate.recruiter.email %>
-
+
Votes: - <%= link_to '#cast-vote-up', remote: true do %> - Yea (<%= @candidate.votes.yea.count %>) + <%= link_to admin_up_vote_path(test_hash: @candidate.test_hash), remote: true do %> + Yea (<%= @candidate.votes.yea.count %>) <% end %> - <%= link_to '#cast-vote-down', remote: true do %> - Nay (<%= @candidate.votes.nay.count %>) - <% end %> -
-
- Manager Vetos: - <%= link_to '#request', remote: true do %> - Request Interview - <% end %> - <%= link_to '#decline', remote: true do %> - Decline Interview + <%= link_to admin_down_vote_path(test_hash: @candidate.test_hash), remote: true do %> + Nay (<%= @candidate.votes.nay.count %>) <% end %> + (Your vote: <%= current_user.my_vote(@candidate) %>)
+ <% if current_user.acts_as_manager? %> +
+ Manager Vetos: + <%= link_to admin_approve_vote_path(test_hash: @candidate.test_hash), remote: true do %> + + <%= @candidate.approved? ? "Requested" : "Request Interview" %> + + <% end %> + <%= link_to admin_decline_vote_path(test_hash: @candidate.test_hash), remote: true do %> + + <%= @candidate.declined? ? "Declined" : "Decline Interview" %> + + <% end %> +
+ <% else %> + Candidate Interview Status: <%= @candidate.review_status %> + <% end %>
diff --git a/test/controllers/admin/result_controller_test.rb b/test/controllers/admin/result_controller_test.rb index 699517d..b186b41 100644 --- a/test/controllers/admin/result_controller_test.rb +++ b/test/controllers/admin/result_controller_test.rb @@ -19,5 +19,12 @@ module Admin assert assigns(:quiz), "@quiz not present" assert assigns(:status), "@status not present" end + + test "reviewer can view result for henry" do + auth_reviewer + + get admin_result_url(candidates(:henry).test_hash) + assert_response :success + end end end