progress bar logic
This commit is contained in:
parent
5207b6b8fd
commit
79e1797295
@ -3,7 +3,7 @@ class CandidateController < ApplicationController
|
||||
end
|
||||
|
||||
def question
|
||||
@question = Question.where(input_type: 'live-coder').order("RAND()").first
|
||||
@question = Question.order("RAND()").first # .where(input_type: 'live-coder')
|
||||
@status = QuizStatus.new(Candidate.order("RAND()").first)
|
||||
@answer = @question.answers.order("RAND()").first
|
||||
end
|
||||
|
@ -27,27 +27,11 @@
|
||||
</main>
|
||||
</form>
|
||||
|
||||
<!--
|
||||
<?php
|
||||
$TotalQuestions;
|
||||
$progressBarValue;
|
||||
//Get Total Number of Questions
|
||||
$TotalQuestions = "SELECT * FROM questions";
|
||||
$result = $link->query($TotalQuestions);
|
||||
$TotalQuestions = $result->num_rows + 1;
|
||||
|
||||
$progressBarValue = round($questionId/$TotalQuestions * 100);
|
||||
$_SESSION['pBarValue'] = $progressBarValue;
|
||||
|
||||
$pValue = $_SESSION['pBarValue'];
|
||||
|
||||
if(!isset($_GET['qid'])) { ?>
|
||||
<div class="progress ignore-margin">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $pValue; ?>"
|
||||
aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $pValue; ?>%">
|
||||
<span><?php echo $pValue; ?>%</span>
|
||||
</div>
|
||||
<% unless @status.on_summary %>
|
||||
<div class="progress ignore-margin">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="<%= @status.progress %>"
|
||||
aria-valuemin="0" aria-valuemax="100" style="width: <%= @status.progress %>%">
|
||||
<span><%= @status.progress %>%</span>
|
||||
</div>
|
||||
<?php }
|
||||
?>
|
||||
-->
|
||||
</div>
|
||||
<% end %>
|
||||
|
@ -21,26 +21,10 @@ class QuizStatus
|
||||
on_summary && candidate.answered_questions.count == candidate.questions.count
|
||||
end
|
||||
|
||||
# <?php
|
||||
# $TotalQuestions;
|
||||
# $progressBarValue;
|
||||
# //Get Total Number of Questions
|
||||
# $TotalQuestions = "SELECT * FROM questions";
|
||||
# $result = $link->query($TotalQuestions);
|
||||
# $TotalQuestions = $result->num_rows + 1;
|
||||
#
|
||||
# $progressBarValue = round($questionId/$TotalQuestions * 100);
|
||||
# $_SESSION['pBarValue'] = $progressBarValue;
|
||||
#
|
||||
# $pValue = $_SESSION['pBarValue'];
|
||||
#
|
||||
# if(!isset($_GET['qid'])) { ?>
|
||||
# <div class="progress ignore-margin">
|
||||
# <div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $pValue; ?>"
|
||||
# aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $pValue; ?>%">
|
||||
# <span><?php echo $pValue; ?>%</span>
|
||||
# </div>
|
||||
# </div>
|
||||
# <?php }
|
||||
# ?>
|
||||
def progress
|
||||
answs = candidate.answered_questions.count.to_f
|
||||
total = candidate.quiz.questions.count.to_f
|
||||
|
||||
(answs / total * 100).round.to_i
|
||||
end
|
||||
end
|
||||
|
@ -56,4 +56,25 @@ class QuizStatusTest < ActiveSupport::TestCase
|
||||
|
||||
assert status.can_submit
|
||||
end
|
||||
|
||||
test "richard is at 100%" do
|
||||
richard = candidates :richard
|
||||
status = QuizStatus.new richard
|
||||
|
||||
assert_equal 100, status.progress
|
||||
end
|
||||
|
||||
test "roy is 20% done" do
|
||||
roy = candidates :roy
|
||||
status = QuizStatus.new roy
|
||||
|
||||
assert_equal 20, status.progress
|
||||
end
|
||||
|
||||
test "martha is 0% done" do
|
||||
martha = candidates :martha
|
||||
status = QuizStatus.new martha
|
||||
|
||||
assert_equal 0, status.progress
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user