Module: Course::Assessment::Question::ProgrammingHelper

Defined in:
app/helpers/course/assessment/question/programming_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_edit_online?Boolean

Returns:

  • (Boolean)

70
71
72
73
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 70

def can_edit_online?
  return true if params[:action] == 'new'
  @meta.present?
end

#can_switch_package_type?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 66

def can_switch_package_type?
  params[:action] == 'new' || params[:action] == 'create'
end

#check_import_job?Boolean

Returns:

  • (Boolean)

58
59
60
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 58

def check_import_job?
  @programming_question.import_job && @programming_question.import_job.status != 'completed'
end

#display_autograded_toggle?Boolean

Returns:

  • (Boolean)

62
63
64
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 62

def display_autograded_toggle?
  @programming_question.edit_online? || can_switch_package_type?
end

#display_build_log?Boolean

Determines if the build log should be displayed.

Returns:

  • (Boolean)

29
30
31
32
33
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 29

def display_build_log?
  import_errored? &&
    @programming_question.import_job.error['class'] ==
      Course::Assessment::ProgrammingEvaluationService::Error.name
end

#display_validation_errors?Boolean

Determines if the programming question errors should be displayed.

Returns:

  • (Boolean)

38
39
40
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 38

def display_validation_errors?
  @programming_question.errors.present?
end

#import_errored?Boolean

Checks if the import job errored.

Returns:

  • (Boolean)

22
23
24
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 22

def import_errored?
  !@programming_question.import_job.nil? && @programming_question.import_job.errored?
end

#import_result_alert(json: false) ⇒ String?

Displays the result alert for an import job.

Returns:

  • (String)

    If there is an import job for the question.

  • (nil)

    If there is no import job for the question.


7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 7

def import_result_alert(json: false)
  import_job = @programming_question.import_job

  return json ? {} : nil unless import_job

  if import_job.completed?
    successful_import_alert(json: json)
  elsif import_job.errored?
    errored_import_alert(json: json)
  end
end

#validation_errors_alertString?

Displays the validation errors alert for programming question.

Returns:

  • (String)

    If there are validation errors for the question.

  • (nil)

    If there are no validation errors for the question.


46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/course/assessment/question/programming_helper.rb', line 46

def validation_errors_alert
  return nil if @programming_question.errors.empty?

  (:div, class: ['alert', 'alert-danger']) do
    messages = @programming_question.errors.full_messages.map do |message|
      (:div, message)
    end

    safe_join messages
  end
end