diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb new file mode 100644 index 0000000000..a6ab1375f1 --- /dev/null +++ b/app/controllers/admin/order_cycles_controller.rb @@ -0,0 +1,10 @@ +module Admin + class OrderCyclesController < ResourceController + before_filter :load_order_cycle_set, :only => :index + + private + def load_order_cycle_set + @order_cycle_set = OrderCycleSet.new :collection => collection + end + end +end diff --git a/app/models/exchange.rb b/app/models/exchange.rb index 25e9ee2f37..154824415d 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -4,10 +4,10 @@ class Exchange < ActiveRecord::Base belongs_to :receiver, :class_name => 'Enterprise' belongs_to :payment_enterprise, :class_name => 'Enterprise' - has_many :exchange_variants + has_many :exchange_variants, :dependent => :destroy has_many :variants, :through => :exchange_variants - has_many :exchange_fees + has_many :exchange_fees, :dependent => :destroy has_many :enterprise_fees, :through => :exchange_fees validates_presence_of :order_cycle, :sender, :receiver diff --git a/app/models/order_cycle_set.rb b/app/models/order_cycle_set.rb new file mode 100644 index 0000000000..f83f40f029 --- /dev/null +++ b/app/models/order_cycle_set.rb @@ -0,0 +1,5 @@ +class OrderCycleSet < ModelSet + def initialize(attributes={}) + super(OrderCycle, OrderCycle.all, nil, attributes) + end +end diff --git a/app/overrides/add_order_cycles_admin_tab.rb b/app/overrides/add_order_cycles_admin_tab.rb new file mode 100644 index 0000000000..1d0dd9b3a8 --- /dev/null +++ b/app/overrides/add_order_cycles_admin_tab.rb @@ -0,0 +1,4 @@ +Deface::Override.new(:virtual_path => "spree/layouts/admin", + :name => "cms_order_cycles_tab", + :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]", + :text => "
  • <%= link_to('Order Cycles', main_app.admin_order_cycles_path) %>
  • ") diff --git a/app/views/admin/enterprise_fees/index.html.haml b/app/views/admin/enterprise_fees/index.html.haml index c52afb060c..82a133fa4f 100644 --- a/app/views/admin/enterprise_fees/index.html.haml +++ b/app/views/admin/enterprise_fees/index.html.haml @@ -1,3 +1,5 @@ +%h1 Enterprise Fees + = ng_form_for @enterprise_fee_set, :url => main_app.bulk_update_admin_enterprise_fees_path, :html => {'ng-app' => 'enterprise_fees', 'ng-controller' => 'AdminEnterpriseFeesCtrl'} do |enterprise_fee_set_form| - if @enterprise_fee_set.errors.present? %h2 Errors diff --git a/app/views/admin/order_cycles/index.html.haml b/app/views/admin/order_cycles/index.html.haml new file mode 100644 index 0000000000..b5bdf735c3 --- /dev/null +++ b/app/views/admin/order_cycles/index.html.haml @@ -0,0 +1,34 @@ +%h1 Order Cycles + += form_for @order_cycle_set, :url => main_app.bulk_update_admin_order_cycles_path do |f| + %table.index#listing_order_cycles + %thead + %tr + %th Name + %th Open + %th Close + %th Coordinator + %th Suppliers + %th Distributors + %th Products + %th + %tbody + = f.fields_for :collection do |order_cycle_form| + - order_cycle = order_cycle_form.object + %tr + %td= link_to order_cycle.name, main_app.edit_admin_order_cycle_path(order_cycle) + %td= order_cycle_form.text_field :orders_open_at, :class => 'datepicker', :value => order_cycle.orders_open_at + %td= order_cycle_form.text_field :orders_close_at, :class => 'datepicker', :value => order_cycle.orders_close_at + %td= order_cycle.coordinator.name + %td + - order_cycle.suppliers.each do |s| + = s.name + %br/ + %td + - order_cycle.distributors.each do |d| + = d.name + %br/ + %td.products + - order_cycle.variants.each do |v| + = image_tag(v.images.first.attachment.url(:mini)) if v.images.present? + %td diff --git a/config/routes.rb b/config/routes.rb index 0ad57b0304..7bbbf022f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,9 +9,14 @@ Openfoodweb::Application.routes.draw do end namespace :admin do + resources :order_cycles do + post :bulk_update, :on => :collection, :as => :bulk_update + end + resources :enterprises do post :bulk_update, :on => :collection, :as => :bulk_update end + resources :enterprise_fees do post :bulk_update, :on => :collection, :as => :bulk_update end diff --git a/spec/requests/admin/order_cycles_spec.rb b/spec/requests/admin/order_cycles_spec.rb new file mode 100644 index 0000000000..73273ed8d6 --- /dev/null +++ b/spec/requests/admin/order_cycles_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +feature %q{ + As an administrator + I want to manage order cycles +}, js: true do + include AuthenticationWorkflow + include WebHelper + + scenario "listing order cycles" do + oc = create(:order_cycle) + + login_to_admin_section + click_link 'Order Cycles' + + # Regular fields + page.should have_selector 'a', text: oc.name + + page.should have_selector "input[value='#{oc.orders_open_at}']" + page.should have_selector "input[value='#{oc.orders_close_at}']" + page.should have_content oc.coordinator.name + + # Suppliers and distributors + oc.suppliers.each { |s| page.should have_content s.name } + oc.distributors.each { |d| page.should have_content d.name } + + # Products + all('td.products img').count.should == 2 + end + +end