Class: ClassificationTerm
- Inherits:
-
Classification
- Object
- Record
- Classification
- ClassificationTerm
- Includes:
- ASModel, AutoGenerator, ClassificationIndexing, Publishable, TreeNodes
- Defined in:
- backend/app/model/classification_term.rb,
public/app/models/classification_term.rb
Constant Summary
Constants included from TreeNodes
TreeNodes::DB_RETRIES, TreeNodes::POSITION_STEP
Constants included from JSONModel
JSONModel::REFERENCE_KEY_REGEX
Constants included from Trees
Constants inherited from Record
Instance Attribute Summary
Attributes inherited from Classification
Attributes inherited from Record
#agents, #classifications, #container_display, #container_summary_for_badge, #container_titles_and_uris, #criteria, #dates, #display_string, #extents, #external_documents, #full, #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
-
.create_from_json(json, opts = {}) ⇒ Object
-
.sequel_to_jsonmodel(objs, opts = {}) ⇒ Object
-
.set_path_from_root(json) ⇒ Object
Instance Method Summary collapse
-
#breadcrumb_title_for_node(node, level) ⇒ Object
we add the identifier to the breadcrumb title.
-
#root_node_uri ⇒ Object
-
#update_from_json(json, opts = {}, apply_nested_records = true) ⇒ Object
-
#validate ⇒ Object
Methods included from AutoGenerator
Methods included from Publishable
Methods included from ClassificationIndexing
Methods included from TreeNodes
#ancestors, #attempt_set_parent_and_position, #attempt_set_position_in_list, #breadcrumb, #breadcrumb_identifier, #breadcrumb_uri_for_node, #children, #ensure_gap, #has_children?, included, #logical_position, #previous_node, #set_parent_and_position, #set_position_in_list, #set_root, #transfer_to_repository, #trigger_index_of_child_nodes
Methods included from ASModel
all_models, included, update_publish_flag, update_suppressed_flag
Methods included from JSONModel
JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, check_valid_refs, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_publish_flags!, set_repository, strict_mode, strict_mode?, validate_schema, with_repository
Methods inherited from Classification
#breadcrumb, #classification_terms?, #description, #display_string_for_breadcrumb, #initialize, #load_node_properties, #load_root_properties
Methods included from Trees
#adopt_children, #apply_exclusions_to_descendants, #assimilate, #build_node_query, #children, #children?, included, #load_node_properties, #load_root_properties, #ordered_records, #partial_tree, #transfer_to_repository, #tree, #trigger_index_of_entire_tree
Methods inherited from Record
#[], #dig, #initialize, #note, #parse_full_title, #request_item
Methods included from PrefixHelper
app_prefix, #app_prefix, app_prefix_js, #app_prefix_js
Methods included from RecordHelper
#badge_for_type, #icon_for_type, #record_class_for_type, #record_for_type, #record_from_resolved_json
Methods included from JsonHelper
#merge_notes, #process_json_notes
Methods included from ManipulateNode
#inheritance, #process_mixed_content, #strip_mixed_content
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 (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 |