From c4f92fd4cc482ce3b2f88c74de36d99b7fe76f74 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 31 Mar 2016 15:45:25 +1100 Subject: [PATCH] Hide closed shops by default, add "show" button --- .../controllers/enterprises_controller.js.coffee | 7 +++++++ app/views/home/_hubs.html.haml | 4 ++++ app/views/home/_hubs_table.html.haml | 2 +- config/locales/en.yml | 2 ++ spec/features/consumer/shops_spec.rb | 10 +++++++++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee index ca4a8c45f4..fa11c0e92f 100644 --- a/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee @@ -8,6 +8,7 @@ Darkswarm.controller "EnterprisesCtrl", ($scope, $rootScope, $timeout, Enterpris $scope.show_profiles = false $scope.filtersActive = false $scope.distanceMatchesShown = false + $scope.filterExpression = {active: true} $scope.$watch "query", (query)-> @@ -65,3 +66,9 @@ Darkswarm.controller "EnterprisesCtrl", ($scope, $rootScope, $timeout, Enterpris $scope.nameMatchesFiltered[0] else undefined + + $scope.showClosedShops = -> + delete $scope.filterExpression['active'] + + $scope.hideClosedShops = -> + $scope.filterExpression['active'] = true diff --git a/app/views/home/_hubs.html.haml b/app/views/home/_hubs.html.haml index 3ff19a7a16..e899270efc 100644 --- a/app/views/home/_hubs.html.haml +++ b/app/views/home/_hubs.html.haml @@ -28,4 +28,8 @@ %a{href: "", "ng-click" => "showDistanceMatches()"} = t :hubs_distance_filter, location: "{{ nameMatchesFiltered[0].name }}" .more-controls + %a.button{href: "", ng: {click: "showClosedShops()", show: "filterExpression.active"}} + = t '.show_closed_shops' + %a.button{href: "", ng: {click: "hideClosedShops()", show: "!filterExpression.active"}} + = t '.hide_closed_shops' %a.button{href: main_app.map_path}= t '.show_on_map' diff --git a/app/views/home/_hubs_table.html.haml b/app/views/home/_hubs_table.html.haml index 13e95ef243..edf9eb5ec8 100644 --- a/app/views/home/_hubs_table.html.haml +++ b/app/views/home/_hubs_table.html.haml @@ -1,5 +1,5 @@ .active_table - %hub.active_table_node.row{"ng-repeat" => "hub in #{enterprises}Filtered = (#{enterprises} | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+distance', '+orders_close_at'])", + %hub.active_table_node.row{"ng-repeat" => "hub in #{enterprises}Filtered = (#{enterprises} | filter:filterExpression | taxons:activeTaxons | shipping:shippingTypes | showHubProfiles:show_profiles | orderBy:['-active', '+distance', '+orders_close_at'])", "ng-class" => "{'is_profile' : hub.category == 'hub_profile', 'closed' : !open(), 'open' : open(), 'inactive' : !hub.active, 'current' : current()}", "ng-controller" => "HubNodeCtrl", id: "{{hub.hash}}"} diff --git a/config/locales/en.yml b/config/locales/en.yml index 03c324eb39..9525b74e9d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -107,6 +107,8 @@ en: home: hubs: + show_closed_shops: "Show closed shops" + hide_closed_shops: "Hide closed shops" show_on_map: "Show all on the map" # Printable Invoice Columns diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb index faeff9c37d..4edaa702e0 100644 --- a/spec/features/consumer/shops_spec.rb +++ b/spec/features/consumer/shops_spec.rb @@ -26,9 +26,17 @@ feature 'Shops', js: true do page.should_not have_content invisible_distributor.name end - it "should grey out hubs that are not in an order cycle" do + it "should not show hubs that are not in an order cycle" do create(:simple_product, distributors: [d1, d2]) visit shops_path + page.should have_no_selector 'hub.inactive' + page.should have_no_selector 'hub', text: d2.name + end + + it "should show closed shops after clicking the button" do + create(:simple_product, distributors: [d1, d2]) + visit shops_path + click_link "Show closed shops" page.should have_selector 'hub.inactive' page.should have_selector 'hub.inactive', text: d2.name end