Class: Hyrax::Forms::CollectionForm

Inherits:
Object
  • Object
show all
Includes:
HydraEditor::Form, HydraEditor::Form::Permissions
Defined in:
app/forms/hyrax/forms/collection_form.rb

Overview

rubocop:disable Metrics/ClassLength

Direct Known Subclasses

AdminSetForm

Defined Under Namespace

Classes: ProxyScope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, current_ability, repository) ⇒ CollectionForm

Returns a new instance of CollectionForm.

Parameters:

  • model (::Collection)

    the collection model that backs this form

  • current_ability (Ability)

    the capabilities of the current user

  • repository (Blacklight::Solr::Repository)

    the solr repository


41
42
43
44
# File 'app/forms/hyrax/forms/collection_form.rb', line 41

def initialize(model, current_ability, repository)
  super(model)
  @scope = ProxyScope.new(current_ability, repository, blacklight_config)
end

Instance Attribute Details

#scopeObject (readonly)

Used by the search builder


9
10
11
# File 'app/forms/hyrax/forms/collection_form.rb', line 9

def scope
  @scope
end

Instance Method Details

#available_parent_collections(scope:) ⇒ Object


126
127
128
129
130
131
132
133
134
135
# File 'app/forms/hyrax/forms/collection_form.rb', line 126

def available_parent_collections(scope:)
  return @available_parents if @available_parents.present?

  collection = ::Collection.find(id)
  colls = Hyrax::Collections::NestedCollectionQueryService.available_parent_collections(child: collection, scope: scope, limit_to_id: nil)
  @available_parents = colls.map do |col|
    { "id" => col.id, "title_first" => col.title.first }
  end
  @available_parents.to_json
end

80
81
82
83
84
85
86
87
88
89
90
# File 'app/forms/hyrax/forms/collection_form.rb', line 80

def banner_info
  @banner_info ||= begin
    # Find Banner filename
    banner_info = CollectionBrandingInfo.where(collection_id: id, role: "banner")
    banner_file = File.split(banner_info.first.local_path).last unless banner_info.empty?
    alttext = banner_info.first.alt_text unless banner_info.empty?
    file_location = banner_info.first.local_path unless banner_info.empty?
    relative_path = "/" + banner_info.first.local_path.split("/")[-4..-1].join("/") unless banner_info.empty?
    { file: banner_file, full_path: file_location, relative_path: relative_path, alttext: alttext }
  end
end

#display_additional_fields?Boolean

Do not display additional fields if there are no secondary terms

Returns:

  • (Boolean)

    display additional fields on the form?


109
110
111
# File 'app/forms/hyrax/forms/collection_form.rb', line 109

def display_additional_fields?
  secondary_terms.any?
end

#list_child_collectionsObject


122
123
124
# File 'app/forms/hyrax/forms/collection_form.rb', line 122

def list_child_collections
  collection_member_service.available_member_subcollections.documents
end

#list_parent_collectionsObject


118
119
120
# File 'app/forms/hyrax/forms/collection_form.rb', line 118

def list_parent_collections
  collection.member_of_collections
end

#logo_infoObject


92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/forms/hyrax/forms/collection_form.rb', line 92

def logo_info
  @logo_info ||= begin
    # Find Logo filename, alttext, linktext
    logos_info = CollectionBrandingInfo.where(collection_id: id, role: "logo")

    logos_info.map do |logo_info|
      logo_file = File.split(logo_info.local_path).last
      relative_path = "/" + logo_info.local_path.split("/")[-4..-1].join("/")
      alttext = logo_info.alt_text
      linkurl = logo_info.target_url
      { file: logo_file, full_path: logo_info.local_path, relative_path: relative_path, alttext: alttext, linkurl: linkurl }
    end
  end
end

#permission_templateObject


46
47
48
49
50
51
# File 'app/forms/hyrax/forms/collection_form.rb', line 46

def permission_template
  @permission_template ||= begin
                             template_model = PermissionTemplate.find_or_create_by(source_id: model.id)
                             PermissionTemplateForm.new(template_model)
                           end
end

#primary_termsObject

Terms that appear above the accordion


59
60
61
# File 'app/forms/hyrax/forms/collection_form.rb', line 59

def primary_terms
  [:title, :description]
end

#secondary_termsObject

Terms that appear within the accordion


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/forms/hyrax/forms/collection_form.rb', line 64

def secondary_terms
  [:alternative_title,
   :creator,
   :contributor,
   :keyword,
   :license,
   :publisher,
   :date_created,
   :subject,
   :language,
   :identifier,
   :based_near,
   :related_url,
   :resource_type]
end

#select_filesHash

Returns All FileSets in the collection, file.to_s is the key, file.id is the value.

Returns:

  • (Hash)

    All FileSets in the collection, file.to_s is the key, file.id is the value


54
55
56
# File 'app/forms/hyrax/forms/collection_form.rb', line 54

def select_files
  Hash[all_files_with_access]
end

#thumbnail_titleObject


113
114
115
116
# File 'app/forms/hyrax/forms/collection_form.rb', line 113

def thumbnail_title
  return unless model.thumbnail
  model.thumbnail.title.first
end