diff --git a/public/app/node.jade b/public/app/node.jade index bd1a387..ce8a0e4 100644 --- a/public/app/node.jade +++ b/public/app/node.jade @@ -3,7 +3,13 @@ .page-header h1 {{node.nodeinfo.hostname}} small {{nodeid}} + form(name="rowForm",ng-submit="save()") + .form-group + label Online + p.form-control-static + span.glyphicon(ng-class="{'glyphicon-ok':node.flags.online,'glyphicon-remove':!node.flags.online}") + span(am-time-ago="node.lastseen") .form-group(ng-class="rowForm.group.$invalid ? 'has-error' : ''") label(for="formGroup") Group input.form-control(id="formGroup",placeholder="Group",type="text",name="group",pattern="[a-zA-Z0-9-]*",ng-model='node.nodeinfo.owner.contact') diff --git a/public/app/nodes/nodesGroup.js b/public/app/nodes/nodesGroup.js index be7f1ce..ff99812 100644 --- a/public/app/nodes/nodesGroup.js +++ b/public/app/nodes/nodesGroup.js @@ -11,24 +11,17 @@ angular.module('ffhb') dataset: [] }); 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); + rowForm.$setPristine(); + originalData[row.nodeid] = angular.copy(row); }; $scope.save = function(row, rowForm) { console.log('save',row,rowForm); row.isEditing = false; - var originalRow = resetRow(row, rowForm); - angular.extend(originalRow, row); + rowForm.$setPristine(); + row = angular.copy(originalData[row.nodeid]); store.saveNode(row.nodeid); }; diff --git a/public/app/nodes/nodesSort.js b/public/app/nodes/nodesSort.js index f5d4550..40dc3ea 100644 --- a/public/app/nodes/nodesSort.js +++ b/public/app/nodes/nodesSort.js @@ -10,35 +10,33 @@ angular.module('ffhb') dataset: [] }); var originalData = {}; - function resetRow(row, rowForm){ - row.isEditing = false; - rowForm.$setPristine(); - return _.findWhere(originalData, function(r){ - return r.id === row.id; + function find(nodeid){ + var node = originalData.filter(function(row){ + return row.nodeid === nodeid; }); + return node[0]; } $scope.cancel = function(row, rowForm) { - console.log('cancel',row,rowForm); + console.log('cancel',row); row.isEditing = false; - var originalRow = resetRow(row, rowForm); - angular.extend(row, originalRow); + rowForm.$setPristine(); + angular.copy(find(row.nodeid),row); }; $scope.save = function(row, rowForm) { - console.log('save',row,rowForm); + console.log('save',row); row.isEditing = false; - var originalRow = resetRow(row, rowForm); - angular.extend(originalRow, row); + rowForm.$setPristine(); + angular.copy(row,find(row.nodeid)); store.saveNode(row.nodeid); }; function render(prom){ prom.then(function(data){ - var result = Object.keys(data.merged).map(function(nodeid){ + originalData = Object.keys(data.merged).map(function(nodeid){ data.merged[nodeid].nodeid = nodeid; return data.merged[nodeid]; }); - originalData = result; - $scope.tableParams.settings({dataset: angular.copy(result),total: data.nodesCount}); + $scope.tableParams.settings({dataset: angular.copy(originalData),total: data.nodesCount}); }); } render(store.getData); diff --git a/public/components/store.js b/public/components/store.js index d1f97ac..ee3a839 100644 --- a/public/components/store.js +++ b/public/components/store.js @@ -123,10 +123,10 @@ angular.module('ffhb') } if(node.nodeinfo.wireless){ obj.wireless = { - 'channel24': node.nodeinfo.wireless.channel24||0, - 'channel5': node.nodeinfo.wireless.channel5||0, - 'txpower24': node.nodeinfo.wireless.txpower24||0, - 'txpower5': node.nodeinfo.wireless.txpower5||0 + 'channel24': parseInt(node.nodeinfo.wireless.channel24)||0, + 'channel5': parseInt(node.nodeinfo.wireless.channel5)||0, + 'txpower24': parseInt(node.nodeinfo.wireless.txpower24)||0, + 'txpower5': parseInt(node.nodeinfo.wireless.txpower5)||0 }; } $http.post(config.api+'/aliases/alias/'+nodeid,obj).then(function(){