Admin list order cycles

This commit is contained in:
Rohan Mitchell
2012-11-27 10:13:12 +11:00
parent 47c28e65a7
commit d5310452b6
8 changed files with 93 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
class OrderCycleSet < ModelSet
def initialize(attributes={})
super(OrderCycle, OrderCycle.all, nil, attributes)
end
end

View File

@@ -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 => "<li><%= link_to('Order Cycles', main_app.admin_order_cycles_path) %></li>")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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