Merge pull request #26 from titilambert/tcohen2

Clean table HTML generated structure
This commit is contained in:
Frédéric Vachon 2015-02-19 13:48:51 -05:00
commit a838a6779a
14 changed files with 53 additions and 39 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 class="data-table__duration">{{entry.last_state_change | timeElapsed}}</div>
<td class="data-table__duration">{{entry.last_state_change | timeElapsed}}</td>

View File

@ -1,3 +1,3 @@
<span class="data-table__host {{state}}" ng-controller="CellHostCtrl">
<td class="data-table__{{ cell }} {{state}}" ng-controller="CellHostCtrl">
<a class="data-table__data" href="#">{{entry.host_name}}</a>
</span>
</td>

View File

@ -14,4 +14,5 @@ angular.module('adagios.table.cell_host', ['adagios.table'])
.run(['tableConfig', function (tableConfig) {
tableConfig.cellToFieldsMap.host = [ 'host_state', 'host_name' ];
}]);

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

@ -1 +1 @@
<div class="data-table__lastcheck">{{entry.last_check * 1000 | date: medium}}</div>
<td class="data-table__lastcheck">{{entry.last_check * 1000 | date: medium}}</td>

View File

@ -1,6 +1,6 @@
<div class="data-table__service {{state}}" ng-controller="CellServiceCheckCtrl">
<td class="data-table__service {{state}}" ng-controller="CellServiceCheckCtrl">
<dl class="data-table__data">
<dt class="data-table__service__name">{{entry.description}}</dt>
<dd class="data-table__service__summary">{{entry.plugin_output}}</dd>
</dl>
</div>
</td>

View File

@ -12,8 +12,7 @@
<tbody class="" ng-repeat="entry in entries">
<tr>
<td><input type="checkbox"></td>
<td class="data-table__{{ cell }}" 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,41 +42,55 @@ 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) {
tableConfig.cells.text = attrs.cellsText.split(',');
tableConfig.cells.name = attrs.cellsName.split(',');
tableConfig.apiName = attrs.apiName;
if (!!attrs.filters) {
tableConfig.filters = attrs.filters;
}
return 'components/table/table.html';
if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName) {
throw new Error('<adg-table> "cells-text", "cells-name" and "api-name" attributes must be defined');
}
console.error('<adg-table> "cells" and "api-name" attributes must be defined');
tableConfig.cells.text = attrs.cellsText.split(',');
tableConfig.cells.name = attrs.cellsName.split(',');
tableConfig.apiName = attrs.apiName;
if (!!attrs.filters) {
tableConfig.filters = attrs.filters;
}
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 () {
.directive('adgCell', function ($http, $compile, $templateCache) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.getTemplateUrl = function () {
if (!!attrs.type) {
return 'components/table/cell_' + attrs.type + '/cell_' + attrs.type + '.html';
compile: function () {
return function (scope, element, attrs) {
if (!attrs.cellName) {
throw new Error('<adg-cell> "cell-name" attribute must be defined');
}
console.error('<adg-cell> "type" attribute is undefined');
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);
});
};
},
template: '<div ng-include="getTemplateUrl()"></div>'
}
};
});

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>