Skip to content

Commit

Permalink
Add finding Features using FindTask to Search + AttributesTable widgets.
Browse files Browse the repository at this point in the history
This initial release includes all the capabilities in CMV's Find widget.
  • Loading branch information
tmcgee committed Oct 17, 2015
1 parent f049b4e commit f6e464f
Show file tree
Hide file tree
Showing 14 changed files with 489 additions and 90 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Widgets for [CMV](http://cmv.io/), the Configurable Map Viewer created by [Tim M
Each widget in this repo has at least one configuration example in the [config folder](https://github.com/tmcgee/cmv-widgets/tree/master/config). This folder also contains additional examples for including ESRI widgets, other widgets and functionality.

### Attributes Table(s)
A highly configurable widget to display the results of one or more QueryTasks.
A highly configurable widget to display the results of one or more Query, Find or Geoprocessor Tasks.
#####[Documentation](https://github.com/tmcgee/cmv-widgets/tree/master/widgets/AttributesTable/README.md)
#####[Demo](http://tmcgee.github.io/cmv-widgets/demo.html?config=table)
![Screenshot](https://tmcgee.github.io/cmv-widgets/images/attributesTables1.jpg)
Expand Down Expand Up @@ -54,7 +54,7 @@ An updated version of the PrintPlus widget originally created by [@LarryStout](h

---
###Search
Used in conjunction with the [Attributes Tables](https://github.com/tmcgee/cmv-widgets#attributes-tables) widget to provide a user interface for querying feature layers, tables and related records.
Used in conjunction with the [Attributes Tables](https://github.com/tmcgee/cmv-widgets#attributes-tables) to provide a user interface for querying feature layers, dynamic layers, tables and related records using QueryTask and FindTask.
#####[Documentation](https://github.com/tmcgee/cmv-widgets/tree/master/widgets/Search/README.md)
#####[Demo](http://tmcgee.github.io/cmv-widgets/demo.html?config=search)
![Screenshot](https://tmcgee.github.io/cmv-widgets/images/search1.jpg)
Expand Down
68 changes: 68 additions & 0 deletions config/searchWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ define([
});
}

function formatDate (value) {
var date = new Date(value);
return locale.format(date, {
selector: 'date',
formatLength: 'medium'
});
}

return {
map: true,
mapClickMode: true,
Expand Down Expand Up @@ -269,6 +277,66 @@ define([
}
}
]
},
{
name: 'Public Safety by Name',
findOptions: {
url: 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyOperationalLayers/MapServer',
layerIds: [1, 2, 3, 4, 5, 6, 7],
searchFields: ['FDNAME, PDNAME', 'NAME', 'RESNAME']
},
attributeSearches: [
{
name: 'Search for Public Safety Locations By Name',
searchFields: [
{
name: 'Name',
label: 'Name',
expression: '[value]%\')',
placeholder: 'fdname, pdname, name or resname',
required: true,
minChars: 3
}
],

title: 'Public Safety Locations',
topicID: 'findPublicSafterQuery',
gridOptions: {
columns: [
{
field: 'value',
label: 'Name'
},
{
field: 'displayFieldName',
label: 'Field',
width: 150
},
{
field: 'layerName',
label: 'Layer',
width: 150
},
{
field: 'Last Update Date',
label: 'Last Updated',
width: 150,
get: function (object) { // allow export as a proper date
return new Date(object['Last Update Date']);
},
formatter: formatDate

}
],
sort: [
{
attribute: 'Name',
descending: false
}
]
}
}
]
}
]
};
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2>Example Configurations</h2>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h2 id="attributes-tables">Attributes Table(s)</h2>
<p>A highly configurable widget to display the results of one or more QueryTasks.</p>
<p>A highly configurable widget to display the results of one or more Query, Find or Geoprocessor Tasks.</p>
<p>
<a href="demo.html?config=table" target="cmv-demo-table" class="btn btn-primary btn-lg">Demo</a>
</p>
Expand Down Expand Up @@ -155,7 +155,7 @@ <h2 id="search">Print Plus</h2>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h2 id="search">Search</h2>
<p>Used in conjunction with the Attribute Table widget to provide a user interface for querying feature layers.</p>
<p>Used in conjunction with the Attribute Table widget to provide a user interface for querying feature layers, dynamic layers, tables and related records using QueryTask and FindTask.</p>
<p>
<a href="demo.html?config=search" target="cmv-demo-search" class="btn btn-primary btn-lg">Demo</a>
</p>
Expand Down
5 changes: 4 additions & 1 deletion widgets/AttributesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ define([
if (tab) {
if (options.queryOptions) {
tab.clearAll();
tab.executeQuery(options);
tab.executeQueryTask(options);
} else if (options.findOptions) {
tab.clearAll();
tab.executeFindTask(options);
}
}
return tab;
Expand Down
75 changes: 74 additions & 1 deletion widgets/AttributesTable/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Attributes Table Widget
A highly configurable widget to display the results of one or more Query, Find or Geoprocessor Tasks.

##AttributesTable Class
Adding Attributes Table to CMV
Expand Down Expand Up @@ -158,7 +159,7 @@ queryOptions:
outputSpatialReference: 4326,

/*
AGS REST URL to Query
AGS REST URL to use for QueryTask
default is null
*/
url: null,
Expand Down Expand Up @@ -218,6 +219,78 @@ queryOptions:
```


---
##find Options
``` javascript
findOptions:
// parameters for the FindTask

/*
AGS REST URL to use for FindTask
default is null, Either a url or a layerID is required
*/
url: null,

/*
If no url provided and the layerID is passed,
the url of the layer will be retrieved from the map.
*/
layerID: null,

/*
The remaining options match those used in a FindTask:
https://developers.arcgis.com/javascript/jsapi/findparameters-amd.html
*/

/*
The contains parameter determines whether to look for an exact match of the search text or not. If true, searches for a value that contains the searchText provided. This is a case-insensitive search. If false, searches for an exact match of the searchText string. The exact match is case-sensitive. The default is "true".
*/
contains: true,

/*
An array of DynamicLayerInfos used to change the layer ordering or redefine the map. When set the find operation will perform the find against the dynamic layers.
*/
dynamicLayerInfos: null,

/*
Array of layer definition expressions that allows you to filter the features of individual layers.
*/
layerDefinitions: null,

/*
The layers to perform the find operation on. The layers are specified as a comma-separated list of layer ids.
*/
layerIds: null,

/*
The maximum allowable offset used for generalizing geometries returned by the find operation. The offset is in the units of the spatialReference. If a spatialReference is not defined the spatial reference of the map is used.
*/
maxAllowableOffset: null,

/*
The spatial reference of the output geometries. If outSpatialReference is not specified, the output geometries are returned in the spatial reference of the map.
*/
outSpatialReference: null,

/*
If "true", the result set include the geometry associated with each result. The default is "true".
*/
returnGeometry: true,

/*
The names of the fields of a layer to search. The fields are specified as a comma-separated list of field names. If this parameter is not specified, all fields are searched.
*/
searchFields: null,

/*
The search string text that is searched across the layers and the fields as specified in the layerIds and searchFields parameters.
*/
searchText: null

},
```


---
##Grid Options
``` javascript
Expand Down
53 changes: 43 additions & 10 deletions widgets/AttributesTable/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ define([
'dijit/registry',

// using mixins to make code easier to maintain
'./_QueryMixin',
'./_QueryTaskMixin',
'./_FindTaskMixin',
'./_GridMixin',
'./_FeaturesMixin',
'./_GraphicsMixin',
Expand Down Expand Up @@ -49,6 +50,7 @@ define([
registry,

_QueryMixin,
_FindMixin,
_GridMixin,
_FeaturesMixin,
_GraphicsMixin,
Expand All @@ -58,7 +60,17 @@ define([
i18n
) {

return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, _GridMixin, _QueryMixin, _FeaturesMixin, _GraphicsMixin, _ToolbarMixin], {
return declare([
_WidgetBase,
_TemplatedMixin,
_WidgetsInTemplateMixin,
_GridMixin,
_QueryMixin,
_FindMixin,
_FeaturesMixin,
_GraphicsMixin,
_ToolbarMixin
], {
widgetsInTemplate: true,
templateString: template,
baseClass: 'cmvAttributesTableWidget',
Expand Down Expand Up @@ -99,9 +111,13 @@ define([
this.createGrid();
this.setToolbarButtons();

if (this.queryParameters.url || this.queryParameters.layerID) {
if (this.queryParameters && (this.queryParameters.url || this.queryParameters.layerID)) {
this.own(aspect.after(this, 'startup', lang.hitch(this, function () {
this.executeQuery();
this.executeQueryTask();
})));
} else if (this.findOptions && this.findOptions.url) {
this.own(aspect.after(this, 'startup', lang.hitch(this, function () {
this.executeFindTask();
})));
}
},
Expand All @@ -111,6 +127,7 @@ define([
if (!options) {
options = {
queryOptions: lang.clone(this.queryOptions),
findOptions: lang.clone(this.findOptions),
gridOptions: lang.clone(this.gridOptions),
featureOptions: lang.clone(this.featureOptions),
symbolOptions: lang.clone(this.symbolOptions),
Expand All @@ -122,6 +139,9 @@ define([
if (options.queryOptions) {
this.getQueryConfiguration(options.queryOptions);
}
if (options.findOptions) {
this.getFindConfiguration(options.findOptions);
}
if (options.gridOptions) {
this.getGridConfiguration(options.gridOptions);
}
Expand All @@ -137,18 +157,30 @@ define([
},

addTopics: function () {
// execute a query
this.own(topic.subscribe(this.topicID + '/executeQuery', lang.hitch(this, 'executeQuery')));
// execute a query task
this.own(topic.subscribe(this.topicID + '/executeQuery', lang.hitch(this, 'executeQueryTask')));

// refresh the grid by running the previous query again
this.own(topic.subscribe(this.topicID + '/refreshQuery', lang.hitch(this, 'refreshQuery')));
// refresh the grid by running the previous query task again
this.own(topic.subscribe(this.topicID + '/refreshQuery', lang.hitch(this, 'refreshQueryTask')));

// get the results of the query
// get the results of the query task
this.own(topic.subscribe(this.topicID + '/getQueryResults', lang.hitch(this, 'getQueryResults')));

// clear the results of the query
// clear the results of the query task
this.own(topic.subscribe(this.topicID + '/clearQueryResults', lang.hitch(this, 'clearQueryResults')));

// execute a find task
this.own(topic.subscribe(this.topicID + '/executeFind', lang.hitch(this, 'executeFindTask')));

// refresh the grid by running the previous find task again
this.own(topic.subscribe(this.topicID + '/refreshFind', lang.hitch(this, 'refreshFindTask')));

// get the results of the find task
this.own(topic.subscribe(this.topicID + '/getFindResults', lang.hitch(this, 'getFindResults')));

// clear the results of the find task
this.own(topic.subscribe(this.topicID + '/clearFindResults', lang.hitch(this, 'clearFindResults')));

// populate the grid
this.own(topic.subscribe(this.topicID + '/populateGrid', lang.hitch(this, 'populateGrid')));

Expand Down Expand Up @@ -234,6 +266,7 @@ define([

clearAll: function () {
this.clearQueryResults();
this.clearFindResults();

this.clearFeatures();
this.clearSelectedFeatures();
Expand Down
27 changes: 26 additions & 1 deletion widgets/AttributesTable/_FeaturesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ define([
getFeaturesFromResults: function () {
var results = this.results;
var features = [];

if (results.features) {
features = results.features;
} else if (this.queryParameters.type === 'relationship') {
} else if (this.queryParameters && this.queryParameters.type === 'relationship') {
for (var key in results) {
if (results.hasOwnProperty(key)) {
var item = results[key];
Expand All @@ -62,7 +63,31 @@ define([
}
}
}
} else if ((results.length > 0) && (results[0].feature)) {
var k = 0, len = results.length, result = null;
var feature = null, attributes = null;
this.idProperty = 'recID-' + Math.random();
for (k =0; k< len; k++) {
result = results[k];
feature = result.feature;
attributes = feature.attributes;
attributes[this.idProperty] = k;
if (!attributes.value) {
attributes.value = result.value;
}
if (!attributes.displayFieldName) {
attributes.displayFieldName = result.displayFieldName;
}
if (!attributes.foundFieldName) {
attributes.foundFieldName = result.foundFieldName;
}
if (!attributes.layerName) {
attributes.layerName = result.layerName;
}
features.push(feature);
}
}

this.features = features;
return features;
},
Expand Down
Loading

0 comments on commit f6e464f

Please sign in to comment.