mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-21 05:09:15 +00:00
BOM: and quick search
This commit is contained in:
@@ -114,6 +114,7 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
$scope.startDate = formatDate start
|
||||
$scope.endDate = formatDate end
|
||||
$scope.pendingChanges = pendingChanges
|
||||
$scope.quickSearch = ""
|
||||
|
||||
$scope.initialise = (spree_api_key) ->
|
||||
authorise_api_reponse = ""
|
||||
@@ -151,18 +152,23 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
$scope.orders = data
|
||||
$scope.resetLineItems()
|
||||
pendingChanges.removeAll()
|
||||
for i,order of $scope.orders
|
||||
order.distributor = $scope.matchObject $scope.distributors, order.distributor, null
|
||||
order.order_cycle = $scope.matchObject $scope.orderCycles, order.order_cycle, null
|
||||
|
||||
$scope.resetLineItems = ->
|
||||
$scope.lineItems = $scope.orders.reduce (lineItems,order) ->
|
||||
orderWithoutLineItems = $scope.lineItemOrder order
|
||||
for i,line_item of order.line_items
|
||||
line_item.supplier = $scope.matchObject $scope.suppliers, line_item.supplier, null
|
||||
line_item.order = order
|
||||
line_item.order = orderWithoutLineItems
|
||||
lineItems.concat order.line_items
|
||||
, []
|
||||
|
||||
$scope.lineItemOrder = (order) ->
|
||||
lineItemOrder = angular.copy(order)
|
||||
delete lineItemOrder.line_items
|
||||
lineItemOrder.distributor = $scope.matchObject $scope.distributors, order.distributor, null
|
||||
lineItemOrder.order_cycle = $scope.matchObject $scope.orderCycles, order.order_cycle, null
|
||||
lineItemOrder
|
||||
|
||||
$scope.matchOrderCycleEnterprises = (orderCycle) ->
|
||||
for i,distributor of orderCycle.distributors
|
||||
orderCycle.distributors[i] = $scope.matchObject $scope.distributors, distributor, null
|
||||
|
||||
@@ -6,30 +6,34 @@
|
||||
%div{ 'ng-app' => 'ofn.bulk_order_management', 'ng-controller' => 'AdminOrderMgmtCtrl', 'ng-init' => "initialise('#{@spree_api_key}');loading=true;" }
|
||||
%div{ 'ng-show' => '!spree_api_key_ok' }
|
||||
{{ api_error_msg }}
|
||||
.filter_selects{ :class => "four columns alpha" }
|
||||
.filter_select{ :class => "four columns alpha" }
|
||||
.filter_selects{ :class => "three columns alpha" }
|
||||
.filter_select{ :class => "three columns alpha" }
|
||||
%label{ :for => 'supplier_filter' }Producer
|
||||
%br
|
||||
%select.select2{ :class => "four columns alpha", :id => 'supplier_filter', 'ng-model' => 'supplierFilter', 'ng-options' => 's.name for s in suppliers' }
|
||||
.filter_select{ :class => "four columns alpha" }
|
||||
%select.select2{ :class => "three columns alpha", :id => 'supplier_filter', 'ng-model' => 'supplierFilter', 'ng-options' => 's.name for s in suppliers' }
|
||||
.filter_select{ :class => "three columns alpha" }
|
||||
%label{ :for => 'distributor_filter' }Hub
|
||||
%br
|
||||
%select.select2{ :class => "four columns alpha", :id => 'distributor_filter', 'ng-model' => 'distributorFilter', 'ng-options' => 'd.name for d in distributors'}
|
||||
.filter_select{ :class => "four columns alpha" }
|
||||
%select.select2{ :class => "three columns alpha", :id => 'distributor_filter', 'ng-model' => 'distributorFilter', 'ng-options' => 'd.name for d in distributors'}
|
||||
.filter_select{ :class => "three columns alpha" }
|
||||
%label{ :for => 'order_cycle_filter' }Order Cycle
|
||||
%br
|
||||
%select.select2{ :class => "four columns alpha", :id => 'order_cycle_filter', 'ng-model' => 'orderCycleFilter', 'ng-options' => 'oc.name for oc in orderCycles'}
|
||||
%select.select2{ :class => "three columns alpha", :id => 'order_cycle_filter', 'ng-model' => 'orderCycleFilter', 'ng-options' => 'oc.name for oc in orderCycles'}
|
||||
.spacer{ :class => "one column alpha" }
|
||||
|
||||
.date_filters{ :class => "four columns alpha" }
|
||||
.date_filter{ :class => "four columns alpha" }
|
||||
.date_filters{ :class => "three columns alpha" }
|
||||
.date_filter{ :class => "three columns alpha" }
|
||||
%label{ :for => 'start_date_filter' }Start Date
|
||||
%br
|
||||
%input{ :class => "four columns alpha", :type => "text", :id => 'start_date_filter', 'ng-model' => 'startDate', 'datetimepicker' => "startDate", 'ofn-confirm-change' => "startDate" }
|
||||
.date_filter{ :class => "four columns alpha" }
|
||||
%input{ :class => "three columns alpha", :type => "text", :id => 'start_date_filter', 'ng-model' => 'startDate', 'datetimepicker' => "startDate", 'ofn-confirm-change' => "startDate" }
|
||||
.date_filter{ :class => "three columns alpha" }
|
||||
%label{ :for => 'end_date_filter' }End Date
|
||||
%br
|
||||
%input{ :class => "four columns alpha", :type => "text", :id => 'end_date_filter', 'ng-model' => 'endDate', 'datetimepicker' => "endDate", 'ofn-confirm-change' => "endDate" }
|
||||
%input{ :class => "three columns alpha", :type => "text", :id => 'end_date_filter', 'ng-model' => 'endDate', 'datetimepicker' => "endDate", 'ofn-confirm-change' => "endDate" }
|
||||
.quick_search{ :class => "three columns alpha"}
|
||||
%label{ :for => 'quick_search' }Quick Search
|
||||
%br
|
||||
%input{ :class => "three columns alpha", :type => "text", :id => 'quick_search', 'ng-model' => 'quickSearch', :placeholder => 'Quick Search' }
|
||||
.spacer{ :class => "seven columns alpha" }
|
||||
|
||||
%hr{ :class => "sixteen columns alpha", :style => "margin-bottom: 15px" }
|
||||
@@ -50,7 +54,7 @@
|
||||
%th.actions
|
||||
Ask?
|
||||
%input{ :type => 'checkbox', 'ng-model' => "confirmDelete" }
|
||||
%tr.line_item{ 'ng-repeat' => 'line_item in lineItems | selectFilter:supplierFilter:distributorFilter:orderCycleFilter', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", :id => "li_{{line_item.id}}" }
|
||||
%tr.line_item{ 'ng-repeat' => 'line_item in lineItems | filter:quickSearch | selectFilter:supplierFilter:distributorFilter:orderCycleFilter:quickSearch', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", :id => "li_{{line_item.id}}" }
|
||||
%td.email {{ line_item.order.email }}
|
||||
%td.date {{ line_item.order.completed_at }}
|
||||
%td.producer {{ line_item.supplier.name }}
|
||||
|
||||
@@ -248,6 +248,33 @@ feature %q{
|
||||
end
|
||||
end
|
||||
|
||||
context "using quick search" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3 ) }
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
end
|
||||
|
||||
it "displays a quick search input" do
|
||||
page.should have_field "quick_search"
|
||||
end
|
||||
|
||||
it "filters line items based on their attributes and the contents of the quick search input" do
|
||||
page.should have_selector "tr#li_#{li1.id}", visible: true
|
||||
page.should have_selector "tr#li_#{li2.id}", visible: true
|
||||
page.should have_selector "tr#li_#{li3.id}", visible: true
|
||||
fill_in "quick_search", :with => o1.email
|
||||
page.should have_selector "tr#li_#{li1.id}", visible: true
|
||||
page.should_not have_selector "tr#li_#{li2.id}", visible: true
|
||||
page.should_not have_selector "tr#li_#{li3.id}", visible: true
|
||||
end
|
||||
end
|
||||
|
||||
context "using date restriction controls" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: (Date.today - 8).strftime("%F %T") ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
|
||||
@@ -70,17 +70,15 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
it "makes a call to $scope.resetLineItems", ->
|
||||
expect(scope.resetLineItems).toHaveBeenCalled()
|
||||
|
||||
it "calls matchObject twice for each order (once for distributor and once for order cycle)", ->
|
||||
expect(scope.matchObject.calls.length).toEqual scope.orders.length * 2
|
||||
|
||||
describe "resetting line items", ->
|
||||
order1 = order2 = order3 = null
|
||||
|
||||
beforeEach ->
|
||||
spyOn(scope, "matchObject").andReturn "nothing"
|
||||
order1 = { line_items: [ { name: "line_item1.1" }, { name: "line_item1.1" }, { name: "line_item1.1" } ] }
|
||||
order2 = { line_items: [ { name: "line_item2.1" }, { name: "line_item2.1" }, { name: "line_item2.1" } ] }
|
||||
order3 = { line_items: [ { name: "line_item3.1" }, { name: "line_item3.1" }, { name: "line_item3.1" } ] }
|
||||
spyOn(scope, "lineItemOrder").andReturn "copied order"
|
||||
order1 = { name: "order1", line_items: [ { name: "line_item1.1" }, { name: "line_item1.1" }, { name: "line_item1.1" } ] }
|
||||
order2 = { name: "order2", line_items: [ { name: "line_item2.1" }, { name: "line_item2.1" }, { name: "line_item2.1" } ] }
|
||||
order3 = { name: "order3", line_items: [ { name: "line_item3.1" }, { name: "line_item3.1" }, { name: "line_item3.1" } ] }
|
||||
scope.orders = [ order1, order2, order3 ]
|
||||
scope.resetLineItems()
|
||||
|
||||
@@ -90,14 +88,31 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
expect(scope.lineItems[3].name).toEqual "line_item2.1"
|
||||
expect(scope.lineItems[6].name).toEqual "line_item3.1"
|
||||
|
||||
it "adds a reference to the parent order to each line item", ->
|
||||
expect(scope.lineItems[0].order).toEqual order1
|
||||
expect(scope.lineItems[3].order).toEqual order2
|
||||
expect(scope.lineItems[6].order).toEqual order3
|
||||
it "adds a reference to a modified parent order object to each line item", ->
|
||||
expect(scope.lineItemOrder.calls.length).toEqual scope.orders.length
|
||||
expect("copied order").toEqual line_item.order for line_item in scope.lineItems
|
||||
|
||||
it "calls matchObject once for each line item", ->
|
||||
expect(scope.matchObject.calls.length).toEqual scope.lineItems.length
|
||||
|
||||
describe "copying orders", ->
|
||||
order1copy = null
|
||||
|
||||
beforeEach ->
|
||||
spyOn(scope, "lineItemOrder").andCallThrough()
|
||||
spyOn(scope, "matchObject").andReturn "matched object"
|
||||
order1 = { name: "order1", line_items: [ ] }
|
||||
scope.orders = [ order1 ]
|
||||
order1copy = scope.lineItemOrder order1
|
||||
|
||||
it "calls removes the line_items attribute of the order, in order to avoid circular referencing)", ->
|
||||
expect(order1copy.hasOwnProperty("line_items")).toEqual false
|
||||
|
||||
it "calls matchObject twice for each order (once for distributor and once for order cycle)", ->
|
||||
expect(scope.matchObject.calls.length).toEqual scope.lineItemOrder.calls.length * 2
|
||||
expect(order1copy.distributor).toEqual "matched object"
|
||||
expect(order1copy.distributor).toEqual "matched object"
|
||||
|
||||
describe "matching objects", ->
|
||||
it "returns the first matching object in the list", ->
|
||||
list_item1 =
|
||||
|
||||
Reference in New Issue
Block a user