Class: Admin::DocumentsController
- Inherits:
-
AdminController
- Object
- ApplicationController
- AdminController
- Admin::DocumentsController
- Defined in:
- app/controllers/admin/documents_controller.rb
Instance Method Summary collapse
-
#admin ⇒ Object
GET /documents/1/admin Admin view for a specific document.
-
#create ⇒ Object
POST /documents POST /documents.json Creates a new document with the provided parameters.
-
#destroy ⇒ Object
DELETE /documents/1 DELETE /documents/1.json Deletes a document.
-
#edit ⇒ Object
GET /documents/1/edit Renders a form for editing an existing document.
- #export ⇒ Object
-
#fetch ⇒ Object
Fetch documents from an array of friendlier_ids This action retrieves documents based on their friendlier IDs.
-
#index ⇒ Object
GET /documents GET /documents.json Lists all documents with support for various export formats.
-
#new ⇒ Object
GET /documents/new Renders a form for creating a new document.
-
#show ⇒ Object
GET /documents/1 Shows a document in various formats.
-
#update ⇒ Object
PATCH/PUT /documents/1 PATCH/PUT /documents/1.json Updates an existing document with the provided parameters.
-
#versions ⇒ Object
GET /documents/1/versions Displays the version history of a document.
Instance Method Details
#admin ⇒ Object
GET /documents/1/admin Admin view for a specific document.
118 119 |
# File 'app/controllers/admin/documents_controller.rb', line 118 def admin end |
#create ⇒ Object
POST /documents POST /documents.json Creates a new document with the provided parameters.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/admin/documents_controller.rb', line 129 def create @document = Document.new(document_params) @document.friendlier_id = @document.send(GeoblacklightAdmin::Schema.instance.solr_fields[:id]) respond_to do |format| if @document.save format.html { redirect_to edit_admin_document_path(@document), notice: "Document was successfully created." } format.json { render :show, status: :created, location: @document } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @document.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /documents/1 DELETE /documents/1.json Deletes a document.
161 162 163 164 165 166 167 168 169 |
# File 'app/controllers/admin/documents_controller.rb', line 161 def destroy @document.destroy respond_to do |format| format.html do redirect_to admin_documents_url, notice: "Document '#{@document.title}' was successfully destroyed." end format.json { head :no_content } end end |
#edit ⇒ Object
GET /documents/1/edit Renders a form for editing an existing document.
113 114 |
# File 'app/controllers/admin/documents_controller.rb', line 113 def edit end |
#export ⇒ Object
184 185 186 187 188 189 190 |
# File 'app/controllers/admin/documents_controller.rb', line 184 def export case params[:format] when "csv_document_licensed_access_links" ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentLicensedAccessLinksService) redirect_to admin_documents_path, notice: "Export job started. You will receive a notification when it is complete." end end |
#fetch ⇒ Object
Fetch documents from an array of friendlier_ids This action retrieves documents based on their friendlier IDs.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/admin/documents_controller.rb', line 70 def fetch @request = "#{request.protocol}#{request.host}:#{request.port}" @documents = Document.where(friendlier_id: params["ids"]) respond_to do |format| format.html { render :index } format.json { render json: @documents.to_json } format.json_btaa_aardvark do ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_btaa_aardvark"}, ExportJsonService) head :no_content end format.json_aardvark do ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_aardvark"}, ExportJsonService) head :no_content end format.json_gbl_v1 do ExportJsonJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "json_gbl_v1"}, ExportJsonService) head :no_content end format.csv do ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv"}, ExportCsvService) head :no_content end format.csv_document_licensed_access_links do ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_licensed_access_links"}, ExportCsvDocumentLicensedAccessLinksService) head :no_content end format.csv_document_distributions do ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_distributions"}, ExportCsvDocumentDistributionsService) head :no_content end end end |
#index ⇒ Object
GET /documents GET /documents.json Lists all documents with support for various export formats.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/admin/documents_controller.rb', line 18 def index # Construct the request URL @request = "#{request.protocol}#{request.host}:#{request.port}" # Define query parameters for the document search query_params = { q: params["q"], f: params["f"], page: params["page"], rows: params["rows"] || 20, sort: params["sort"] || "score desc", daterange: params["daterange"] || nil } @documents = BlacklightApi.new(@request, **query_params) # Respond to different formats respond_to do |format| format.html { render :index } format.json { render json: @documents.results.to_json } format.json_btaa_aardvark do ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_btaa_aardvark"}), ExportJsonService) head :no_content end format.json_aardvark do ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_aardvark"}), ExportJsonService) head :no_content end format.json_gbl_v1 do ExportJsonJob.perform_later(@request, current_user, query_params.merge!({format: "json_gbl_v1"}), ExportJsonService) head :no_content end format.json_file do ExportJsonBulkJob.perform_later(@request, current_user, query_params.merge!({format: "json_file"}), ExportJsonService) head :no_content end format.csv do ExportJob.perform_later(@request, current_user, query_params, ExportCsvService) head :no_content end format.csv_document_licensed_access_links do ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentLicensedAccessLinksService) head :no_content end format.csv_document_distributions do ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentDistributionsService) head :no_content end end end |
#new ⇒ Object
GET /documents/new Renders a form for creating a new document.
106 107 108 109 |
# File 'app/controllers/admin/documents_controller.rb', line 106 def new @document = Document.new render :edit end |
#show ⇒ Object
GET /documents/1 Shows a document in various formats.
173 174 175 176 177 178 179 180 181 182 |
# File 'app/controllers/admin/documents_controller.rb', line 173 def show respond_to do |format| format.html { redirect_to edit_admin_document_url(@document) } format.json { render json: @document.to_json } # App-style JSON format.json_aardvark format.json_btaa_aardvark format.json_gbl_v1 format.csv { send_data collect_csv([@document]), filename: "documents-#{Time.zone.today}.csv" } end end |
#update ⇒ Object
PATCH/PUT /documents/1 PATCH/PUT /documents/1.json Updates an existing document with the provided parameters.
146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/admin/documents_controller.rb', line 146 def update respond_to do |format| if @document.update(document_params) format.html { redirect_to edit_admin_document_path(@document), notice: "Document was successfully updated." } format.json { render :show, status: :ok, location: @document } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @document.errors, status: :unprocessable_entity } end end end |
#versions ⇒ Object
GET /documents/1/versions Displays the version history of a document.
123 124 |
# File 'app/controllers/admin/documents_controller.rb', line 123 def versions end |