Module: ExerciseInputHelper

Defined in:
app/helpers/exercise_input_helper.rb

Instance Method Summary collapse

Instance Method Details

#exercise_container_typeObject



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

def exercise_container_type
  input_kids? ? 'container-fluid' : 'container'
end

#input_kids?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/helpers/exercise_input_helper.rb', line 38

def input_kids?
  @exercise&.input_kids?
end

#render_custom_editor(exercise) ⇒ Object



33
34
35
36
# File 'app/helpers/exercise_input_helper.rb', line 33

def render_custom_editor(exercise)
  custom_editor_tag = "mu-#{exercise.language}-custom-editor"
  "<#{custom_editor_tag}> </#{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/#{exercise.class.name.underscore}_form"
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}"
end

#render_submit_button(exercise) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/exercise_input_helper.rb', line 22

def render_submit_button(exercise)
  options = submit_button_options(exercise)
  text = t(options.t) if options.t.present?
  waiting_text = t(options.waiting_t) if options.waiting_t.present?
  %Q{<#{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: text}
     </#{options.tag}>}.html_safe
end

#should_render_message_input?(exercise, organization = Organization.current) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/helpers/exercise_input_helper.rb', line 18

def should_render_message_input?(exercise, organization = Organization.current)
  exercise.is_a?(Problem) && !exercise.hidden? && organization.raise_hand_enabled?
end

#should_render_problem_tabs?(exercise, user) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/helpers/exercise_input_helper.rb', line 14

def should_render_problem_tabs?(exercise, user)
  !exercise.hidden? && (exercise.queriable? || exercise.extra_visible? || exercise.has_messages_for?(user))
end

#submit_button_options(exercise) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/exercise_input_helper.rb', line 46

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