freifunkmanager/public/app/nodes/nodesSort.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-07-06 22:52:31 +02:00
'use strict';
angular.module('ffhb')
.controller('NodesSortCtrl',function(NgTableParams,$scope,store){
$scope.tableParams = new NgTableParams({
2016-07-12 18:29:02 +02:00
sorting: { 'nodeinfo.hostname': 'asc' },
2016-07-06 22:52:31 +02:00
total: 0,
2016-07-12 18:29:02 +02:00
count: 100
2016-07-06 22:52:31 +02:00
}, {
dataset: []
});
2016-07-09 10:15:03 +02:00
var originalData = {};
2016-07-12 08:44:38 +02:00
function find(nodeid){
var node = originalData.filter(function(row){
return row.nodeid === nodeid;
2016-07-09 10:15:03 +02:00
});
2016-07-12 08:44:38 +02:00
return node[0];
2016-07-09 10:15:03 +02:00
}
$scope.cancel = function(row, rowForm) {
2016-07-12 08:44:38 +02:00
console.log('cancel',row);
2016-07-09 10:15:03 +02:00
row.isEditing = false;
2016-07-12 08:44:38 +02:00
rowForm.$setPristine();
angular.copy(find(row.nodeid),row);
2016-07-09 10:15:03 +02:00
};
$scope.save = function(row, rowForm) {
2016-07-12 08:44:38 +02:00
console.log('save',row);
2016-07-09 10:15:03 +02:00
row.isEditing = false;
2016-07-12 08:44:38 +02:00
rowForm.$setPristine();
angular.copy(row,find(row.nodeid));
2016-07-09 10:15:03 +02:00
store.saveNode(row.nodeid);
};
2016-07-06 22:52:31 +02:00
function render(prom){
prom.then(function(data){
2016-07-12 08:44:38 +02:00
originalData = 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-12 08:44:38 +02:00
$scope.tableParams.settings({dataset: angular.copy(originalData),total: data.nodesCount});
2016-07-06 22:52:31 +02:00
});
}
render(store.getData);
$scope.$on('store', function(ev, prom) {
render(prom);
});
});