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

Class Method 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



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

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

Class Method Details

.build_permitted_paramsArray

This describes the parameters we are expecting to receive from the client

Returns:

  • (Array)

    a list of parameters used by sanitize_params



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

def self.build_permitted_params
  super + [{ based_near_attributes: [:id, :_destroy] }]
end

Instance Method Details



86
87
88
89
90
91
92
93
94
95
96
# File 'app/forms/hyrax/forms/collection_form.rb', line 86

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?



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

def display_additional_fields?
  secondary_terms.any?
end

#list_child_collectionsObject



128
129
130
# File 'app/forms/hyrax/forms/collection_form.rb', line 128

def list_child_collections
  collection_member_service.available_member_subcollections.documents
end

#list_parent_collectionsObject



124
125
126
# File 'app/forms/hyrax/forms/collection_form.rb', line 124

def list_parent_collections
  collection.member_of_collections
end

#logo_infoObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/forms/hyrax/forms/collection_form.rb', line 98

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



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

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



65
66
67
# File 'app/forms/hyrax/forms/collection_form.rb', line 65

def primary_terms
  [:title, :description]
end

#secondary_termsObject

Terms that appear within the accordion



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/forms/hyrax/forms/collection_form.rb', line 70

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



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

def select_files
  Hash[all_files_with_access]
end

#thumbnail_titleObject



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

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