move summary and questions to quiz controller
This commit is contained in:
5
app/views/quiz/_answer_errors.html.erb
Normal file
5
app/views/quiz/_answer_errors.html.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<% if flash[:answer_error] == question.question_id && answer.present? %>
|
||||
<% answer.errors.messages[:answer].each do |message| %>
|
||||
<div class="error"><%= message %></div>
|
||||
<% end %>
|
||||
<% end %>
|
17
app/views/quiz/_checkbox.html.erb
Normal file
17
app/views/quiz/_checkbox.html.erb
Normal file
@ -0,0 +1,17 @@
|
||||
<%
|
||||
question.input_options.each_with_index do | option, i |
|
||||
option_id = "#{question.question_id}_#{i}"
|
||||
|
||||
checkbox_html = {class: 'checkbox',
|
||||
id: "answer_#{option_id}",
|
||||
name: "answer[checkbox][]",
|
||||
checked: Array(question.answer).include?(option)
|
||||
}
|
||||
%>
|
||||
<div class="form-group-multiples">
|
||||
<%= form.check_box(:answer, checkbox_html, option, '') %>
|
||||
<%= form.label(option_id, option) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: @answer} %>
|
37
app/views/quiz/_live_code.html.erb
Normal file
37
app/views/quiz/_live_code.html.erb
Normal file
@ -0,0 +1,37 @@
|
||||
<%
|
||||
option_id = "#{question.question_id}_finish-later"
|
||||
|
||||
checkbox_html = {class: 'checkbox',
|
||||
id: "answer_#{option_id}",
|
||||
name: "answer[#{question.input_type}][later]",
|
||||
checked: Array(question.answer).include?('finish-later')
|
||||
}
|
||||
%>
|
||||
<!-- <div class="js-error">
|
||||
Please revisit this page with JavaScript enabled to modify your answer.
|
||||
</div> -->
|
||||
|
||||
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: @answer} %>
|
||||
|
||||
<div data-id="live-coder-finish-later">
|
||||
<p class="warning">
|
||||
This is a question where you will be asked to write code, and it utilizes a JavaScript-enabled
|
||||
environment. It looks like JavaScript is not loaded.
|
||||
<% unless params[:action] == 'summary' %>
|
||||
Please check the box below to acknowledge that you agree to come back at a later time to finish
|
||||
answering this question before you can submit the test.
|
||||
<% else %>
|
||||
You will need to enable JavaScript and answer this question before you can submit the test.
|
||||
<% end %>
|
||||
</p>
|
||||
<% unless params[:action] == 'summary' %>
|
||||
<%= form.check_box(:answer, checkbox_html, true, '') %>
|
||||
<%= form.label(option_id, 'I will come back later to finish this code question') %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div data-id="live-coder-answer">
|
||||
<% # answers inserted dynamically via jQuery .load()
|
||||
# to check for JS capability/enabled
|
||||
%>
|
||||
</div>
|
1
app/views/quiz/_live_code_text.html.erb
Normal file
1
app/views/quiz/_live_code_text.html.erb
Normal file
@ -0,0 +1 @@
|
||||
<%= render partial: "quiz/live_code", locals: {question: question, form: form} %>
|
12
app/views/quiz/_radio.html.erb
Normal file
12
app/views/quiz/_radio.html.erb
Normal file
@ -0,0 +1,12 @@
|
||||
<%
|
||||
question.input_options.each do | option |
|
||||
option_id = "#{option.parameterize}_#{question.to_i}"
|
||||
radio_html = {class: 'radio', id: option_id}
|
||||
%>
|
||||
<div class="form-group-multiples">
|
||||
<%= radio_button_tag('answer[radio]', option, (question.answer == option), radio_html) %>
|
||||
<%= label_tag(option_id, option) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: @answer} %>
|
8
app/views/quiz/_text.html.erb
Normal file
8
app/views/quiz/_text.html.erb
Normal file
@ -0,0 +1,8 @@
|
||||
<% hidden = params[:action] == 'summary' ? 'hidden' : '' %>
|
||||
|
||||
<label for="answer_text">Enter answer here</label>
|
||||
<textarea id="answer_text" name="answer[text]" rows="10"><%= question.answer %></textarea>
|
||||
|
||||
<div class="chars <%= hidden %>">Characters remaining: <span></span></div>
|
||||
|
||||
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: @answer} %>
|
18
app/views/quiz/live_code.html.erb
Normal file
18
app/views/quiz/live_code.html.erb
Normal file
@ -0,0 +1,18 @@
|
||||
<% answer = @answer.answer || {} %>
|
||||
|
||||
<div class="code-input">
|
||||
<label for="answer_live_code_html">HTML</label>
|
||||
<%= text_area_tag 'answer[live_code][html]', (answer['html']), { 'data-id' => 'code-html', class: 'code-answer code-html' } %>
|
||||
</div>
|
||||
|
||||
<div class="code-input">
|
||||
<label for="answer_live_code_css">CSS</label>
|
||||
<%= text_area_tag 'answer[live_code][css]', (answer['css']), { 'data-id' => 'code-css', class: 'code-answer code-css' } %>
|
||||
</div>
|
||||
|
||||
<div class="code-input">
|
||||
<label for="answer_live_code_js">JS</label>
|
||||
<%= text_area_tag 'answer[live_code][js]', (answer['js']), { 'data-id' => 'code-js', class: 'code-answer code-js' } %>
|
||||
</div>
|
||||
|
||||
<div class="results" data-id="results"></div>
|
21
app/views/quiz/live_code_text.html.erb
Normal file
21
app/views/quiz/live_code_text.html.erb
Normal file
@ -0,0 +1,21 @@
|
||||
<% answer = @answer.answer || {} %>
|
||||
|
||||
<label for="answer_live_code_text">Reasoning</label>
|
||||
<%= text_area_tag 'answer[live_code_text][text]', (answer['text']) %>
|
||||
|
||||
<div class="code-input">
|
||||
<label for="answer_live_code_html">HTML</label>
|
||||
<%= text_area_tag 'answer[live_code_text][html]', (answer['html']), { 'data-id' => 'code-html', class: 'code-answer code-html' } %>
|
||||
</div>
|
||||
|
||||
<div class="code-input">
|
||||
<label for="answer_live_code_css">CSS</label>
|
||||
<%= text_area_tag 'answer[live_code_text][css]', (answer['css']), { 'data-id' => 'code-css', class: 'code-answer code-css' } %>
|
||||
</div>
|
||||
|
||||
<div class="code-input">
|
||||
<label for="answer_live_code_js">JS</label>
|
||||
<%= text_area_tag 'answer[live_code_text][js]', (answer['js']), { 'data-id' => 'code-js', class: 'code-answer code-js' } %>
|
||||
</div>
|
||||
|
||||
<div class="results" data-id="results"></div>
|
48
app/views/quiz/question.html.erb
Normal file
48
app/views/quiz/question.html.erb
Normal file
@ -0,0 +1,48 @@
|
||||
<%
|
||||
content_for :title, "Skills Assessment"
|
||||
content_for :category, @question.category
|
||||
content_for :summary, true if @status.on_summary
|
||||
content_for :footer_title, "Skills Assessment"
|
||||
%>
|
||||
|
||||
<%= form_for(@answer, url: post_answer_path(@answer.id), html:{method: :post, id: 'answer-form', data: {qid: @question.question_id}}) do |form| %>
|
||||
<main class="answer-sec <%= @question.input_type %>-type questions_tpl" data-qid="<%= @question.question_id %>">
|
||||
<h2 class="question-text"><%= @question.question %></h2>
|
||||
|
||||
<% if @question.attachment.present? %>
|
||||
<%= image_tag @question.attachment %>
|
||||
<% end %>
|
||||
|
||||
<div class="content-well">
|
||||
<%= hidden_field_tag 'answer[question_id]', @question.question_id %>
|
||||
<%= hidden_field_tag 'answer[answer_id]', @question.answer_id %>
|
||||
<%= render partial: @question.input_type, locals: {question: @question, form: form} %>
|
||||
</div>
|
||||
|
||||
<% if @status.on_summary %>
|
||||
|
||||
<div class="btn-container-summary button-wrap">
|
||||
<input type="submit" name="submit" value="Save and return to summary">
|
||||
</div>
|
||||
|
||||
<% else %>
|
||||
|
||||
<div class="btn-container-left">
|
||||
<input type="submit" class="secondary-btn" name="save" value="Save">
|
||||
</div>
|
||||
<div class="btn-container-right">
|
||||
<input type="submit" class="tertiary-btn arrow-btn-right" name="submit" value="Next →">
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
</main>
|
||||
<% end %>
|
||||
|
||||
<% 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>
|
||||
</div>
|
||||
<% end %>
|
47
app/views/quiz/summary.html.erb
Normal file
47
app/views/quiz/summary.html.erb
Normal file
@ -0,0 +1,47 @@
|
||||
<main class="summary_tpl">
|
||||
<h2 class="prft-heading">Almost done!</h2>
|
||||
<p>
|
||||
Now's the time to review your answers and go back and change any, if you need to.
|
||||
Once you're done, hit the button at the bottom of the page to submit your answers.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<% @quiz.each do |question| %>
|
||||
<%= form_for(:answer, url: post_answer_path(answer_id: question.answer_id), html:{class: 'summary-form'}) do |form| %>
|
||||
<article class="answer-sec <%= question.input_type %>-type" data-qid="<%= question.question_id %>">
|
||||
<div class="question-heading">
|
||||
<div class="question-title">
|
||||
<h3><%= question.question %></h3>
|
||||
</div>
|
||||
<div class="answer-buttons">
|
||||
<a href="<%= question_path(question.question_id) %>" class="tertiary-btn button-edit" data-answerId="<%= question.answer_id %>" data-questionId="<%= question.question_id %>">Edit</a>
|
||||
<button class="tertiary-btn button-save">Save</button>
|
||||
<button class="tertiary-btn button-cancel">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="answer-container">
|
||||
<% if question.attachment.present? %>
|
||||
<%= image_tag question.attachment %>
|
||||
<% end %>
|
||||
|
||||
<fieldset disabled class="answer-block">
|
||||
<%= hidden_field_tag 'answer[question_id]', question.question_id %>
|
||||
<%= render partial: question.input_type, locals: {question: question, form: form} %>
|
||||
</fieldset>
|
||||
</div>
|
||||
</article>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @status.can_submit %>
|
||||
<%= form_tag post_summary_path, class: "btn-container-right" do %>
|
||||
<input type="submit" class="submit-button" value="Submit all answers" name="submit" />
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="error">Sorry, you must answer all questions before you can submit.</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
</main>
|
Reference in New Issue
Block a user