Skip to content

Commit

Permalink
Allow blank values in drop-down lists of unique values.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgee committed Sep 24, 2016
1 parent 04382ca commit 766a949
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
39 changes: 29 additions & 10 deletions widgets/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ define([
return null;
}
}
if (searchTerm === '*') {
if (searchTerm === '*' || searchTerm === null) {
searchTerm = '';
}
return searchTerm;
Expand Down Expand Up @@ -745,7 +745,7 @@ define([
});
// should actually only do this for the first control
if ((i === 0) && (j === 0)) {
this.getDistinctValues(inputId, layer.queryParameters.layerID, layer.queryParameters.sublayerID, field.name);
this.getDistinctValues(inputId, layer.queryParameters, field.name, field.includeBlankValue);
}
} else if (field.values) {
options = [];
Expand Down Expand Up @@ -920,7 +920,7 @@ define([
for (var k = 0; k < search.searchFields.length; k++) {
var field = search.searchFields[k];
if (field.unique) {
this.getDistinctValues(search.inputIds[k], layer.queryParameters.layerID, layer.queryParameters.sublayerID, field.name);
this.getDistinctValues(search.inputIds[k], layer.queryParameters, field.name, field.includeBlankValue);
}
}
domStyle.set(search.divName, 'display', 'block');
Expand All @@ -942,16 +942,35 @@ define([
/*
* Retrieve the list of distinct values from ArcGIS Server using the ArcGIS API for JavaScript.
* @param {string} inputId The Dojo id of the control to populate with unique values.
* @param {string} layerID The id defined for the layer in the operationalLayers setting of the viewer configuration file.
* @param {integer} sublayerID The id of the layer within the operational layer to query for unique values.
* @param {object} queryParameters Used to get the operational layer's url to be queried for unique values.
* @param {string} fieldName The field name for which to retrieve unique values.
* @param {boolean} includeBlankValue Whether to add a blank (null) value to the resulting list.
*/
getDistinctValues: function (inputId, layerID, sublayerID, fieldName) {
var layer = this.map._layers[layerID];
var url = layer.url + '/' + sublayerID;
getDistinctValues: function (inputId, queryParameters, fieldName, includeBlankValue) {
var url = this.getLayerURL(queryParameters);
if (url) {
var q = new GetDistinctValues(inputId, url, fieldName, includeBlankValue);
q.executeQuery();
}
},

var q = new GetDistinctValues(inputId, url, fieldName);
q.executeQuery();
getLayerURL: function (qp) {
var url = qp.url;
if (!url && qp.layerID) {
var layer = this.map.getLayer(qp.layerID);
if (layer) {
if (layer.declaredClass === 'esri.layers.FeatureLayer') { // Feature Layer
url = layer.url;
} else if (layer.declaredClass === 'esri.layers.ArcGISDynamicMapServiceLayer') { // Dynamic Layer
if (qp.sublayerID !== null) {
url = layer.url + '/' + qp.sublayerID;
} else if (layer.visibleLayers && layer.visibleLayers.length === 1) {
url = layer.url + '/' + layer.visibleLayers[0];
}
}
}
}
return url;
},

doAttributeSearch: function () {
Expand Down
24 changes: 18 additions & 6 deletions widgets/Search/GetDistinctValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ define([
* @param {string} registryId The Dojo id of the control to populate with unique values.
* @param {string} url The URL to the ArcGIS Server REST resource that represents a map service layer.
* @param {string} fieldName The field name for which to retrieve unique values.
* @param {boolean} includeBlankValue Whether to include a blank value.
*/
constructor: function (registryId, url, fieldName) {
constructor: function (registryId, url, fieldName, includeBlankValue) {
this.registryId = registryId;
this.url = url;
this.fieldName = fieldName;
this.includeBlankValue = includeBlankValue || false;

var input = registry.byId(this.registryId);
input.set('disabled', true);
},

/**
Expand All @@ -54,21 +59,28 @@ define([
queryTask.on('complete', lang.hitch(this, function (results) {
var featureSet = results.featureSet,
options = [];
if (this.includeBlankValue) {
options.push({
label: '&nbsp;',
value: null,
selected: false
});
}
if (featureSet.features) {
if (featureSet.features.length > 0) {
arrayUtil.forEach(featureSet.features, function (feature) {
options.push({
label: feature.attributes[this.fieldName],
value: feature.attributes[this.fieldName],
label: feature.attributes[this.fieldName].toString(),
value: feature.attributes[this.fieldName].toString(),
selected: false
});
}, this);
var input = registry.byId(this.registryId);
input.set('options', options);
if (options.length > 0) {
options[0].selected = true;
input.set('value', 0);
}
var input = registry.byId(this.registryId);
input.set('options', options);
input.set('disabled', false);
}
}
}));
Expand Down
4 changes: 2 additions & 2 deletions widgets/Search/css/Search.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.cmvSearchWidget {
width: 100%;
min-width: 225px;
height: 450px;
height: 490px;
}

.cmvSearchWidget .tabContainer {
Expand All @@ -26,7 +26,7 @@
}

.cmvSearchWidget .searchFields {
max-height: 180px;
max-height: 220px;
overflow-x: hidden;
overflow-y: auto;
}
Expand Down

0 comments on commit 766a949

Please sign in to comment.