Class: ClassificationTerm
- Inherits:
-
Classification
show all
- Defined in:
- backend/app/model/classification_term.rb,
public/app/models/classification_term.rb
Constant Summary
Constants inherited
from Record
Record::ABSTRACT
Instance Attribute Summary
#creator, #linked_records
Attributes inherited from Record
#agents, #classifications, #container_display, #container_summary_for_badge, #container_titles_and_uris, #criteria, #dates, #display_string, #extents, #external_documents, #full, #highlights, #identifier, #json, #lang_materials, #level, #linked_digital_objects, #notes, #other_level, #primary_type, #raw, #repository_information, #resolved_repository, #resolved_resource, #resolved_top_container, #subjects, #uri
Class Method Summary
collapse
Instance Method Summary
collapse
#breadcrumb, #classification_terms?, #description, #display_string_for_breadcrumb, #initialize, #load_node_properties, #load_root_properties
Methods inherited from Record
#[], #apply_highlighting, #dig, #initialize, #note, #parse_full_title, #request_item
Constructor Details
This class inherits a constructor from Classification
Class Method Details
.create_from_json(json, opts = {}) ⇒ Object
48
49
50
51
52
53
|
# File 'backend/app/model/classification_term.rb', line 48
def self.create_from_json(json, opts = {})
self.set_path_from_root(json)
obj = super(json, :title_sha1 => Digest::SHA1.hexdigest(json.title))
obj.reindex_children
obj
end
|
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'backend/app/model/classification_term.rb', line 81
def self.sequel_to_jsonmodel(objs, opts = {})
jsons = super
jsons.each do |json|
self.set_path_from_root(json)
end
jsons
end
|
.set_path_from_root(json) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'backend/app/model/classification_term.rb', line 64
def self.set_path_from_root(json)
path = [{'title' => json.title, 'identifier' => json.identifier}]
parent_id = json.parent ? self.parse_reference(json.parent['ref'], {})[:id] : nil
while parent_id
node = ClassificationTerm[parent_id]
path << {'title' => node.title, 'identifier' => node.identifier}
parent_id = node.parent_id
end
root = Classification[self.parse_reference(json.classification['ref'], {})[:id]]
path << {'title' => root.title, 'identifier' => root.identifier}
json['path_from_root'] = path.reverse
end
|
Instance Method Details
#breadcrumb_title_for_node(node, level) ⇒ Object
we add the identifier to the breadcrumb title
9
10
11
12
13
14
|
# File 'public/app/models/classification_term.rb', line 9
def breadcrumb_title_for_node(node, level)
json_path_to_root = json.fetch('path_from_root')
json_identifiers = json_path_to_root[0..level].map {|n| n.fetch('identifier')}
"#{json_identifiers.join(I18n.t('classification_term.identifier_separator'))}#{I18n.t('classification.identifier_separator')} #{super}"
end
|
#root_node_uri ⇒ Object
4
5
6
|
# File 'public/app/models/classification_term.rb', line 4
def root_node_uri
json.fetch('classification').fetch('ref')
end
|
#update_from_json(json, opts = {}, apply_nested_records = true) ⇒ Object
56
57
58
59
60
61
|
# File 'backend/app/model/classification_term.rb', line 56
def update_from_json(json, opts = {}, apply_nested_records = true)
self.class.set_path_from_root(json)
obj = super(json, {:title_sha1 => Digest::SHA1.hexdigest(json.title)}, apply_nested_records)
obj.reindex_children
obj
end
|
#validate ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'backend/app/model/classification_term.rb', line 92
def validate
validates_unique([:parent_name, :title_sha1],
:message => "must be unique to its level in the tree")
validates_unique([:parent_name, :identifier],
:message => "must be unique to its level in the tree")
map_validation_to_json_property([:parent_name, :title_sha1], :title)
map_validation_to_json_property([:parent_name, :identifier], :identifier)
super
end
|