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
- #destroy ⇒ Object
- #display_attach_form ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
-
#update ⇒ Object
PATCH/PUT /works/1 PATCH/PUT /works/1.json.
Instance Method Details
#attach_files ⇒ Object
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 |
# File 'app/controllers/admin/document_assets_controller.rb', line 75 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
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/admin/document_assets_controller.rb', line 53 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
66 67 68 |
# File 'app/controllers/admin/document_assets_controller.rb', line 66 def display_attach_form @document = Document.find_by_friendlier_id!(params[:document_id]) end |
#edit ⇒ Object
34 35 |
# File 'app/controllers/admin/document_assets_controller.rb', line 34 def edit end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/admin/document_assets_controller.rb', line 9 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
24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/admin/document_assets_controller.rb', line 24 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 /works/1 PATCH/PUT /works/1.json
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/admin/document_assets_controller.rb', line 39 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_asset.parent), 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 |