Adds ability to add devices

This commit is contained in:
Patrick McDonagh
2016-04-29 16:44:53 -05:00
parent 3684d5c480
commit 46b02d6fd4
2 changed files with 98 additions and 23 deletions

View File

@@ -254,9 +254,54 @@ poconsole.factory('devices', function($q, $http, $log){
return deferred.promise;
};
var addDevice = function(d){
$log.info(d);
$http.post('/device/create', {
address: d.address,
device_type: d.device_type.id
}).success(function(data){
return data;
});
};
var updateDevice = function(d){
$http.post('/device/update/' + d.id, {
address: d.address,
device_type: d.device_type.id
}).success(function(data){
return data;
});
};
var deleteDevice = function(id){
var deferred = $q.defer();
var url = '/device/delete/' + id;
$http.get(url).success(function(data) {
deferred.resolve({
data:data
});
});
return deferred.promise;
};
var getDeviceTypes = function(){
var deferred = $q.defer();
$http.get('/device_type').success(function(data) {
deferred.resolve({
device_types:data
});
});
return deferred.promise;
};
return {
getAllDevices : getAllDevices,
getDevice: getDevice,
addDevice: addDevice,
deleteDevice: deleteDevice,
updateDevice: updateDevice,
getDeviceTypes: getDeviceTypes
};
});
@@ -651,6 +696,19 @@ poconsole.controller('configCtrl', function($scope, Page, $log, config, devices)
$scope.getDevices();
$scope.addDevice = function(dev){
var addDevice = devices.addDevice(dev);
getDevices.then(function(d){
$scope.getDevices();
});
};
var getDeviceTypes = devices.getDeviceTypes();
getDeviceTypes.then(function(d){
$scope.device_types = d.device_types;
});

View File

@@ -75,8 +75,25 @@
</table>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h2>New Device</h2>
<form>
<div class="form-group">
<label for="ip_address">IP Address</label>
<input type="text" class="form-control" id="ip_address" ng-model="newDevice.address" placeholder="###.###.###.###">
</div>
<div class="row well">
<div class="form-group">
<label for="device_type">Device Type</label>
<select ng-model="newDevice.device_type" ng-options="t as t.dType for t in device_types track by t.id" class="form-control" id="device_type"></select>
</div>
<button class="btn btn-primary" ng-click="addDevice(newDevice)">Set Parameter</button>
</form>
</div>
<div class="col-md-6">
<h2>New Parameter</h2>
<form>
<div class="form-group">
@@ -100,7 +117,7 @@
<button class="btn btn-primary" ng-click="addParameter()">Set Parameter</button>
</form>
<!--<pre>{{newParam}}</pre>-->
</div>
</div>
</div>
</div>