First step for no-repeat support
This commit is contained in:
parent
80934ea2e9
commit
5251c7acce
|
@ -117,8 +117,11 @@ module.exports = function (grunt) {
|
|||
'!<%= project.app %>/bower_components/**',
|
||||
'!<%= project.app %>/build/**',
|
||||
'!<%= project.app %>/**/*_test.js'
|
||||
]
|
||||
}]
|
||||
],
|
||||
}],
|
||||
options: {
|
||||
mangle: false
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
"0"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"wrap" : ["host"],
|
||||
"noRepeat" : ["host"]
|
||||
},
|
||||
"hostsConfig": {
|
||||
"title": "Hosts",
|
||||
|
|
|
@ -15,9 +15,12 @@ angular.module('adagios.table', ['adagios.live',
|
|||
.value('tableConfig', { cells: { 'text': [], 'name': [] },
|
||||
apiName: '',
|
||||
filters: {},
|
||||
cellToFieldsMap: {} })
|
||||
cellToFieldsMap: {},
|
||||
toWrap: [],
|
||||
noRepeat: []})
|
||||
|
||||
.controller('TableCtrl', ['$scope', 'getServices', 'tableConfig', function ($scope, getServices, tableConfig) {
|
||||
.controller('TableCtrl', ['$scope', 'getServices', 'tableConfig', 'processColumnRepeat',
|
||||
function ($scope, getServices, tableConfig, processColumnRepeat) {
|
||||
|
||||
var requestFields = [],
|
||||
filters = JSON.parse(tableConfig.filters),
|
||||
|
@ -37,53 +40,14 @@ angular.module('adagios.table', ['adagios.live',
|
|||
});
|
||||
});
|
||||
|
||||
function processMultipleServicesPerHost(data) {
|
||||
var last_host = "",
|
||||
actual_host = "",
|
||||
entry = {},
|
||||
first_child = false,
|
||||
parent_found = false,
|
||||
i;
|
||||
|
||||
for (i = 0; i < data.length; i += 1) {
|
||||
entry = data[i];
|
||||
if (entry.host_name === undefined) return data;
|
||||
actual_host = entry.host_name;
|
||||
|
||||
if (entry.host_name === last_host) {
|
||||
|
||||
if (!data[i-1].has_child && !parent_found) {
|
||||
data[i-1].has_child = 1;
|
||||
data[i-1].child_class='state--hasChild';
|
||||
entry.child_class='state--isChild';
|
||||
entry.host_state = "";
|
||||
parent_found = true;
|
||||
} else {
|
||||
entry.is_child = 1;
|
||||
entry.child_class='state--isChild';
|
||||
entry.host_state = "";
|
||||
}
|
||||
|
||||
entry.host_name = "";
|
||||
|
||||
} else {
|
||||
first_child = false;
|
||||
parent_found = false;
|
||||
}
|
||||
|
||||
last_host = actual_host;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
getServices(requestFields, filters, tableConfig.apiName)
|
||||
.success(function (data) {
|
||||
$scope.entries = processMultipleServicesPerHost(data);
|
||||
console.log(tableConfig.toWrap[0]);
|
||||
$scope.entries = processColumnRepeat(data, tableConfig.cellToFieldsMap[tableConfig.toWrap[0]][1], tableConfig.cellToFieldsMap[tableConfig.toWrap[0]]);
|
||||
});
|
||||
}])
|
||||
|
||||
.directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) {
|
||||
.directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
compile: function () {
|
||||
|
@ -96,6 +60,8 @@ angular.module('adagios.table', ['adagios.live',
|
|||
tableConfig.cells.text = attrs.cellsText.split(',');
|
||||
tableConfig.cells.name = attrs.cellsName.split(',');
|
||||
tableConfig.apiName = attrs.apiName;
|
||||
tableConfig.toWrap = attrs.toWrap.split(',');
|
||||
tableConfig.noRepeat = attrs.noRepeat.split(',');
|
||||
|
||||
if (!!attrs.filters) {
|
||||
tableConfig.filters = attrs.filters;
|
||||
|
@ -134,4 +100,52 @@ angular.module('adagios.table', ['adagios.live',
|
|||
};
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}])
|
||||
|
||||
.service('processColumnRepeat', function() {
|
||||
|
||||
function clearFields(entry, fields) {
|
||||
angular.forEach(fields, function (value) {
|
||||
entry[value] = '';
|
||||
});
|
||||
};
|
||||
|
||||
return function (data, fieldToProcess, fields) {
|
||||
var last = '',
|
||||
actual = '',
|
||||
entry = {},
|
||||
first_child = false,
|
||||
parent_found = false,
|
||||
i;
|
||||
|
||||
console.log(fieldToProcess);
|
||||
for (i = 0; i < data.length; i += 1) {
|
||||
entry = data[i];
|
||||
actual = entry[fieldToProcess];
|
||||
|
||||
console.log(entry.host_name + " " + entry[fieldToProcess] + " === " + last);
|
||||
if (entry[fieldToProcess] === last) {
|
||||
|
||||
if (!data[i-1].has_child && !parent_found) {
|
||||
data[i-1].has_child = 1;
|
||||
data[i-1].child_class='state--hasChild';
|
||||
entry.child_class='state--isChild';
|
||||
parent_found = true;
|
||||
} else {
|
||||
entry.is_child = 1;
|
||||
entry.child_class='state--isChild';
|
||||
}
|
||||
|
||||
clearFields(entry, fields);
|
||||
|
||||
} else {
|
||||
first_child = false;
|
||||
parent_found = false;
|
||||
}
|
||||
|
||||
last = actual;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -44,7 +44,9 @@
|
|||
<adg-table cells-text="{{dashboardCellsText}}"
|
||||
cells-name="{{dashboardCellsName}}"
|
||||
api-name="{{dashboardApiName}}"
|
||||
filters="{{dashboardFilters}}"></adg-table>
|
||||
filters="{{dashboardFilters}}"
|
||||
to-wrap="{{dashboardToWrap}}"
|
||||
no-repeat="{{dashboardNoRepeat}}"></adg-table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -26,6 +26,8 @@ angular.module('adagios.view.dashboard', ['ngRoute',
|
|||
$scope.dashboardCellsName = dashboardConfig.cellsName.join();
|
||||
$scope.dashboardApiName = dashboardConfig.apiName;
|
||||
$scope.dashboardFilters = dashboardConfig.filters;
|
||||
$scope.dashboardToWrap = dashboardConfig.toWrap.join();
|
||||
$scope.dashboardNoRepeat = dashboardConfig.noRepeat.join();
|
||||
|
||||
getServices(fields, filters, apiName)
|
||||
.success(function (data) {
|
||||
|
@ -40,4 +42,6 @@ angular.module('adagios.view.dashboard', ['ngRoute',
|
|||
dashboardConfig.cellsName = readConfig.data.dashboardConfig.cells.name;
|
||||
dashboardConfig.apiName = readConfig.data.dashboardConfig.apiName;
|
||||
dashboardConfig.filters = readConfig.data.dashboardConfig.filters;
|
||||
dashboardConfig.toWrap = readConfig.data.dashboardConfig.wrap;
|
||||
dashboardConfig.noRepeat = readConfig.data.dashboardConfig.noRepeat;
|
||||
}]);
|
||||
|
|
Loading…
Reference in New Issue