Class: Admin::DocumentAssetsController
- Inherits:
-
AdminController
- Object
- ApplicationController
- AdminController
- Admin::DocumentAssetsController
- Defined in:
- app/controllers/admin/document_assets_controller.rb
Instance Method Summary collapse
-
#attach_files ⇒ Object
POST /document/:id/ingest.
-
#destroy ⇒ Object
DELETE /admin/document_assets/:id.
-
#display_attach_form ⇒ Object
GET /admin/document_assets/display_attach_form.
-
#edit ⇒ Object
GET /admin/document_assets/:id/edit.
-
#index ⇒ Object
GET /admin/document_assets.
-
#show ⇒ Object
GET /admin/document_assets/:id.
-
#update ⇒ Object
PATCH/PUT /admin/document_assets/:id.
Instance Method Details
#attach_files ⇒ Object
POST /document/:id/ingest
Attaches files to a document. Receives JSON hashes for direct uploaded files in params and creates filesets for them.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/admin/document_assets_controller.rb', line 103 def attach_files @parent = Document.find_by_friendlier_id!(params[:id]) current_position = @parent.members.maximum(:position) || 0 files_params = (params[:cached_files] || []) .collect { |s| JSON.parse(s) } .sort_by { |h| h&.dig("metadata", "filename") } files_params.each do |file_data| asset = Asset.new # if derivative_storage_type = params.dig(:storage_type_for, file_data["id"]) # asset.derivative_storage_type = derivative_storage_type # end # References references = params.dig(:dct_references_for, file_data["id"]) asset.dct_references_uri_key = references if references asset.position = (current_position += 1) asset.parent_id = @parent.id asset.file = file_data asset.title = (asset.file&.original_filename || "Untitled") asset.save! end @parent.update(representative: @parent.members.order(:position).first) if @parent.representative_id.nil? redirect_to admin_document_document_assets_path(@parent.friendlier_id, anchor: "nav-members") end |
#destroy ⇒ Object
DELETE /admin/document_assets/:id
Destroys a specific document asset. Redirects to the document assets index with a success notice.
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/admin/document_assets_controller.rb', line 79 def destroy @asset = Asset.find_by_friendlier_id!(params[:id]) @asset.destroy respond_to do |format| format.html do redirect_to admin_document_document_assets_path(@document), notice: "Asset '#{@asset.title}' was successfully destroyed." end format.json { head :no_content } end end |
#display_attach_form ⇒ Object
GET /admin/document_assets/display_attach_form
Displays the form to attach files to a document.
95 96 97 |
# File 'app/controllers/admin/document_assets_controller.rb', line 95 def display_attach_form @document = Document.find_by_friendlier_id!(params[:document_id]) end |
#edit ⇒ Object
GET /admin/document_assets/:id/edit
Renders the edit form for a specific document asset.
53 54 |
# File 'app/controllers/admin/document_assets_controller.rb', line 53 def edit end |
#index ⇒ Object
GET /admin/document_assets
Lists all document assets. If a document_id is provided, it filters the assets by the specified document.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/admin/document_assets_controller.rb', line 21 def index scope = Asset # simple simple search on a few simple attributes with OR combo. if params[:document_id].present? document = Document.find_by_friendlier_id(params[:document_id]) scope = scope.where(parent_id: document.id) end # scope = scope.page(params[:page]).per(20).order(created_at: :desc) scope = scope.includes(:parent) @document_assets = scope end |
#show ⇒ Object
GET /admin/document_assets/:id
Shows a specific document asset. If the asset is stored, it also retrieves the fixity checks associated with the asset.
40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/document_assets_controller.rb', line 40 def show @asset = Asset.find_by_friendlier_id!(params[:id]) return unless @asset.stored? @checks = @asset.fixity_checks.order("created_at asc") @latest_check = @checks.last @earliest_check = @checks.first end |
#update ⇒ Object
PATCH/PUT /admin/document_assets/:id
Updates a specific document asset. If successful, redirects to the document assets index with a success notice. Otherwise, re-renders the edit form with errors.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/admin/document_assets_controller.rb', line 61 def update @document_asset = Asset.find_by_friendlier_id!(params[:id]) respond_to do |format| if @document_asset.update(document_asset_params) format.html { redirect_to admin_document_document_assets_path(@document), notice: "Asset was successfully updated." } format.json { render :show, status: :ok, location: @document_asset } else format.html { render :edit } format.json { render json: @document_asset.errors, status: :unprocessable_entity } end end end |