Table DOM cleaning

This commit is contained in:
Frédéric Vachon 2015-02-19 13:43:27 -05:00
parent 956c349923
commit b4390253ad
9 changed files with 46 additions and 41 deletions

View File

@ -37,7 +37,7 @@ angular.module('adagios.live')
return $http.get('/rest/status/json/' + apiName + '/?fields=' + columns + filtersQuery)
.error(function (data, status, headers, config) {
console.error('getServices : GET Request failed');
throw new Error('getServices : GET Request failed');
});
};
}]);

View File

@ -1 +1 @@
<div ng-controller="CellHostAddressCtrl">{{entry.address}}</div>
<td ng-controller="CellHostAddressCtrl">{{entry.address}}</td>

View File

@ -1 +1 @@
<div class="{{alert_level}}" ng-controller="CellHostStatusCtrl">{{entry.host_status}}</div>
<td class="{{alert_level}}" ng-controller="CellHostStatusCtrl">{{entry.host_status}}</td>

View File

@ -1 +1 @@
<div ng-controller="CellHostsHostCtrl">{{entry.name}}</div>
<td ng-controller="CellHostsHostCtrl">{{entry.name}}</td>

View File

@ -12,7 +12,7 @@
<tbody class="" ng-repeat="entry in entries">
<tr>
<td><input type="checkbox"></td>
<td adg-cell type="{{cell}}" ng-repeat="cell in cellsName"> </td >
<td adg-cell cell-name="{{cell}}" ng-repeat="cell in cellsName"></td>
</tr>
</tbody>

View File

@ -42,13 +42,16 @@ angular.module('adagios.table', ['adagios.live',
});
}])
.directive('adgTable', ['tableConfig', function (tableConfig) {
.directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) {
return {
restrict: 'E',
link: function (scope, element, attrs) {
scope.generateTable = function () {
compile: function () {
return function (scope, element, attrs) {
if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName) {
throw new Error('<adg-table> "cells-text", "cells-name" and "api-name" attributes must be defined');
}
if (!!attrs.cellsText && !!attrs.cellsName && !!attrs.apiName) {
tableConfig.cells.text = attrs.cellsText.split(',');
tableConfig.cells.name = attrs.cellsName.split(',');
tableConfig.apiName = attrs.apiName;
@ -57,35 +60,37 @@ angular.module('adagios.table', ['adagios.live',
tableConfig.filters = attrs.filters;
}
return 'components/table/table.html';
}
console.error('<adg-table> "cells" and "api-name" attributes must be defined');
var template = 'components/table/table.html';
$http.get(template, { cache: true })
.success(function (data) {
var elem = $compile(data)(scope);
element.append(elem);
});
};
},
template: '<div ng-include="generateTable()"></div>'
}
};
}])
.directive('adgCell', function ($http, $compile, $templateCache) {
return {
restrict:'A',
compile: function() {
return function postCompile(scope, element, attrs) {
var template = 'components/table/cell_' + attrs.type + '/cell_' + attrs.type + '.html'
// TODO: Manage a true caching
var toto = $templateCache.get(template)
$http.get(template)
.success(function(data) {
$templateCache.put(template, data);
var titi = $compile(data)(scope)
// We do this HACK because we are in a "table" element
// Which accept only td element :(
// Don't do this anywhere else
element.replaceWith(titi)
});
restrict: 'A',
compile: function () {
return function (scope, element, attrs) {
if (!attrs.cellName) {
throw new Error('<adg-cell> "cell-name" attribute must be defined');
}
var template = 'components/table/cell_' + attrs.cellName + '/cell_' + attrs.cellName + '.html';
$http.get(template, { cache: true })
.success(function (data) {
var td = $compile(data)(scope);
// HACK : replaceWith is a necessary hack because <tr> only accepts <td> as a child
element.replaceWith(td);
});
};
}
};
});

View File

@ -139,7 +139,7 @@
<adg-table cells-text="{{dashboardCellsText}}"
cells-name="{{dashboardCellsName}}"
api-name="{{dashboardApiName}}"
filters="{{dashboardFilters}}">
filters="{{dashboardFilters}}"></adg-table>
</div>
</div>

View File

@ -13,7 +13,7 @@
<adg-table cells-name="{{hostsCellsName}}"
cells-text="{{hostsCellsText}}"
api-name="{{hostsApiName}}"
filters="{{hostsFilters}}">
filters="{{hostsFilters}}"></adg-table>
</section>
</article>

View File

@ -13,7 +13,7 @@
<adg-table cells-name="{{servicesCellsName}}"
cells-text="{{servicesCellsText}}"
api-name="{{servicesApiName}}"
filters="{{servicesFilters}}">
filters="{{servicesFilters}}"></adg-table>
</section>
</article>