Class: Admin::AssetsController
- Inherits:
-
AdminController
- Object
- ApplicationController
- AdminController
- Admin::AssetsController
- Defined in:
- app/controllers/admin/assets_controller.rb
Instance Method Summary collapse
- #attach_files ⇒ Object
-
#destroy ⇒ Object
DELETE /assets/1 or /assets/1.json.
-
#display_attach_form ⇒ Object
/assets/display_attach_form.
-
#edit ⇒ Object
GET /assets/1/edit.
-
#index ⇒ Object
GET /admin/asset_files.
-
#show ⇒ Object
GET /assets/1 or /assets/1.json.
-
#update ⇒ Object
PATCH/PUT /assets/1 or /assets/1.json.
Instance Method Details
#attach_files ⇒ Object
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 |
# File 'app/controllers/admin/assets_controller.rb', line 71 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 # 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_assets_url, notice: "Files attached successfully." end |
#destroy ⇒ Object
DELETE /assets/1 or /assets/1.json
53 54 55 56 57 58 59 60 |
# File 'app/controllers/admin/assets_controller.rb', line 53 def destroy @asset.destroy respond_to do |format| format.html { redirect_to admin_assets_url, notice: "Asset was successfully destroyed." } format.json { head :no_content } end end |
#display_attach_form ⇒ Object
/assets/display_attach_form
63 64 |
# File 'app/controllers/admin/assets_controller.rb', line 63 def display_attach_form end |
#edit ⇒ Object
GET /assets/1/edit
36 37 |
# File 'app/controllers/admin/assets_controller.rb', line 36 def edit end |
#index ⇒ Object
GET /admin/asset_files
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/admin/assets_controller.rb', line 9 def index scope = Asset search_query = params[:q].strip if params[:q].present? # Basic search functionality if search_query.present? scope = if date_check?(search_query) Asset.where("created_at BETWEEN ? AND ?", search_query.to_date.beginning_of_day, search_query.to_date.end_of_day) else scope.where(id: search_query).or( Asset.where(friendlier_id: search_query) ).or( Asset.where("title like ?", "%" + Asset.sanitize_sql_like(search_query) + "%") ).or( Asset.where(parent_id: search_query) ) end end @pagy, @assets = pagy(scope, items: 20) end |
#show ⇒ Object
GET /assets/1 or /assets/1.json
32 33 |
# File 'app/controllers/admin/assets_controller.rb', line 32 def show end |
#update ⇒ Object
PATCH/PUT /assets/1 or /assets/1.json
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/admin/assets_controller.rb', line 40 def update respond_to do |format| if @asset.update(asset_params.merge!(parent_id: parent_id_via_friendly_id(asset_params[:parent_id]))) format.html { redirect_to admin_asset_url(@asset.id), notice: "Asset was successfully updated." } format.json { render :show, status: :ok, location: @asset } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @asset.errors, status: :unprocessable_entity } end end end |