Module: ExerciseInputHelper

Defined in:
app/helpers/exercise_input_helper.rb

Instance Method Summary collapse

Instance Method Details

#custom_editor_read_onlyObject



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 (exercise)
  exercise.custom? ? 'mu-custom-editor-default-value' : 'default_content'
end

#exercise_container_typeObject



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

Returns:

  • (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 render_submit_button(assignment)
  options = submit_button_options(assignment.exercise)
  text = t(options.t) if options.t.present?
  waiting_text = t(options.waiting_t) if options.waiting_t.present?
  %Q{
    <div class="btn-submit-container">
      <#{options.tag} for="#{options.for}"
                     class="btn btn-success btn-block btn-submit #{options.classes}"
                     data-waiting="#{waiting_text}">
        #{fa_icon options.fa_icon}
        #{text} #{remaining_attempts_text(assignment)}
     </#{options.tag}>
    </div>
  }.html_safe
end

#should_render_exercise_tabs?(exercise, &block) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


42
43
44
# File 'app/helpers/exercise_input_helper.rb', line 42

def should_render_message_input?(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

Returns:

  • (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

Returns:

  • (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.has_messages_for? user }
end

#should_render_read_only_exercise_tabs?(discussion) ⇒ Boolean

Returns:

  • (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 submit_button_options(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