FIX: Load admin-specific JS when compiling via ember-cli (#18086)

The previous sprockets implementation was including admin-specific JS in the plugin's main JS file, which would be served to all users regardless of admin status. This commit achieves the same result under the ember-cli plugin asset compiler with one difference: the admin js is compiled into a separate file. That means that in future, we'll be able to make it loaded only for admins. For now though, it's loaded for everyone, just like before.
This commit is contained in:
David Taylor
2022-08-25 11:36:02 +01:00
committed by GitHub
parent e141208605
commit 9ebebfb4cc
4 changed files with 73 additions and 23 deletions

View File

@ -862,6 +862,15 @@ class Plugin::Instance
EmberCli.plugin_assets? && File.exist?(extra_js_file_path)
end
def admin_js_asset_exists?
if EmberCli.plugin_assets?
# If this directory exists, ember-cli will output a .js file
File.exist?("#{File.dirname(@path)}/admin/assets/javascripts")
else
false
end
end
# Receives an array with two elements:
# 1. A symbol that represents the name of the value to filter.
# 2. A Proc that takes the existing ActiveRecord::Relation and the value received from the front-end.