wired up vote ux
This commit is contained in:
parent
5ef7f82dbf
commit
74b2415b91
@ -1,7 +1,8 @@
|
|||||||
function handleAjaxResponse($el) {
|
function handleAjaxResponse($el, callback) {
|
||||||
var $header = $('header');
|
var $header = $('header');
|
||||||
$el.on("ajax:success", function(e, data){
|
$el.on("ajax:success", function(e, data){
|
||||||
$header.after('<div class="success">' + data.message + '</div>');
|
$header.after('<div class="success">' + data.message + '</div>');
|
||||||
|
callback(data);
|
||||||
}).on("ajax:error", function(e, xhr) {
|
}).on("ajax:error", function(e, xhr) {
|
||||||
if (xhr.status === 400){
|
if (xhr.status === 400){
|
||||||
$header.after('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
|
$header.after('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
|
||||||
@ -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() {
|
$(document).ready(function() {
|
||||||
$('[data-id=ajax-action]').each(function(){ handleAjaxResponse($(this)); });
|
$('[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); });
|
||||||
|
});
|
||||||
|
@ -7,9 +7,10 @@ module Admin
|
|||||||
current_user.cast_yea_on(@candidate)
|
current_user.cast_yea_on(@candidate)
|
||||||
|
|
||||||
results = {
|
results = {
|
||||||
message: "Vote tallied!",
|
message: "Vote Counted",
|
||||||
upCount: @candidate.votes.yea.count,
|
upCount: @candidate.votes.yea.count,
|
||||||
downCount: @candidate.votes.nay.count
|
downCount: @candidate.votes.nay.count,
|
||||||
|
myVote: "yea"
|
||||||
}
|
}
|
||||||
render json: results.to_json
|
render json: results.to_json
|
||||||
end
|
end
|
||||||
@ -20,9 +21,10 @@ module Admin
|
|||||||
current_user.cast_nay_on(@candidate)
|
current_user.cast_nay_on(@candidate)
|
||||||
|
|
||||||
results = {
|
results = {
|
||||||
message: "Vote tallied!",
|
message: "Vote Counted",
|
||||||
upCount: @candidate.votes.yea.count,
|
upCount: @candidate.votes.yea.count,
|
||||||
downCount: @candidate.votes.nay.count
|
downCount: @candidate.votes.nay.count,
|
||||||
|
myVote: "nay"
|
||||||
}
|
}
|
||||||
render json: results.to_json
|
render json: results.to_json
|
||||||
end
|
end
|
||||||
@ -32,7 +34,11 @@ module Admin
|
|||||||
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
||||||
current_user.approve_candidate(@candidate)
|
current_user.approve_candidate(@candidate)
|
||||||
|
|
||||||
results = { message: "Interview requested!" }
|
results = {
|
||||||
|
message: "Interview requested!",
|
||||||
|
requestCopy: "Requested",
|
||||||
|
declineCopy: "Decline Interview"
|
||||||
|
}
|
||||||
render json: results.to_json
|
render json: results.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -41,7 +47,11 @@ module Admin
|
|||||||
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
@candidate = Candidate.find_by(test_hash: params[:test_hash])
|
||||||
current_user.decline_candidate(@candidate)
|
current_user.decline_candidate(@candidate)
|
||||||
|
|
||||||
results = { message: "Interview declined." }
|
results = {
|
||||||
|
message: "Interview declined.",
|
||||||
|
requestCopy: "Request Interview",
|
||||||
|
declineCopy: "Declined"
|
||||||
|
}
|
||||||
render json: results.to_json
|
render json: results.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,7 @@ class Candidate < ApplicationRecord
|
|||||||
validates :test_hash, uniqueness: true, presence: true
|
validates :test_hash, uniqueness: true, presence: true
|
||||||
|
|
||||||
enum review_status: {
|
enum review_status: {
|
||||||
# pending: 0,
|
pending: 0,
|
||||||
approved: 1,
|
approved: 1,
|
||||||
declined: 2
|
declined: 2
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,13 @@ class User < ApplicationRecord
|
|||||||
candidate.update_attribute(:review_status, :declined) if vote.save
|
candidate.update_attribute(:review_status, :declined) if vote.save
|
||||||
end
|
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
|
# Roles
|
||||||
def admin?
|
def admin?
|
||||||
'admin' == role
|
'admin' == role
|
||||||
|
@ -8,24 +8,33 @@
|
|||||||
<strong>Recruiter Email:</strong> <%= mail_to @candidate.recruiter.name, @candidate.recruiter.email %><br />
|
<strong>Recruiter Email:</strong> <%= mail_to @candidate.recruiter.name, @candidate.recruiter.email %><br />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="review_meta__votes">
|
<div class="review_meta__votes" data-id="vote-count">
|
||||||
<strong>Votes: </strong>
|
<strong>Votes: </strong>
|
||||||
<%= link_to '#cast-vote-up', remote: true do %>
|
<%= link_to admin_up_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||||
Yea (<%= @candidate.votes.yea.count %>)
|
Yea (<span data-id="up-votes"><%= @candidate.votes.yea.count %></span>)
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= link_to '#cast-vote-down', remote: true do %>
|
<%= link_to admin_down_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||||
Nay (<%= @candidate.votes.nay.count %>)
|
Nay (<span data-id="down-votes"><%= @candidate.votes.nay.count %></span>)
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<div class="review_meta__vetos">
|
|
||||||
<strong>Manager Vetos: </strong>
|
|
||||||
<%= link_to '#request', remote: true do %>
|
|
||||||
Request Interview
|
|
||||||
<% end %>
|
|
||||||
<%= link_to '#decline', remote: true do %>
|
|
||||||
Decline Interview
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<small>(Your vote: <span data-id="my-vote"><%= current_user.my_vote(@candidate) %></span>)</small>
|
||||||
</div>
|
</div>
|
||||||
|
<% if current_user.acts_as_manager? %>
|
||||||
|
<div class="review_meta__vetos" data-id="veto-status">
|
||||||
|
<strong>Manager Vetos: </strong>
|
||||||
|
<%= link_to admin_approve_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||||
|
<span data-id="interview-request">
|
||||||
|
<%= @candidate.approved? ? "Requested" : "Request Interview" %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
<%= link_to admin_decline_vote_path(test_hash: @candidate.test_hash), remote: true do %>
|
||||||
|
<span data-id="interview-decline">
|
||||||
|
<%= @candidate.declined? ? "Declined" : "Decline Interview" %>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<strong>Candidate Interview Status: </strong><%= @candidate.review_status %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -19,5 +19,12 @@ module Admin
|
|||||||
assert assigns(:quiz), "@quiz not present"
|
assert assigns(:quiz), "@quiz not present"
|
||||||
assert assigns(:status), "@status not present"
|
assert assigns(:status), "@status not present"
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user