Updating how controllers work together with shared data.

This commit is contained in:
Admin
2015-08-14 16:19:51 -05:00
parent 4a80ce4230
commit b9076d1f2e
6 changed files with 74 additions and 44 deletions

View File

@@ -106,8 +106,8 @@ public class DeviceResponse {
deviceState.setCt(313);
List<Double> xv = new LinkedList<>();
xv.add(0.4255);
xv.add(0.3998);
xv.add(Double.valueOf("0.4255"));
xv.add(Double.valueOf("0.3998"));
deviceState.setXy(xv);
deviceState.setColormode("ct");
response.setName(name);

View File

@@ -62,12 +62,15 @@ public class DeviceRepository {
}
private void put(int id, DeviceDescriptor aDescriptor) {
devices.put(String.valueOf(id),aDescriptor);
devices.put(String.valueOf(id), aDescriptor);
}
public void save(DeviceDescriptor aDescriptor) {
int id = random.nextInt(Integer.MAX_VALUE);
aDescriptor.setId(String.valueOf(id));
if(aDescriptor.getId() != null)
devices.remove(aDescriptor.getId());
else
aDescriptor.setId(String.valueOf(id));
put(id, aDescriptor);
JsonTransformer aRenderer = new JsonTransformer();
String jsonValue = aRenderer.render(findAll());

View File

@@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HA Bridge Configuration</title>
<title>HA Bridge</title>
<style>
body {
padding-top: 60px;

View File

@@ -15,15 +15,46 @@ app.config(function ($routeProvider) {
})
});
app.factory('BridgeSettings'), function() {
return {
name : 'anonymous'
};
app.run( function (bridgeService) {
bridgeService.viewBridgeSettings();
});
app.service('bridgeService', function ($http) {
app.factory('BridgeSettings', function() {
var BridgeSettings = {};
BridgeSettings.upnpconfigaddress = "";
BridgeSettings.serverport = "";
BridgeSettings.upnpdevicedb = "";
BridgeSettings.upnpresponseport = "";
BridgeSettings.veraaddress = "";
BridgeSettings.setupnpconfigaddress = function(aconfigaddress){
BridgeSettings.upnpconfigaddress = aconfigaddress;
};
BridgeSettings.setserverport = function(aserverport){
BridgeSettings.serverport = aserverport;
};
BridgeSettings.setupnpdevicedb = function(aupnpdevicedb){
BridgeSettings.upnpdevicedb = aupnpdevicedb;
};
BridgeSettings.setupnpresponseport = function(aupnpresponseport){
BridgeSettings.upnpresponseport = aupnpresponseport;
};
BridgeSettings.setveraaddress = function(averaaddress){
BridgeSettings.veraaddress = averaaddress;
};
return BridgeSettings;
});
app.service('bridgeService', function ($http, BridgeSettings) {
var self = this;
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], error: ""};
self.BridgeSettings = BridgeSettings;
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/settings", devices: [], device: [], error: ""};
this.viewDevices = function () {
this.state.error = "";
@@ -47,11 +78,11 @@ app.service('bridgeService', function ($http) {
this.state.error = "";
return $http.get(this.state.upnpbase).then(
function (response) {
self.state.upnpconfigaddress = response.data.upnpconfigaddress;
self.state.serverport = response.data.serverport;
self.state.upnpdevicedb = response.data.upnpdevicedb;
self.state.upnpresponseport = response.data.upnpresponseport;
self.state.veraaddress = response.data.veraaddress;
self.BridgeSettings.setupnpconfigaddress(response.data.upnpconfigaddress);
self.BridgeSettings.setserverport(response.data.serverport);
self.BridgeSettings.setupnpdevicedb(response.data.upnpdevicedb);
self.BridgeSettings.setupnpresponseport(response.data.upnpresponseport);
self.BridgeSettings.setveraaddress(response.data.veraaddress);
},
function (error) {
if (error.data) {
@@ -158,18 +189,14 @@ app.service('bridgeService', function ($http) {
};
this.editDevice = function (id, name, onUrl, offUrl) {
this.device.id = id;
this.device.name = name;
this.device.onUrl = onUrl;
this.device.offUrl = offUrl;
self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl};
};
});
app.controller('ViewingController', function ($scope, bridgeService) {
app.controller('ViewingController', function ($scope, $location, bridgeService, BridgeSettings) {
$scope.BridgeSettings = bridgeService.BridgeSettings;
bridgeService.viewDevices();
bridgeService.viewBridgeSettings();
bridgeService.viewVeraDevices();
bridgeService.viewVeraScenes();
$scope.bridge = bridgeService.state;
$scope.deleteDevice = function (device) {
bridgeService.deleteDevice(device.id);
@@ -183,14 +210,21 @@ app.controller('ViewingController', function ($scope, bridgeService) {
};
$scope.editDevice = function (device) {
bridgeService.editDevice(device.id, device.name, device.onUrl, device.offUrl);
$location.path('/editor');
};
});
app.controller('AddingController', function ($scope, bridgeService) {
app.controller('AddingController', function ($scope, bridgeService, BridgeSettings) {
$scope.device = {id: "", name: "", type: "switch", onUrl: "", offUrl: ""};
$scope.vera = {base: "", port: "3480", id: ""};
$scope.vera.base = "http://" + BridgeSettings.veraaddress;
bridgeService.device = $scope.device;
bridgeService.viewVeraDevices();
bridgeService.viewVeraScenes();
$scope.bridge = bridgeService.state;
$scope.device = bridgeService.state.device;
$scope.buildUrls = function () {
if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + $scope.vera.base;
@@ -203,9 +237,9 @@ app.controller('AddingController', function ($scope, bridgeService) {
+ $scope.vera.id;
};
$scope.buildDeviceUrls = function (veradevice, veraaddr) {
$scope.buildDeviceUrls = function (veradevice) {
if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + veraaddr;
$scope.vera.base = "http://" + $scope.vera.base;
}
$scope.device.name = veradevice.name;
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
@@ -216,9 +250,9 @@ app.controller('AddingController', function ($scope, bridgeService) {
+ veradevice.id;
};
$scope.buildSceneUrls = function (verascene, veraaddr) {
$scope.buildSceneUrls = function (verascene) {
if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + veraaddr;
$scope.vera.base = "http://" + $scope.vera.base;
}
$scope.device.name = verascene.name;
$scope.device.onUrl = $scope.vera.base + ":" + $scope.vera.port
@@ -229,10 +263,6 @@ app.controller('AddingController', function ($scope, bridgeService) {
+ verascene.id;
};
$scope.setVeraAddress = function (anAddress) {
$scope.vera.base = "http://" + anAddress;
};
$scope.testUrl = function (url) {
window.open(url, "_blank");
};

View File

@@ -33,23 +33,23 @@
</thead>
<tr>
<td>upnp.config.address</td>
<td>{{bridge.upnpconfigaddress}}</td>
<td>{{BridgeSettings.upnpconfigaddress}}</td>
</tr>
<tr>
<td>server.port</td>
<td>{{bridge.serverport}}</td>
<td>{{BridgeSettings.serverport}}</td>
</tr>
<tr>
<td>upnp.devices.db</td>
<td>{{bridge.upnpdevicedb}}</td>
<td>{{BridgeSettings.upnpdevicedb}}</td>
</tr>
<tr>
<td>upnp.response.port</td>
<td>{{bridge.upnpresponseport}}</td>
<td>{{BridgeSettings.upnpresponseport}}</td>
</tr>
<tr>
<td>vera.address</td>
<td>{{bridge.veraaddress}}</td>
<td>{{BridgeSettings.veraaddress}}</td>
</tr>
</table>
</div>

View File

@@ -29,7 +29,7 @@
<td>{{veradevice.room}}</td>
<td>
<button class="btn btn-success" type="submit"
ng-click="buildDeviceUrls(veradevice, bridge.veraaddress)">Generate
ng-click="buildDeviceUrls(veradevice)">Generate
Device URLs</button>
</td>
</tr>
@@ -61,7 +61,7 @@
<td>{{verascene.room}}</td>
<td>
<button class="btn btn-success" type="submit"
ng-click="buildSceneUrls(verascene, bridge.veraaddress)">Generate
ng-click="buildSceneUrls(verascene)">Generate
Device URLs</button>
</td>
</tr>
@@ -89,9 +89,6 @@
ng-model="vera.base"
placeholder="Vera URL (e.g. http://192.168.1.100)">
</div>
<button type="submit" ng-click="setVeraAddress(bridge.veraaddress)"
class="col-xs-4 col-sm-2 btn btn-success">Use
vera.address</button>
</div>
<div class="form-group">
<label class="col-xs-2 col-sm-2 control-label" for="vera-port">Vera