From ffde0307e2dcb5f3370dfb9a0932a2651515e759 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 15:53:16 +0100 Subject: [PATCH 01/12] Add controllers from spree_backend related to config --- .../spree/admin/countries_controller.rb | 11 +++++++ .../spree/admin/states_controller.rb | 29 +++++++++++++++++++ .../spree/admin/zones_controller.rb | 26 +++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 app/controllers/spree/admin/countries_controller.rb create mode 100644 app/controllers/spree/admin/states_controller.rb create mode 100644 app/controllers/spree/admin/zones_controller.rb diff --git a/app/controllers/spree/admin/countries_controller.rb b/app/controllers/spree/admin/countries_controller.rb new file mode 100644 index 0000000000..1b0ddde02d --- /dev/null +++ b/app/controllers/spree/admin/countries_controller.rb @@ -0,0 +1,11 @@ +module Spree + module Admin + class CountriesController < ResourceController + + def collection + super.order(:name) + end + + end + end +end diff --git a/app/controllers/spree/admin/states_controller.rb b/app/controllers/spree/admin/states_controller.rb new file mode 100644 index 0000000000..20736203fe --- /dev/null +++ b/app/controllers/spree/admin/states_controller.rb @@ -0,0 +1,29 @@ +module Spree + module Admin + class StatesController < ResourceController + belongs_to 'spree/country' + before_filter :load_data + + def index + respond_with(@collection) do |format| + format.html + format.js { render :partial => 'state_list' } + end + end + + protected + + def location_after_save + admin_country_states_url(@country) + end + + def collection + super.order(:name) + end + + def load_data + @countries = Country.order(:name) + end + end + end +end diff --git a/app/controllers/spree/admin/zones_controller.rb b/app/controllers/spree/admin/zones_controller.rb new file mode 100644 index 0000000000..bd298e7f2c --- /dev/null +++ b/app/controllers/spree/admin/zones_controller.rb @@ -0,0 +1,26 @@ +module Spree + module Admin + class ZonesController < ResourceController + before_filter :load_data, :except => [:index] + + def new + @zone.zone_members.build + end + + protected + + def collection + params[:q] ||= {} + params[:q][:s] ||= "ascend_by_name" + @search = super.ransack(params[:q]) + @zones = @search.result.page(params[:page]).per(Spree::Config[:orders_per_page]) + end + + def load_data + @countries = Country.order(:name) + @states = State.order(:name) + @zones = Zone.order(:name) + end + end + end +end From 822a17f732eb3355f23edbfdfb124d02b3bd9d58 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 15:56:53 +0100 Subject: [PATCH 02/12] Fix basic rubocop issues in newly added controllers --- .../spree/admin/countries_controller.rb | 8 +++---- .../spree/admin/states_controller.rb | 20 ++++++++-------- .../spree/admin/zones_controller.rb | 24 +++++++++---------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/app/controllers/spree/admin/countries_controller.rb b/app/controllers/spree/admin/countries_controller.rb index 1b0ddde02d..4314e54b37 100644 --- a/app/controllers/spree/admin/countries_controller.rb +++ b/app/controllers/spree/admin/countries_controller.rb @@ -1,11 +1,9 @@ module Spree module Admin class CountriesController < ResourceController - - def collection - super.order(:name) - end - + def collection + super.order(:name) + end end end end diff --git a/app/controllers/spree/admin/states_controller.rb b/app/controllers/spree/admin/states_controller.rb index 20736203fe..eebbee8d44 100644 --- a/app/controllers/spree/admin/states_controller.rb +++ b/app/controllers/spree/admin/states_controller.rb @@ -7,23 +7,23 @@ module Spree def index respond_with(@collection) do |format| format.html - format.js { render :partial => 'state_list' } + format.js { render partial: 'state_list' } end end protected - def location_after_save - admin_country_states_url(@country) - end + def location_after_save + admin_country_states_url(@country) + end - def collection - super.order(:name) - end + def collection + super.order(:name) + end - def load_data - @countries = Country.order(:name) - end + def load_data + @countries = Country.order(:name) + end end end end diff --git a/app/controllers/spree/admin/zones_controller.rb b/app/controllers/spree/admin/zones_controller.rb index bd298e7f2c..5b5b9d876b 100644 --- a/app/controllers/spree/admin/zones_controller.rb +++ b/app/controllers/spree/admin/zones_controller.rb @@ -1,7 +1,7 @@ module Spree module Admin class ZonesController < ResourceController - before_filter :load_data, :except => [:index] + before_filter :load_data, except: [:index] def new @zone.zone_members.build @@ -9,18 +9,18 @@ module Spree protected - def collection - params[:q] ||= {} - params[:q][:s] ||= "ascend_by_name" - @search = super.ransack(params[:q]) - @zones = @search.result.page(params[:page]).per(Spree::Config[:orders_per_page]) - end + def collection + params[:q] ||= {} + params[:q][:s] ||= "ascend_by_name" + @search = super.ransack(params[:q]) + @zones = @search.result.page(params[:page]).per(Spree::Config[:orders_per_page]) + end - def load_data - @countries = Country.order(:name) - @states = State.order(:name) - @zones = Zone.order(:name) - end + def load_data + @countries = Country.order(:name) + @states = State.order(:name) + @zones = Zone.order(:name) + end end end end From 3df65d046313bd3948c24eaa6a566bd8f3f6bb52 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 16:23:39 +0100 Subject: [PATCH 03/12] Add spree_backend views related to admin/configuration menu that are missing in ofn --- .../spree/admin/countries/_form.html.erb | 22 ++++++++ app/views/spree/admin/countries/edit.html.erb | 21 ++++++++ .../spree/admin/countries/index.html.erb | 34 ++++++++++++ app/views/spree/admin/states/_form.html.erb | 14 +++++ .../spree/admin/states/_state_list.html.erb | 31 +++++++++++ app/views/spree/admin/states/edit.html.erb | 20 +++++++ app/views/spree/admin/states/index.html.erb | 24 +++++++++ app/views/spree/admin/states/new.html.erb | 15 ++++++ app/views/spree/admin/states/new.js.erb | 2 + .../admin/zones/_country_member.html.erb | 5 ++ app/views/spree/admin/zones/_form.html.erb | 34 ++++++++++++ .../spree/admin/zones/_member_type.html.erb | 19 +++++++ .../spree/admin/zones/_state_member.html.erb | 5 ++ app/views/spree/admin/zones/edit.html.erb | 23 ++++++++ app/views/spree/admin/zones/index.html.erb | 53 +++++++++++++++++++ app/views/spree/admin/zones/new.html.erb | 21 ++++++++ 16 files changed, 343 insertions(+) create mode 100644 app/views/spree/admin/countries/_form.html.erb create mode 100644 app/views/spree/admin/countries/edit.html.erb create mode 100644 app/views/spree/admin/countries/index.html.erb create mode 100644 app/views/spree/admin/states/_form.html.erb create mode 100644 app/views/spree/admin/states/_state_list.html.erb create mode 100644 app/views/spree/admin/states/edit.html.erb create mode 100644 app/views/spree/admin/states/index.html.erb create mode 100644 app/views/spree/admin/states/new.html.erb create mode 100644 app/views/spree/admin/states/new.js.erb create mode 100644 app/views/spree/admin/zones/_country_member.html.erb create mode 100644 app/views/spree/admin/zones/_form.html.erb create mode 100644 app/views/spree/admin/zones/_member_type.html.erb create mode 100644 app/views/spree/admin/zones/_state_member.html.erb create mode 100644 app/views/spree/admin/zones/edit.html.erb create mode 100644 app/views/spree/admin/zones/index.html.erb create mode 100644 app/views/spree/admin/zones/new.html.erb diff --git a/app/views/spree/admin/countries/_form.html.erb b/app/views/spree/admin/countries/_form.html.erb new file mode 100644 index 0000000000..347d5e6577 --- /dev/null +++ b/app/views/spree/admin/countries/_form.html.erb @@ -0,0 +1,22 @@ +
+
+
+ <%= f.label :name, Spree.t(:name) %> + <%= f.text_field :name, :class => 'fullwidth' %> +
+
+
+
+ <%= f.label :iso_name, Spree.t(:iso_name) %> + <%= f.text_field :iso_name, :class => 'fullwidth' %> +
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/app/views/spree/admin/countries/edit.html.erb b/app/views/spree/admin/countries/edit.html.erb new file mode 100644 index 0000000000..d5f8fc27d1 --- /dev/null +++ b/app/views/spree/admin/countries/edit.html.erb @@ -0,0 +1,21 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:editing_country) %> +<% end %> + +<% content_for :page_actions do %> +
  • + <%= button_link_to Spree.t(:back_to_countries_list), spree.admin_countries_path, :icon => 'icon-arrow-left' %> +
  • +<% end %> + +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @country } %> + +<%= form_for [:admin, @country] do |f| %> +
    + <%= render :partial => 'form', :locals => { :f => f } %> +
    + <%= render :partial => 'spree/admin/shared/edit_resource_links' %> +
    +<% end %> diff --git a/app/views/spree/admin/countries/index.html.erb b/app/views/spree/admin/countries/index.html.erb new file mode 100644 index 0000000000..2ad4c47956 --- /dev/null +++ b/app/views/spree/admin/countries/index.html.erb @@ -0,0 +1,34 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:listing_countries) %> +<% end %> + + + + + + + + + + + + + + + + + + <% @countries.each do |country| %> + + + + + + + <% end %> + +
    <%= Spree.t(:country_name) %><%= Spree.t(:iso_name) %><%= Spree.t(:states_required) %>
    <%= country.name %><%= country.iso_name %><%= country.states_required.to_s.titleize %> + <%= link_to_edit country, :no_text => true %> +
    \ No newline at end of file diff --git a/app/views/spree/admin/states/_form.html.erb b/app/views/spree/admin/states/_form.html.erb new file mode 100644 index 0000000000..c9dff9e35c --- /dev/null +++ b/app/views/spree/admin/states/_form.html.erb @@ -0,0 +1,14 @@ +
    +
    + <%= f.field_container :name do %> + <%= f.label :name, Spree.t(:name) %> + <%= f.text_field :name, :class => 'fullwidth' %> + <% end %> +
    +
    + <%= f.field_container :abbr do %> + <%= f.label :abbr, Spree.t(:abbreviation) %> + <%= f.text_field :abbr, :class => 'fullwidth' %> + <% end %> +
    +
    diff --git a/app/views/spree/admin/states/_state_list.html.erb b/app/views/spree/admin/states/_state_list.html.erb new file mode 100644 index 0000000000..177921eadb --- /dev/null +++ b/app/views/spree/admin/states/_state_list.html.erb @@ -0,0 +1,31 @@ +
    + + + + + + + + + + + + + + + + <% @states.each do |state| %> + + + + + + <% end %> + <% if @states.empty? %> + + <% end %> + +
    <%= Spree.t(:name) %><%= Spree.t(:abbreviation) %>
    <%= state.name %><%= state.abbr %> + <%= link_to_with_icon 'icon-edit', Spree.t(:edit), edit_admin_country_state_url(@country, state), :no_text => true %> + <%= link_to_delete state, :no_text => true %> +
    <%= Spree.t(:none) %>
    diff --git a/app/views/spree/admin/states/edit.html.erb b/app/views/spree/admin/states/edit.html.erb new file mode 100644 index 0000000000..a83c9d0f5e --- /dev/null +++ b/app/views/spree/admin/states/edit.html.erb @@ -0,0 +1,20 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:editing_state) %> <%= @state.name %> +<% end %> + +<% content_for :page_actions do %> +
  • + <%= button_link_to Spree.t(:back_to_states_list), spree.admin_country_states_url(@country), :icon => 'icon-arrow-left' %> +
  • +<% end %> + +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @state } %> + +<%= form_for [:admin, @country, @state] do |f| %> +
    + <%= render :partial => 'form', :locals => { :f => f } %> + <%= render :partial => 'spree/admin/shared/edit_resource_links' %> +
    +<% end %> diff --git a/app/views/spree/admin/states/index.html.erb b/app/views/spree/admin/states/index.html.erb new file mode 100644 index 0000000000..3eba92daea --- /dev/null +++ b/app/views/spree/admin/states/index.html.erb @@ -0,0 +1,24 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:states) %> +<% end %> + +<% content_for :page_actions do %> + +<% end %> + +
    + <%= label_tag :country, Spree.t(:country) %> + +
    + +<%= image_tag 'select2-spinner.gif', :plugin => 'spree', :style => 'display:none;', :id => 'busy_indicator' %> + +
    + <%= render :partial => 'state_list'%> +
    diff --git a/app/views/spree/admin/states/new.html.erb b/app/views/spree/admin/states/new.html.erb new file mode 100644 index 0000000000..1db852502c --- /dev/null +++ b/app/views/spree/admin/states/new.html.erb @@ -0,0 +1,15 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @state } %> + +<% content_for :page_title do %> + <%= Spree.t(:new_state) %> +<% end %> + +<%= form_for [:admin, @country, @state] do |f| %> +
    + <%= Spree.t(:new_state) %> + <%= render :partial => 'form', :locals => { :f => f } %> + <%= render :partial => 'spree/admin/shared/new_resource_links' %> +
    +<% end %> diff --git a/app/views/spree/admin/states/new.js.erb b/app/views/spree/admin/states/new.js.erb new file mode 100644 index 0000000000..4f8226e695 --- /dev/null +++ b/app/views/spree/admin/states/new.js.erb @@ -0,0 +1,2 @@ +$("#new_state").html("<%= escape_javascript(render :template => 'spree/admin/states/new', :formats => [:html], :handlers => [:erb]) %>"); +$("#new_state_link").parent().hide(); diff --git a/app/views/spree/admin/zones/_country_member.html.erb b/app/views/spree/admin/zones/_country_member.html.erb new file mode 100644 index 0000000000..8294b5d151 --- /dev/null +++ b/app/views/spree/admin/zones/_country_member.html.erb @@ -0,0 +1,5 @@ +
  • + <%= f.hidden_field :zoneable_type, :value => 'Spree::Country' %> + <%= f.collection_select(:zoneable_id, @countries, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth'}) %> + <%= remove_nested f %> +
  • diff --git a/app/views/spree/admin/zones/_form.html.erb b/app/views/spree/admin/zones/_form.html.erb new file mode 100644 index 0000000000..8d0d9886c3 --- /dev/null +++ b/app/views/spree/admin/zones/_form.html.erb @@ -0,0 +1,34 @@ +
    +
    + <%= Spree.t(:general_settings)%> + + <%= zone_form.field_container :name do %> + <%= zone_form.label :name, Spree.t(:name) %>
    + <%= zone_form.text_field :name, :class => 'fullwidth' %> + <% end %> + + <%= zone_form.field_container :description do %> + <%= zone_form.label :description, Spree.t(:description) %>
    + <%= zone_form.text_field :description, :class => 'fullwidth' %> + <% end %> + +
    + <%= zone_form.check_box :default_tax %> + <%= label_tag Spree.t(:default_tax_zone) %> +
    + +
    + <%= label_tag Spree.t(:type) %> +
      +
    • + <%= zone_form.radio_button('kind', 'country', { :id => 'country_based' }) %> + <%= label_tag :country_based, Spree.t(:country_based) %> +
    • +
    • + <%= zone_form.radio_button('kind', 'state', { :id => 'state_based' }) %> + <%= label_tag :state_based, Spree.t(:state_based) %> +
    • +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/spree/admin/zones/_member_type.html.erb b/app/views/spree/admin/zones/_member_type.html.erb new file mode 100644 index 0000000000..c28ca0e546 --- /dev/null +++ b/app/views/spree/admin/zones/_member_type.html.erb @@ -0,0 +1,19 @@ +<%= javascript_tag "var #{type}_member='#{generate_template(zone_form, :zone_members, {:partial => type + "_member"})}';" %> + + +
    +
    + <%= Spree.t(type) %> + +
      + <% members_of_type = zone_form.object.zone_members.select { |member| member.zoneable_type && member.zoneable_type == "Spree::#{type.camelize}" } %> + <%= zone_form.fields_for :zone_members, members_of_type do |member_form| %> + <%= render :partial => "#{type}_member", :locals => { :f => member_form } %> + <% end %> +
    + +
    + <%= button_link_to Spree.t("add_#{type}"), "##{type}_member", { :icon => 'icon-plus', :id => "nested-#{type.dasherize}" } %> +
    +
    +
    diff --git a/app/views/spree/admin/zones/_state_member.html.erb b/app/views/spree/admin/zones/_state_member.html.erb new file mode 100644 index 0000000000..28e2afe3b5 --- /dev/null +++ b/app/views/spree/admin/zones/_state_member.html.erb @@ -0,0 +1,5 @@ +
  • + <%= f.hidden_field :zoneable_type, :value => 'Spree::State' %> + <%= f.collection_select(:zoneable_id, @states, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth'}) %> + <%= remove_nested f %> +
  • diff --git a/app/views/spree/admin/zones/edit.html.erb b/app/views/spree/admin/zones/edit.html.erb new file mode 100644 index 0000000000..2b0007b196 --- /dev/null +++ b/app/views/spree/admin/zones/edit.html.erb @@ -0,0 +1,23 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:editing_zone) %> +<% end %> + +<% content_for :page_actions do %> +
  • + <%= button_link_to Spree.t(:back_to_zones_list), admin_zones_path, :icon => 'icon-arrow-left' %> +
  • +<% end %> + +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @zone } %> + +<%= form_for [:admin, @zone] do |zone_form| %> +
    + <%= render :partial => 'form', :locals => { :zone_form => zone_form } %> + <%= render :partial => 'member_type', :locals => { :type => 'country', :zone_form => zone_form }%> + <%= render :partial => 'member_type', :locals => { :type => 'state', :zone_form => zone_form } %> +
    + <%= render :partial => 'spree/admin/shared/edit_resource_links' %> +
    +<% end %> diff --git a/app/views/spree/admin/zones/index.html.erb b/app/views/spree/admin/zones/index.html.erb new file mode 100644 index 0000000000..19b081b19b --- /dev/null +++ b/app/views/spree/admin/zones/index.html.erb @@ -0,0 +1,53 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:zones) %> +<% end %> + +<% content_for :page_actions do %> +
  • + <%= button_link_to Spree.t(:new_zone), new_object_url, :icon => 'icon-plus', :id => 'admin_new_zone_link' %> +
  • +<% end %> + +<%= paginate @zones %> + +<% if @zones.empty? %> +
    + <%= Spree.t(:none) %> +
    +<% else %> + + + + + + + + + + + + + + + + + <% @zones.each do |zone| %> + + + + + + + <% end %> + +
    <%= sort_link @search,:name, Spree.t(:name), :title => 'zones_order_by_name_title' %> + <%= sort_link @search,:description, Spree.t(:description), {}, {:title => 'zones_order_by_description_title'} %> + <%= Spree.t(:default_tax) %>
    <%=zone.name %><%=zone.description %><%=zone.default_tax %> + <%=link_to_edit zone, :no_text => true %> + <%=link_to_delete zone, :no_text => true %> +
    +<% end%> + +<%= paginate @zones %> diff --git a/app/views/spree/admin/zones/new.html.erb b/app/views/spree/admin/zones/new.html.erb new file mode 100644 index 0000000000..36c0c0a2e1 --- /dev/null +++ b/app/views/spree/admin/zones/new.html.erb @@ -0,0 +1,21 @@ +<%= render :partial => 'spree/admin/shared/configuration_menu' %> + +<% content_for :page_title do %> + <%= Spree.t(:new_zone) %> +<% end %> + +<% content_for :page_actions do %> +
  • + <%= button_link_to Spree.t(:back_to_zones_list), spree.admin_zones_path, :icon => 'icon-arrow-left' %> +
  • +<% end %> + +<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @zone } %> + +<%= form_for [:admin, @zone] do |zone_form| %> + <%= render :partial => 'form', :locals => { :zone_form => zone_form } %> + +
    + + <%= render :partial => 'spree/admin/shared/new_resource_links' %> +<% end %> From e1c3d2442a4cf43720e487cc05b1bb76ae0a93c1 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 16:35:25 +0100 Subject: [PATCH 04/12] Convert spree/admin/countries from erb to haml --- .../spree/admin/countries/_form.html.erb | 22 ------------ .../spree/admin/countries/_form.html.haml | 14 ++++++++ app/views/spree/admin/countries/edit.html.erb | 21 ------------ .../spree/admin/countries/edit.html.haml | 16 +++++++++ .../spree/admin/countries/index.html.erb | 34 ------------------- .../spree/admin/countries/index.html.haml | 27 +++++++++++++++ 6 files changed, 57 insertions(+), 77 deletions(-) delete mode 100644 app/views/spree/admin/countries/_form.html.erb create mode 100644 app/views/spree/admin/countries/_form.html.haml delete mode 100644 app/views/spree/admin/countries/edit.html.erb create mode 100644 app/views/spree/admin/countries/edit.html.haml delete mode 100644 app/views/spree/admin/countries/index.html.erb create mode 100644 app/views/spree/admin/countries/index.html.haml diff --git a/app/views/spree/admin/countries/_form.html.erb b/app/views/spree/admin/countries/_form.html.erb deleted file mode 100644 index 347d5e6577..0000000000 --- a/app/views/spree/admin/countries/_form.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
    -
    -
    - <%= f.label :name, Spree.t(:name) %> - <%= f.text_field :name, :class => 'fullwidth' %> -
    -
    -
    -
    - <%= f.label :iso_name, Spree.t(:iso_name) %> - <%= f.text_field :iso_name, :class => 'fullwidth' %> -
    -
    -
    -
    - -
    -
    -
    \ No newline at end of file diff --git a/app/views/spree/admin/countries/_form.html.haml b/app/views/spree/admin/countries/_form.html.haml new file mode 100644 index 0000000000..8a2951ca9c --- /dev/null +++ b/app/views/spree/admin/countries/_form.html.haml @@ -0,0 +1,14 @@ +.row + .alpha.four.columns + .field + = f.label :name, t("spree.name") + = f.text_field :name, class: 'fullwidth' + .four.columns + .field + = f.label :iso_name, t("spree.iso_name") + = f.text_field :iso_name, class: 'fullwidth' + .omega.four.columns + .field.checkbox + %label + = f.check_box :states_required + = t("spree.states_required") diff --git a/app/views/spree/admin/countries/edit.html.erb b/app/views/spree/admin/countries/edit.html.erb deleted file mode 100644 index d5f8fc27d1..0000000000 --- a/app/views/spree/admin/countries/edit.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:editing_country) %> -<% end %> - -<% content_for :page_actions do %> -
  • - <%= button_link_to Spree.t(:back_to_countries_list), spree.admin_countries_path, :icon => 'icon-arrow-left' %> -
  • -<% end %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @country } %> - -<%= form_for [:admin, @country] do |f| %> -
    - <%= render :partial => 'form', :locals => { :f => f } %> -
    - <%= render :partial => 'spree/admin/shared/edit_resource_links' %> -
    -<% end %> diff --git a/app/views/spree/admin/countries/edit.html.haml b/app/views/spree/admin/countries/edit.html.haml new file mode 100644 index 0000000000..5c46ea91ea --- /dev/null +++ b/app/views/spree/admin/countries/edit.html.haml @@ -0,0 +1,16 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.editing_country") + +- content_for :page_actions do + %li + = button_link_to t("spree.back_to_countries_list"), spree.admin_countries_path, icon: 'icon-arrow-left' + += render partial: 'spree/shared/error_messages', locals: { target: @country } + += form_for [:admin, @country] do |f| + %fieldset.no-border-top + = render partial: 'form', locals: { f: f } + .clear + = render partial: 'spree/admin/shared/edit_resource_links' diff --git a/app/views/spree/admin/countries/index.html.erb b/app/views/spree/admin/countries/index.html.erb deleted file mode 100644 index 2ad4c47956..0000000000 --- a/app/views/spree/admin/countries/index.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:listing_countries) %> -<% end %> - - - - - - - - - - - - - - - - - - <% @countries.each do |country| %> - - - - - - - <% end %> - -
    <%= Spree.t(:country_name) %><%= Spree.t(:iso_name) %><%= Spree.t(:states_required) %>
    <%= country.name %><%= country.iso_name %><%= country.states_required.to_s.titleize %> - <%= link_to_edit country, :no_text => true %> -
    \ No newline at end of file diff --git a/app/views/spree/admin/countries/index.html.haml b/app/views/spree/admin/countries/index.html.haml new file mode 100644 index 0000000000..0eb473667b --- /dev/null +++ b/app/views/spree/admin/countries/index.html.haml @@ -0,0 +1,27 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.listing_countries") + +%table#listing_countries.index + %colgroup + %col{:style => "width: 35%"}/ + %col{:style => "width: 35%"}/ + %col{:style => "width: 20%"}/ + %col{:style => "width: 10%"}/ + %thead + %tr + %th= t("spree.country_name") + %th= t("spree.iso_name") + %th= t("spree.states_required") + %th.actions + %tbody + - @countries.each do |country| + - tr_class = cycle('odd', 'even') + - tr_id = spree_dom_id(country) + %tr{class: tr_class, id: tr_id} + %td= country.name + %td= country.iso_name + %td.align-center= country.states_required.to_s.titleize + %td.actions + = link_to_edit country, no_text: true From bd2045cad75847092baff82ff1d3db364beebda0 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 16:53:10 +0100 Subject: [PATCH 05/12] Convert spree/admin/states from erb to haml --- app/views/spree/admin/states/_form.html.erb | 14 --------- app/views/spree/admin/states/_form.html.haml | 9 ++++++ .../spree/admin/states/_state_list.html.erb | 31 ------------------- .../spree/admin/states/_state_list.html.haml | 24 ++++++++++++++ app/views/spree/admin/states/edit.html.erb | 20 ------------ app/views/spree/admin/states/edit.html.haml | 16 ++++++++++ app/views/spree/admin/states/index.html.erb | 24 -------------- app/views/spree/admin/states/index.html.haml | 16 ++++++++++ app/views/spree/admin/states/new.html.erb | 15 --------- app/views/spree/admin/states/new.html.haml | 12 +++++++ 10 files changed, 77 insertions(+), 104 deletions(-) delete mode 100644 app/views/spree/admin/states/_form.html.erb create mode 100644 app/views/spree/admin/states/_form.html.haml delete mode 100644 app/views/spree/admin/states/_state_list.html.erb create mode 100644 app/views/spree/admin/states/_state_list.html.haml delete mode 100644 app/views/spree/admin/states/edit.html.erb create mode 100644 app/views/spree/admin/states/edit.html.haml delete mode 100644 app/views/spree/admin/states/index.html.erb create mode 100644 app/views/spree/admin/states/index.html.haml delete mode 100644 app/views/spree/admin/states/new.html.erb create mode 100644 app/views/spree/admin/states/new.html.haml diff --git a/app/views/spree/admin/states/_form.html.erb b/app/views/spree/admin/states/_form.html.erb deleted file mode 100644 index c9dff9e35c..0000000000 --- a/app/views/spree/admin/states/_form.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
    -
    - <%= f.field_container :name do %> - <%= f.label :name, Spree.t(:name) %> - <%= f.text_field :name, :class => 'fullwidth' %> - <% end %> -
    -
    - <%= f.field_container :abbr do %> - <%= f.label :abbr, Spree.t(:abbreviation) %> - <%= f.text_field :abbr, :class => 'fullwidth' %> - <% end %> -
    -
    diff --git a/app/views/spree/admin/states/_form.html.haml b/app/views/spree/admin/states/_form.html.haml new file mode 100644 index 0000000000..9f56da37d9 --- /dev/null +++ b/app/views/spree/admin/states/_form.html.haml @@ -0,0 +1,9 @@ +.row + .alpha.six.columns + = f.field_container :name do + = f.label :name, t("spree.name") + = f.text_field :name, class: 'fullwidth' + .omega.six.columns + = f.field_container :abbr do + = f.label :abbr, t("spree.abbreviation") + = f.text_field :abbr, class: 'fullwidth' diff --git a/app/views/spree/admin/states/_state_list.html.erb b/app/views/spree/admin/states/_state_list.html.erb deleted file mode 100644 index 177921eadb..0000000000 --- a/app/views/spree/admin/states/_state_list.html.erb +++ /dev/null @@ -1,31 +0,0 @@ -
    - - - - - - - - - - - - - - - - <% @states.each do |state| %> - - - - - - <% end %> - <% if @states.empty? %> - - <% end %> - -
    <%= Spree.t(:name) %><%= Spree.t(:abbreviation) %>
    <%= state.name %><%= state.abbr %> - <%= link_to_with_icon 'icon-edit', Spree.t(:edit), edit_admin_country_state_url(@country, state), :no_text => true %> - <%= link_to_delete state, :no_text => true %> -
    <%= Spree.t(:none) %>
    diff --git a/app/views/spree/admin/states/_state_list.html.haml b/app/views/spree/admin/states/_state_list.html.haml new file mode 100644 index 0000000000..688a08f114 --- /dev/null +++ b/app/views/spree/admin/states/_state_list.html.haml @@ -0,0 +1,24 @@ +#new_state +%table#listing_states.index + %colgroup + %col{:style => "width: 70%"}/ + %col{:style => "width: 15%"}/ + %col{:style => "width: 15%"}/ + %thead + %tr + %th= t("spree.name") + %th= t("spree.abbreviation") + %th.actions + %tbody + - @states.each do |state| + - tr_class = cycle('odd', 'even') + - tr_id = spree_dom_id(state) + %tr{class: tr_class, id: tr_id} + %td= state.name + %td.align-center= state.abbr + %td.actions + = link_to_with_icon 'icon-edit', t("spree.edit"), edit_admin_country_state_url(@country, state), no_text: true + = link_to_delete state, no_text: true + - if @states.empty? + %tr + %td{colspan: "3"}= t("spree.none") diff --git a/app/views/spree/admin/states/edit.html.erb b/app/views/spree/admin/states/edit.html.erb deleted file mode 100644 index a83c9d0f5e..0000000000 --- a/app/views/spree/admin/states/edit.html.erb +++ /dev/null @@ -1,20 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:editing_state) %> <%= @state.name %> -<% end %> - -<% content_for :page_actions do %> -
  • - <%= button_link_to Spree.t(:back_to_states_list), spree.admin_country_states_url(@country), :icon => 'icon-arrow-left' %> -
  • -<% end %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @state } %> - -<%= form_for [:admin, @country, @state] do |f| %> -
    - <%= render :partial => 'form', :locals => { :f => f } %> - <%= render :partial => 'spree/admin/shared/edit_resource_links' %> -
    -<% end %> diff --git a/app/views/spree/admin/states/edit.html.haml b/app/views/spree/admin/states/edit.html.haml new file mode 100644 index 0000000000..636d1d022d --- /dev/null +++ b/app/views/spree/admin/states/edit.html.haml @@ -0,0 +1,16 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.editing_state") + %i.icon-arrow-right + = @state.name + +- content_for :page_actions do + %li + = button_link_to t("spree.back_to_states_list"), spree.admin_country_states_url(@country), icon: 'icon-arrow-left' + += render partial: 'spree/shared/error_messages', locals: { target: @state } += form_for [:admin, @country, @state] do |f| + %fieldset.no-border-top + = render partial: 'form', locals: { f: f } + = render partial: 'spree/admin/shared/edit_resource_links' diff --git a/app/views/spree/admin/states/index.html.erb b/app/views/spree/admin/states/index.html.erb deleted file mode 100644 index 3eba92daea..0000000000 --- a/app/views/spree/admin/states/index.html.erb +++ /dev/null @@ -1,24 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:states) %> -<% end %> - -<% content_for :page_actions do %> - -<% end %> - -
    - <%= label_tag :country, Spree.t(:country) %> - -
    - -<%= image_tag 'select2-spinner.gif', :plugin => 'spree', :style => 'display:none;', :id => 'busy_indicator' %> - -
    - <%= render :partial => 'state_list'%> -
    diff --git a/app/views/spree/admin/states/index.html.haml b/app/views/spree/admin/states/index.html.haml new file mode 100644 index 0000000000..9010f8a94c --- /dev/null +++ b/app/views/spree/admin/states/index.html.haml @@ -0,0 +1,16 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.states") + +- content_for :page_actions do + %li#new_state_link + = button_link_to t("spree.new_state"), new_admin_country_state_url(@country), { remote: true, icon: 'icon-plus', id: 'new_state_link' } +.field.row + = label_tag :country, t("spree.country") + - databaseurl = "#{admin_states_path(format: :js)}?country_id=" + %select#country.observe_field.select2.fullwidth{"data-base-url": databaseurl, "data-update": "#state-list"} + = options_from_collection_for_select(@countries, :id, :name, @country.id) += image_tag 'select2-spinner.gif', plugin: 'spree', style: 'display:none;', id: 'busy_indicator' +#state-list + = render partial: 'state_list' diff --git a/app/views/spree/admin/states/new.html.erb b/app/views/spree/admin/states/new.html.erb deleted file mode 100644 index 1db852502c..0000000000 --- a/app/views/spree/admin/states/new.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @state } %> - -<% content_for :page_title do %> - <%= Spree.t(:new_state) %> -<% end %> - -<%= form_for [:admin, @country, @state] do |f| %> -
    - <%= Spree.t(:new_state) %> - <%= render :partial => 'form', :locals => { :f => f } %> - <%= render :partial => 'spree/admin/shared/new_resource_links' %> -
    -<% end %> diff --git a/app/views/spree/admin/states/new.html.haml b/app/views/spree/admin/states/new.html.haml new file mode 100644 index 0000000000..f7b988b24c --- /dev/null +++ b/app/views/spree/admin/states/new.html.haml @@ -0,0 +1,12 @@ += render partial: 'spree/admin/shared/configuration_menu' + += render partial: 'spree/shared/error_messages', locals: { target: @state } + +- content_for :page_title do + = t("spree.new_state") + += form_for [:admin, @country, @state] do |f| + %fieldset + %legend= t("spree.new_state") + = render partial: 'form', locals: { f: f } + = render partial: 'spree/admin/shared/new_resource_links' From 6d8c7a4bee3e43cad3fbd1ec05e4e6c7119b62a4 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 17:02:56 +0100 Subject: [PATCH 06/12] Fix minor detail in states and countries views --- app/views/spree/admin/countries/index.html.haml | 8 ++++---- app/views/spree/admin/states/_state_list.html.haml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/spree/admin/countries/index.html.haml b/app/views/spree/admin/countries/index.html.haml index 0eb473667b..285bf9d55f 100644 --- a/app/views/spree/admin/countries/index.html.haml +++ b/app/views/spree/admin/countries/index.html.haml @@ -5,10 +5,10 @@ %table#listing_countries.index %colgroup - %col{:style => "width: 35%"}/ - %col{:style => "width: 35%"}/ - %col{:style => "width: 20%"}/ - %col{:style => "width: 10%"}/ + %col{style: "width: 35%"}/ + %col{style: "width: 35%"}/ + %col{style: "width: 20%"}/ + %col{style: "width: 10%"}/ %thead %tr %th= t("spree.country_name") diff --git a/app/views/spree/admin/states/_state_list.html.haml b/app/views/spree/admin/states/_state_list.html.haml index 688a08f114..774c447a94 100644 --- a/app/views/spree/admin/states/_state_list.html.haml +++ b/app/views/spree/admin/states/_state_list.html.haml @@ -1,9 +1,9 @@ #new_state %table#listing_states.index %colgroup - %col{:style => "width: 70%"}/ - %col{:style => "width: 15%"}/ - %col{:style => "width: 15%"}/ + %col{style: "width: 70%"}/ + %col{style: "width: 15%"}/ + %col{style: "width: 15%"}/ %thead %tr %th= t("spree.name") From 32c1eececee34e113bbfdc81f115da68d871e856 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 17:31:31 +0100 Subject: [PATCH 07/12] Convert spree/admin/zones from erb to haml --- .../admin/zones/_country_member.html.erb | 5 -- .../admin/zones/_country_member.html.haml | 4 ++ app/views/spree/admin/zones/_form.html.erb | 34 ------------ app/views/spree/admin/zones/_form.html.haml | 23 ++++++++ .../spree/admin/zones/_member_type.html.erb | 19 ------- .../spree/admin/zones/_member_type.html.haml | 11 ++++ .../spree/admin/zones/_state_member.html.erb | 5 -- .../spree/admin/zones/_state_member.html.haml | 4 ++ app/views/spree/admin/zones/edit.html.erb | 23 -------- app/views/spree/admin/zones/edit.html.haml | 18 +++++++ app/views/spree/admin/zones/index.html.erb | 53 ------------------- app/views/spree/admin/zones/index.html.haml | 41 ++++++++++++++ app/views/spree/admin/zones/new.html.erb | 21 -------- app/views/spree/admin/zones/new.html.haml | 15 ++++++ 14 files changed, 116 insertions(+), 160 deletions(-) delete mode 100644 app/views/spree/admin/zones/_country_member.html.erb create mode 100644 app/views/spree/admin/zones/_country_member.html.haml delete mode 100644 app/views/spree/admin/zones/_form.html.erb create mode 100644 app/views/spree/admin/zones/_form.html.haml delete mode 100644 app/views/spree/admin/zones/_member_type.html.erb create mode 100644 app/views/spree/admin/zones/_member_type.html.haml delete mode 100644 app/views/spree/admin/zones/_state_member.html.erb create mode 100644 app/views/spree/admin/zones/_state_member.html.haml delete mode 100644 app/views/spree/admin/zones/edit.html.erb create mode 100644 app/views/spree/admin/zones/edit.html.haml delete mode 100644 app/views/spree/admin/zones/index.html.erb create mode 100644 app/views/spree/admin/zones/index.html.haml delete mode 100644 app/views/spree/admin/zones/new.html.erb create mode 100644 app/views/spree/admin/zones/new.html.haml diff --git a/app/views/spree/admin/zones/_country_member.html.erb b/app/views/spree/admin/zones/_country_member.html.erb deleted file mode 100644 index 8294b5d151..0000000000 --- a/app/views/spree/admin/zones/_country_member.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -
  • - <%= f.hidden_field :zoneable_type, :value => 'Spree::Country' %> - <%= f.collection_select(:zoneable_id, @countries, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth'}) %> - <%= remove_nested f %> -
  • diff --git a/app/views/spree/admin/zones/_country_member.html.haml b/app/views/spree/admin/zones/_country_member.html.haml new file mode 100644 index 0000000000..f09ba19efc --- /dev/null +++ b/app/views/spree/admin/zones/_country_member.html.haml @@ -0,0 +1,4 @@ +%li + = f.hidden_field :zoneable_type, value: 'Spree::Country' + = f.collection_select(:zoneable_id, @countries, :id, :name, {include_blank: true}, {class: 'select2 fullwidth'}) + = remove_nested f diff --git a/app/views/spree/admin/zones/_form.html.erb b/app/views/spree/admin/zones/_form.html.erb deleted file mode 100644 index 8d0d9886c3..0000000000 --- a/app/views/spree/admin/zones/_form.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -
    -
    - <%= Spree.t(:general_settings)%> - - <%= zone_form.field_container :name do %> - <%= zone_form.label :name, Spree.t(:name) %>
    - <%= zone_form.text_field :name, :class => 'fullwidth' %> - <% end %> - - <%= zone_form.field_container :description do %> - <%= zone_form.label :description, Spree.t(:description) %>
    - <%= zone_form.text_field :description, :class => 'fullwidth' %> - <% end %> - -
    - <%= zone_form.check_box :default_tax %> - <%= label_tag Spree.t(:default_tax_zone) %> -
    - -
    - <%= label_tag Spree.t(:type) %> -
      -
    • - <%= zone_form.radio_button('kind', 'country', { :id => 'country_based' }) %> - <%= label_tag :country_based, Spree.t(:country_based) %> -
    • -
    • - <%= zone_form.radio_button('kind', 'state', { :id => 'state_based' }) %> - <%= label_tag :state_based, Spree.t(:state_based) %> -
    • -
    -
    -
    -
    \ No newline at end of file diff --git a/app/views/spree/admin/zones/_form.html.haml b/app/views/spree/admin/zones/_form.html.haml new file mode 100644 index 0000000000..3fae4a2ee6 --- /dev/null +++ b/app/views/spree/admin/zones/_form.html.haml @@ -0,0 +1,23 @@ +.alpha.six.columns + %fieldset.no-border-bottom + %legend{align: "center"}= t("spree.general_settings") + = zone_form.field_container :name do + = zone_form.label :name, t("spree.name") + %br/ + = zone_form.text_field :name, class: 'fullwidth' + = zone_form.field_container :description do + = zone_form.label :description, t("spree.description") + %br/ + = zone_form.text_field :description, class: 'fullwidth' + .field + = zone_form.check_box :default_tax + = label_tag t("spree.default_tax_zone") + .field + = label_tag t("spree.type") + %ul + %li + = zone_form.radio_button('kind', 'country', { id: 'country_based' }) + = label_tag :country_based, t("spree.country_based") + %li + = zone_form.radio_button('kind', 'state', { id: 'state_based' }) + = label_tag :state_based, t("spree.state_based") diff --git a/app/views/spree/admin/zones/_member_type.html.erb b/app/views/spree/admin/zones/_member_type.html.erb deleted file mode 100644 index c28ca0e546..0000000000 --- a/app/views/spree/admin/zones/_member_type.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<%= javascript_tag "var #{type}_member='#{generate_template(zone_form, :zone_members, {:partial => type + "_member"})}';" %> - - -
    -
    - <%= Spree.t(type) %> - -
      - <% members_of_type = zone_form.object.zone_members.select { |member| member.zoneable_type && member.zoneable_type == "Spree::#{type.camelize}" } %> - <%= zone_form.fields_for :zone_members, members_of_type do |member_form| %> - <%= render :partial => "#{type}_member", :locals => { :f => member_form } %> - <% end %> -
    - -
    - <%= button_link_to Spree.t("add_#{type}"), "##{type}_member", { :icon => 'icon-plus', :id => "nested-#{type.dasherize}" } %> -
    -
    -
    diff --git a/app/views/spree/admin/zones/_member_type.html.haml b/app/views/spree/admin/zones/_member_type.html.haml new file mode 100644 index 0000000000..633067fabc --- /dev/null +++ b/app/views/spree/admin/zones/_member_type.html.haml @@ -0,0 +1,11 @@ += javascript_tag "var #{type}_member='#{generate_template(zone_form, :zone_members, {:partial => type + "_member"})}';" + +.omega.six.columns{id: "#{type}_members"} + %fieldset.no-border-bottom + %legend{align: "center"}= t("spree.type") + %ul.member-list.fields{id: "ul-nested-#{type.dasherize}"} + - members_of_type = zone_form.object.zone_members.select { |member| member.zoneable_type && member.zoneable_type == "Spree::#{type.camelize}" } + = zone_form.fields_for :zone_members, members_of_type do |member_form| + = render partial: "#{type}_member", locals: { f: member_form } + .field.align-center + = button_link_to t("spree.add_#{type}"), "##{type}_member", { icon: 'icon-plus', id:"nested-#{type.dasherize}" } diff --git a/app/views/spree/admin/zones/_state_member.html.erb b/app/views/spree/admin/zones/_state_member.html.erb deleted file mode 100644 index 28e2afe3b5..0000000000 --- a/app/views/spree/admin/zones/_state_member.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -
  • - <%= f.hidden_field :zoneable_type, :value => 'Spree::State' %> - <%= f.collection_select(:zoneable_id, @states, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth'}) %> - <%= remove_nested f %> -
  • diff --git a/app/views/spree/admin/zones/_state_member.html.haml b/app/views/spree/admin/zones/_state_member.html.haml new file mode 100644 index 0000000000..4b917288a7 --- /dev/null +++ b/app/views/spree/admin/zones/_state_member.html.haml @@ -0,0 +1,4 @@ +%li.field + = f.hidden_field :zoneable_type, value: 'Spree::State' + = f.collection_select(:zoneable_id, @states, :id, :name, {include_blank: true}, {class: 'select2 fullwidth'}) + = remove_nested f diff --git a/app/views/spree/admin/zones/edit.html.erb b/app/views/spree/admin/zones/edit.html.erb deleted file mode 100644 index 2b0007b196..0000000000 --- a/app/views/spree/admin/zones/edit.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:editing_zone) %> -<% end %> - -<% content_for :page_actions do %> -
  • - <%= button_link_to Spree.t(:back_to_zones_list), admin_zones_path, :icon => 'icon-arrow-left' %> -
  • -<% end %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @zone } %> - -<%= form_for [:admin, @zone] do |zone_form| %> -
    - <%= render :partial => 'form', :locals => { :zone_form => zone_form } %> - <%= render :partial => 'member_type', :locals => { :type => 'country', :zone_form => zone_form }%> - <%= render :partial => 'member_type', :locals => { :type => 'state', :zone_form => zone_form } %> -
    - <%= render :partial => 'spree/admin/shared/edit_resource_links' %> -
    -<% end %> diff --git a/app/views/spree/admin/zones/edit.html.haml b/app/views/spree/admin/zones/edit.html.haml new file mode 100644 index 0000000000..4ef88128bc --- /dev/null +++ b/app/views/spree/admin/zones/edit.html.haml @@ -0,0 +1,18 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.editing_zone") + +- content_for :page_actions do + %li + = button_link_to t("spree.back_to_zones_list"), admin_zones_path, icon: 'icon-arrow-left' + += render partial: 'spree/shared/error_messages', locals: { target: @zone } + += form_for [:admin, @zone] do |zone_form| + %fieldset.no-border-top + = render partial: 'form', locals: { zone_form: zone_form } + = render partial: 'member_type', locals: { type: 'country', zone_form: zone_form } + = render partial: 'member_type', locals: { type: 'state', zone_form: zone_form } + .clear + = render partial: 'spree/admin/shared/edit_resource_links' diff --git a/app/views/spree/admin/zones/index.html.erb b/app/views/spree/admin/zones/index.html.erb deleted file mode 100644 index 19b081b19b..0000000000 --- a/app/views/spree/admin/zones/index.html.erb +++ /dev/null @@ -1,53 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:zones) %> -<% end %> - -<% content_for :page_actions do %> -
  • - <%= button_link_to Spree.t(:new_zone), new_object_url, :icon => 'icon-plus', :id => 'admin_new_zone_link' %> -
  • -<% end %> - -<%= paginate @zones %> - -<% if @zones.empty? %> -
    - <%= Spree.t(:none) %> -
    -<% else %> - - - - - - - - - - - - - - - - - <% @zones.each do |zone| %> - - - - - - - <% end %> - -
    <%= sort_link @search,:name, Spree.t(:name), :title => 'zones_order_by_name_title' %> - <%= sort_link @search,:description, Spree.t(:description), {}, {:title => 'zones_order_by_description_title'} %> - <%= Spree.t(:default_tax) %>
    <%=zone.name %><%=zone.description %><%=zone.default_tax %> - <%=link_to_edit zone, :no_text => true %> - <%=link_to_delete zone, :no_text => true %> -
    -<% end%> - -<%= paginate @zones %> diff --git a/app/views/spree/admin/zones/index.html.haml b/app/views/spree/admin/zones/index.html.haml new file mode 100644 index 0000000000..29c1cd4211 --- /dev/null +++ b/app/views/spree/admin/zones/index.html.haml @@ -0,0 +1,41 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.zones") + +- content_for :page_actions do + %li + = button_link_to t("spree.new_zone"), new_object_url, icon: 'icon-plus', id: 'admin_new_zone_link' + += paginate @zones + +- if @zones.empty? + .no-objects-found + = t("spree.none") + +- else + %table#listing_zones.index + %colgroup + %col{style: "width: 30%"}/ + %col{style: "width: 40%"}/ + %col{style: "width: 15%"}/ + %col{style: "width: 15%"}/ + %thead + %tr + %th= sort_link @search,:name, t("spree.name"), title: 'zones_order_by_name_title' + %th + = sort_link @search,:description, t("spree.description"), {}, {title: 'zones_order_by_description_title'} + %th= t("spree.default_tax") + %th.actions + %tbody + - @zones.each do |zone| + - tr_class = cycle('odd', 'even') + - tr_id = spree_dom_id(zone) + %tr{class: tr_class, id: tr_id} + %td= zone.name + %td= zone.description + %td.align-center= zone.default_tax + %td.actions + = link_to_edit zone, no_text: true + = link_to_delete zone, no_text: true += paginate @zones diff --git a/app/views/spree/admin/zones/new.html.erb b/app/views/spree/admin/zones/new.html.erb deleted file mode 100644 index 36c0c0a2e1..0000000000 --- a/app/views/spree/admin/zones/new.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<%= render :partial => 'spree/admin/shared/configuration_menu' %> - -<% content_for :page_title do %> - <%= Spree.t(:new_zone) %> -<% end %> - -<% content_for :page_actions do %> -
  • - <%= button_link_to Spree.t(:back_to_zones_list), spree.admin_zones_path, :icon => 'icon-arrow-left' %> -
  • -<% end %> - -<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @zone } %> - -<%= form_for [:admin, @zone] do |zone_form| %> - <%= render :partial => 'form', :locals => { :zone_form => zone_form } %> - -
    - - <%= render :partial => 'spree/admin/shared/new_resource_links' %> -<% end %> diff --git a/app/views/spree/admin/zones/new.html.haml b/app/views/spree/admin/zones/new.html.haml new file mode 100644 index 0000000000..b6bac9e73b --- /dev/null +++ b/app/views/spree/admin/zones/new.html.haml @@ -0,0 +1,15 @@ += render partial: 'spree/admin/shared/configuration_menu' + +- content_for :page_title do + = t("spree.new_zone") + +- content_for :page_actions do + %li + = button_link_to t("spree.back_to_zones_list"), spree.admin_zones_path, icon: 'icon-arrow-left' + += render partial: 'spree/shared/error_messages', locals: { target: @zone } + += form_for [:admin, @zone] do |zone_form| + = render partial: 'form', locals: { zone_form: zone_form } + .clear + = render partial: 'spree/admin/shared/new_resource_links' From b2c4b97d94930740130e014b8bc1fb1d0d4c95d7 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 17:45:30 +0100 Subject: [PATCH 08/12] Bring spree/admin configuration routes to ofn --- config/routes/spree.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/routes/spree.rb b/config/routes/spree.rb index 94da909f8b..a06644de8f 100644 --- a/config/routes/spree.rb +++ b/config/routes/spree.rb @@ -88,6 +88,12 @@ Spree::Core::Engine.routes.prepend do put :clear_api_key end end + + resources :zones + resources :countries do + resources :states + end + resources :states end resources :orders do From 4954db64b3c051d969d4ec720918853db4d4a5d5 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:21:14 +0100 Subject: [PATCH 09/12] Bring feature specs for configuration pages from spree_backend --- .../admin/configuration/states_spec.rb | 78 +++++++++++++++++++ .../admin/configuration/zones_spec.rb | 39 ++++++++++ 2 files changed, 117 insertions(+) create mode 100755 spec/features/admin/configuration/states_spec.rb create mode 100644 spec/features/admin/configuration/zones_spec.rb diff --git a/spec/features/admin/configuration/states_spec.rb b/spec/features/admin/configuration/states_spec.rb new file mode 100755 index 0000000000..c3cd2b8205 --- /dev/null +++ b/spec/features/admin/configuration/states_spec.rb @@ -0,0 +1,78 @@ +require 'spec_helper' + +describe "States" do + stub_authorization! + + let!(:country) { create(:country) } + + before(:each) do + @hungary = Spree::Country.create!(:name => "Hungary", :iso_name => "Hungary") + Spree::Config[:default_country_id] = country.id + end + + # TODO: For whatever reason, rendering of the states page takes a non-trivial amount of time + # Therefore we navigate to it, and wait until what we see is visible + def go_to_states_page + visit spree.admin_country_states_path(country) + counter = 0 + until page.has_css?("#new_state_link") + if counter < 10 + sleep(2) + counter += 1 + else + raise "Could not see new state link!" + end + end + end + + context "admin visiting states listing" do + let!(:state) { create(:state, :country => country) } + + it "should correctly display the states" do + visit spree.admin_country_states_path(country) + page.should have_content(state.name) + end + end + + context "creating and editing states" do + it "should allow an admin to edit existing states", :js => true do + go_to_states_page + set_select2_field("country", country.id) + + click_link "new_state_link" + fill_in "state_name", :with => "Calgary" + fill_in "Abbreviation", :with => "CL" + click_button "Create" + page.should have_content("successfully created!") + page.should have_content("Calgary") + end + + it "should allow an admin to create states for non default countries", :js => true do + go_to_states_page + set_select2_field "#country", @hungary.id + # Just so the change event actually gets triggered in this spec + # It is definitely triggered in the "real world" + page.execute_script("$('#country').trigger('change');") + + click_link "new_state_link" + fill_in "state_name", :with => "Pest megye" + fill_in "Abbreviation", :with => "PE" + click_button "Create" + page.should have_content("successfully created!") + page.should have_content("Pest megye") + find("#s2id_country span").text.should == "Hungary" + end + + it "should show validation errors", :js => true do + go_to_states_page + set_select2_field("country", country.id) + + click_link "new_state_link" + + fill_in "state_name", :with => "" + fill_in "Abbreviation", :with => "" + click_button "Create" + page.should have_content("Name can't be blank") + end + end +end diff --git a/spec/features/admin/configuration/zones_spec.rb b/spec/features/admin/configuration/zones_spec.rb new file mode 100644 index 0000000000..7c5c8b4cc5 --- /dev/null +++ b/spec/features/admin/configuration/zones_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe "Zones" do + stub_authorization! + + before(:each) do + Spree::Zone.delete_all + visit spree.admin_path + click_link "Configuration" + end + + context "show" do + it "should display existing zones" do + create(:zone, :name => "eastern", :description => "zone is eastern") + create(:zone, :name => "western", :description => "cool san fran") + click_link "Zones" + + within_row(1) { page.should have_content("eastern") } + within_row(2) { page.should have_content("western") } + + click_link "zones_order_by_description_title" + + within_row(1) { page.should have_content("western") } + within_row(2) { page.should have_content("eastern") } + end + end + + context "create" do + it "should allow an admin to create a new zone" do + click_link "Zones" + click_link "admin_new_zone_link" + page.should have_content("New Zone") + fill_in "zone_name", :with => "japan" + fill_in "zone_description", :with => "japanese time zone" + click_button "Create" + page.should have_content("successfully created!") + end + end +end From 4a83eca8325be255be3e6ab24d7c781297494ac7 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:51:10 +0100 Subject: [PATCH 10/12] Fix feature specs added from spree_backend in the configuration area --- app/views/spree/admin/states/index.html.haml | 2 +- spec/features/admin/configuration/states_spec.rb | 5 +++-- spec/features/admin/configuration/zones_spec.rb | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/spree/admin/states/index.html.haml b/app/views/spree/admin/states/index.html.haml index 9010f8a94c..57035c79af 100644 --- a/app/views/spree/admin/states/index.html.haml +++ b/app/views/spree/admin/states/index.html.haml @@ -9,7 +9,7 @@ .field.row = label_tag :country, t("spree.country") - databaseurl = "#{admin_states_path(format: :js)}?country_id=" - %select#country.observe_field.select2.fullwidth{"data-base-url": databaseurl, "data-update": "#state-list"} + %select#country.observe_field.select2.fullwidth{"data-base-url" => databaseurl, "data-update" => "#state-list"} = options_from_collection_for_select(@countries, :id, :name, @country.id) = image_tag 'select2-spinner.gif', plugin: 'spree', style: 'display:none;', id: 'busy_indicator' #state-list diff --git a/spec/features/admin/configuration/states_spec.rb b/spec/features/admin/configuration/states_spec.rb index c3cd2b8205..10947611a9 100755 --- a/spec/features/admin/configuration/states_spec.rb +++ b/spec/features/admin/configuration/states_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper' describe "States" do - stub_authorization! + include AuthenticationWorkflow let!(:country) { create(:country) } before(:each) do + quick_login_as_admin @hungary = Spree::Country.create!(:name => "Hungary", :iso_name => "Hungary") Spree::Config[:default_country_id] = country.id end @@ -60,7 +61,7 @@ describe "States" do click_button "Create" page.should have_content("successfully created!") page.should have_content("Pest megye") - find("#s2id_country span").text.should == "Hungary" + find("#s2id_country span.select2-chosen").text.should == "Hungary" end it "should show validation errors", :js => true do diff --git a/spec/features/admin/configuration/zones_spec.rb b/spec/features/admin/configuration/zones_spec.rb index 7c5c8b4cc5..8a807e632e 100644 --- a/spec/features/admin/configuration/zones_spec.rb +++ b/spec/features/admin/configuration/zones_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' describe "Zones" do - stub_authorization! + include AuthenticationWorkflow before(:each) do + quick_login_as_admin Spree::Zone.delete_all visit spree.admin_path click_link "Configuration" From f9c6f09cd475fe6f7a4b7f50e2973837adbefbb7 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 17 Sep 2019 18:52:45 +0100 Subject: [PATCH 11/12] Transpec feature specs brought from spre_backend --- spec/features/admin/configuration/states_spec.rb | 14 +++++++------- spec/features/admin/configuration/zones_spec.rb | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/features/admin/configuration/states_spec.rb b/spec/features/admin/configuration/states_spec.rb index 10947611a9..cabae1fd1b 100755 --- a/spec/features/admin/configuration/states_spec.rb +++ b/spec/features/admin/configuration/states_spec.rb @@ -31,7 +31,7 @@ describe "States" do it "should correctly display the states" do visit spree.admin_country_states_path(country) - page.should have_content(state.name) + expect(page).to have_content(state.name) end end @@ -44,8 +44,8 @@ describe "States" do fill_in "state_name", :with => "Calgary" fill_in "Abbreviation", :with => "CL" click_button "Create" - page.should have_content("successfully created!") - page.should have_content("Calgary") + expect(page).to have_content("successfully created!") + expect(page).to have_content("Calgary") end it "should allow an admin to create states for non default countries", :js => true do @@ -59,9 +59,9 @@ describe "States" do fill_in "state_name", :with => "Pest megye" fill_in "Abbreviation", :with => "PE" click_button "Create" - page.should have_content("successfully created!") - page.should have_content("Pest megye") - find("#s2id_country span.select2-chosen").text.should == "Hungary" + expect(page).to have_content("successfully created!") + expect(page).to have_content("Pest megye") + expect(find("#s2id_country span.select2-chosen").text).to eq("Hungary") end it "should show validation errors", :js => true do @@ -73,7 +73,7 @@ describe "States" do fill_in "state_name", :with => "" fill_in "Abbreviation", :with => "" click_button "Create" - page.should have_content("Name can't be blank") + expect(page).to have_content("Name can't be blank") end end end diff --git a/spec/features/admin/configuration/zones_spec.rb b/spec/features/admin/configuration/zones_spec.rb index 8a807e632e..af722fedf1 100644 --- a/spec/features/admin/configuration/zones_spec.rb +++ b/spec/features/admin/configuration/zones_spec.rb @@ -16,13 +16,13 @@ describe "Zones" do create(:zone, :name => "western", :description => "cool san fran") click_link "Zones" - within_row(1) { page.should have_content("eastern") } - within_row(2) { page.should have_content("western") } + within_row(1) { expect(page).to have_content("eastern") } + within_row(2) { expect(page).to have_content("western") } click_link "zones_order_by_description_title" - within_row(1) { page.should have_content("western") } - within_row(2) { page.should have_content("eastern") } + within_row(1) { expect(page).to have_content("western") } + within_row(2) { expect(page).to have_content("eastern") } end end @@ -30,11 +30,11 @@ describe "Zones" do it "should allow an admin to create a new zone" do click_link "Zones" click_link "admin_new_zone_link" - page.should have_content("New Zone") + expect(page).to have_content("New Zone") fill_in "zone_name", :with => "japan" fill_in "zone_description", :with => "japanese time zone" click_button "Create" - page.should have_content("successfully created!") + expect(page).to have_content("successfully created!") end end end From 7d9de0ca7056c63752c0d49e8833220a9bf20572 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 20 Sep 2019 15:07:34 +0100 Subject: [PATCH 12/12] Fix rubocop issues in feature specs --- .../admin/configuration/states_spec.rb | 32 +++++++++---------- .../admin/configuration/zones_spec.rb | 8 ++--- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/spec/features/admin/configuration/states_spec.rb b/spec/features/admin/configuration/states_spec.rb index cabae1fd1b..b762b33c84 100755 --- a/spec/features/admin/configuration/states_spec.rb +++ b/spec/features/admin/configuration/states_spec.rb @@ -7,7 +7,7 @@ describe "States" do before(:each) do quick_login_as_admin - @hungary = Spree::Country.create!(:name => "Hungary", :iso_name => "Hungary") + @hungary = Spree::Country.create!(name: "Hungary", iso_name: "Hungary") Spree::Config[:default_country_id] = country.id end @@ -17,17 +17,15 @@ describe "States" do visit spree.admin_country_states_path(country) counter = 0 until page.has_css?("#new_state_link") - if counter < 10 - sleep(2) - counter += 1 - else - raise "Could not see new state link!" - end + raise "Could not see new state link!" if counter >= 10 + + sleep(2) + counter += 1 end end context "admin visiting states listing" do - let!(:state) { create(:state, :country => country) } + let!(:state) { create(:state, country: country) } it "should correctly display the states" do visit spree.admin_country_states_path(country) @@ -36,19 +34,19 @@ describe "States" do end context "creating and editing states" do - it "should allow an admin to edit existing states", :js => true do + it "should allow an admin to edit existing states", js: true do go_to_states_page set_select2_field("country", country.id) click_link "new_state_link" - fill_in "state_name", :with => "Calgary" - fill_in "Abbreviation", :with => "CL" + fill_in "state_name", with: "Calgary" + fill_in "Abbreviation", with: "CL" click_button "Create" expect(page).to have_content("successfully created!") expect(page).to have_content("Calgary") end - it "should allow an admin to create states for non default countries", :js => true do + it "should allow an admin to create states for non default countries", js: true do go_to_states_page set_select2_field "#country", @hungary.id # Just so the change event actually gets triggered in this spec @@ -56,22 +54,22 @@ describe "States" do page.execute_script("$('#country').trigger('change');") click_link "new_state_link" - fill_in "state_name", :with => "Pest megye" - fill_in "Abbreviation", :with => "PE" + fill_in "state_name", with: "Pest megye" + fill_in "Abbreviation", with: "PE" click_button "Create" expect(page).to have_content("successfully created!") expect(page).to have_content("Pest megye") expect(find("#s2id_country span.select2-chosen").text).to eq("Hungary") end - it "should show validation errors", :js => true do + it "should show validation errors", js: true do go_to_states_page set_select2_field("country", country.id) click_link "new_state_link" - fill_in "state_name", :with => "" - fill_in "Abbreviation", :with => "" + fill_in "state_name", with: "" + fill_in "Abbreviation", with: "" click_button "Create" expect(page).to have_content("Name can't be blank") end diff --git a/spec/features/admin/configuration/zones_spec.rb b/spec/features/admin/configuration/zones_spec.rb index af722fedf1..394b06c0a3 100644 --- a/spec/features/admin/configuration/zones_spec.rb +++ b/spec/features/admin/configuration/zones_spec.rb @@ -12,8 +12,8 @@ describe "Zones" do context "show" do it "should display existing zones" do - create(:zone, :name => "eastern", :description => "zone is eastern") - create(:zone, :name => "western", :description => "cool san fran") + create(:zone, name: "eastern", description: "zone is eastern") + create(:zone, name: "western", description: "cool san fran") click_link "Zones" within_row(1) { expect(page).to have_content("eastern") } @@ -31,8 +31,8 @@ describe "Zones" do click_link "Zones" click_link "admin_new_zone_link" expect(page).to have_content("New Zone") - fill_in "zone_name", :with => "japan" - fill_in "zone_description", :with => "japanese time zone" + fill_in "zone_name", with: "japan" + fill_in "zone_description", with: "japanese time zone" click_button "Create" expect(page).to have_content("successfully created!") end