Add bulk action checkboxes to BOM

This commit is contained in:
Rob H
2014-03-12 18:25:51 +11:00
parent 9230bce6bb
commit 9a291e28ec
4 changed files with 66 additions and 1 deletions

View File

@@ -157,6 +157,7 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
$scope.lineItems = $scope.orders.reduce (lineItems,order) ->
orderWithoutLineItems = $scope.lineItemOrder order
for i,line_item of order.line_items
line_item.checked = false
line_item.supplier = $scope.matchObject $scope.suppliers, line_item.supplier, null
line_item.order = orderWithoutLineItems
lineItems.concat order.line_items
@@ -190,6 +191,16 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
).success (data) ->
$scope.lineItems.splice $scope.lineItems.indexOf(lineItem), 1
lineItem.order.line_items.splice lineItem.order.line_items.indexOf(lineItem), 1
$scope.allBoxesChecked = ->
checkedCount = $scope.lineItems.reduce (count,lineItem) ->
count + (if lineItem.checked then 1 else 0 )
, 0
checkedCount == $scope.lineItems.length
$scope.toggleAllCheckboxes = ->
changeTo = !$scope.allBoxesChecked()
lineItem.checked = changeTo for lineItem in $scope.lineItems
]
orderManagementModule.filter "selectFilter", [

View File

@@ -45,6 +45,8 @@
%table.index#listing_orders.bulk
%thead
%tr
%th.bulk
%input{ :type => "checkbox", :name => 'toggle_bulk', 'ng-click' => 'toggleAllCheckboxes()', 'ng-checked' => "allBoxesChecked()" }
%th.full_name Name
%th.date Order Date
%th.producer Producer
@@ -55,6 +57,8 @@
Ask? 
%input{ :type => 'checkbox', 'ng-model' => "confirmDelete" }
%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.bulk
%input.bulk{ :type => "checkbox", 'ng-model' => 'line_item.checked' }
%td.full_name {{ line_item.order.full_name }}
%td.date {{ line_item.order.completed_at }}
%td.producer {{ line_item.supplier.name }}

View File

@@ -86,7 +86,7 @@ feature %q{
end
it "displays a column for variant description, which shows only product name when options text is blank" do
page.should have_selector "th.variant", text: "PRODUCT (UNIT): VAR", :visible => true
page.should have_selector "th.variant", text: "PRODUCT: UNIT", :visible => true
page.should have_selector "td.variant", text: li1.product.name, :visible => true
page.should have_selector "td.variant", text: (li2.product.name + ": " + li2.variant.options_text), :visible => true
end
@@ -349,6 +349,29 @@ feature %q{
end
end
context "bulk actions" do
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
let!(:o2) { 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 ) }
before :each do
visit '/admin/orders/bulk_management'
end
it "displays a checkbox for each line item in the list" do
page.should have_selector "tr#li_#{li1.id} input[type='checkbox'].bulk"
page.should have_selector "tr#li_#{li2.id} input[type='checkbox'].bulk"
end
it "displays a checkbox to which toggles the 'checked' state of all checkboxes" do
check "toggle_bulk"
page.all("input[type='checkbox'].bulk").each{ |checkbox| checkbox.checked?.should == true }
uncheck "toggle_bulk"
page.all("input[type='checkbox'].bulk").each{ |checkbox| checkbox.checked?.should == false }
end
end
context "using action buttons" do
context "using delete buttons" do
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }

View File

@@ -209,6 +209,33 @@ describe "AdminOrderMgmtCtrl", ->
httpBackend.flush()
expect(order.line_items).toEqual [line_item1, line_item2]
describe "check boxes for line items", ->
line_item1 = line_item2 = null
beforeEach ->
line_item1 = { name: "line item 1", checked: false }
line_item2 = { name: "line item 2", checked: false }
scope.lineItems = [ line_item1, line_item2 ]
it "keeps track of whether all lines items are 'checked' or not", ->
expect(scope.allBoxesChecked()).toEqual false
line_item1.checked = true
expect(scope.allBoxesChecked()).toEqual false
line_item2.checked = true
expect(scope.allBoxesChecked()).toEqual true
line_item1.checked = false
expect(scope.allBoxesChecked()).toEqual false
it "toggles the 'checked' attribute of all line items based to the value of allBoxesChecked", ->
scope.toggleAllCheckboxes()
expect(scope.allBoxesChecked()).toEqual true
line_item1.checked = false
expect(scope.allBoxesChecked()).toEqual false
scope.toggleAllCheckboxes()
expect(scope.allBoxesChecked()).toEqual true
scope.toggleAllCheckboxes()
expect(scope.allBoxesChecked()).toEqual false
describe "managing pending changes", ->
dataSubmitter = pendingChangesService = null