Sha256: 4b60a81ed47d4983a502e92c8679e39b1c320a7dc005d49d373701d3e7bab066

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

module Mumuki::Laboratory::Controllers::ResultsRendering
  extend ActiveSupport::Concern

  included do
    include ProgressBarHelper, ExerciseInputHelper

    before_action :set_guide_previously_done!
  end

  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))
  end

  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,
        test_results: assignment.affable_test_results)
  end

  def progress_json
    {
      guide_finished_by_solution: guide_finished_by_solution?,
      class_for_progress_list_item: class_for_progress_list_item(@exercise, true)
    }
  end

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

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

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mumuki-laboratory-7.6.2 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-7.6.1 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-7.6.0 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-7.5.2 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-7.5.1 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-7.5.0 lib/mumuki/laboratory/controllers/results_rendering.rb