Class: Hyrax::Forms::Dashboard::NestCollectionForm
- Inherits:
-
Object
- Object
- Hyrax::Forms::Dashboard::NestCollectionForm
- Includes:
- ActiveModel::Model
- Defined in:
- app/forms/hyrax/forms/dashboard/nest_collection_form.rb
Overview
Responsible for validating that both the parent and child are valid for nesting; If so, then also responsible for persisting those changes.
Instance Attribute Summary collapse
-
#child ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
#parent ⇒ Object
rubocop:enable Metrics/ParameterLists.
Instance Method Summary collapse
-
#available_child_collections ⇒ Object
deprecated
Deprecated.
this method is unused by hyrax, and is effectively a delegation to ‘Hyrax::Collections::NestedCollectionQueryService`. if you want to be sure to use nested indexing to generate this list, use the query service directly.
-
#available_parent_collections ⇒ Object
deprecated
Deprecated.
this method is unused by hyrax, and is effectively a delegation to ‘Hyrax::Collections::NestedCollectionQueryService`. if you want to be sure to use nested indexing to generate this list, use the query service directly.
-
#initialize(parent: nil, child: nil, parent_id: nil, child_id: nil, context:, query_service: default_query_service, persistence_service: default_persistence_service) ⇒ NestCollectionForm
constructor
rubocop:disable Metrics/ParameterLists.
- #remove ⇒ Object
- #save ⇒ Object
-
#validate_add ⇒ Object
when creating a NEW collection, we need to do some basic validation before rerouting to new_dashboard_collection_path to add the new collection as a child.
Constructor Details
#initialize(parent: nil, child: nil, parent_id: nil, child_id: nil, context:, query_service: default_query_service, persistence_service: default_persistence_service) ⇒ NestCollectionForm
rubocop:disable Metrics/ParameterLists
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 22 def initialize(parent: nil, child: nil, parent_id: nil, child_id: nil, context:, query_service: default_query_service, persistence_service: default_persistence_service) self.context = context self.query_service = query_service self.persistence_service = persistence_service self.parent = parent || (parent_id.present? && find_parent(parent_id)) self.child = child || (child_id.present? && find_child(child_id)) end |
Instance Attribute Details
#child ⇒ Object
rubocop:enable Metrics/ParameterLists
36 37 38 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 36 def child @child end |
#parent ⇒ Object
rubocop:enable Metrics/ParameterLists
36 37 38 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 36 def parent @parent end |
Instance Method Details
#available_child_collections ⇒ Object
this method is unused by hyrax, and is effectively a delegation to ‘Hyrax::Collections::NestedCollectionQueryService`. if you want to be sure to use nested indexing to generate this list, use the query service directly.
For the given parent, what are all of the available collections that can be added as sub-collection of the parent.
55 56 57 58 59 60 61 62 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 55 def available_child_collections Deprecation.warn "#{self.class}#available_child_collections " \ "is deprecated. the helper of the same name or " \ "Hyrax::Collections::NestedCollectionQueryService " \ "instead." query_service.available_child_collections(parent: parent, scope: context) end |
#available_parent_collections ⇒ Object
this method is unused by hyrax, and is effectively a delegation to ‘Hyrax::Collections::NestedCollectionQueryService`. if you want to be sure to use nested indexing to generate this list, use the query service directly.
For the given child, what are all of the available collections to which the child can be added as a sub-collection.
72 73 74 75 76 77 78 79 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 72 def available_parent_collections Deprecation.warn "#{self.class}#available_parent_collections " \ "is deprecated. the helper of the same name or " \ "Hyrax::Collections::NestedCollectionQueryService " \ "instead." query_service.available_parent_collections(child: child, scope: context) end |
#remove ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 92 def remove if context.can? :edit, parent persistence_service.remove_nested_relationship_for(parent: parent, child: child, user: context.current_user) else errors.add(:parent, :cannot_remove_relationship) false end end |
#save ⇒ Object
42 43 44 45 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 42 def save return false unless valid? persistence_service.persist_nested_collection_for(parent: parent, child: child, user: context.current_user) end |
#validate_add ⇒ Object
when creating a NEW collection, we need to do some basic validation before rerouting to new_dashboard_collection_path to add the new collection as a child. Since we don’t yet have a child collection, the valid? option can’t be used here.
84 85 86 87 88 89 90 |
# File 'app/forms/hyrax/forms/dashboard/nest_collection_form.rb', line 84 def validate_add unless nestable?(parent) errors.add(:parent, :cannot_have_child_nested) return false end true end |