Skip to content

Commit

Permalink
#50: export des filtres d'interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbonifas committed Aug 11, 2015
1 parent 983ce27 commit eb9d775
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 17 deletions.
17 changes: 7 additions & 10 deletions app/scripts/controllers/commonmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ angular.module('accessimapEditeurDerApp')
'deletable': false
}];

var checkboxTemplate = '<input ng-if="row.entity.type === \'boolean\'" type="checkbox" value="{{row.entity[col.field]}}" ng-model="row.entity[col.field]">';
checkboxTemplate += '<div ng-if="row.entity.type !== \'boolean\'">{{row.entity[col.field]}}</div>';
var cellTemplate = '<input ng-if="row.entity.type === \'boolean\'" type="checkbox" value="{{row.entity[col.field]}}" ng-model="row.entity[col.field]">';
cellTemplate += '<div ng-if="row.entity.type !== \'boolean\'">{{row.entity[col.field]}}</div>';

var removeTemplate = '<button ng-if="row.entity.deletable" class="btn btn-danger" ng-click="grid.appScope.removeRow(row.entity)"><i class="glyphicon glyphicon-remove"></i></button>';

Expand All @@ -105,7 +105,7 @@ angular.module('accessimapEditeurDerApp')
var interactiveFiltersColumns = [
{ name: 'id', enableCellEdit: false, enableHiding: false, cellClass: cellClassId},
{ name: 'f0',
cellTemplate: checkboxTemplate,
cellTemplate: cellTemplate,
menuItems: [
{
title: 'Supprimer cette colonne',
Expand All @@ -119,7 +119,7 @@ angular.module('accessimapEditeurDerApp')
enableHiding: false, cellClass: cellClassId
},
{ name: 'f1',
cellTemplate: checkboxTemplate,
cellTemplate: cellTemplate,
menuItems: [
{
title: 'Supprimer cette colonne',
Expand All @@ -142,8 +142,8 @@ angular.module('accessimapEditeurDerApp')
enableSorting: false,
enableRowSelection: true,
columnDefs: interactiveFiltersColumns,
onRegisterApi: function(gridApi){
$scope.gridApi = gridApi;
onRegisterApi: function(gridApi) {
shareSvg.addInteractions(gridApi);
}
};

Expand All @@ -153,7 +153,7 @@ angular.module('accessimapEditeurDerApp')
var filterPosition = interactiveFiltersColumns.length - 1;
interactiveFiltersColumns.splice(filterPosition, 0, {
name: 'f' + $scope.nextFilterNumber,
cellTemplate: checkboxTemplate,
cellTemplate: cellTemplate,
menuItems: [
{
title: 'Supprimer cette colonne',
Expand Down Expand Up @@ -431,9 +431,6 @@ angular.module('accessimapEditeurDerApp')
feature.attr(k, v);
}
});
feature.append('actions')
.append('action')
.attr('id', '1');
});
}
if ($scope.mode === 'circle') {
Expand Down
1 change: 0 additions & 1 deletion app/scripts/controllers/globalmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ angular.module('accessimapEditeurDerApp')
var reader = new FileReader();
reader.readAsDataURL(svgFile); //readAsDataURL
reader.onload = function(e) {
console.log(e)
appendSvg(e.target.result);
};
};
Expand Down
88 changes: 84 additions & 4 deletions app/scripts/services/exportservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* Service in the accessimapEditeurDerApp.
*/
angular.module('accessimapEditeurDerApp')
.service('exportService', function() {
.service('exportService', ['shareSvg',
function(shareSvg) {

this.mapExport = function(filename) {
var zip = new JSZip();
Expand All @@ -25,8 +26,87 @@ angular.module('accessimapEditeurDerApp')
zip.file('legende.svg', (new XMLSerializer()).serializeToString(legendNode));
}
zip.file('commentaires.txt', $('#comment').val());
var content = zip.generate({type: 'blob'});
saveAs(content, filename + '.zip');


shareSvg.getInteractions()
.then(function(data) {
var columns = [];
for (var i = 0; i < data.grid.columns.length; i++) {
columns.push({'field': data.grid.columns[i].field});
}

var rows = [];
for (var i = 0; i < data.grid.rows.length; i++) {
rows.push(data.grid.rows[i].entity);
}

// Remove the first and last columns
columns.shift();
columns.pop();

var filterName = rows[0];
var filterExpandable = rows[1];

for (var i = 0; i < columns.length; i++) {
var currentField = columns[i].field;
columns[i].name = filterName[currentField];
columns[i].expandable = filterExpandable[currentField];
}

var interactions = d3.select('#der').append('xml');
var config = interactions.append('config');
var filters = config.append('filters');
filters.selectAll('filter')
.data(columns)
.enter()
.append('filter')
.attr('id', function(d) {
return d.field;
})
.attr('name', function(d) {
return d.name;
})
.attr('expandable', function(d) {
return d.expandable;
});

// Remove the first two rows
rows.shift();
rows.shift();
var pois = config.append('pois');
pois.selectAll('poi')
.data(rows)
.enter()
.append('poi')
.attr('id', function(d) {
return d.id;
})
.each(function(d) {
var shapeD;
d3.select('#der').select('svg').selectAll('path')[0]
.forEach(function(shape) {
if ('poi-' + d3.select(shape).attr('iid') === d.id) {
shapeD = d3.select(shape).attr('d');
}
});
var poi = d3.select(this);
poi.attr('id', d.id);
poi.attr('coord', shapeD);
var actions = poi.append('actions');
// loop through the keys - this assumes no extra data
d3.keys(d).forEach(function(key) {
if (key !== '$$hashKey' && key !== 'deletable' && key !== 'id') {
actions.append('action')
.attr('filter', key)
.attr('value', d[key]);
}
});
});
var interactionsNode = d3.select('#der').select('xml').node();
zip.file('interactions.xml', (new XMLSerializer()).serializeToString(interactionsNode));
var content = zip.generate({type: 'blob'});
saveAs(content, filename + '.zip');
});
};

});
}]);
24 changes: 22 additions & 2 deletions app/scripts/services/sharesvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
angular.module('accessimapEditeurDerApp')
.service('shareSvg', ['$q', function($q) {
var map,
legend;
legend,
interactions;

var addMap = function(newMap) {
var deferred = $q.defer();
Expand Down Expand Up @@ -46,10 +47,29 @@ angular.module('accessimapEditeurDerApp')
return deferred.promise;
};

var addInteractions = function(newInteractions) {
var deferred = $q.defer();
interactions = newInteractions;

deferred.resolve();

return deferred.promise;
};

var getInteractions = function() {
var deferred = $q.defer();

deferred.resolve(interactions);

return deferred.promise;
};

return {
addMap: addMap,
getMap: getMap,
addLegend: addLegend,
getLegend: getLegend
getLegend: getLegend,
addInteractions: addInteractions,
getInteractions: getInteractions
};
}]);

0 comments on commit eb9d775

Please sign in to comment.