From 44dde2b705e5f40018a5bd7fac87a7edc042dc01 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 15 Nov 2017 12:53:32 +0100 Subject: [PATCH] searchbar clean filters --- client/client/src/search-panel/search-panel.js | 10 +++++----- .../salix/src/components/searchbar/searchbar.html | 2 +- .../salix/src/components/searchbar/searchbar.js | 15 +++++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/client/client/src/search-panel/search-panel.js b/client/client/src/search-panel/search-panel.js index 88aa89af3..3f78dc809 100644 --- a/client/client/src/search-panel/search-panel.js +++ b/client/client/src/search-panel/search-panel.js @@ -1,8 +1,8 @@ import ngModule from '../module'; export default class Controller { - constructor($window) { - this.$window = $window; + constructor(sessionStorage) { + this.sessionStorage = sessionStorage; // onSubmit() is defined by @vnSearchbar this.onSubmit = () => {}; } @@ -13,16 +13,16 @@ export default class Controller { } $onChanges() { - var value = JSON.parse(this.$window.sessionStorage.getItem('filter')); + var value = this.sessionStorage.get('filter'); if (value !== undefined) this.filter = value; } setStorageValue() { - this.$window.sessionStorage.setItem('filter', JSON.stringify(this.filter)); + this.sessionStorage.set('filter', this.filter); } } -Controller.$inject = ['$window']; +Controller.$inject = ['sessionStorage']; ngModule.component('vnClientSearchPanel', { template: require('./search-panel.html'), diff --git a/client/salix/src/components/searchbar/searchbar.html b/client/salix/src/components/searchbar/searchbar.html index 179c77f7a..d4636aaf1 100644 --- a/client/salix/src/components/searchbar/searchbar.html +++ b/client/salix/src/components/searchbar/searchbar.html @@ -9,6 +9,6 @@ style="cursor: pointer;"> - + \ No newline at end of file diff --git a/client/salix/src/components/searchbar/searchbar.js b/client/salix/src/components/searchbar/searchbar.js index 5f3ad79be..2f0864bf7 100644 --- a/client/salix/src/components/searchbar/searchbar.js +++ b/client/salix/src/components/searchbar/searchbar.js @@ -1,15 +1,22 @@ import ngModule from '../../module'; export default class Controller { - constructor($element, $scope, $document, $compile, vnPopover, $window) { + constructor($element, $scope, $document, $compile, vnPopover, sessionStorage, $timeout) { this.element = $element[0]; this.$scope = $scope; this.$document = $document; this.$compile = $compile; this.vnPopover = vnPopover; - this.$window = $window; + this.sessionStorage = sessionStorage; + this.$timeout = $timeout; + } + clearFilter() { + this.index.filter = {}; + this.sessionStorage.remove('filter'); } onClick(event) { + this.search = null; + this.child = this.vnPopover.showComponent(this.popover, this.$scope, this.element); // XXX: ¿Existe una forma más adecuada de acceder al controlador de un componente? @@ -37,10 +44,10 @@ export default class Controller { delete this.child; } $onDestroy() { - this.$window.sessionStorage.removeItem('filter'); + this.clearFilter(); } } -Controller.$inject = ['$element', '$scope', '$document', '$compile', 'vnPopover', '$window']; +Controller.$inject = ['$element', '$scope', '$document', '$compile', 'vnPopover', 'sessionStorage', '$timeout']; ngModule.component('vnSearchbar', { template: require('./searchbar.html'),