mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Move distributors into sidebar for new & edit shipping methods screen
This commit is contained in:
@@ -2,6 +2,7 @@ module Spree
|
||||
module Admin
|
||||
ShippingMethodsController.class_eval do
|
||||
before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
|
||||
before_filter :load_hubs, only: [:new, :edit]
|
||||
|
||||
# Sort shipping methods by distributor name
|
||||
# ! Code copied from Spree::Admin::ResourceController with two added lines
|
||||
@@ -41,6 +42,11 @@ module Spree
|
||||
redirect_to collection_url and return
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_hubs
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@shipping_method.has_distributor? d) ? 0 : 1, d.name] }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,6 +34,10 @@ Spree::ShippingMethod.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def has_distributor?(distributor)
|
||||
self.distributors.include?(distributor)
|
||||
end
|
||||
|
||||
def adjustment_label
|
||||
'Shipping'
|
||||
end
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
/ insert_bottom "[data-hook='admin_shipping_method_form_availability_fields'] > fieldset"
|
||||
|
||||
= f.field_container :distributors do
|
||||
= f.label :distributor_ids, 'Distributors'
|
||||
- distributors = Enterprise.is_distributor.managed_by(spree_current_user) | f.object.distributors
|
||||
= f.collection_select(:distributor_ids, distributors, :id, :name, {include_blank: false}, {class: "select2 fullwidth", multiple: true})
|
||||
@@ -0,0 +1,3 @@
|
||||
/ insert_after "code[erb-loud]:contains(\"render :partial => 'form', :locals => { :f => f }\")"
|
||||
|
||||
= render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { :f => f }
|
||||
@@ -0,0 +1,3 @@
|
||||
/ insert_after "code[erb-loud]:contains(\"render :partial => 'form', :locals => { :f => f }\")"
|
||||
|
||||
= render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { :f => f }
|
||||
@@ -0,0 +1 @@
|
||||
remove "code[erb-loud]:contains(\"render :partial => 'spree/admin/shared/configuration_menu'\")"
|
||||
21
app/views/spree/admin/shared/_hubs_sidebar.html.haml
Normal file
21
app/views/spree/admin/shared/_hubs_sidebar.html.haml
Normal file
@@ -0,0 +1,21 @@
|
||||
- hubs_color = @hubs.count > 0 ? "blue" : "red"
|
||||
.sidebar_item.four.columns#hubs
|
||||
.four.columns.alpha.header{ class: "#{hubs_color}" }
|
||||
%span.four.columns.alpha.centered Distributors
|
||||
.four.columns.alpha.list{ class: "#{hubs_color}" }
|
||||
- if @hubs.count > 0
|
||||
-# = hidden_field_tag "enterprise[hub_ids][]", []
|
||||
- @hubs.each do |hub|
|
||||
%a.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(hub)}" }
|
||||
%span.three.columns.alpha
|
||||
= hub.name
|
||||
%span.one.column.omega
|
||||
= f.check_box :distributor_ids, { multiple: true }, hub.id, nil
|
||||
- else
|
||||
.four.columns.alpha.list-item
|
||||
%span.three.columns.alpha None Available
|
||||
%span.one.column.omega
|
||||
%span.icon-remove-sign
|
||||
%a.four.columns.alpha.button{ href: "#{main_app.admin_enterprises_path}", class: "#{hubs_color}" }
|
||||
MANAGE
|
||||
%span.icon-arrow-right
|
||||
@@ -21,8 +21,8 @@ feature 'shipping methods' do
|
||||
# When I create a shipping method and set the distributors
|
||||
visit spree.new_admin_shipping_method_path
|
||||
fill_in 'shipping_method_name', with: 'Carrier Pidgeon'
|
||||
select 'Aeronautical Adventures', from: 'shipping_method_distributor_ids'
|
||||
select 'Nautical Travels', from: 'shipping_method_distributor_ids'
|
||||
check "shipping_method_distributor_ids_#{d1.id}"
|
||||
check "shipping_method_distributor_ids_#{d2.id}"
|
||||
click_button 'Create'
|
||||
|
||||
# Then the shipping method should have its distributor set
|
||||
@@ -85,7 +85,7 @@ feature 'shipping methods' do
|
||||
|
||||
fill_in 'shipping_method_name', :with => 'Teleport'
|
||||
|
||||
select distributor1.name, :from => 'shipping_method_distributor_ids'
|
||||
check "shipping_method_distributor_ids_#{distributor1.id}"
|
||||
click_button 'Create'
|
||||
|
||||
flash_message.should == 'Shipping method "Teleport" has been successfully created!'
|
||||
|
||||
Reference in New Issue
Block a user