Class: Avo::MediaLibraryController

Inherits:
ApplicationController show all
Includes:
Pagy::Method
Defined in:
app/controllers/avo/media_library_controller.rb

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Method Summary collapse

Methods inherited from BaseApplicationController

#exception_logger, #turbo_frame_request?

Methods included from Concerns::FindAssociationField

#find_association_field

Methods included from Concerns::Breadcrumbs

#add_breadcrumb, #avo_breadcrumbs

Methods included from UrlHelpers

#edit_resource_path, #new_resource_path, #preview_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resource_view_path, #resources_path

Methods included from ApplicationHelper

#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #rtl?, #text_direction, #ui, #wrap_in_modal

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table

Methods included from CommonController

#default_url_options, #extra_default_url_options

Methods included from InitializesAvo

#_current_user, #context, #init_app

Methods included from Concerns::SafeCall

#safe_call

Instance Method Details

#attachObject



44
45
46
47
48
# File 'app/controllers/avo/media_library_controller.rb', line 44

def attach
  @attaching = true

  render :index
end

#destroyObject



30
31
32
33
34
35
# File 'app/controllers/avo/media_library_controller.rb', line 30

def destroy
  @blob = ActiveStorage::Blob.find(params[:id])
  @blob.destroy!

  redirect_to avo.media_library_index_path
end

#extract_initials(filename) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/avo/media_library_controller.rb', line 19

def extract_initials(filename)
  # Remove file extension
  name_without_ext = File.basename(filename, File.extname(filename))

  # Split by spaces and take first 2 words
  words = name_without_ext.split(" ").first(2)

  # Extract first character of each word and join
  words.map { |word| word[0] }.join("").upcase
end

#indexObject



7
8
9
10
# File 'app/controllers/avo/media_library_controller.rb', line 7

def index
  @attaching = false
  add_breadcrumb title: "Media Library", initials: "ML"
end

#showObject



12
13
14
15
16
17
# File 'app/controllers/avo/media_library_controller.rb', line 12

def show
  @blob = ActiveStorage::Blob.find(params[:id])

  add_breadcrumb title: "Media Library", path: avo.media_library_index_path, initials: "ML"
  add_breadcrumb title: @blob.filename.to_s, path: nil, initials: extract_initials(@blob.filename.to_s)
end

#updateObject



37
38
39
40
41
42
# File 'app/controllers/avo/media_library_controller.rb', line 37

def update
  @blob = ActiveStorage::Blob.find(params[:id])
  @blob.update!(blob_params)

  redirect_to avo.media_library_path(@blob)
end