From 6ce89577492a550f67c734c2d9412ab2d864ba3b Mon Sep 17 00:00:00 2001 From: Juanfran Date: Thu, 19 Feb 2015 11:29:13 +0100 Subject: [PATCH] prevent location search if the url has the same parameters --- app/coffee/modules/base/location.coffee | 4 ++++ app/coffee/modules/controllerMixins.coffee | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/coffee/modules/base/location.coffee b/app/coffee/modules/base/location.coffee index f99f0391..a6c3fc46 100644 --- a/app/coffee/modules/base/location.coffee +++ b/app/coffee/modules/base/location.coffee @@ -28,6 +28,10 @@ locationFactory = ($location, $route, $rootscope) -> un() return $location + + $location.isInCurrentRouteParams = (name, value) -> + return $route.current.params[name] == value + return $location diff --git a/app/coffee/modules/controllerMixins.coffee b/app/coffee/modules/controllerMixins.coffee index cf63d08e..68cced92 100644 --- a/app/coffee/modules/controllerMixins.coffee +++ b/app/coffee/modules/controllerMixins.coffee @@ -62,7 +62,7 @@ taiga.PageMixin = PageMixin ############################################################################# ## Filters Mixin ############################################################################# -# This mixin requires @location ($tgLocation) and @scope +# This mixin requires @location ($tgLocation), and @scope class FiltersMixin selectFilter: (name, value, load=false) -> @@ -73,16 +73,19 @@ class FiltersMixin existing = _.compact(existing) value = joinStr(",", _.uniq(existing)) - location = if load then @location else @location.noreload(@scope) - location.search(name, value) + if !@location.isInCurrentRouteParams(name, value) + location = if load then @location else @location.noreload(@scope) + location.search(name, value) replaceFilter: (name, value, load=false) -> - location = if load then @location else @location.noreload(@scope) - location.search(name, value) + if !@location.isInCurrentRouteParams(name, value) + location = if load then @location else @location.noreload(@scope) + location.search(name, value) replaceAllFilters: (filters, load=false) -> - location = if load then @location else @location.noreload(@scope) - location.search(filters) + if !@location.isInCurrentRouteParams(name, value) + location = if load then @location else @location.noreload(@scope) + location.search(filters) unselectFilter: (name, value, load=false) -> params = @location.search()