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.
-
#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.
126 127 |
# File 'app/controllers/admin/documents_controller.rb', line 126 def admin end |
#create ⇒ Object
POST /documents POST /documents.json Creates a new document with the provided parameters.
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/controllers/admin/documents_controller.rb', line 137 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.
169 170 171 172 173 174 175 176 177 |
# File 'app/controllers/admin/documents_controller.rb', line 169 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.
121 122 |
# File 'app/controllers/admin/documents_controller.rb', line 121 def edit end |
#fetch ⇒ Object
Fetch documents from an array of friendlier_ids This action retrieves documents based on their friendlier IDs.
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 103 104 105 106 107 108 109 110 |
# File 'app/controllers/admin/documents_controller.rb', line 74 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_downloads do ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_downloads"}, ExportCsvDocumentDownloadsService) head :no_content end format.csv_document_access_links do ExportJob.perform_later(@request, current_user, {ids: @documents.pluck(:friendlier_id), format: "csv_document_access_links"}, ExportCsvDocumentAccessLinksService) 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 67 68 69 70 |
# 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_downloads do ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentDownloadsService) head :no_content end format.csv_document_access_links do ExportJob.perform_later(@request, current_user, query_params, ExportCsvDocumentAccessLinksService) 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.
114 115 116 117 |
# File 'app/controllers/admin/documents_controller.rb', line 114 def new @document = Document.new render :edit end |
#show ⇒ Object
GET /documents/1 Shows a document in various formats.
181 182 183 184 185 186 187 188 189 190 |
# File 'app/controllers/admin/documents_controller.rb', line 181 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.
154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/controllers/admin/documents_controller.rb', line 154 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.
131 132 |
# File 'app/controllers/admin/documents_controller.rb', line 131 def versions end |