"angular-ui-router": "http://cloudistic.me/angular-ui-router.min.js",
"d3": "~3.3.2"
},
- "dependencies": {}
+ "dependencies": {
+ "ng-grid": "~2.0.7"
+ }
}
'vendor/angular-route/index.js',
'vendor/angular-ui-router/index.js',
'vendor/angular-ui-select2/index.js',
+ 'vendor/ng-grid/ng-grid-2.0.7.min.js',
'vendor/restangular/dist/restangular.min.js'
],
css: [
'vendor/bootstrap/dist/css/bootstrap.min.css',
'vendor/select2/select2.css',
- 'vendor/select2-bootstrap-css/select2-bootstrap.css'
+ 'vendor/select2-bootstrap-css/select2-bootstrap.css',
+ 'vendor/ng-grid/ng-grid.min.css'
],
assets: [
'vendor/**/*.gif',
'restangular',
'ui.router',
'ui.select2',
+ 'ngGrid',
'dlux.nbapi',
'dlux.auth',
'dlux.navigation',
$stateProvider.state('container.index', {
url: '/index',
- templateUrl: 'container/index.tpl.html'
+ views: {
+ '': {
+ templateUrl: 'container/index.tpl.html',
+ controller: function ($scope, ContainerSvc) {
+ $scope.svc = ContainerSvc;
+
+ $scope.gridOptions = {
+ data: 'data["container-config"]',
+ selectedItems: [],
+ enableRowSelection: true,
+ showSelectionCheckbox: true,
+ selectWithCheckboxOnly: true,
+ columnDefs: [
+ {
+ field: 'container', displayName: 'Name',
+ },
+ {
+ field: 'nodeConnectors.length', displayName: 'Connector Count',
+ },
+ {
+ displayName: 'Options', cellTemplate: '<div><a ng-click="console.log(row)"><span class="glyphicon glyphicon-remove"></span> Delete</a></div>'
+ }
+ ]
+ }
+
+ $scope.$watch(
+ function () {
+ return ContainerSvc.data;
+ },
+ function (data) {
+ $scope.data = data;
+ }
+ );
+ }
+ }
+ }
});
$stateProvider.state('container.detail', {
'': {
templateUrl: 'container/detail.tpl.html',
controller: function ($scope, ContainerSvc) {
- $scope.data = ContainerSvc.containerUrl($scope.$stateParams.container).get();
+ ContainerSvc.containerUrl($scope.$stateParams.container).get().then(
+ function (data) {
+ $scope.data = data;
+ }
+ );
}
}
}
+<div class="col-md-6">
+ <ctrl-reload service="svc"></ctrl-reload>
+ <ctrl-delete service="svc"></ctrl-delete>
+ <count-selected data="gridOptions.selectedItems"></count-selected>
+ <div style='height: 300px; width: 100%;' ng-grid="gridOptions"></div>
+</div>
return svc.base().one('container', container);
};
+ svc.delete = function (container) {
+ container = angular.isObject(container) ? container.container : container
+ return svc.containerUrl(container).remove()
+ }
+
svc.getAll = function() {
svc.containersUrl().getList().then(function (data) {
svc.data = data;
}
}
};
-});
+})
+
+
+.directive('showSelected', function() {
+ // Runs during compile
+ return {
+ restrict: 'E',
+ replace: true,
+ scope: {
+ 'data': '='
+ },
+ template: '<div>{{data.length}}</div>',
+ };
+})
+
+.directive('ctrlReload', function() {
+ // Runs during compile
+ return {
+ replace: true,
+ restrict: 'E',
+ scope: {
+ svc: '=service'
+ },
+ template: '<button class="btn btn-primary btn-xs" ng-click="svc.getAll()"><i class="glyphicon glyphicon-refresh"></i></button>',
+ link: function ($scope, iElm, iAttrs, controller) {
+ $scope.$on('evt:refresh', function() {
+ $scope.svc.getAll();
+ })
+ }
+ };
+})
+
+.directive('ctrlDelete', function($rootScope) {
+ // Runs during compile
+ return {
+ replace: true,
+ restrict: 'E',
+ template: '<button class="btn btn-danger btn-xs" ng-click="deleteSelected()" ng-disabled="gridOptions.selectedItems.length == 0"><i class="glyphicon glyphicon-remove"></i></button>',
+ link: function($scope, iElm, iAttrs, controller) {
+ var i = 0;
+ var selected = $scope.gridOptions.selectedItems;
+
+ // Fire up a evt:refresh event once done.
+ $scope.deleteSelected = function () {
+ angular.forEach(selected, function(value, key) {
+ $scope.svc.delete(value).then(
+ function () {
+ i++;
+ if (i == selected.length) {
+ $rootScope.$broadcast('evt:refresh')
+ }
+ }
+ )
+ });
+ }
+ }
+ };
+})
\ No newline at end of file