Gui improvements and ideas
This commit is contained in:
parent
3f4c7d17bf
commit
2ae0b55e42
54 changed files with 639 additions and 237 deletions
|
|
@ -1,4 +1,6 @@
|
|||
class Check < ApplicationRecord
|
||||
include RichTextTargetBlank
|
||||
|
||||
enum :level, %i[A AA AAA]
|
||||
|
||||
has_rich_text :success_criterion_html
|
||||
|
|
|
|||
|
|
@ -5,4 +5,6 @@ class Checklist < ApplicationRecord
|
|||
has_rich_text :description_html
|
||||
|
||||
accepts_nested_attributes_for :checklist_entries, reject_if: :all_blank, allow_destroy: true
|
||||
|
||||
delegate :empty?, to: :checklist_entries
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,18 @@
|
|||
class ChecklistEntry < ApplicationRecord
|
||||
belongs_to :checklist
|
||||
belongs_to :check
|
||||
|
||||
before_validation :set_position
|
||||
after_validation :normalize_positions
|
||||
|
||||
def set_position
|
||||
self.position ||= checklist.checklist_entries.maximum(:position).to_i + 1
|
||||
end
|
||||
|
||||
def normalize_positions
|
||||
checklist.checklist_entries.where.not(id:).find_by(position:)&.update_attribute(:position, position_was)
|
||||
# checklist.checklist_entries.order(:position).each_with_index do |entry, index|
|
||||
# entry.update_column(:position, index + 1) if entry.position != index + 1
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
20
app/models/concerns/rich_text_target_blank.rb
Normal file
20
app/models/concerns/rich_text_target_blank.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module RichTextTargetBlank
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
# Override has_rich_text to include target="_blank" functionality
|
||||
def has_rich_text(name)
|
||||
super # Call the original has_rich_text to set up the rich text association
|
||||
|
||||
# Define the before_save callback to modify the links
|
||||
before_save do
|
||||
rich_text_attribute = send(name)
|
||||
if rich_text_attribute.present?
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(rich_text_attribute.body.to_html)
|
||||
doc.css('a').each { |a| a['target'] ||= '_blank' }
|
||||
rich_text_attribute.body = doc.to_html
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -3,6 +3,8 @@ class Element < ApplicationRecord
|
|||
|
||||
has_rich_text :description_html
|
||||
|
||||
belongs_to :report
|
||||
belongs_to :report, touch: true
|
||||
has_many :success_criteria, dependent: :destroy
|
||||
|
||||
validates :path, :title, presence: true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
class Report < ApplicationRecord
|
||||
has_rich_text :comment_html
|
||||
|
||||
has_many :elements, dependent: :destroy
|
||||
|
||||
has_rich_text :comment_html
|
||||
validates :name, presence: true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
class SuccessCriterion < ApplicationRecord
|
||||
enum :result, %i[passed failed not_applicable]
|
||||
enum :level, %i[A AA AAA]
|
||||
|
||||
has_rich_text :comment_html
|
||||
has_rich_text :description_html
|
||||
|
||||
belongs_to :element
|
||||
belongs_to :element, touch: true
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue