From 60ea59a0dc5942c28ac69a4d786eb695b4b36ffc Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 27 Oct 2016 13:15:46 -0700 Subject: [PATCH] Allow editing multiple stores --- .../admin/general_settings_controller.rb | 35 -------- .../spree/admin/stores_controller.rb | 23 ++++++ .../app/models/spree/backend_configuration.rb | 6 +- .../admin/general_settings/edit.html.erb | 80 ------------------- .../admin/shared/_configuration_menu.html.erb | 4 +- .../admin/shared/_settings_sub_menu.html.erb | 4 +- .../views/spree/admin/stores/_form.html.erb | 52 ++++++++++++ .../views/spree/admin/stores/edit.html.erb | 19 +++++ .../views/spree/admin/stores/index.html.erb | 41 ++++++++++ .../app/views/spree/admin/stores/new.html.erb | 15 ++++ backend/config/routes.rb | 2 +- ...general_settings_spec.rb => store_spec.rb} | 9 +-- core/config/locales/en.yml | 10 ++- 13 files changed, 169 insertions(+), 131 deletions(-) delete mode 100644 backend/app/controllers/spree/admin/general_settings_controller.rb create mode 100644 backend/app/controllers/spree/admin/stores_controller.rb delete mode 100644 backend/app/views/spree/admin/general_settings/edit.html.erb create mode 100644 backend/app/views/spree/admin/stores/_form.html.erb create mode 100644 backend/app/views/spree/admin/stores/edit.html.erb create mode 100644 backend/app/views/spree/admin/stores/index.html.erb create mode 100644 backend/app/views/spree/admin/stores/new.html.erb rename backend/spec/features/admin/configuration/{general_settings_spec.rb => store_spec.rb} (86%) diff --git a/backend/app/controllers/spree/admin/general_settings_controller.rb b/backend/app/controllers/spree/admin/general_settings_controller.rb deleted file mode 100644 index 66efd94617e..00000000000 --- a/backend/app/controllers/spree/admin/general_settings_controller.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Spree - module Admin - class GeneralSettingsController < Spree::Admin::BaseController - include Spree::Backend::Callbacks - - before_action :set_store - - def edit - end - - def update - if @store.update_attributes(store_params) - flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:general_settings)) - redirect_to edit_admin_general_settings_path - else - render :edit - end - end - - private - - def store_params - params.require(:store).permit(permitted_params) - end - - def permitted_params - Spree::PermittedAttributes.store_attributes - end - - def set_store - @store = current_store - end - end - end -end diff --git a/backend/app/controllers/spree/admin/stores_controller.rb b/backend/app/controllers/spree/admin/stores_controller.rb new file mode 100644 index 00000000000..c9ee06163fb --- /dev/null +++ b/backend/app/controllers/spree/admin/stores_controller.rb @@ -0,0 +1,23 @@ +module Spree + module Admin + class StoresController < Spree::Admin::ResourceController + def index + if Spree::Store.count == 1 + redirect_to edit_admin_store_path(Spree::Store.first) + else + @stores = Spree::Store.all + end + end + + private + + def store_params + params.require(:store).permit(permitted_params) + end + + def permitted_params + Spree::PermittedAttributes.store_attributes + end + end + end +end diff --git a/backend/app/models/spree/backend_configuration.rb b/backend/app/models/spree/backend_configuration.rb index 4fc05854572..c44a7956377 100644 --- a/backend/app/models/spree/backend_configuration.rb +++ b/backend/app/models/spree/backend_configuration.rb @@ -9,7 +9,7 @@ class BackendConfiguration < Preferences::Configuration :variants, :product_properties, :taxonomies, :taxons] REPORT_TABS ||= [:reports] - CONFIGURATION_TABS ||= [:configurations, :general_settings, :tax_categories, + CONFIGURATION_TABS ||= [:stores, :tax_categories, :tax_rates, :zones, :countries, :states, :payment_methods, :shipping_methods, :shipping_categories, :stock_locations, @@ -90,10 +90,10 @@ def menu_items MenuItem.new( CONFIGURATION_TABS, 'wrench', - condition: -> { can?(:admin, :general_settings) }, + condition: -> { can?(:admin, Spree::Store) }, label: :settings, partial: 'spree/admin/shared/settings_sub_menu', - url: :edit_admin_general_settings_path + url: :admin_stores_path ), MenuItem.new( PROMOTION_TABS, diff --git a/backend/app/views/spree/admin/general_settings/edit.html.erb b/backend/app/views/spree/admin/general_settings/edit.html.erb deleted file mode 100644 index aa45eac44d2..00000000000 --- a/backend/app/views/spree/admin/general_settings/edit.html.erb +++ /dev/null @@ -1,80 +0,0 @@ -<%= render 'spree/admin/shared/general_tabs' %> - -<% admin_breadcrumb(Spree.t(:settings)) %> -<% admin_breadcrumb(Spree.t(:general_settings)) %> -<%= form_for @store, url: admin_general_settings_path do |f| %> -
- -
- -
- <%= f.field_container :name do %> - <%= f.label :name %> - <%= f.text_field :name, class: 'fullwidth' %> - <%= f.error_message_on :name %> - <% end %> -
- -
- <%= f.field_container :seo_title do %> - <%= f.label :seo_title %> - <%= f.text_field :seo_title, class: 'fullwidth' %> - <%= f.error_message_on :seo_title %> - <% end %> -
- -
- <%= f.field_container :meta_keywords do %> - <%= f.label :meta_keywords %> - <%= f.text_field :meta_keywords, class: 'fullwidth' %> - <%= f.error_message_on :meta_keywords %> - <% end %> -
- -
- <%= f.field_container :meta_description do %> - <%= f.label :meta_description %> - <%= f.text_field :meta_description, class: 'fullwidth' %> - <%= f.error_message_on :meta_description %> - <% end %> -
- -
- <%= f.field_container :url do %> - <%= f.label :url %> - <%= f.text_field :url, class: 'fullwidth' %> - <%= f.error_message_on :url %> - <% end %> -
- -
- <%= f.field_container :mail_from_address do %> - <%= f.label :mail_from_address %> - <%= f.text_field :mail_from_address, class: 'fullwidth' %> - <%= f.error_message_on :mail_from_address %> - <% end %> -
- -
- <%= f.field_container :cart_tax_country_iso do %> - <%= f.field_hint :cart_tax_country_iso %> - <%= f.label :cart_tax_country_iso %> - <%= f.select :cart_tax_country_iso, - Spree::Country.all.map { |c| [c.name, c.iso] }, - { include_blank: t(".no_cart_tax_country") }, - { class: "select2 fullwidth" } %> - <%= f.error_message_on :cart_tax_country_iso %> - <% end %> -
- - <% if can? :update, :general_settings %> -
- <%= button Spree.t('actions.update') %> - <%= link_to Spree.t('actions.cancel'), edit_admin_general_settings_url, :class => 'button' %> -
- <% end %> - -
- -
-<% end %> diff --git a/backend/app/views/spree/admin/shared/_configuration_menu.html.erb b/backend/app/views/spree/admin/shared/_configuration_menu.html.erb index 691e81e8b61..fe28dbda2f1 100644 --- a/backend/app/views/spree/admin/shared/_configuration_menu.html.erb +++ b/backend/app/views/spree/admin/shared/_configuration_menu.html.erb @@ -4,8 +4,8 @@ <% content_for :tabs do %> diff --git a/backend/app/views/spree/admin/shared/_settings_sub_menu.html.erb b/backend/app/views/spree/admin/shared/_settings_sub_menu.html.erb index 8eeccb617d3..95e373ba49e 100644 --- a/backend/app/views/spree/admin/shared/_settings_sub_menu.html.erb +++ b/backend/app/views/spree/admin/shared/_settings_sub_menu.html.erb @@ -1,6 +1,6 @@