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

Methods included from Breadcrumbs

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

Methods inherited from My::CollectionsController

#index

Methods inherited from MyController

configure_facets, #index, #suppressed_to_status

Instance Method Details

#after_createObject



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

def after_create
  form
  respond_to do |format|
    ActiveFedora::SolrService.instance.conn.commit
    format.html { redirect_to dashboard_collection_path(@collection), notice: 'Collection was successfully created.' }
    format.json { render json: @collection, status: :created, location: dashboard_collection_path(@collection) }
  end
end

#after_create_errorObject



93
94
95
96
97
98
99
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 93

def after_create_error
  form
  respond_to do |format|
    format.html { render action: 'new' }
    format.json { render json: @collection.errors, status: :unprocessable_entity }
  end
end

#after_destroy(id) ⇒ Object



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

def after_destroy(id)
  respond_to do |format|
    format.html do
      redirect_to my_collections_path,
                  notice: "Collection #{id} was successfully deleted"
    end
    format.json { head :no_content, location: my_collections_path }
  end
end

#after_destroy_error(id) ⇒ Object



156
157
158
159
160
161
162
163
164
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 156

def after_destroy_error(id)
  respond_to do |format|
    format.html do
      flash[:notice] = "Collection #{id} could not be deleted"
      render :edit, status: :unprocessable_entity
    end
    format.json { render json: { id: id }, status: :unprocessable_entity, location: dashboard_collection_path(@collection) }
  end
end

#after_updateObject



118
119
120
121
122
123
124
125
126
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 118

def after_update
  if flash[:notice].nil?
    flash[:notice] = 'Collection was successfully updated.'
  end
  respond_to do |format|
    format.html { redirect_to dashboard_collection_path(@collection) }
    format.json { render json: @collection, status: :updated, location: dashboard_collection_path(@collection) }
  end
end

#after_update_errorObject



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

def after_update_error
  form
  query_collection_members
  respond_to do |format|
    format.html { render action: 'edit' }
    format.json { render json: @collection.errors, status: :unprocessable_entity }
  end
end

#collectionObject



174
175
176
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 174

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

#createObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 101

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 = ::Collection.new
  authorize! :create, @collection

  @collection.attributes = collection_params.except(:members)
  @collection.(current_user.user_key)
  add_members_to_collection unless batch.empty?
  if @collection.save
    after_create
  else
    after_create_error
  end
end

#deny_collection_access(exception) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 53

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 && 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



166
167
168
169
170
171
172
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 166

def destroy
  if @collection.destroy
    after_destroy(params[:id])
  else
    after_destroy_error(params[:id])
  end
end

#editObject



77
78
79
80
81
82
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 77

def edit
  query_collection_members
  # this is used to populate the "add to a collection" action for the members
  @user_collections = find_collections_for_form
  form
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



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

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

#newObject



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

def new
  add_breadcrumb t(:'hyrax.controls.home'), root_path
  add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
  add_breadcrumb t(:'hyrax.collections.new.header'), hyrax.new_dashboard_collection_path
  @collection.(current_user.user_key)
  form
end

#search_builder_classObject



187
188
189
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 187

def search_builder_class
  Hyrax::CollectionSearchBuilder
end

#showObject



72
73
74
75
# File 'app/controllers/hyrax/dashboard/collections_controller.rb', line 72

def show
  presenter
  query_collection_members
end

#updateObject



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

def update
  process_member_changes
  if @collection.update(collection_params.except(:members))
    after_update
  else
    after_update_error
  end
end