Skip to content

Commit

Permalink
#91: possibilité d'ajouter et de supprimer un filtre
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericbonifas committed Jul 22, 2015
1 parent 0328bb8 commit 1af6016
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
44 changes: 38 additions & 6 deletions app/scripts/controllers/commonmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,49 @@ angular.module('accessimapEditeurDerApp')
'f0': 'Titre par défaut',
}];

var checkboxTemplate = '<input ng-if="row.entity.type === \'boolean\'" type="checkbox" value="{{row.entity[col.field]}}" ng-model="row.entity[col.field]"><div ng-if="row.entity.type !== \'boolean\'">{{row.entity[col.field]}}</div>';
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 menuItems = [
{
title: 'Supprimer cette colonne',
icon: 'ui-grid-icon-cancel',
action: function() {
var colName = this.context.col.name;

// Remove the column from interactiveFiltersColumns
var columnToDelete = interactiveFiltersColumns.filter(function(col) {
return col.name === colName;
});
var index = interactiveFiltersColumns.indexOf(columnToDelete[0]);
interactiveFiltersColumns.splice(index, 1);

// Remove the column from interactiveFiltersColumns
angular.forEach($scope.interactiveFilters.data, function(row) {
delete row[colName];
});
}
}
];

var interactiveFiltersColumns = [
{ name: 'id', enableCellEdit: false, enableHiding: false },
{ name: 'f0', cellTemplate: checkboxTemplate, menuItems: menuItems, enableHiding: false },
{ name: 'f1', cellTemplate: checkboxTemplate, menuItems: menuItems, enableHiding: false }
];

$scope.interactiveFilters = {
data: $scope.interactiveFiltersInit,
showSelectionCheckbox: true,
enableSorting: false,
columnDefs: [
{ name: 'id', enableCellEdit: false },
{ name: 'f0', cellTemplate: checkboxTemplate },
{ name: 'f1', cellTemplate: checkboxTemplate }
],
columnDefs: interactiveFiltersColumns,
};

$scope.nextFilterNumber = 2;

$scope.addFilter = function() {
interactiveFiltersColumns.push({ name: 'f' + $scope.nextFilterNumber, cellTemplate: checkboxTemplate, menuItems: menuItems, enableHiding: false });
$scope.nextFilterNumber += 1;
};

d3.select('svg').append('defs')
Expand Down
2 changes: 1 addition & 1 deletion app/styles/map.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
}

.myGrid {
width: 500px;
width: 800px;
height: 250px;
}
4 changes: 2 additions & 2 deletions app/views/commonmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<span class="pull-right" id="slide-submenu" ng-click="hideMenu()">
<i class="fa fa-times"></i>
</span>
Ajouter des interactions
<div ui-grid="interactiveFilters" ui-grid-edit class="myGrid"></div>
<button id="button_add" class="btn btn-success" ng-click="addFilter()">Ajouter un filtre d'interaction</button>
<div ui-grid="interactiveFilters" ui-grid-edit class="myGrid"></div>
</div>

0 comments on commit 1af6016

Please sign in to comment.