mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Admin list order cycles
This commit is contained in:
10
app/controllers/admin/order_cycles_controller.rb
Normal file
10
app/controllers/admin/order_cycles_controller.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
5
app/models/order_cycle_set.rb
Normal file
5
app/models/order_cycle_set.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class OrderCycleSet < ModelSet
|
||||
def initialize(attributes={})
|
||||
super(OrderCycle, OrderCycle.all, nil, attributes)
|
||||
end
|
||||
end
|
||||
4
app/overrides/add_order_cycles_admin_tab.rb
Normal file
4
app/overrides/add_order_cycles_admin_tab.rb
Normal 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>")
|
||||
@@ -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
|
||||
|
||||
34
app/views/admin/order_cycles/index.html.haml
Normal file
34
app/views/admin/order_cycles/index.html.haml
Normal 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
|
||||
@@ -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
|
||||
|
||||
31
spec/requests/admin/order_cycles_spec.rb
Normal file
31
spec/requests/admin/order_cycles_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user