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
- #should_render_read_only_exercise_tabs?(discussion) ⇒ Boolean
- #submit_button_options(exercise) ⇒ Object
Instance Method Details
#custom_editor_read_only ⇒ Object
81 82 83 |
# File 'app/helpers/exercise_input_helper.rb', line 81 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
89 90 91 |
# File 'app/helpers/exercise_input_helper.rb', line 89 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
85 86 87 |
# File 'app/helpers/exercise_input_helper.rb', line 85 def input_kids? @exercise&.input_kids? end |
#remaining_attempts_text(assignment) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/exercise_input_helper.rb', line 66 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
76 77 78 79 |
# File 'app/helpers/exercise_input_helper.rb', line 76 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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/helpers/exercise_input_helper.rb', line 50 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"> <#{.tag} for="#{.for}" class="btn btn-success btn-block btn-submit #{.classes}" data-waiting="#{waiting_text}"> #{fa_icon .fa_icon} #{text} #{remaining_attempts_text(assignment)} </#{.tag}> </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
42 43 44 |
# File 'app/helpers/exercise_input_helper.rb', line 42 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
46 47 48 |
# File 'app/helpers/exercise_input_helper.rb', line 46 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 |
#should_render_read_only_exercise_tabs?(discussion) ⇒ Boolean
38 39 40 |
# File 'app/helpers/exercise_input_helper.rb', line 38 def should_render_read_only_exercise_tabs?(discussion) should_render_exercise_tabs?(discussion.exercise) { discussion.has_submission? } end |
#submit_button_options(exercise) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/exercise_input_helper.rb', line 93 def (exercise) if exercise.upload? struct for: 'upload-input', tag: :label, waiting_t: :uploading_solution, fa_icon: :upload, t: :upload_solution elsif exercise.hidden? struct tag: :button, classes: 'submission_control', waiting_t: :working, fa_icon: :play, t: :continue_exercise elsif exercise.input_kids? struct tag: :button, classes: 'submission_control', fa_icon: :play else struct tag: :button, classes: 'submission_control', waiting_t: :sending_solution, fa_icon: :play, t: :create_submission end end |