Class: Hyrax::Dashboard::CollectionsController

Inherits:
My::CollectionsController show all
Includes:
Blacklight::AccessControls::Catalog, Blacklight::Base, BreadcrumbsForCollections, Collections::AcceptsBatches
Defined in:
app/controllers/hyrax/dashboard/collections_controller.rb

Overview

Shows a list of all collections to the admins

Instance Method Summary collapse

Methods included from Collections::AcceptsBatches

#batch, #batch=, #check_for_empty_batch?

Methods included from BreadcrumbsForCollections

#add_breadcrumb_for_action, #add_breadcrumb_for_controller, #mark_active_action

Methods included from Breadcrumbs

#add_breadcrumb_for_action, #add_breadcrumb_for_controller, #build_breadcrumbs, #default_trail, #trail_from_referer

Methods inherited from My::CollectionsController

configure_facets, #index

Methods inherited from MyController

configure_facets, #index

Instance Method Details

#after_createObject


86
87
88
89
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 86

def after_create
  Deprecation.warn("Method `#after_create` will be removed in Hyrax 4.0.")
  after_create_response # call private method for processing
end

#after_create_errorObject


91
92
93
94
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 91

def after_create_error
  Deprecation.warn("Method `#after_create_error` will be removed in Hyrax 4.0.")
  after_create_errors("") # call private method for processing
end

#after_destroy(_id) ⇒ Object


135
136
137
138
139
140
141
142
143
144
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 135

def after_destroy(_id)
  # leaving id to avoid changing the method's parameters prior to release
  respond_to do |format|
    format.html do
      redirect_to hyrax.my_collections_path,
                  notice: t('hyrax.dashboard.my.action.collection_delete_success')
    end
    format.json { head :no_content, location: hyrax.my_collections_path }
  end
end

#after_destroy_error(id) ⇒ Object


146
147
148
149
150
151
152
153
154
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 146

def after_destroy_error(id)
  respond_to do |format|
    format.html do
      flash[:notice] = t('hyrax.dashboard.my.action.collection_delete_fail')
      render :edit, status: :unprocessable_entity
    end
    format.json { render json: { id: id }, status: :unprocessable_entity, location: dashboard_collection_path(@collection) }
  end
end

#after_updateObject


111
112
113
114
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 111

def after_update
  Deprecation.warn("Method `#after_update` will be removed in Hyrax 4.0.")
  after_update_response # call private method for processing
end

#after_update_errorObject


116
117
118
119
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 116

def after_update_error
  Deprecation.warn("Method `#after_update_error` will be removed in Hyrax 4.0.")
  after_update_errors(@collection.errors) # call private method for processing
end

#collectionObject


172
173
174
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 172

def collection
  action_name == 'show' ? @presenter : @collection
end

#createObject


96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 96

def create
  # Manual load and authorize necessary because Cancan will pass in all
  # form attributes. When `permissions_attributes` are present the
  # collection is saved without a value for `has_model.`
  @collection = Hyrax.config.collection_class.new
  authorize! :create, @collection

  case @collection
  when ActiveFedora::Base
    create_active_fedora_collection
  else
    create_valkyrie_collection
  end
end

#deny_collection_access(exception) ⇒ Object


50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 50

def deny_collection_access(exception)
  if exception.action == :edit
    redirect_to(url_for(action: 'show'), alert: 'You do not have sufficient privileges to edit this document')
  elsif current_user&.persisted?
    redirect_to root_url, alert: exception.message
  else
    session['user_return_to'] = request.url
    redirect_to main_app.new_user_session_url, alert: exception.message
  end
end

#destroyObject


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 156

def destroy
  case @collection
  when Valkyrie::Resource
    valkyrie_destroy
  else
    if @collection.destroy
      after_destroy(params[:id])
    else
      after_destroy_error(params[:id])
    end
  end
rescue StandardError => err
  Rails.logger.error(err)
  after_destroy_error(params[:id])
end

#editObject


81
82
83
84
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 81

def edit
  form
  collection_type
end

#filesObject

Renders a JSON response with a list of files in this collection This is used by the edit form to populate the thumbnail_id dropdown


178
179
180
181
182
183
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 178

def files
  result = form.select_files.map do |label, id|
    { id: id, text: label }
  end
  render json: result
end

#newObject


61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 61

def new
  # Coming from the UI, a collection type id should always be present.  Coming from the API, if a collection type id is not specified,
  # use the default collection type (provides backward compatibility with versions < Hyrax 2.1.0)
  collection_type_id = params[:collection_type_id].presence || default_collection_type.id
  @collection.collection_type_gid = CollectionType.find(collection_type_id).to_global_id
  add_breadcrumb t(:'hyrax.controls.home'), root_path
  add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
  add_breadcrumb t('.header', type_title: collection_type.title), request.path
  @collection.try(:apply_depositor_metadata, current_user.user_key)
  form
end

#process_brandingObject


130
131
132
133
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 130

def process_branding
  process_banner_input
  process_logo_input
end

#showObject


73
74
75
76
77
78
79
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 73

def show
  # @todo: remove this unused assignment in 4.0.0
  @banner_file = presenter.banner_file if collection_type.brandable?

  presenter
  query_collection_members
end

#updateObject


121
122
123
124
125
126
127
128
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 121

def update
  case @collection
  when ActiveFedora::Base
    update_active_fedora_collection
  else
    update_valkyrie_collection
  end
end