Skip to content

Commit

Permalink
chore: media library and asset tweaks (#3625)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Jan 31, 2025
1 parent 3a44e99 commit 624537a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
<% end %>

<%# This is the last script to run so it can register custom StimulusJS controllers from plugins. %>
<% if Avo::PACKED %>
<%= javascript_include_tag '/avo-assets/late-registration', "data-turbo-track": "reload", defer: true %>
<% else %>
<%= javascript_include_tag 'late-registration', "data-turbo-track": "reload", defer: true %>
<% end %>
<% path = Avo::PACKED ? '/avo-assets/late-registration' : 'late-registration' %>
<%= javascript_include_tag path, "data-turbo-track": "reload", defer: true %>
2 changes: 1 addition & 1 deletion app/controllers/avo/media_library_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def blob_params
end

def authorize_access!
raise_404 unless Avo::MediaLibrary.configuration.visible?
raise_404 if Avo::MediaLibrary.configuration.disabled?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ export default class extends Controller {

const mediaLibraryPath = new URI(`${this.rootPath.path()}/attach-media`)
mediaLibraryPath.addSearch(params)
const mediaLibraryVisible = window.Avo.configuration.media_library.visible && window.Avo.configuration.media_library.enabled

// Add the gallery button to the toolbar
// const buttonHTML = `<button type="button" data-trix-action="gallery" class="trix-button trix-button--icon">${galleryButtonSVG}</button>`
const buttonHTML = `<a href="${mediaLibraryPath}" data-turbo-frame="${window.Avo.configuration.modal_frame_id}" class="trix-button trix-button--icon">${galleryButtonSVG}</a>`
if (mediaLibraryVisible && event.target.toolbarElement && event.target.toolbarElement.querySelector('.trix-button-group--file-tools')) {
if (window.Avo.configuration.media_library.visible && event.target.toolbarElement && event.target.toolbarElement.querySelector('.trix-button-group--file-tools')) {
event.target.toolbarElement
.querySelector('.trix-button-group--file-tools')
.insertAdjacentHTML('beforeend', buttonHTML)
Expand Down
2 changes: 1 addition & 1 deletion app/views/avo/partials/_javascript.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Avo.configuration.modal_frame_id = '<%= ::Avo::MODAL_FRAME_ID %>'
Avo.configuration.stimulus_controllers = []
Avo.configuration.media_library = {
enabled: <%= Avo::MediaLibrary.configuration.enabled %>,
enabled: <%= Avo::MediaLibrary.configuration.enabled? %>,
visible: <%= Avo::MediaLibrary.configuration.visible? %>
}
<% end %>
14 changes: 7 additions & 7 deletions app/views/layouts/avo/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<%= render partial: "avo/partials/pre_head" %>
<%= render Avo::AssetManager::StylesheetComponent.new asset_manager: Avo.asset_manager %>
<%= stylesheet_link_tag @stylesheet_assets_path, "data-turbo-track": "reload", defer: true, as: "style" %>
<% if Avo::PACKED %>
<%= javascript_include_tag "/avo-assets/avo.base", "data-turbo-track": "reload", defer: true %>
<% else %>
<%= javascript_include_tag "avo.base", "data-turbo-track": "reload", defer: true %>
<% if Rails.env.development? && defined?(Hotwire::Livereload) %>
<%= javascript_include_tag "hotwire-livereload", defer: true %>
<% end %>

<% path = Avo::PACKED ? "/avo-assets/avo.base" : "avo.base" %>
<%= javascript_include_tag path, "data-turbo-track": "reload", defer: true %>

<% if !Avo::PACKED && defined?(Hotwire::Livereload) %>
<%= javascript_include_tag "hotwire-livereload", defer: true %>
<% end %>

<%= render Avo::AssetManager::JavascriptComponent.new asset_manager: Avo.asset_manager %>
<%= render partial: "avo/partials/head" %>
<%= content_for :head %>
Expand Down
8 changes: 8 additions & 0 deletions lib/avo/media_library/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ class Configuration
config_accessor(:enabled) { false }

def visible?
return false if disabled?

Avo::ExecutionContext.new(target: config[:visible]).handle
end

def enabled?
Avo::ExecutionContext.new(target: config[:enabled]).handle
end

def disabled? = !enabled?
end

def self.configuration
Expand Down

0 comments on commit 624537a

Please sign in to comment.