Module: Mumuki::Laboratory::Controllers::ResultsRendering

Extended by:
ActiveSupport::Concern
Included in:
ExerciseConfirmationsController, ExerciseSolutionsController, ExerciseTriesController
Defined in:
lib/mumuki/laboratory/controllers/results_rendering.rb

Instance Method Summary collapse

Instance Method Details

#guide_finished_by_solution?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 58

def guide_finished_by_solution?
  !@guide_previously_done && @exercise.guide_done_for?(current_user)
end

#merge_kids_specific_renders(assignment, results) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 27

def merge_kids_specific_renders(assignment, results)
  results.merge!(
      button_html: render_results_button(assignment),
      title_html: render_results_title(assignment),
      expectations: assignment.affable_expectation_results,
      tips: assignment.affable_tips,
      level_up_html: render_results('exercise_solutions/kids_level_up', assignment),
      test_results: assignment.sanitized_affable_test_results) # these results could include escaped characters so they should be rendered as HTML to display properly
end

#progress_jsonObject



37
38
39
40
41
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 37

def progress_json
  {
    guide_finished_by_solution: guide_finished_by_solution?
  }
end

#render_results(results_partial, assignment) ⇒ Object



43
44
45
46
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 43

def render_results(results_partial, assignment)
  render_to_string partial: results_partial,
                   locals: {assignment: assignment}
end

#render_results_button(assignment) ⇒ Object



53
54
55
56
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 53

def render_results_button(assignment)
  render_to_string partial: 'exercise_solutions/kids_results_button',
                   locals: {assignment: assignment}
end

#render_results_json(assignment, results = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 10

def render_results_json(assignment, results = {})
  if assignment.input_kids?
    merge_kids_specific_renders(assignment, results)
    layout = 'exercise_solutions/kids_results'
  else
    layout = 'exercise_solutions/results'
  end

  render json: results
                .merge(progress_json)
                .merge(
                  html: render_results(layout, assignment),
                  remaining_attempts_html: remaining_attempts_text(assignment),
                  current_exp: UserStats.exp_for(assignment.submitter),
                  in_gamified_context: Organization.current.gamification_enabled?)
end

#render_results_title(assignment) ⇒ Object



48
49
50
51
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 48

def render_results_title(assignment)
  render_to_string partial: 'exercise_solutions/results_title',
                   locals: {contextualization: assignment}
end

#set_guide_previously_done!Object



62
63
64
# File 'lib/mumuki/laboratory/controllers/results_rendering.rb', line 62

def set_guide_previously_done!
  @guide_previously_done = @exercise.guide_done_for?(current_user)
end