mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Create order cycle basic fields
This commit is contained in:
20
app/assets/javascripts/admin/order_cycle.js
Normal file
20
app/assets/javascripts/admin/order_cycle.js
Normal file
@@ -0,0 +1,20 @@
|
||||
function AdminOrderCycleCtrl($scope, $http) {
|
||||
$http.get('/admin/order_cycles/new.json').success(function(data) {
|
||||
$scope.order_cycle = data;
|
||||
});
|
||||
|
||||
$scope.submit = function() {
|
||||
$http.post('/admin/order_cycles', {order_cycle: $scope.order_cycle}).success(function(data) {
|
||||
if(data['success']) {
|
||||
window.location = '/admin/order_cycles';
|
||||
} else {
|
||||
console.log('fail');
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
angular.module('order_cycle', []).
|
||||
config(function($httpProvider) {
|
||||
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
|
||||
});
|
||||
@@ -9,6 +9,21 @@ module Admin
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@order_cycle = OrderCycle.new(params[:order_cycle])
|
||||
respond_to do |format|
|
||||
if @order_cycle.save
|
||||
flash[:notice] = 'Your order cycle has been created.'
|
||||
format.html { redirect_to admin_order_cycles_path }
|
||||
format.json { render :json => {:success => true} }
|
||||
else
|
||||
format.html
|
||||
format.json { render :json => {:success => false} }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
def load_order_cycle_set
|
||||
|
||||
@@ -5,7 +5,7 @@ class OrderCycle < ActiveRecord::Base
|
||||
|
||||
has_many :exchanges, :dependent => :destroy
|
||||
|
||||
validates_presence_of :name
|
||||
validates_presence_of :name, :coordinator_id
|
||||
|
||||
|
||||
def suppliers
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
.toolbar{'data-hook' => "toolbar"}
|
||||
%ul.actions
|
||||
%li
|
||||
= button_link_to "New Order Cycle", main_app.new_admin_order_cycle_path, :icon => 'add', :id => 'admin_new_order_cycle_link'
|
||||
%br.clear/
|
||||
|
||||
%h1 Order Cycles
|
||||
|
||||
= form_for @order_cycle_set, :url => main_app.bulk_update_admin_order_cycles_path do |f|
|
||||
|
||||
28
app/views/admin/order_cycles/new.html.haml
Normal file
28
app/views/admin/order_cycles/new.html.haml
Normal file
@@ -0,0 +1,28 @@
|
||||
%h1 New Order Cycle
|
||||
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {'ng-app' => 'order_cycle', 'ng-controller' => 'AdminOrderCycleCtrl', 'ng-submit' => 'submit()'} do |f|
|
||||
= f.label :name
|
||||
= f.text_field :name, 'ng-model' => 'order_cycle.name'
|
||||
%br/
|
||||
|
||||
= f.label :orders_open_at, 'Orders open'
|
||||
= f.text_field :orders_open_at, 'ng-model' => 'order_cycle.orders_open_at'
|
||||
= f.label :orders_close_at, 'Orders close'
|
||||
= f.text_field :orders_close_at, 'ng-model' => 'order_cycle.orders_close_at'
|
||||
%br/
|
||||
|
||||
%h2 Incoming
|
||||
%p TODO
|
||||
|
||||
%h2 Coordinator
|
||||
= f.label :coordinator_id, 'Coordinator'
|
||||
= f.collection_select :coordinator_id, Enterprise.all, :id, :name, {}, {'ng-model' => 'order_cycle.coordinator_id'}
|
||||
|
||||
%h2 Outgoing
|
||||
%p TODO
|
||||
|
||||
= f.submit 'Create'
|
||||
or
|
||||
= link_to 'Cancel', main_app.admin_order_cycles_path
|
||||
|
||||
%pre {{ order_cycle | json }}
|
||||
@@ -8,24 +8,51 @@ feature %q{
|
||||
include WebHelper
|
||||
|
||||
scenario "listing order cycles" do
|
||||
# Given an order cycle
|
||||
oc = create(:order_cycle)
|
||||
|
||||
# When I go to the admin order cycles page
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
|
||||
# Regular fields
|
||||
# Then I should see the basic 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
|
||||
# And I should see the suppliers and distributors
|
||||
oc.suppliers.each { |s| page.should have_content s.name }
|
||||
oc.distributors.each { |d| page.should have_content d.name }
|
||||
|
||||
# Products
|
||||
# And I should see a thumbnail image for each product
|
||||
all('td.products img').count.should == 2
|
||||
end
|
||||
|
||||
scenario "creating an order cycle" do
|
||||
# Given a coordinating enterprise
|
||||
create(:enterprise, name: 'My coordinator')
|
||||
|
||||
# When I go to the new order cycle page
|
||||
login_to_admin_section
|
||||
click_link 'Order Cycles'
|
||||
click_link 'New Order Cycle'
|
||||
|
||||
# And I fill in the basic fields and click Create
|
||||
fill_in 'order_cycle_name', with: 'Plums & Avos'
|
||||
fill_in 'order_cycle_orders_open_at', with: '2012-11-06 06:00:00'
|
||||
fill_in 'order_cycle_orders_close_at', with: '2012-11-13 17:00:00'
|
||||
select 'My coordinator', from: 'order_cycle_coordinator_id'
|
||||
click_button 'Create'
|
||||
|
||||
# Then my order cycle should have been created
|
||||
page.should have_content 'Your order cycle has been created.'
|
||||
|
||||
page.should have_selector 'a', text: 'Plums & Avos'
|
||||
|
||||
page.should have_selector "input[value='2012-11-06 06:00:00 UTC']"
|
||||
page.should have_selector "input[value='2012-11-13 17:00:00 UTC']"
|
||||
page.should have_content 'My coordinator'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user