Skip to content

Commit

Permalink
Merge pull request #14 from spark-solutions/feature/bootstrap-4
Browse files Browse the repository at this point in the history
Migrate to Bootstrap 4
  • Loading branch information
damianlegawiec authored Sep 10, 2019
2 parents c500a5b + 890e390 commit 28bfc38
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
23 changes: 16 additions & 7 deletions app/helpers/spree/trackers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ def product_for_segment(product, optional = {})
brand: product.brand.try(:name),
price: product.price.to_f,
currency: product.currency,
url: product_url(product),
url: product_url(product)
}.tap do |hash|
# This method returns either asset_url (Paperclip) or rails_blob_path (ActiveStorage) to return the specified image(s)
if defined?(ActiveStorage) && !Rails.application.config.use_paperclip
hash[:image_url] = request.base_url + Rails.application.routes.url_helpers.rails_blob_path(optional.delete(:image).attachment, only_path: true) if optional[:image]
else
hash[:image_url] = request.base_url + asset_url(optional.delete(:image).attachment) if optional[:image]
end
hash[:image_url] = product_for_segment_image_url(hash, optional)
end.merge(optional).to_json.html_safe
end

private

# This method returns either asset_url (Paperclip) or rails_blob_path (ActiveStorage) to return the specified image(s)
def product_for_segment_image_url(hash, optional)
return unless optional[:image]

# Spree 4.0 dropped Paperclip support
if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('4.0.0.alpha') || (defined?(ActiveStorage) && !Rails.application.config.use_paperclip)
request.base_url + Rails.application.routes.url_helpers.rails_blob_path(optional.delete(:image).attachment, only_path: true)
else
request.base_url + asset_url(optional.delete(:image).attachment)
end
end
end
end
5 changes: 2 additions & 3 deletions app/overrides/add_analytics_to_admin_sidebar.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0')
Deface::Override.new(
virtual_path: 'spree/admin/shared/sub_menu/_configuration',
name: 'add_analytics_to_admin_configurations_sidebar_menu',
name: 'add_analytics_to_admin_sidebar',
insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]',
original: '72f6a33afb2627a467ae458d42991ab0ce4cc6df',
text: '<%= configurations_sidebar_menu_item(Spree.t(:analytics_trackers), spree.admin_trackers_path) if can? :manage, Spree::Tracker %>'
partial: 'spree/admin/shared/analytics_sidebar_menu'
)
end
8 changes: 3 additions & 5 deletions app/views/spree/admin/shared/_analytics_sidebar_menu.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<% if can? :admin, Spree::Tracker %>
<ul class="nav nav-sidebar">
<%= tab :analytic_trackers, url: spree.admin_trackers_path, icon: 'tasks' %>
</ul>
<% end %>
<%= configurations_sidebar_menu_item(
Spree.t(:analytics), spree.admin_trackers_path
) if can? :manage, Spree::Config %>
12 changes: 6 additions & 6 deletions app/views/spree/admin/trackers/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div data-hook="admin_tracker_form_fields" class="row">
<div class="col-xs-12 col-md-4" data-hook="analytics_engine">
<div class="col-12 col-lg-6" data-hook="analytics_engine">
<%= f.field_container :engine, class: ["form-group"], "data-hook" => "analytics_engine" do %>
<%= f.label :engine, Spree.t(:analytics_engine) %>
<%= f.select :engine, Spree::Tracker.engines.keys.sort.map { |k| [k.humanize, k] }, {}, { class: 'select2' } %>
<%= f.error_message_on :engine %>
<% end %>
</div>
<div class="col-xs-12 col-md-8">
<div class="col-12 col-lg-6">
<div data-hook="active" class="form-group">
<%= label_tag nil, Spree.t(:active) %>
<div class="radio">
Expand All @@ -23,14 +23,14 @@
</div>
</div>
</div>
<div class="col-xs-12 col-md-4" data-hook="analytics_id">
<div class="col-12 col-lg-6" data-hook="analytics_id">
<%= f.field_container :analytics_id, class: ["form-group"], "data-hook" => "analytics_id" do %>
<%= f.label :analytics_id, Spree.t(:google_analytics_id) %>
<%= f.text_field :analytics_id, class: 'form-control' %>
<%= f.error_message_on :analytics_id %>
<% end %>
</div>
<div data-hook="additional_tracker_fields"></div>
</div>
<div data-hook="admin_tracker_form_fields" class="row">
<div class="col-12 col-lg-6" data-hook="additional_tracker_fields"></div>
</div>

<div data-hook="admin_tracker_form_fields" class="row"></div>
12 changes: 4 additions & 8 deletions app/views/spree/admin/trackers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
<% if @trackers.any? %>
<table class="table">
<colgroup>
<col style="width: 30%">
<col style="width: 40%">
<col style="width: 15%">
<col style="width: 15%">
</colgroup>
<thead>
<tr data-hook="admin_trackers_index_headers">
<th><%= Spree.t(:google_analytics_id) %></th>
Expand All @@ -27,7 +21,9 @@
<tr id="<%= spree_dom_id tracker %>" data-hook="admin_trackers_index_rows">
<td><%= tracker.analytics_id %></td>
<td><%= tracker.engine.humanize %></td>
<td class="text-center"><%= tracker.active ? Spree.t(:say_yes) : Spree.t(:say_no) %></td>
<td class="text-center">
<%= tracker.active ? Spree.t(:say_yes) : Spree.t(:say_no) %>
</td>
<td class="actions text-right">
<%= link_to_edit(tracker, no_text: true) if can? :edit, tracker %>
<%= link_to_delete(tracker, no_text: true) if can? :delete, tracker %>
Expand All @@ -37,7 +33,7 @@
</tbody>
</table>
<% else %>
<div class="alert alert-warning">
<div class="alert alert-info">
<%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::Tracker)) %>,
<%= link_to(Spree.t(:add_one), new_object_url) if can? :create, Spree::Tracker %>!
</div>
Expand Down

0 comments on commit 28bfc38

Please sign in to comment.