progress bar logic
This commit is contained in:
		@@ -3,7 +3,7 @@ class CandidateController < ApplicationController
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def question
 | 
					  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)
 | 
					    @status = QuizStatus.new(Candidate.order("RAND()").first)
 | 
				
			||||||
    @answer = @question.answers.order("RAND()").first
 | 
					    @answer = @question.answers.order("RAND()").first
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,27 +27,11 @@
 | 
				
			|||||||
  </main>
 | 
					  </main>
 | 
				
			||||||
</form>
 | 
					</form>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<!--
 | 
					<% unless @status.on_summary %>
 | 
				
			||||||
<?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 ignore-margin">
 | 
				
			||||||
      <div class="progress-bar" role="progressbar" aria-valuenow="<?php echo $pValue; ?>"
 | 
					    <div class="progress-bar" role="progressbar" aria-valuenow="<%= @status.progress %>"
 | 
				
			||||||
      aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $pValue; ?>%">
 | 
					        aria-valuemin="0" aria-valuemax="100" style="width: <%= @status.progress %>%">
 | 
				
			||||||
        <span><?php echo $pValue; ?>%</span>
 | 
					      <span><%= @status.progress %>%</span>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <?php }
 | 
					<% end %>
 | 
				
			||||||
?>
 | 
					 | 
				
			||||||
-->
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,26 +21,10 @@ class QuizStatus
 | 
				
			|||||||
    on_summary && candidate.answered_questions.count == candidate.questions.count
 | 
					    on_summary && candidate.answered_questions.count == candidate.questions.count
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # <?php
 | 
					  def progress
 | 
				
			||||||
  #   $TotalQuestions;
 | 
					    answs = candidate.answered_questions.count.to_f
 | 
				
			||||||
  #   $progressBarValue;
 | 
					    total = candidate.quiz.questions.count.to_f
 | 
				
			||||||
  #   //Get Total Number of Questions
 | 
					
 | 
				
			||||||
  #   $TotalQuestions = "SELECT * FROM questions";
 | 
					    (answs / total * 100).round.to_i
 | 
				
			||||||
  #   $result = $link->query($TotalQuestions);
 | 
					  end
 | 
				
			||||||
  #   $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 }
 | 
					 | 
				
			||||||
  # ?>
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,4 +56,25 @@ class QuizStatusTest < ActiveSupport::TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    assert status.can_submit
 | 
					    assert status.can_submit
 | 
				
			||||||
  end
 | 
					  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
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user