mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Position enterprise groups
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
table .blank-action {
|
||||
display: inline-block;
|
||||
width: 29px;
|
||||
}
|
||||
|
||||
#header #logo {
|
||||
top: 10px;
|
||||
}
|
||||
@@ -101,3 +106,9 @@ table#listing_payment_methods {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
table#listing_enterprise_groups {
|
||||
td.actions {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,24 @@ module Admin
|
||||
def index
|
||||
end
|
||||
|
||||
def move_up
|
||||
@enterprise_group = EnterpriseGroup.find params[:enterprise_group_id]
|
||||
@enterprise_group.move_higher
|
||||
redirect_to main_app.admin_enterprise_groups_path
|
||||
end
|
||||
|
||||
def move_down
|
||||
@enterprise_group = EnterpriseGroup.find params[:enterprise_group_id]
|
||||
@enterprise_group.move_lower
|
||||
redirect_to main_app.admin_enterprise_groups_path
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def collection
|
||||
EnterpriseGroup.by_position
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
class EnterpriseGroup < ActiveRecord::Base
|
||||
acts_as_list
|
||||
|
||||
has_and_belongs_to_many :enterprises
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
scope :by_position, order('position ASC')
|
||||
scope :on_front_page, where(on_front_page: true)
|
||||
end
|
||||
|
||||
@@ -17,9 +17,15 @@
|
||||
%tbody
|
||||
- @enterprise_groups.each do |enterprise_group|
|
||||
%tr
|
||||
%td= enterprise_group.name
|
||||
%td.name= enterprise_group.name
|
||||
%td= enterprise_group.on_front_page ? 'Y' : 'N'
|
||||
%td= enterprise_group.enterprises.map(&:name).join ', '
|
||||
%td.actions
|
||||
= link_to '', main_app.edit_admin_enterprise_group_path(enterprise_group), class: 'edit-enterprise-group icon-edit no-text'
|
||||
= link_to_delete enterprise_group, no_text: true
|
||||
|
||||
- if enterprise_group.last?
|
||||
.blank-action
|
||||
- else
|
||||
= link_to_with_icon 'icon-arrow-down', '', main_app.admin_enterprise_group_move_down_path(enterprise_group), class: 'move-down no-text'
|
||||
= link_to_with_icon 'icon-arrow-up', '', main_app.admin_enterprise_group_move_up_path(enterprise_group), class: 'move-up no-text' unless enterprise_group.first?
|
||||
|
||||
@@ -30,7 +30,10 @@ Openfoodnetwork::Application.routes.draw do
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
|
||||
resources :enterprise_groups
|
||||
resources :enterprise_groups do
|
||||
get :move_up
|
||||
get :move_down
|
||||
end
|
||||
end
|
||||
|
||||
get "new_landing_page", :controller => 'home', :action => "new_landing_page"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddPositionToEnterpriseGroups < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :enterprise_groups, :position, :integer
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20131024005253) do
|
||||
ActiveRecord::Schema.define(:version => 20131030031125) do
|
||||
|
||||
create_table "adjustment_metadata", :force => true do |t|
|
||||
t.integer "adjustment_id"
|
||||
@@ -173,6 +173,7 @@ ActiveRecord::Schema.define(:version => 20131024005253) do
|
||||
create_table "enterprise_groups", :force => true do |t|
|
||||
t.string "name"
|
||||
t.boolean "on_front_page"
|
||||
t.integer "position"
|
||||
end
|
||||
|
||||
create_table "enterprise_groups_enterprises", :id => false, :force => true do |t|
|
||||
|
||||
@@ -73,6 +73,20 @@ feature %q{
|
||||
eg.enterprises.should == [e2]
|
||||
end
|
||||
|
||||
scenario "re-ordering enterprise groups" do
|
||||
eg1 = create(:enterprise_group, name: 'A')
|
||||
eg2 = create(:enterprise_group, name: 'B')
|
||||
|
||||
click_link 'Configuration'
|
||||
click_link 'Enterprise Groups'
|
||||
|
||||
page.all('td.name').map(&:text).should == ['A', 'B']
|
||||
all("a.move-down").first.click
|
||||
page.all('td.name').map(&:text).should == ['B', 'A']
|
||||
all("a.move-up").last.click
|
||||
page.all('td.name').map(&:text).should == ['A', 'B']
|
||||
end
|
||||
|
||||
scenario "deleting an enterprise group", js: true do
|
||||
eg = create(:enterprise_group, name: 'EGEGEG')
|
||||
|
||||
|
||||
@@ -30,6 +30,14 @@ describe EnterpriseGroup do
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
it "orders enterprise groups by their position" do
|
||||
eg1 = create(:enterprise_group, position: 1)
|
||||
eg2 = create(:enterprise_group, position: 3)
|
||||
eg3 = create(:enterprise_group, position: 2)
|
||||
|
||||
EnterpriseGroup.by_position.should == [eg1, eg3, eg2]
|
||||
end
|
||||
|
||||
it "finds enterprise groups on the front page" do
|
||||
eg1 = create(:enterprise_group, on_front_page: true)
|
||||
eg2 = create(:enterprise_group, on_front_page: false)
|
||||
|
||||
Reference in New Issue
Block a user