Added dynamically generated table

This commit is contained in:
Frédéric Vachon 2015-01-22 17:11:28 -05:00
parent c913bd7547
commit ef0deb12f9
14 changed files with 34 additions and 104 deletions

View File

@ -1,3 +1 @@
<div ng-app="adagios.table.cell_duration" ng-controller="CellDurationCtrl"> <div>{{entry.duration}}</div>
Cell duration
</div>

View File

@ -1,22 +0,0 @@
'use strict';
angular.module('adagios.table.cell_duration', ['ngSanitize'])
.controller('CellDurationCtrl', ['$scope', '$sce', function ($scope, $sce) {
$scope.balise = 'salut';
}])
.directive('cellDuration', function () {
return {
restrict: 'E',
replace: true,
scope: false,
templateUrl: 'table/cell_duration/cell_duration.html',
link: function(scope, element, attrs) {
var factory = angular.element('<div></div>');
factory.html('<p>{{balise}}</p>');
console.log(scope);
$compile(factory)(scope);
}
};
});

View File

@ -1,3 +1 @@
<div ng-app="adagios.table.cell_host" ng-controller="cellHostCtrl"> <div>{{entry.host_name}}</div>
Cell host
</div>

View File

@ -1,15 +0,0 @@
'use strict';
angular.module('adagios.table.cell_host', [])
.controller('CellHostCtrl', ['$scope', function ($scope) {
return;
}])
.directive('cellHost', function () {
return {
restrict: 'E',
replace: true,
templateUrl: "table/cell_host/cell_host.html"
};
});

View File

@ -1,3 +1 @@
<div ng-app="adagios.table.cell_last_check" ng-controller="cellLastCheckCtrl"> <div>{{entry.last_check}}</div>
Cell last check
</div>

View File

@ -1,15 +0,0 @@
'use strict';
angular.module('adagios.table.cell_last_check', [])
.controller('CellLastCheckCtrl', ['$scope', function ($scope) {
return;
}])
.directive('cellLastCheck', function () {
return {
restrict: 'E',
replace: true,
templateUrl: "table/cell_last_check/cell_last_check.html"
};
});

View File

@ -1,3 +1 @@
<div ng-app="adagios.table.cell_service_check" ng-controller="cellServiceCheckCtrl"> <div>{{entry.service_check}</div>
Cell service check
</div>

View File

@ -1,14 +0,0 @@
'use strict';
angular.module('adagios.table.cell_service_check', [])
.controller('CellServiceCheck', ['$scope', function ($scope) {
return;
}])
.directive('cellServiceCheck', function () {
return {
restrict: 'E',
templateUrl: "table/cell_service_check/cell_service_check.html"
};
});

View File

@ -1,17 +1,17 @@
<div ng-app="adagios.table" ng-controller="TableCtrl" id="table"> <div ng-app="adagios.table" ng-controller="TableCtrl" id="table">
<table class="table table-bordered table-hover"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th></th> <th></th>
<th ng-repeat="thead in columns"> <th ng-repeat="thead in cells">
{{thead}} {{thead}}
</th> </th>
</tr> </tr>
</thead> </thead>
<tr ng-repeat="entry in entries"> <tr ng-repeat="entry in entries">
<td><input type="checkbox"></td> <td><input type="checkbox"></td>
<td ng-repeat="cell in columns"> <td ng-repeat="cell in cells">
{{cell}} <custom-cell type="{{cell}}"></custom-cell>
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -1,30 +1,27 @@
'use strict'; 'use strict';
angular.module('adagios.table', ['ngRoute', angular.module('adagios.table', ['ngRoute',
'ngSanitize', 'adagios.live'
'adagios.live',
'adagios.table.cell_duration',
'adagios.table.cell_host',
'adagios.table.cell_last_check',
'adagios.table.cell_service_check'
]) ])
.controller('TableCtrl', ['$scope', '$sce', 'GetServices', function ($scope, $sce, GetServices) { .controller('TableCtrl', ['$scope', 'GetServices', function ($scope, GetServices) {
$scope.cellTagMapping = {
duration: $sce.trustAsHtml('<cell-duration></cell-duration>'),
host_name: $sce.trustAsHtml('<cell-host></cell-host>'),
last_check: $sce.trustAsHtml('<cell-last-check></cell-last-check>'),
service_check: $sce.trustAsHtml('<service-check></service-check>')
};
$scope.columns = ['host_name', 'last_check'];
console.log(new GetServices($scope.columns) $scope.cellPathMapping = {
duration: 'duration',
host_name: 'host',
last_check: 'last_check',
service_check: 'service_check'
};
$scope.cells = ['host_name', 'duration', 'last_check'];
console.log(new GetServices($scope.cells)
.success(function (data) { .success(function (data) {
$scope.entries = data; $scope.entries = data;
})); }));
}]) }])
.directive('servicesTable', function () { .directive('customTable', function () {
return { return {
restrict: 'E', restrict: 'E',
replace: true, replace: true,
@ -32,10 +29,18 @@ angular.module('adagios.table', ['ngRoute',
}; };
}) })
.directive('servicesEntry', function () { .directive('customCell', function () {
return { return {
restrict: 'E', restrict: 'E',
replace: true, link: function (scope, element, attrs) {
templateUrl: 'table/table.html' var path = scope.cellPathMapping[attrs.type];
scope.getTemplateUrl = function () {
if (path) {
return 'table/cell_' + path + '/cell_' + path + '.html';
}
};
},
template: '<div ng-include="getTemplateUrl()"></div>'
}; };
}); });

View File

@ -19,6 +19,6 @@
</div> </div>
<services-table></services-table> <custom-table></custom-table>
</div> </div>

View File

@ -10,7 +10,6 @@
"angular-route": "1.2.x", "angular-route": "1.2.x",
"angular-loader": "1.2.x", "angular-loader": "1.2.x",
"angular-mocks": "~1.2.x", "angular-mocks": "~1.2.x",
"angular-sanitize": "~1.2.x",
"html5-boilerplate": "~4.3.0", "html5-boilerplate": "~4.3.0",
"bootstrap-sass-official": "3.3.1", "bootstrap-sass-official": "3.3.1",
"fontawesome": "4.2.0", "fontawesome": "4.2.0",