Files
openfoodnetwork/app/assets/javascripts/darkswarm/controllers/enterprises_controller.js.coffee
Maikel Linke 73041e9263 Show shop profiles without closed shops
The filter for closed shops was filtering profiles as well. That made it
impossible to show profiles without showing closed shops as well.

Replacing the filter for closed shops fixes the "show profiles" feature.

Fixes https://github.com/openfoodfoundation/openfoodnetwork/issues/1718
2017-09-22 12:53:21 +10:00

82 lines
2.7 KiB
CoffeeScript

Darkswarm.controller "EnterprisesCtrl", ($scope, $rootScope, $timeout, $location, Enterprises, Search, $document, HashNavigation, FilterSelectorsService, EnterpriseModal, enterpriseMatchesNameQueryFilter, distanceWithinKmFilter) ->
$scope.Enterprises = Enterprises
$scope.producers_to_filter = Enterprises.producers
$scope.filterSelectors = FilterSelectorsService.createSelectors()
$scope.query = Search.search()
$scope.openModal = EnterpriseModal.open
$scope.activeTaxons = []
$scope.show_profiles = false
$scope.show_closed = false
$scope.filtersActive = false
$scope.distanceMatchesShown = false
$scope.$watch "query", (query)->
Enterprises.flagMatching query
Search.search query
$rootScope.$broadcast 'enterprisesChanged'
$scope.distanceMatchesShown = false
$timeout ->
Enterprises.calculateDistance query, $scope.firstNameMatch()
$rootScope.$broadcast 'enterprisesChanged'
$timeout ->
if $location.search()['show_closed']?
$scope.showClosedShops()
$scope.$watch "filtersActive", (value) ->
$scope.$broadcast 'filtersToggled'
$rootScope.$on "enterprisesChanged", ->
$scope.filterEnterprises()
$scope.updateVisibleMatches()
# When filter settings change, this could change which name match is at the top, or even
# result in no matches. This affects the reference point that the distance matches are
# calculated from, so we need to recalculate distances.
$scope.$watch '[activeTaxons, activeProperties, shippingTypes, show_profiles, show_closed]', ->
$timeout ->
Enterprises.calculateDistance $scope.query, $scope.firstNameMatch()
$rootScope.$broadcast 'enterprisesChanged'
, true
$rootScope.$on "$locationChangeSuccess", (newRoute, oldRoute) ->
if HashNavigation.active "hubs"
$document.scrollTo $("#hubs"), 100, 200
$scope.filterEnterprises = ->
es = Enterprises.hubs
$scope.nameMatches = enterpriseMatchesNameQueryFilter(es, true)
noNameMatches = enterpriseMatchesNameQueryFilter(es, false)
$scope.distanceMatches = distanceWithinKmFilter(noNameMatches, 50)
$scope.updateVisibleMatches = ->
$scope.visibleMatches = if $scope.nameMatches.length == 0 || $scope.distanceMatchesShown
$scope.nameMatches.concat $scope.distanceMatches
else
$scope.nameMatches
$scope.showDistanceMatches = ->
$scope.distanceMatchesShown = true
$scope.updateVisibleMatches()
$scope.firstNameMatch = ->
if $scope.nameMatchesFiltered?
$scope.nameMatchesFiltered[0]
else
undefined
$scope.showClosedShops = ->
$scope.show_closed = true
$location.search('show_closed', '1')
$scope.hideClosedShops = ->
$scope.show_closed = false
$location.search('show_closed', null)