From 6247bd2541bb10f1edf4f6d4f503cce3f7ae3d75 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 15 Nov 2012 15:03:12 +1100 Subject: [PATCH] Display admin table of enterprise fees with enterprise, fee type and name columns --- .../admin/enterprise_fees_controller.rb | 10 ++++++++++ app/helpers/enterprise_fees_helper.rb | 5 +++++ app/models/enterprise_fee.rb | 2 +- .../admin/enterprise_fees/index.html.haml | 20 +++++++++++++++++++ config/routes.rb | 4 +++- spec/factories.rb | 3 +++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/enterprise_fees_controller.rb create mode 100644 app/helpers/enterprise_fees_helper.rb create mode 100644 app/views/admin/enterprise_fees/index.html.haml diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb new file mode 100644 index 0000000000..bdb74d59dd --- /dev/null +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -0,0 +1,10 @@ +module Admin + class EnterpriseFeesController < ResourceController + before_filter :load_enterprise_fees_set, :only => :index + + private + def load_enterprise_fees_set + @enterprise_fees_set = ModelSet.new EnterpriseFee.all, :collection => collection + end + end +end diff --git a/app/helpers/enterprise_fees_helper.rb b/app/helpers/enterprise_fees_helper.rb new file mode 100644 index 0000000000..2399a1737e --- /dev/null +++ b/app/helpers/enterprise_fees_helper.rb @@ -0,0 +1,5 @@ +module EnterpriseFeesHelper + def enterprise_fee_options + EnterpriseFee::FEE_TYPES.map { |f| [f.capitalize, f] } + end +end diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 04223ea586..ea5ba91446 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -1,7 +1,7 @@ class EnterpriseFee < ActiveRecord::Base belongs_to :enterprise - FEE_TYPES = %w(Packing Transport Admin Sales) + FEE_TYPES = %w(packing transport admin sales) validates_inclusion_of :fee_type, :in => FEE_TYPES validates_presence_of :name diff --git a/app/views/admin/enterprise_fees/index.html.haml b/app/views/admin/enterprise_fees/index.html.haml new file mode 100644 index 0000000000..bdac2f5ce5 --- /dev/null +++ b/app/views/admin/enterprise_fees/index.html.haml @@ -0,0 +1,20 @@ += form_for @enterprise_fees_set, :url => main_app.bulk_update_admin_enterprise_fees_path do |enterprise_fees_set_form| + %table.index#listing_enterprise_fees + %thead + %tr + %th Enterprise + %th Fee Type + %th Name + %th Calculator + %th Calculator values + %th + %tbody + = enterprise_fees_set_form.fields_for :collection do |f| + - enterprise_fee = f.object + %tr + %td= f.collection_select :enterprise_id, Enterprise.all, :id, :name + %td= f.select :fee_type, enterprise_fee_options + %td= f.text_field :name + %td TODO + %td TODO + %td TODO diff --git a/config/routes.rb b/config/routes.rb index 31871a0ecc..0ad57b0304 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,9 @@ Openfoodweb::Application.routes.draw do resources :enterprises do post :bulk_update, :on => :collection, :as => :bulk_update end - resources :enterprise_fees + resources :enterprise_fees do + post :bulk_update, :on => :collection, :as => :bulk_update + end end # Mount Spree's routes diff --git a/spec/factories.rb b/spec/factories.rb index d4b6504514..6b76ab47c7 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -21,6 +21,9 @@ FactoryGirl.define do end factory :enterprise_fee, :class => EnterpriseFee do + enterprise { Enterprise.first || FactoryGirl.create(:supplier_enterprise) } + fee_type 'packing' + name '$0.50 / kg' end factory :product_distribution, :class => ProductDistribution do