searchbar clean filters

This commit is contained in:
Daniel Herrero 2017-11-15 12:53:32 +01:00
parent d4a0cf205d
commit 44dde2b705
3 changed files with 17 additions and 10 deletions

View File

@ -1,8 +1,8 @@
import ngModule from '../module'; import ngModule from '../module';
export default class Controller { export default class Controller {
constructor($window) { constructor(sessionStorage) {
this.$window = $window; this.sessionStorage = sessionStorage;
// onSubmit() is defined by @vnSearchbar // onSubmit() is defined by @vnSearchbar
this.onSubmit = () => {}; this.onSubmit = () => {};
} }
@ -13,16 +13,16 @@ export default class Controller {
} }
$onChanges() { $onChanges() {
var value = JSON.parse(this.$window.sessionStorage.getItem('filter')); var value = this.sessionStorage.get('filter');
if (value !== undefined) if (value !== undefined)
this.filter = value; this.filter = value;
} }
setStorageValue() { 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', { ngModule.component('vnClientSearchPanel', {
template: require('./search-panel.html'), template: require('./search-panel.html'),

View File

@ -9,6 +9,6 @@
style="cursor: pointer;"> style="cursor: pointer;">
</vn-icon> </vn-icon>
<vn-button ng-if="$ctrl.label" vn-none label="{{$ctrl.label}}"></vn-button> <vn-button ng-if="$ctrl.label" vn-none label="{{$ctrl.label}}"></vn-button>
<vn-icon-button ng-if="!$ctrl.label" icon="search"></vn-icon-button> <vn-icon-button ng-if="!$ctrl.label" icon="search" ng-click="$ctrl.clearFilter()"></vn-icon-button>
</vn-horizontal> </vn-horizontal>
</form> </form>

View File

@ -1,15 +1,22 @@
import ngModule from '../../module'; import ngModule from '../../module';
export default class Controller { export default class Controller {
constructor($element, $scope, $document, $compile, vnPopover, $window) { constructor($element, $scope, $document, $compile, vnPopover, sessionStorage, $timeout) {
this.element = $element[0]; this.element = $element[0];
this.$scope = $scope; this.$scope = $scope;
this.$document = $document; this.$document = $document;
this.$compile = $compile; this.$compile = $compile;
this.vnPopover = vnPopover; this.vnPopover = vnPopover;
this.$window = $window; this.sessionStorage = sessionStorage;
this.$timeout = $timeout;
}
clearFilter() {
this.index.filter = {};
this.sessionStorage.remove('filter');
} }
onClick(event) { onClick(event) {
this.search = null;
this.child = this.vnPopover.showComponent(this.popover, this.$scope, this.element); 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? // 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; delete this.child;
} }
$onDestroy() { $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', { ngModule.component('vnSearchbar', {
template: require('./searchbar.html'), template: require('./searchbar.html'),