Skip to content

Commit

Permalink
Using ofnSelect2 instead of plain select on BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
oeoeaio committed Aug 24, 2016
1 parent b97683a commit b2d82b6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ angular.module("admin.enterprises").factory 'Enterprises', ($q, EnterpriseResour
pristineByID: {}

index: (params={}, callback=null) ->
includeBlank = !!params['includeBlank']
delete params['includeBlank']
EnterpriseResource.index(params, (data) =>
for enterprise in data
@enterprisesByID[enterprise.id] = enterprise
@pristineByID[enterprise.id] = angular.copy(enterprise)

(callback || angular.noop)(data)

data.unshift(blankOption()) if includeBlank
data
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
LineItems.allSaved() || confirm(t("unsaved_changes_warning"))

$scope.resetSelectFilters = ->
$scope.distributorFilter = blankOption().id
$scope.supplierFilter = blankOption().id
$scope.orderCycleFilter = blankOption().id
$scope.distributorFilter = 0
$scope.supplierFilter = 0
$scope.orderCycleFilter = 0
$scope.quickSearch = ""

$scope.refreshData = ->
unless !$scope.orderCycleFilter? || $scope.orderCycleFilter == "0"
$scope.startDate = OrderCycles.orderCyclesByID[$scope.orderCycleFilter].first_order
$scope.endDate = OrderCycles.orderCyclesByID[$scope.orderCycleFilter].last_order
unless !$scope.orderCycleFilter? || $scope.orderCycleFilter == 0
$scope.startDate = OrderCycles.byID[$scope.orderCycleFilter].first_order
$scope.endDate = OrderCycles.byID[$scope.orderCycleFilter].last_order

RequestMonitor.load $scope.orders = Orders.index("q[state_not_eq]": "canceled", "q[completed_at_not_null]": "true", "q[completed_at_gt]": "#{parseDate($scope.startDate)}", "q[completed_at_lt]": "#{parseDate($scope.endDate)}")
RequestMonitor.load $scope.lineItems = LineItems.index("q[order][state_not_eq]": "canceled", "q[order][completed_at_not_null]": "true", "q[order][completed_at_gt]": "#{parseDate($scope.startDate)}", "q[order][completed_at_lt]": "#{parseDate($scope.endDate)}")

unless $scope.initialized
RequestMonitor.load $scope.distributors = Enterprises.index(includeBlank: true, action: "visible", ams_prefix: "basic", "q[sells_in][]": ["own", "any"])
RequestMonitor.load $scope.orderCycles = OrderCycles.index(includeBlank: true, ams_prefix: "basic", as: "distributor", "q[orders_close_at_gt]": "#{daysFromToday(-90)}")
RequestMonitor.load $scope.suppliers = Enterprises.index(includeBlank: true, action: "visible", ams_prefix: "basic", "q[is_primary_producer_eq]": "true")
RequestMonitor.load $scope.distributors = Enterprises.index(action: "visible", ams_prefix: "basic", "q[sells_in][]": ["own", "any"])
RequestMonitor.load $scope.orderCycles = OrderCycles.index(ams_prefix: "basic", as: "distributor", "q[orders_close_at_gt]": "#{daysFromToday(-90)}")
RequestMonitor.load $scope.suppliers = Enterprises.index(action: "visible", ams_prefix: "basic", "q[is_primary_producer_eq]": "true")

RequestMonitor.load $q.all([$scope.orders.$promise, $scope.distributors.$promise, $scope.orderCycles.$promise]).then ->
Dereferencer.dereferenceAttr $scope.orders, "distributor", Enterprises.enterprisesByID
Dereferencer.dereferenceAttr $scope.orders, "order_cycle", OrderCycles.orderCyclesByID
Dereferencer.dereferenceAttr $scope.orders, "order_cycle", OrderCycles.byID

RequestMonitor.load $q.all([$scope.orders.$promise, $scope.suppliers.$promise, $scope.lineItems.$promise]).then ->
Dereferencer.dereferenceAttr $scope.lineItems, "supplier", Enterprises.enterprisesByID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module("admin.lineItems").filter "selectFilter", (blankOption, RequestMo
return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle) ->
filtered = []
unless RequestMonitor.loading
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,"0") || lineItem.supplier.id == selectedSupplier) &&
(angular.equals(selectedDistributor,"0") || lineItem.order.distributor.id == selectedDistributor) &&
(angular.equals(selectedOrderCycle,"0") || lineItem.order.order_cycle.id == selectedOrderCycle)
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,0) || lineItem.supplier.id == selectedSupplier) &&
(angular.equals(selectedDistributor,0) || lineItem.order.distributor.id == selectedDistributor) &&
(angular.equals(selectedOrderCycle,0) || lineItem.order.order_cycle.id == selectedOrderCycle)
filtered
6 changes: 3 additions & 3 deletions app/views/spree/admin/orders/bulk_management.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
%label{ :for => 'supplier_filter' }
= t("admin.producer")
%br
%select{ :class => "three columns alpha", :id => 'supplier_filter', 'select2-min-search' => 5, 'ng-model' => 'supplierFilter', 'ng-options' => 's.id as s.name for s in suppliers' }
%input#supplier_filter.ofn-select2.fullwidth{ type: 'number', 'min-search' => 5, data: 'suppliers', blank: "{ id: '0', name: 'All' }", ng: { model: 'supplierFilter' } }
.filter_select{ :class => "three columns" }
%label{ :for => 'distributor_filter' }
= t("admin.shop")
%br
%select{ :class => "three columns alpha", :id => 'distributor_filter', 'select2-min-search' => 5, 'ng-model' => 'distributorFilter', 'ng-options' => 'd.id as d.name for d in distributors'}
%input#distributor_filter.ofn-select2.fullwidth{ type: 'number', 'min-search' => 5, data: 'distributors', blank: "{ id: '0', name: 'All' }", ng: { model: 'distributorFilter' } }
.filter_select{ :class => "three columns" }
%label{ :for => 'order_cycle_filter' }
= t("admin.order_cycle")
%br
%select{ :class => "three columns alpha", :id => 'order_cycle_filter', 'select2-min-search' => 5, 'ng-model' => 'orderCycleFilter', 'ng-options' => 'oc.id as oc.name for oc in orderCycles', 'confirm-change' => "confirmRefresh()", 'ng-change' => 'refreshData()'}
%input#order_cycle_filter.ofn-select2.fullwidth{ type: 'number', 'min-search' => 5, data: 'orderCycles', blank: "{ id: '0', name: 'All' }", on: { selecting: "confirmRefresh" }, ng: { model: 'orderCycleFilter', change: 'refreshData()' } }
.filter_clear{ :class => "two columns omega" }
%label{ :for => 'clear_all_filters' }
%br
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,14 @@ describe "Enterprises service", ->
expect(result).toDeepEqual response

