Sha256: 5fa37b2b51ef5ffb4ff267a325109242f7a84e736fe35da3e1a279f228807eaf

Contents?: true

Size: 1.87 KB

Versions: 16

Compression:

Stored size: 1.87 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 = {})
    render json: results.merge(progress_json).merge(
      html: render_results_html(assignment),
      title_html: render_results_title_html(assignment),
      button_html: render_results_button_html(assignment),
      expectations_html: render_results_expectations_html(assignment),
      remaining_attempts_html: remaining_attempts_text(assignment))
  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_html(assignment)
    render_to_string partial: results_partial(assignment),
                     locals: {assignment: assignment}
  end

  def results_partial(assignment)
    return 'out_of_attempts' unless assignment.attempts_left?
    assignment.input_kids? ? 'exercise_solutions/kids_results' : 'exercise_solutions/results'
  end

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

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

  def render_results_expectations_html(assignment)
    render_to_string partial: 'exercise_solutions/expectations',
                     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

16 entries across 16 versions & 1 rubygems

Version Path
mumuki-laboratory-6.4.2 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.4.1 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.4.0 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.2.0 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.1.5 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.0.4 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.1.4 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.1.3 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.0.3 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.1.2 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.1.1 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.1.0 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.0.2 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.0.1 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-6.0.0 lib/mumuki/laboratory/controllers/results_rendering.rb
mumuki-laboratory-5.13.0 lib/mumuki/laboratory/controllers/results_rendering.rb