ElasticUI icon indicating copy to clipboard operation
ElasticUI copied to clipboard

Remove query, filter, etc. on controller $destroy

Open tomykaira opened this issue 10 years ago • 3 comments

Current implementation seems to assume eui-filters are stable, but I am trying to dynamically add/remove them like elasticsearch-head does. It is not intuitive that a disappeared eui-filter is still in indexVM, and the user must reload the page to deactivate it. I appreciate if FilterController and its families add something like follows in init().

this.scope.$on '$destroy', (ev) =>
  this.scope.filter.enabled = false
  this.updateFilter()

tomykaira avatar Jan 27 '15 17:01 tomykaira

Thanks, that's good feedback on an issue I didn't run into myself yet. Do you think you could apply the changes and submit a PR? On Jan 27, 2015 6:09 PM, "tomykaira" [email protected] wrote:

Current implementation seems to assume eui-filters are stable, but I am trying to dynamically add/remove them like elasticsearch-head does. It is not intuitive that a disappeared eui-filter is still in indexVM, and the user must reload the page to deactivate it. I appreciate if FilterController and its families add something like follows in init().

this.scope.$on '$destroy', (ev) => this.scope.filter.enabled = false this.updateFilter()

Reply to this email directly or view it on GitHub https://github.com/YousefED/ElasticUI/issues/21.

YousefED avatar Jan 27 '15 17:01 YousefED

Sure! I am new to TypeScript, so please point out something is awkward.

tomykaira avatar Jan 28 '15 07:01 tomykaira

I think I have the same problem, when a eui-filter disappears it's still in indexVM.

I try to add like you said in FilterController.prototype.init

 FilterController.prototype.init = function() {
                var _this = this;
                if (this.scope.filter.filter) {
                    var isEnabled = this.scope.filters.contains(this.scope.filter.filter);
                    if (!isEnabled && this.scope.filter.enabled) {
                        this.scope.filters.add(this.scope.filter.filter);
                        isEnabled = true;
                    }
                }
                this.scope.filter.enabled = isEnabled;
                this.scope.$watch('filter.enabled', function(newVal, oldVal) {
                    if (newVal !== oldVal) {
                        _this.updateFilter();
                    }
                });
                this.scope.$watch('filter.filter', function(newVal, oldVal) {
                    if (!elasticui.util.EjsTool.equals(oldVal, newVal)) {
                        if (oldVal) {
                            _this.scope.filters.remove(oldVal);
                        }
                        _this.updateFilter();
                    }
                });
                this.scope.$on('$destroy', function() {
                    _this.scope.filter.enabled = false;
                    _this.updateFilter();
                });
            };

But when I checked one item filter.enabled always change on false.

devads avatar Nov 09 '15 17:11 devads