Module: ExerciseInputHelper
- Defined in:
- app/helpers/exercise_input_helper.rb
Instance Method Summary collapse
- #custom_editor_read_only ⇒ Object
- #default_content_tag_id(exercise) ⇒ Object
- #exercise_container_type ⇒ Object
- #input_form_for(exercise) ⇒ Object
- #input_kids? ⇒ Boolean
- #remaining_attempts_text(assignment) ⇒ Object
- #render_custom_editor(exercise, read_only = false) ⇒ Object
- #render_exercise_input_editor(form, exercise) ⇒ Object
- #render_exercise_input_form(exercise) ⇒ Object
- #render_exercise_input_layout(exercise) ⇒ Object
- #render_exercise_read_only_editor(exercise, content) ⇒ Object
- #render_submit_button(assignment) ⇒ Object
- #should_render_exercise_tabs?(exercise, &block) ⇒ Boolean
- #should_render_message_input?(exercise, organization = Organization.current) ⇒ Boolean
- #should_render_need_help_dropdown?(assignment, organization = Organization.current) ⇒ Boolean
- #should_render_problem_tabs?(exercise, user) ⇒ Boolean
- #submit_button_options(exercise) ⇒ Object
Instance Method Details
#custom_editor_read_only ⇒ Object
75 76 77 |
# File 'app/helpers/exercise_input_helper.rb', line 75 def custom_editor_read_only "read-only=true" end |
#default_content_tag_id(exercise) ⇒ Object
14 15 16 |
# File 'app/helpers/exercise_input_helper.rb', line 14 def default_content_tag_id(exercise) exercise.custom? ? 'mu-custom-editor-default-value' : 'default_content' end |
#exercise_container_type ⇒ Object
83 84 85 |
# File 'app/helpers/exercise_input_helper.rb', line 83 def exercise_container_type input_kids? ? 'container-fluid' : 'container' end |
#input_form_for(exercise) ⇒ Object
22 23 24 25 26 27 28 |
# File 'app/helpers/exercise_input_helper.rb', line 22 def input_form_for(exercise) if exercise&.input_kids? 'kids' else exercise.class.name.underscore end end |
#input_kids? ⇒ Boolean
79 80 81 |
# File 'app/helpers/exercise_input_helper.rb', line 79 def input_kids? @exercise&.input_kids? end |
#remaining_attempts_text(assignment) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/exercise_input_helper.rb', line 60 def remaining_attempts_text(assignment) if assignment.limited? %Q{ <span id="attempts-left-text" data-disabled="#{!assignment.attempts_left?}"> (#{t(:attempts_left, count: assignment.attempts_left)}) </span> } end end |
#render_custom_editor(exercise, read_only = false) ⇒ Object
70 71 72 73 |
# File 'app/helpers/exercise_input_helper.rb', line 70 def render_custom_editor(exercise, read_only=false) custom_editor_tag = "mu-#{exercise.language}-custom-editor" "<#{custom_editor_tag} id='#{custom_editor_tag}' class='#{custom_editor_tag}' #{custom_editor_read_only if read_only}> </#{custom_editor_tag}>".html_safe end |
#render_exercise_input_editor(form, exercise) ⇒ Object
10 11 12 |
# File 'app/helpers/exercise_input_helper.rb', line 10 def render_exercise_input_editor(form, exercise) render "layouts/exercise_inputs/editors/#{exercise.editor}", form: form, exercise: exercise end |
#render_exercise_input_form(exercise) ⇒ Object
6 7 8 |
# File 'app/helpers/exercise_input_helper.rb', line 6 def render_exercise_input_form(exercise) render "layouts/exercise_inputs/forms/#{input_form_for(exercise)}_form", exercise: exercise end |
#render_exercise_input_layout(exercise) ⇒ Object
2 3 4 |
# File 'app/helpers/exercise_input_helper.rb', line 2 def render_exercise_input_layout(exercise) render "layouts/exercise_inputs/layouts/#{exercise.layout}", exercise: exercise end |
#render_exercise_read_only_editor(exercise, content) ⇒ Object
18 19 20 |
# File 'app/helpers/exercise_input_helper.rb', line 18 def render_exercise_read_only_editor(exercise, content) render "layouts/exercise_inputs/read_only_editors/#{exercise.editor}", exercise: exercise, content: content end |
#render_submit_button(assignment) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/exercise_input_helper.rb', line 46 def (assignment) = (assignment.exercise) text = t(.t) if .t.present? waiting_text = t(.waiting_t) if .waiting_t.present? %Q{ <div class="btn-submit-container"> <button class="btn btn-complementary w-100 btn-submit #{.classes}" data-waiting="#{waiting_text}"> #{fa_icon 'play', text: ([text, remaining_attempts_text(assignment)].join('')).html_safe} </button> </div> }.html_safe end |
#should_render_exercise_tabs?(exercise, &block) ⇒ Boolean
30 31 32 |
# File 'app/helpers/exercise_input_helper.rb', line 30 def should_render_exercise_tabs?(exercise, &block) !exercise.hidden? && (exercise.queriable? || exercise.extra_visible? || block&.call) end |
#should_render_message_input?(exercise, organization = Organization.current) ⇒ Boolean
38 39 40 |
# File 'app/helpers/exercise_input_helper.rb', line 38 def (exercise, organization = Organization.current) exercise.is_a?(Problem) && !exercise.hidden? && organization.raise_hand_enabled? end |
#should_render_need_help_dropdown?(assignment, organization = Organization.current) ⇒ Boolean
42 43 44 |
# File 'app/helpers/exercise_input_helper.rb', line 42 def should_render_need_help_dropdown?(assignment, organization = Organization.current) !assignment.solved? && organization.ask_for_help_enabled?(assignment.submitter) end |
#should_render_problem_tabs?(exercise, user) ⇒ Boolean
34 35 36 |
# File 'app/helpers/exercise_input_helper.rb', line 34 def should_render_problem_tabs?(exercise, user) should_render_exercise_tabs?(exercise) { exercise. user } end |
#submit_button_options(exercise) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/exercise_input_helper.rb', line 87 def (exercise) if exercise.upload? struct classes: 'disabled', waiting_t: :uploading_solution, t: :create_submission elsif exercise.hidden? struct classes: 'submission_control', waiting_t: :working, t: :continue_exercise elsif exercise.input_kids? struct classes: 'submission_control' else struct classes: 'submission_control', waiting_t: :sending_solution, t: :create_submission end end |