Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only run this.search() when a query is set #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dist/elasticui.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ declare module elasticui.filters {
constructor();
}
}
declare module elasticui.controllers {
var controllers: ng.IModule;
}
declare module elasticui.controllers {
interface IAggregationScope extends IIndexScope {
aggResult: any;
Expand Down Expand Up @@ -172,6 +175,7 @@ declare module elasticui.controllers {
loaded(): void;
static $inject: string[];
constructor($scope: any, $timeout: any, $window: any, es: services.ElasticService, $rootScope: any);
private isQuerySet();
private getSearchPromise();
private searchPromise;
private refreshPromise;
Expand Down
78 changes: 52 additions & 26 deletions dist/elasticui.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,13 @@ var elasticui;
filters.filters.filter('euiTimestamp', TimestampFilter);
})(filters = elasticui.filters || (elasticui.filters = {}));
})(elasticui || (elasticui = {}));
angular.module('elasticui.controllers', []).controller(elasticui.controllers);
var elasticui;
(function (elasticui) {
var controllers;
(function (_controllers) {
_controllers.controllers = angular.module('elasticui.controllers', []);
})(controllers = elasticui.controllers || (elasticui.controllers = {}));
})(elasticui || (elasticui = {}));
var elasticui;
(function (elasticui) {
var controllers;
Expand Down Expand Up @@ -625,36 +631,56 @@ var elasticui;
$scope.filters = this.filters;
$scope.$watchCollection('indexVM.filters.ejsObjects', function () {
_this.indexVM.page = 1;
_this.search();
if (_this.isQuerySet())
return _this.search();
});
$scope.$watchCollection('indexVM.aggregationProviders.objects', function () {
if (_this.isQuerySet())
return _this.search();
});
$scope.$watchCollection('indexVM.aggregationProviders.objects', function () { return _this.search(); });
$scope.$watch('indexVM.host', function () {
if (_this.indexVM.host != null && es.setHost(_this.indexVM.host)) {
if (_this.indexVM.host != null && es.setHost(_this.indexVM.host) && _this.isQuerySet()) {
_this.search();
}
});
$scope.$watch('indexVM.sort', function () {
_this.indexVM.page = 1;
_this.search();
if (_this.isQuerySet())
return _this.search();
});
$scope.$watch('indexVM.pageSize', function () {
_this.indexVM.page = 1;
_this.search();
if (_this.isQuerySet())
return _this.search();
});
$scope.$watch('indexVM.page', function () {
if (_this.isQuerySet())
return _this.search();
});
$scope.$watch('indexVM.index', function () {
if (_this.isQuerySet())
return _this.search();
});
$scope.$watch('indexVM.query', function () {
if (_this.isQuerySet())
return _this.search();
});
$scope.$watch('indexVM.highlight', function () {
if (_this.isQuerySet())
return _this.search();
});
$scope.$watch('indexVM.page', function () { return _this.search(); });
$scope.$watch('indexVM.index', function () { return _this.search(); });
$scope.$watch('indexVM.query', function () { return _this.search(); });
$scope.$watch('indexVM.highlight', function () { return _this.search(); });
$timeout(function () { return _this.loaded(); }, 200); // TODO: find better way to recognize loading of app
}
IndexController.prototype.loaded = function () {
if (!this.indexVM.loaded) {
this.indexVM.loaded = true;
if (this.indexVM.autoLoad) {
if (this.indexVM.autoLoad && this.isQuerySet()) {
this.search();
}
}
};
IndexController.prototype.isQuerySet = function () {
return this.indexVM.query != null;
};
IndexController.prototype.getSearchPromise = function () {
var request = ejs.Request();
for (var i = 0; i < this.indexVM.aggregationProviders.objects.length; i++) {
Expand Down Expand Up @@ -912,12 +938,12 @@ var elasticui;
var directive = {};
directive.restrict = 'E';
directive.scope = true;
directive.template = '\
<ul class="pager">\
<li ng-if="indexVM.page <= 1" class="disabled"><a href="">Previous</a></li>\
<li ng-if="indexVM.page > 1"><a href="" ng-click="indexVM.page=indexVM.page - 1">Previous</a></li>\
<li ng-if="indexVM.pageCount <= indexVM.page" class="disabled"><a href="">Next</a></li>\
<li ng-if="indexVM.pageCount > indexVM.page"><a href="" ng-click="indexVM.page=indexVM.page + 1">Next</a></li>\
directive.template = '\
<ul class="pager">\
<li ng-if="indexVM.page <= 1" class="disabled"><a href="">Previous</a></li>\
<li ng-if="indexVM.page > 1"><a href="" ng-click="indexVM.page=indexVM.page - 1">Previous</a></li>\
<li ng-if="indexVM.pageCount <= indexVM.page" class="disabled"><a href="">Next</a></li>\
<li ng-if="indexVM.pageCount > indexVM.page"><a href="" ng-click="indexVM.page=indexVM.page + 1">Next</a></li>\
</ul>';
return directive;
}
Expand Down Expand Up @@ -947,14 +973,14 @@ var elasticui;
scope.agg_name = scope.field.replace(/[^a-z_0-9]/gmi, "_") + "_" + (directives.default_agg_count++);
}
};
directive.template = '\
<ul class="nav nav-list" eui-aggregation="ejs.TermsAggregation(agg_name).field(field).size(size)">\
<li ng-repeat="bucket in aggResult.buckets">\
<label eui-filter="ejs.TermsFilter(field, bucket.key)">\
<span ng-if="!filter.enabled"><a href="" ng-click="filter.enabled=true">{{bucket.key}} <span class="muted">({{bucket.doc_count}})</span></a></span>\
<span ng-if="filter.enabled">{{bucket.key}} <a href="" ng-click="filter.enabled=false" class="facet-remove">x</a></span>\
</label>\
</li>\
directive.template = '\
<ul class="nav nav-list" eui-aggregation="ejs.TermsAggregation(agg_name).field(field).size(size)">\
<li ng-repeat="bucket in aggResult.buckets">\
<label eui-filter="ejs.TermsFilter(field, bucket.key)">\
<span ng-if="!filter.enabled"><a href="" ng-click="filter.enabled=true">{{bucket.key}} <span class="muted">({{bucket.doc_count}})</span></a></span>\
<span ng-if="filter.enabled">{{bucket.key}} <a href="" ng-click="filter.enabled=false" class="facet-remove">x</a></span>\
</label>\
</li>\
</ul>';
return directive;
}
Expand Down
1 change: 0 additions & 1 deletion dist/elasticui.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions dist/elasticui.min.js

Large diffs are not rendered by default.

57 changes: 46 additions & 11 deletions src/controllers/IndexController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module elasticui.controllers {
if (!this.indexVM.loaded) {
this.indexVM.loaded = true;

if (this.indexVM.autoLoad) {
if (this.indexVM.autoLoad && this.isQuerySet()) {
this.search();
}
}
Expand All @@ -43,20 +43,55 @@ module elasticui.controllers {
$scope.indexVM = this.indexVM;
$scope.ejs = $window.ejs; // so we can use ejs in attributes etc. TODO: better to have a ejs service instead of loading from window
$scope.filters = this.filters;
$scope.$watchCollection('indexVM.filters.ejsObjects', () => { this.indexVM.page = 1; this.search() });
$scope.$watchCollection('indexVM.aggregationProviders.objects', () => this.search());

$scope.$watch('indexVM.host', () => { if (this.indexVM.host != null && es.setHost(this.indexVM.host)) { this.search(); } });
$scope.$watch('indexVM.sort',() => { this.indexVM.page = 1; this.search() });
$scope.$watch('indexVM.pageSize',() => { this.indexVM.page = 1; this.search() });
$scope.$watch('indexVM.page', () => this.search());
$scope.$watch('indexVM.index', () => this.search());
$scope.$watch('indexVM.query', () => this.search());
$scope.$watch('indexVM.highlight', () => this.search());
$scope.$watchCollection('indexVM.filters.ejsObjects', () => {
this.indexVM.page = 1;
if (this.isQuerySet()) return this.search();
});

$scope.$watchCollection('indexVM.aggregationProviders.objects', () => {
if (this.isQuerySet()) return this.search();
});

$scope.$watch('indexVM.host', () => {
if (this.indexVM.host != null && es.setHost(this.indexVM.host) && this.isQuerySet()) {
this.search();
}
});

$scope.$watch('indexVM.sort',() => {
this.indexVM.page = 1;

if (this.isQuerySet()) return this.search();
});

$scope.$watch('indexVM.pageSize',() => {
if (this.isQuerySet()) return this.search();
});

$scope.$watch('indexVM.page', () => {
if (this.isQuerySet()) return this.search();
});

$scope.$watch('indexVM.index', () => {
if (this.isQuerySet()) return this.search();
});

$scope.$watch('indexVM.query', () => {
if (this.isQuerySet()) return this.search();
});

$scope.$watch('indexVM.highlight', () => {
if (this.isQuerySet()) return this.search();
});

$timeout(() => this.loaded(), 200); // TODO: find better way to recognize loading of app
}

private isQuerySet() {
return this.indexVM.query != null;
}

private getSearchPromise() {
var request = ejs.Request();

Expand Down Expand Up @@ -121,7 +156,7 @@ module elasticui.controllers {
var promiseToAbort = this.searchPromise;
this.searchPromise = null;
promiseToAbort.abort();
}
}

this.indexVM.loading = true;
this.searchPromise = this.getSearchPromise();
Expand Down