magma-labs / solidus_simple_dash

Overview dashboard for use with Solidus
BSD 3-Clause "New" or "Revised" License
2 stars 10 forks source link

When viewing other admin pages an error appears in console #10

Open MrFehr opened 4 years ago

MrFehr commented 4 years ago
dashboard.self-0bc1eb29111ae6a206f0cde86d8b2390b012403bf6f18f1295e020f4ef179f1b.js?body=1:86

Uncaught ReferenceError: pie_colors is not defined

    at HTMLDocument.<anonymous> (dashboard.self-0bc1eb29111ae6a206f0cde86d8b2390b012403bf6f18f1295e020f4ef179f1b.js?body=1:86)
    at fire (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3233)
    at Object.fireWith [as resolveWith] (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3363)
    at Function.ready (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3583)
    at HTMLDocument.completed (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:3618)
rsmithlal commented 3 years ago

I'm running into the same issue, except that I'm also getting it on the overview tab.

rsmithlal commented 3 years ago

This is a problem with the installed JS and CSS assets from this extension being included in the overall application manifest after running the install generator.

Because these files are only used on a single view, I was able to solve this problem by removing the lines from the backend all.js and all.css manifest files and instead adding this extension's assets to the precompile list and including them in the head content block inside overview/index.html file.

<% content_for :head do %>
  <% if @display_ability %>
    <%= stylesheet_link_tag 'spree/backend/solidus_simple_dash', media: 'all', data: {turbolinks_track: 'reload'} %>
    <%= javascript_include_tag 'spree/backend/solidus_simple_dash', data: {turbolinks_track: 'reload'} %>
    <%= javascript_tag do -%>
      var orders_by_day_points = [[ <%== @orders_by_day.map { |day| "[\"#{day[0]}\",#{day[1]}]" }.join(",") %> ]];
      var abandoned_carts_by_day_points = [[ <%== @abandoned_carts_by_day.map { |day| "[\"#{day[0]}\",#{day[1]}]" }.join(",") %> ]];
      var new_users_by_day_points = [[ <%== @new_users_by_day.map { |day| "[\"#{day[0]}\",#{day[1]}]" }.join(",") %> ]];
      var best_selling_variants_points = [ <%== @best_selling_variants.map { |v| "[\"#{h(v[0])}\",#{v[1]}]" }.join(",") %> ];
      var top_grossing_variants_points = [ <%== @top_grossing_variants.map { |v| "[\"#{h(v[0])}\",#{v[1]}]" }.join(",") %> ];
      var best_selling_taxons_points = [ <%== @best_selling_taxons.map { |t| "[\"#{h(t[0])}\",#{t[1]}]" }.join(",") %> ];
      var abandoned_carts_points = [ <%== @abandoned_carts.map { |v| "[\"#{h(v[0])}\",#{v[1]}]" }.join(",") %> ];
      var checkout_steps_points = [ <%== @checkout_steps.map { |v| "[\"#{h(v[0])}\",#{v[1]}]" }.join(",") %> ];
      var abandoned_carts_products_points = [ <%== @abandoned_carts_products.map { |v| "[\"#{h(v[0])}\",#{v[1]}]" }.join(",") %> ];

      var orders = "<%= t('spree.simple_dash.orders') %>";
      var abandoned_orders = "<%= t('spree.simple_dash.abandoned_orders') %>";
      var new_users = "<%= t('spree.simple_dash.new_users') %>";
      var by_day = "<%= t('spree.simple_dash.by_day') %>";

      var pie_colors = [<%== @pie_colors.map{|c| "'#{c}'"}.join(",") %>];
    <% end -%>
  <% end %>
<% end %>

Rails.application.configure do
  config.assets.precompile += %w(
    spree/backend/solidus_simple_dash.js
    spree/backend/solidus_simple_dash.css
  )
end