mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Can remove filters from BPE
This commit is contained in:
@@ -165,7 +165,7 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
$scope.$watch ->
|
||||
$scope.totalPages()
|
||||
, (newVal, oldVal) ->
|
||||
$scope.currentPage = $scope.totalPages() if newVal != oldVal && $scope.totalPages() < $scope.currentPage
|
||||
$scope.currentPage = Math.max $scope.totalPages(), 1 if newVal != oldVal && $scope.totalPages() < $scope.currentPage
|
||||
|
||||
$scope.initialise = (spree_api_key) ->
|
||||
authorise_api_reponse = ""
|
||||
@@ -252,6 +252,12 @@ productsApp.controller "AdminBulkProductsCtrl", [
|
||||
$scope.currentFilters.push filter
|
||||
$scope.fetchProducts()
|
||||
|
||||
$scope.removeFilter = (filter) ->
|
||||
index = $scope.currentFilters.indexOf(filter)
|
||||
if index != -1
|
||||
$scope.currentFilters.splice index, 1
|
||||
$scope.fetchProducts()
|
||||
|
||||
|
||||
$scope.editWarn = (product, variant) ->
|
||||
if ($scope.dirtyProductCount() > 0 and confirm("Unsaved changes will be lost. Continue anyway?")) or ($scope.dirtyProductCount() == 0)
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
{{ filter.predicate.name }}
|
||||
%div{ :class => "six columns omega" }
|
||||
{{ filter.value }}
|
||||
%div{ :class => "two columns omega" }
|
||||
%a{ 'ng-click' => "removeFilter(filter)" } Remove Filter
|
||||
%hr
|
||||
%div.loading{ 'ng-show' => 'loading' }
|
||||
%h4 Loading Products...
|
||||
|
||||
@@ -647,6 +647,25 @@ feature %q{
|
||||
page.should have_field "product_name", :with => "Product1"
|
||||
page.should_not have_field "product_name", :with => "Product2"
|
||||
end
|
||||
|
||||
describe "clicking the 'Remove Filter' link" do
|
||||
before(:each) do
|
||||
click_link "Remove Filter"
|
||||
end
|
||||
|
||||
it "removes the filter from the list of applied filters" do
|
||||
page.should_not have_text "Name Equals Product1"
|
||||
end
|
||||
|
||||
it "displays the 'loading' splash" do
|
||||
page.should have_selector "div.loading", :text => "Loading Products..."
|
||||
end
|
||||
|
||||
it "loads appropriate products" do
|
||||
page.should have_field "product_name", :with => "Product1"
|
||||
page.should have_field "product_name", :with => "Product2"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -931,8 +931,8 @@ describe "AdminBulkProductsCtrl", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product1"}
|
||||
filterObject2 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product2"}
|
||||
scope.addFilter(filterObject1)
|
||||
scope.addFilter(filterObject2)
|
||||
scope.addFilter filterObject1
|
||||
scope.addFilter filterObject2
|
||||
expect(scope.currentFilters).toEqual [filterObject1, filterObject2]
|
||||
|
||||
it "ignores objects sent to addFilter() which do not contain a 'property' with a corresponding key in filterableColumns", ->
|
||||
@@ -940,9 +940,9 @@ describe "AdminBulkProductsCtrl", ->
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "value1"}
|
||||
filterObject2 = {property: scope.filterableColumns[1], predicate: scope.filterTypes[0], value: "value2"}
|
||||
filterObject3 = {property: "some_random_property", predicate: scope.filterTypes[0], value: "value3"}
|
||||
scope.addFilter(filterObject1)
|
||||
scope.addFilter(filterObject2)
|
||||
scope.addFilter(filterObject3)
|
||||
scope.addFilter filterObject1
|
||||
scope.addFilter filterObject2
|
||||
scope.addFilter filterObject3
|
||||
expect(scope.currentFilters).toEqual [filterObject1, filterObject2]
|
||||
|
||||
it "ignores objects sent to addFilter() which do not contain a query with a corresponding key in filterTypes", ->
|
||||
@@ -950,9 +950,9 @@ describe "AdminBulkProductsCtrl", ->
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "value1"}
|
||||
filterObject2 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[1], value: "value2"}
|
||||
filterObject3 = {property: scope.filterableColumns[0], predicate: "something", value: "value3"}
|
||||
scope.addFilter(filterObject1)
|
||||
scope.addFilter(filterObject2)
|
||||
scope.addFilter(filterObject3)
|
||||
scope.addFilter filterObject1
|
||||
scope.addFilter filterObject2
|
||||
scope.addFilter filterObject3
|
||||
expect(scope.currentFilters).toEqual [filterObject1, filterObject2]
|
||||
|
||||
it "calls fetchProducts when adding a new filter", ->
|
||||
@@ -960,6 +960,27 @@ describe "AdminBulkProductsCtrl", ->
|
||||
scope.addFilter( { property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "value1" } )
|
||||
expect(scope.fetchProducts.calls.length).toEqual(1)
|
||||
|
||||
describe "removing a filter from the filter list", ->
|
||||
filterObject1 = filterObject2 = null
|
||||
|
||||
beforeEach ->
|
||||
filterObject1 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product1"}
|
||||
filterObject2 = {property: scope.filterableColumns[0], predicate: scope.filterTypes[0], value: "Product2"}
|
||||
scope.currentFilters = [ filterObject1, filterObject2 ]
|
||||
|
||||
it "removes the specified filter from $scope.currentFilters and calls fetchProducts", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
scope.removeFilter filterObject1
|
||||
expect(scope.currentFilters).toEqual [ filterObject2 ]
|
||||
expect(scope.fetchProducts.calls.length).toEqual 1
|
||||
|
||||
it "ignores filters which do not exist in currentFilters", ->
|
||||
spyOn(scope, "fetchProducts").andReturn "nothing"
|
||||
filterObject3 = {property: scope.filterableColumns[1], predicate: scope.filterTypes[1], value: "SomethingElse"}
|
||||
scope.removeFilter filterObject3
|
||||
expect(scope.currentFilters).toEqual [ filterObject1, filterObject2 ]
|
||||
expect(scope.fetchProducts.calls.length).toEqual 0
|
||||
|
||||
|
||||
describe "converting arrays of objects with ids to an object with ids as keys", ->
|
||||
it "returns an object", ->
|
||||
|
||||
Reference in New Issue
Block a user