2016-07-06 22:52:31 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ffhb')
|
|
|
|
.controller('NodesGroupCtrl',function(NgTableParams,$scope,store){
|
|
|
|
$scope.tableParams = new NgTableParams({
|
|
|
|
sorting: { hostname: 'asc' },
|
|
|
|
group: 'nodeinfo.owner.contact',
|
|
|
|
total: 0,
|
|
|
|
count: 50
|
|
|
|
}, {
|
|
|
|
dataset: []
|
|
|
|
});
|
2016-07-09 10:15:03 +02:00
|
|
|
var originalData = {};
|
|
|
|
function resetRow(row, rowForm){
|
|
|
|
row.isEditing = false;
|
|
|
|
rowForm.$setPristine();
|
|
|
|
return _.findWhere(originalData, function(r){
|
|
|
|
return r.id === row.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$scope.cancel = function(row, rowForm) {
|
|
|
|
console.log('cancel',row,rowForm);
|
|
|
|
row.isEditing = false;
|
|
|
|
var originalRow = resetRow(row, rowForm);
|
|
|
|
angular.extend(row, originalRow);
|
|
|
|
};
|
|
|
|
$scope.save = function(row, rowForm) {
|
|
|
|
console.log('save',row,rowForm);
|
|
|
|
row.isEditing = false;
|
|
|
|
var originalRow = resetRow(row, rowForm);
|
|
|
|
angular.extend(originalRow, row);
|
|
|
|
store.saveNode(row.nodeid);
|
|
|
|
};
|
|
|
|
|
2016-07-06 22:52:31 +02:00
|
|
|
function render(prom){
|
|
|
|
prom.then(function(data){
|
2016-07-09 02:58:47 +02:00
|
|
|
var result = Object.keys(data.merged).map(function(nodeid){
|
2016-07-06 22:52:31 +02:00
|
|
|
data.merged[nodeid].nodeid = nodeid;
|
|
|
|
return data.merged[nodeid];
|
|
|
|
});
|
2016-07-09 10:15:03 +02:00
|
|
|
originalData = result;
|
|
|
|
$scope.tableParams.settings({dataset: angular.copy(result),total: data.nodesCount});
|
2016-07-06 22:52:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
render(store.getData);
|
|
|
|
$scope.$on('store', function(ev, prom) {
|
|
|
|
render(prom);
|
|
|
|
});
|
|
|
|
});
|