46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class SuccessCriterion < ApplicationRecord
|
|
belongs_to :element, touch: true
|
|
belongs_to :check, optional: true
|
|
|
|
has_rich_text :test_comment
|
|
has_rich_text :quick_criterion
|
|
has_rich_text :quick_fail
|
|
has_rich_text :quick_fix
|
|
|
|
delegate :page, :report, to: :element
|
|
|
|
enum :result, %i[passed failed not_applicable]
|
|
enum :level, %i[A AA AAA]
|
|
|
|
before_save :set_position
|
|
before_update :update_positions, if: :position_changed?
|
|
|
|
def level_value
|
|
return nil unless level
|
|
|
|
self.class.levels.values.index_of(level)
|
|
end
|
|
|
|
def header
|
|
"HEADER"
|
|
end
|
|
|
|
def number
|
|
[ page.position, element.position, position ].join(".")
|
|
end
|
|
|
|
private
|
|
def set_position
|
|
self.position ||= (element.success_criteria.pluck(:position).max || 0) + 1
|
|
Rails.logger.debug("set position: "+position.to_s)
|
|
end
|
|
|
|
def update_positions
|
|
if position_was
|
|
element.success_criteria.where("position > ?", position_was).update_all("position = position - 1")
|
|
end
|
|
element.success_criteria.where(position: position..).update_all("position = position + 1")
|
|
end
|
|
end
|