Skip to content

Commit

Permalink
Merge pull request #2416 from camptocamp/displayquerywindow_no_prop
Browse files Browse the repository at this point in the history
Don't display features without properties
  • Loading branch information
fredj committed Mar 10, 2017
2 parents 847d39c + c0eb72a commit 331c4b0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 26 deletions.
28 changes: 25 additions & 3 deletions contribs/gmf/src/directives/displayquerywindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ gmf.DisplayquerywindowController = function($scope, ngeoQueryResult,
* @type {ngeox.QueryResult}
* @export
*/
this.ngeoQueryResult = ngeoQueryResult;

this.ngeoQueryResult = {
sources: [],
total: 0,
pending: false
};

/**
* @type {ngeo.FeatureHelper}
Expand Down Expand Up @@ -225,7 +228,8 @@ gmf.DisplayquerywindowController = function($scope, ngeoQueryResult,
return ngeoQueryResult;
},
function(newQueryResult, oldQueryResult) {
if (newQueryResult.total > 0) {
this.updateQueryResult_(newQueryResult);
if (this.ngeoQueryResult.total > 0) {
this.show();
} else if (oldQueryResult !== newQueryResult) {
this.close();
Expand Down Expand Up @@ -334,6 +338,24 @@ gmf.DisplayquerywindowController.prototype.next = function() {
};


/**
* Remove features without properties from the query result.
* @param {ngeox.QueryResult} queryResult ngeo query result.
* @private
*/
gmf.DisplayquerywindowController.prototype.updateQueryResult_ = function(queryResult) {
this.ngeoQueryResult.total = 0;
this.ngeoQueryResult.sources.length = 0;
for (var i = 0; i < queryResult.sources.length; i++) {
var source = queryResult.sources[i];
source.features = source.features.filter(function(feature) {
return !ol.obj.isEmpty(this.ngeoFeatureHelper_.getFilteredFeatureValues(feature));
}, this);
this.ngeoQueryResult.sources.push(source);
this.ngeoQueryResult.total += source.features.length;
}
};

/**
* Get the total count of features in the result of the query. If a source
* has been select, only the number of features of that source are returned.
Expand Down
56 changes: 33 additions & 23 deletions contribs/gmf/test/spec/directives/displayquerywindow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ describe('gmf.displayquerywindowDirective', function() {
ngeoQueryResult.total = 2;
ngeoQueryResult.sources = [{
features: [
new ol.Feature(),
new ol.Feature()
new ol.Feature({
foo: 'bar'
}),
new ol.Feature({
bar: 'baz'
})
],
id: 123,
label: 'Test',
Expand All @@ -65,8 +69,12 @@ describe('gmf.displayquerywindowDirective', function() {
ngeoQueryResult.total = 5;
ngeoQueryResult.sources = [{
features: [
new ol.Feature(),
new ol.Feature()
new ol.Feature({
foo: 'bar'
}),
new ol.Feature({
bar: 'baz'
})
],
id: 123,
label: 'Test 1',
Expand All @@ -80,9 +88,13 @@ describe('gmf.displayquerywindowDirective', function() {
queried: true
}, {
features: [
new ol.Feature({
foo: 'bar'
}),
new ol.Feature(),
new ol.Feature(),
new ol.Feature()
new ol.Feature({
bar: 'baz'
})
],
id: 345,
label: 'Test 3',
Expand All @@ -103,16 +115,12 @@ describe('gmf.displayquerywindowDirective', function() {
displayQueriesController.next();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[1]);
displayQueriesController.next();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[2]);
displayQueriesController.next();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[0].features[0]);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[0]);

displayQueriesController.previous();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[2]);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[2]);
displayQueriesController.previous();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[1]);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[2]);
displayQueriesController.previous();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[0]);
displayQueriesController.previous();
Expand All @@ -126,8 +134,12 @@ describe('gmf.displayquerywindowDirective', function() {
ngeoQueryResult.total = 5;
ngeoQueryResult.sources = [{
features: [
new ol.Feature(),
new ol.Feature()
new ol.Feature({
foo: 'bar'
}),
new ol.Feature({
bar: 'baz'
})
],
id: 123,
label: 'Test 1',
Expand All @@ -141,9 +153,13 @@ describe('gmf.displayquerywindowDirective', function() {
queried: true
}, {
features: [
new ol.Feature({
foo: 'bar'
}),
new ol.Feature(),
new ol.Feature(),
new ol.Feature()
new ol.Feature({
bar: 'baz'
})
],
id: 345,
label: 'Test 3',
Expand Down Expand Up @@ -181,32 +197,26 @@ describe('gmf.displayquerywindowDirective', function() {

// select the 3rd source
displayQueriesController.setSelectedSource(ngeoQueryResult.sources[2]);
expect(displayQueriesController.getResultLength()).toBe(3);
expect(displayQueriesController.getResultLength()).toBe(2);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[2]);
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[0]);

displayQueriesController.next();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[1]);
displayQueriesController.next();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[2]);
displayQueriesController.next();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[0]);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[2]);

displayQueriesController.previous();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[2]);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[2]);
displayQueriesController.previous();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[1]);
displayQueriesController.previous();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[0]);
displayQueriesController.previous();
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[2].features[2]);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[2]);

// show results for all sources
displayQueriesController.setSelectedSource(null);
expect(displayQueriesController.getResultLength()).toBe(5);
expect(displayQueriesController.getResultLength()).toBe(4);
expect(displayQueriesController.source).toBe(ngeoQueryResult.sources[0]);
expect(displayQueriesController.feature).toBe(ngeoQueryResult.sources[0].features[0]);
});
Expand Down

0 comments on commit 331c4b0

Please sign in to comment.