generated from BCDevOps/opendev-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrequirement_template_section.rb
More file actions
44 lines (38 loc) · 1.23 KB
/
requirement_template_section.rb
File metadata and controls
44 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class RequirementTemplateSection < ApplicationRecord
belongs_to :requirement_template
belongs_to :copied_from,
class_name: "RequirementTemplateSection",
optional: true
has_many :template_section_blocks,
-> { order(position: :asc) },
dependent: :destroy
has_many :requirement_blocks, through: :template_section_blocks
# Self-referential association for copied_from
belongs_to :copied_from,
class_name: "RequirementTemplateSection",
foreign_key: "copied_from_id",
optional: true
# Self-referential association for sections copied from this section
has_many :copied_sections,
class_name: "RequirementTemplateSection",
foreign_key: "copied_from_id",
dependent: :nullify
accepts_nested_attributes_for :template_section_blocks, allow_destroy: true
def key
"section#{id}"
end
def to_form_json
{
id: id,
key: key,
type: "container",
title: name,
label: name,
custom_class: "formio-section-container",
hide_label: false,
collapsible: false,
initially_collapsed: false,
components: requirement_blocks.map { |rb| rb.to_form_json(key) }
}
end
end