Updated persistence

This commit is contained in:
Admin
2015-08-05 16:21:20 -05:00
parent cf92620617
commit 561d3cfed5
8 changed files with 120 additions and 65 deletions

View File

@@ -1,7 +1,7 @@
angular.module('amazonechobridge', [])
.service('bridgeService', ["$http", function ($http) {
var self = this;
this.state = {base: window.location.origin + "/api/devices/", devices: [], error: ""};
this.state = {base: window.location.origin + "/api/devices", upnpbase: window.location.origin + "/upnp/configaddress", devices: [], error: ""};
this.viewDevices = function () {
this.state.error = "";
@@ -21,6 +21,24 @@ angular.module('amazonechobridge', [])
);
};
this.viewConfigAddress = function () {
this.state.error = "";
return $http.get(this.state.upnpbase).then(
function (response) {
self.state.upnpconfigaddress = response.data;
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
} else {
self.state.error = "If you're not seeing any address, you may be running into problems with CORS. " +
"You can work around this by running a fresh launch of Chrome with the --disable-web-security flag.";
}
console.log(error);
}
);
};
this.addDevice = function (id, name, type, onUrl, offUrl) {
this.state.error = "";
if (id) {
@@ -87,6 +105,7 @@ angular.module('amazonechobridge', [])
.controller('ViewingController', ["$scope", "bridgeService", function ($scope, bridgeService) {
bridgeService.viewDevices();
bridgeService.viewConfigAddress();
$scope.bridge = bridgeService.state;
$scope.deleteDevice = function (device) {
bridgeService.deleteDevice(device.id);