mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-26 05:55:15 +00:00
Display count of dirty variant overrides
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, StatusMessage, hubs, producers, hubPermissions, VariantOverrides) ->
|
||||
angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, StatusMessage, hubs, producers, hubPermissions, VariantOverrides, DirtyVariantOverrides) ->
|
||||
$scope.hubs = hubs
|
||||
$scope.hub = null
|
||||
$scope.products = []
|
||||
@@ -31,6 +31,11 @@ angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Ind
|
||||
|
||||
|
||||
$scope.displayDirty = ->
|
||||
if DirtyVariantOverrides.count() > 0
|
||||
num = if DirtyVariantOverrides.count() == 1 then "one override" else "#{DirtyVariantOverrides.count()} overrides"
|
||||
StatusMessage.display 'notice', "Changes to #{num} remain unsaved."
|
||||
else
|
||||
StatusMessage.clear()
|
||||
|
||||
|
||||
$scope.update = ->
|
||||
|
||||
@@ -5,3 +5,9 @@ angular.module("ofn.admin").factory "DirtyVariantOverrides", ->
|
||||
add: (vo) ->
|
||||
@dirtyVariantOverrides[vo.hub_id] ||= {}
|
||||
@dirtyVariantOverrides[vo.hub_id][vo.variant_id] = vo
|
||||
|
||||
count: ->
|
||||
count = 0
|
||||
for hub_id, vos of @dirtyVariantOverrides
|
||||
count += Object.keys(vos).length
|
||||
count
|
||||
@@ -38,3 +38,24 @@ describe "maintaining a list of dirty variant overrides", ->
|
||||
hub_id: 2
|
||||
price: 3
|
||||
count_on_hand: 4
|
||||
|
||||
it "counts dirty variant overrides", ->
|
||||
DirtyVariantOverrides.dirtyVariantOverrides =
|
||||
2:
|
||||
1:
|
||||
variant_id: 5
|
||||
hub_id: 6
|
||||
price: 7
|
||||
count_on_hand: 8
|
||||
3:
|
||||
variant_id: 9
|
||||
hub_id: 10
|
||||
price: 11
|
||||
count_on_hand: 12
|
||||
4:
|
||||
5:
|
||||
variant_id: 13
|
||||
hub_id: 14
|
||||
price: 15
|
||||
count_on_hand: 16
|
||||
expect(DirtyVariantOverrides.count()).toEqual 3
|
||||
|
||||
Reference in New Issue
Block a user