Skip to content

Commit

Permalink
Merge pull request #23 from gobsmack/master
Browse files Browse the repository at this point in the history
Initial Commit for Export FeatureSet, with new tests and Grunt
  • Loading branch information
tmcgee committed Jul 30, 2015
2 parents 05a56ea + 94edc2e commit 8bda9e5
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.sublime-workspace
*.sublime-project
node_modules/
42 changes: 42 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = function(grunt){

grunt.initConfig({

pkg: grunt.file.readJSON('package.json'),

watch: {
options: {
livereload: true
}
},

connect: {
dev: {
options: {
//port: '?',
port: '62332',
base: '',
hostname: '*'
//open: ''
//open: '//localhost:50390/node_modules/intern/client.html',
//open: true
}
}
},
open: {
dev: {
path: 'http://localhost:62332/tests/Export/index.html'
}
}
});


// load the tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-open');

// define the tasks
grunt.registerTask('dev', ['connect:dev', 'open:dev', 'watch']);

};
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "cmv-widgets",
"version": "v1.0.0",
"author": "Tim McGee",
"license": "",
"year": "2015",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-connect": "0.4.x",
"grunt-contrib-watch": "0.5.x",
"grunt-open": "^0.2.3"
},
"dependencies": {
},
"engine": "node >= 0.10"
}
218 changes: 218 additions & 0 deletions tests/Export/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title></title>
<link rel="stylesheet" type="text/css" href="//js.arcgis.com/3.13compact/esri/css/esri.css">
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="/cmv/css/theme/dbootstrap/dbootstrap.css">
<link rel="stylesheet" type="text/css" href="/cmv/css/main.css">
<body class="dbootstrap">
<div class="appHeader">
<div class="headerLogo">
<img alt="logo" src="./../../cmv/images/rocket-logo.png" height="54" />
</div>
<div class="headerTitle">
<span id="headerTitleSpan"></span>
<div id="subHeaderTitleSpan" class="subHeaderTitle"></div>
</div>
<div class="search">
</div>
<div class="headerLinks">
<div id="buttonsDiv"></div>
</div>
</div>
<script type="text/javascript">
var path = location.pathname.replace(/[^\/]+$/, '');
var dojoConfig = {
async: true,
packages: [{
name: 'viewer',
location: path + './../../cmv/js/viewer'
},{
name: 'gis',
location: path + './../../cmv/js/gis'
},{
name: 'config',
location: path + './../../config'
},{
name: 'widgets',
location: path + './../../widgets'
}]
};
</script>
<!--[if lt IE 9]>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/es5-shim/4.0.3/es5-shim.min.js"></script>
<![endif]-->
<script type="text/javascript" src="//js.arcgis.com/3.13compact/"></script>
<script type="text/javascript">
require(['dojo/on', 'dojo/dom', 'dojo/dom-construct', 'esri/tasks/FeatureSet', 'esri/tasks/query', 'esri/tasks/QueryTask', 'esri/graphic', 'dijit/form/Button', 'dojo/topic', 'viewer/Controller'], function(on, dom, domConstruct, FeatureSet, Query, QueryTask, Graphic, Button, topic, Controller){
Controller.startup({
isDebug: true,

mapOptions: {
basemap: 'topo',
center: [-120.0417, 39.0917],
zoom: 10,
sliderStyle: 'small'
},

titles: {
header: 'CMV Export Tests',
subHeader: 'This is an example of the Export Widget',
pageTitle: 'CMV Export Widget'
},

panes: {
left: {
collapsible: false,
style: 'display:none'
},
bottom: {
id: 'sidebarBottom',
placeAt: 'outer',
splitter: true,
collapsible: true,
region: 'bottom',
style: 'height:200px;',
content: '<div id="attributesContainer"></div>'
}
},

collapseButtonsPane: 'center', //center or outer

operationalLayers: [],

widgets: {
growler: {
include: true,
id: 'growler',
type: 'domNode',
path: 'gis/dijit/Growler',
srcNodeRef: 'growlerDijit',
options: {}
},
attributesTable: {
include: true,
id: 'attributesContainer',
type: 'domNode',
srcNodeRef: 'attributesContainer',
path: 'widgets/AttributesTable',
options: {
map: true,
mapClickMode: true,

// use a tab container for multiple tables or
// show only a single table
useTabs: false,

// used to open the sidebar after a query has completed
sidebarID: 'sidebarBottom',

tables: [
{
title: 'Census',
topicID: 'censusQuery',
queryOptions: {
queryParameters: {
url: 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4',
maxAllowableOffset: 100,
where: 'STATE_FIPS = \'06\' OR STATE_FIPS = \'08\''
}
}
}
]
}
},
exportDialog: {
include: true,
id: 'export',
type: 'floating',
path: 'widgets/Export',
title:'Export Widget Test',
options: {}
}
}
}); // end Controller

var buttonsDiv = dom.byId('buttonsDiv');

new Button({
label: 'Show Parameter Missing',
onClick: function() {
topic.publish('exportWidget/openDialog', {

});
}
}, domConstruct.create('div', {}, buttonsDiv));

new Button({
label: 'Show Parameter False',
onClick: function() {
topic.publish('exportWidget/openDialog', {
show: false
});
}
}, domConstruct.create('div', {}, buttonsDiv));

new Button({
label: 'Pass No Data',
onClick: function() {
topic.publish('exportWidget/openDialog', {
show: true
});
}
}, domConstruct.create('div', {}, buttonsDiv));

new Button({
label: 'Export QueryTask',
onClick: function() {

var query = new Query();
var queryTask = new QueryTask('http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4');
query.where = 'STATE_FIPS = \'06\' OR STATE_FIPS = \'08\'';
query.returnGeometry = false;
query.outFields = ["*"];
query.maxAllowableOffset = 100;
queryTask.execute(query, function(theFeatureSet) {
topic.publish('exportWidget/openDialog', {
show: true,
featureSet: theFeatureSet
});
});
}
}, domConstruct.create('div', {}, buttonsDiv));

new Button({
label: 'Export Manual FeatureSet',
onClick: function() {
var attr = {
'col1': 'val1',
'col2': 'val2',
'col3': 'val3'
};
var graphic = new Graphic(null, null, attr, null);
var features= [];
features.push(graphic);
var featureSet = new FeatureSet();
featureSet.features = features;
featureSet.fieldAliases = {
'col1': 'Column 1',
'col2': 'Column 2',
'col3': 'Column 3'
};
topic.publish('exportWidget/openDialog', {
show: true,
featureSet: featureSet
});
}
}, domConstruct.create('div', {}, buttonsDiv));

}); //end require
</script>
</body>
</html>
52 changes: 49 additions & 3 deletions widgets/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ define([
//geojson: false, // allow features to be exported to GeoJSON
//shapefile: false, // allow the features to be exported to a Shape File

// featureSet to export
featureSet: null,
// query results to export
results: null,
// optional grid if you want to export only visible columns and use column names
Expand Down Expand Up @@ -124,6 +126,7 @@ define([
},

openDialog: function (options) {
this.featureSet = options.featureSet;
this.results = options.results;
this.grid = options.grid;

Expand Down Expand Up @@ -254,8 +257,9 @@ define([
var c = 0,
field, val;
var aliases = null; //this.results.fieldAliases;
var rows = this.grid.get('store').data;
var columns = this.grid.get('columns');
var rc = this.getRowsAndColumns();
var rows = rc.rows;
var columns = rc.columns;
var wscols = [];

// build the header row with field names
Expand Down Expand Up @@ -292,10 +296,13 @@ define([
if (column.exportable !== false && column.hidden !== true) {
field = column.field;
val = row[field];

/*
// this was specific to Stor; do we lose anything by removing it?
if (column.get) {
val = column.get(row);
}
*/
if (val === null) {
c++;
return;
Expand Down Expand Up @@ -423,6 +430,45 @@ define([
}
},

getRowsAndColumns: function() {
var rows = [];
var columns = [];
if(this.grid) {
rows = this.grid.get('store').data;
columns = this.grid.get('columns');
}
else if(this.featureSet) {
if(this.featureSet.features && this.featureSet.features.length > 0) {
columns = [];
var firstFeature = this.featureSet.features[0];
for(var key in firstFeature.attributes) {
if(firstFeature.attributes.hasOwnProperty(key)) {
columns.push({
exportable: true,
hidden: false,
label: this.featureSet.fieldAliases[key] || key,
field: key,
width: null
});
}
}
rows = array.map(this.featureSet.features, function(aFeature) {
return aFeature.attributes;
});
}
else {
// cannot build columns because nothing to export; not really an error;
}
}
else {
// no datasource was provided; was not an error, so still not an error;
}
return {
rows: rows,
columns: columns
};
},

/*******************************
* Download Functions
*******************************/
Expand Down

0 comments on commit 8bda9e5

Please sign in to comment.