describe "when params are passed", ->
describe "where includeBlank param is truthy", ->
beforeEach ->
params = {includeBlank: true, someParam: 'someVal'}
$httpBackend.expectGET('/admin/enterprises.json?someParam=someVal').respond 200, response
result = Enterprises.index(params)
$httpBackend.flush()

it "returns an array of enterprises, with a blank option appended to the beginning", ->
expect(result).toDeepEqual [{id: '0', name: 'All'} ,{ id: 5, name: 'Enterprise 1'}]

describe "where includeBlank param is falsey", ->
beforeEach ->
params = {includeBlank: false, someParam: 'someVal'}
$httpBackend.expectGET('/admin/enterprises.json?someParam=someVal').respond 200, response
result = Enterprises.index(params)
$httpBackend.flush()

it "returns an array of enterprises, with a blank option appended to the beginning", ->
expect(result).toDeepEqual response
beforeEach ->
params = { someParam: 'someVal'}
$httpBackend.expectGET('/admin/enterprises.json?someParam=someVal').respond 200, response
result = Enterprises.index(params)
$httpBackend.flush()

it "returns an array of enterprises", ->
expect(result).toDeepEqual response


describe "#save", ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ describe "LineItemsCtrl", ->
$timeout.flush()

describe "initialisation", ->
it "gets suppliers, adds a blank option as the first in the list", ->
expect(scope.suppliers).toDeepEqual [ { id : '0', name : 'All' }, supplier ]
it "gets suppliers", ->
expect(scope.suppliers).toDeepEqual [supplier ]

it "gets distributors, adds a blank option as the first in the list", ->
expect(scope.distributors).toDeepEqual [ { id : '0', name : 'All' }, distributor ]
it "gets distributors", ->
expect(scope.distributors).toDeepEqual [ distributor ]

it "stores enterprises in an list that is accessible by id", ->
expect(Enterprises.enterprisesByID[1]).toDeepEqual supplier

it "gets order cycles, adds a blank option as the first in the list", ->
expect(scope.orderCycles).toDeepEqual [ { id : '0', name : 'All' }, orderCycle ]
it "gets order cycles", ->
expect(scope.orderCycles).toDeepEqual [ orderCycle ]

it "gets orders, with dereferenced order cycles and distributors", ->
expect(scope.orders).toDeepEqual [ { id: 9, order_cycle: orderCycle, distributor: distributor, number: "R123456" } ]
Expand All @@ -85,9 +85,9 @@ describe "LineItemsCtrl", ->
expect(scope.RequestMonitor.loading).toBe false

it "resets the select filters", ->
expect(scope.distributorFilter).toBe '0'
expect(scope.supplierFilter).toBe '0'
expect(scope.orderCycleFilter).toBe '0'
expect(scope.distributorFilter).toBe 0
expect(scope.supplierFilter).toBe 0
expect(scope.orderCycleFilter).toBe 0
expect(scope.quickSearch).toBe = ""

it "resets the form state to pristine", ->
Expand Down

0 comments on commit b2d82b6

Please sign in to comment.