Class: Hyrax::Admin::MetadataProfilesController

Inherits:
ApplicationController
  • Object
show all
Includes:
ThemedLayoutController
Defined in:
app/controllers/hyrax/admin/metadata_profiles_controller.rb

Instance Method Summary collapse

Methods included from ThemedLayoutController

#show_site_actions?, #show_site_search?

Instance Method Details

#exportObject

rubocop:enable Metrics/MethodLength



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/hyrax/admin/metadata_profiles_controller.rb', line 41

def export
  @schema = Hyrax::FlexibleSchema.find(params[:metadata_profile_id])
  filename = "metadata-profile-v.#{@schema.version}.yml"

  profile_hash = @schema.profile.deep_dup

  profile_hash['profile']['version'] = @schema.version
  profile_hash['profile']['date_modified'] = Time.current.strftime('%Y-%m-%d')

  yaml_data = profile_hash.to_yaml(indentation: 2)
  send_data yaml_data, filename: filename, type: "application/yaml"
end

#importObject

rubocop:disable Metrics/MethodLength



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/hyrax/admin/metadata_profiles_controller.rb', line 18

def import
  uploaded_io = params[:file]
  if uploaded_io.blank?
    redirect_to , alert: 'Please select a file to upload'
    return
  end

  begin
    @flexible_schema = Hyrax::FlexibleSchema.create(profile: YAML.safe_load_file(uploaded_io.path))

    if @flexible_schema.persisted?
      redirect_to , notice: 'Flexible Metadata Profile was successfully created.'
    else
      error_message = @flexible_schema.errors.messages.values.flatten.join(', ')
      redirect_to , flash: { error: error_message }
    end
  rescue => e
    redirect_to , flash: { error: e.message }
    nil
  end
end

#indexObject

GET /allinson_flex_profiles



12
13
14
15
# File 'app/controllers/hyrax/admin/metadata_profiles_controller.rb', line 12

def index
  add_breadcrumbs
  @metadata_profiles = Hyrax::FlexibleSchema.page(params[:profile_entries_page])
end