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


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

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


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

def scope
  @scope
end

Instance Method Details

#available_parent_collections(scope:) ⇒ Object


121
122
123
124
125
126
127
128
129
130
# File 'app/forms/hyrax/forms/collection_form.rb', line 121

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

77
78
79
80
81
82
83
84
85
86
# File 'app/forms/hyrax/forms/collection_form.rb', line 77

def banner_info
  @banner_info ||= begin
    # Find Banner filename
    banner_info = CollectionBrandingInfo.where(collection_id: id).where(role: "banner")
    banner_file = File.split(banner_info.first.local_path).last 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 }
  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?


104
105
106
# File 'app/forms/hyrax/forms/collection_form.rb', line 104

def display_additional_fields?
  secondary_terms.any?
end

#list_child_collectionsObject


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

def list_child_collections
  collection_member_service.available_member_subcollections.documents
end

#list_parent_collectionsObject


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

def list_parent_collections
  collection.member_of_collections
end

#logo_infoObject


88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/forms/hyrax/forms/collection_form.rb', line 88

def logo_info
  @logo_info ||= begin
    # Find Logo filename, alttext, linktext
    logos_info = CollectionBrandingInfo.where(collection_id: id).where(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


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

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


57
58
59
# File 'app/forms/hyrax/forms/collection_form.rb', line 57

def primary_terms
  [:title, :description]
end

#secondary_termsObject

Terms that appear within the accordion


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

def secondary_terms
  [: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


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

def select_files
  Hash[all_files_with_access]
end

#thumbnail_titleObject


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

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