From 41e22ee64d0b729488a949831efe4a43a6cb10c7 Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 16 Nov 2015 16:33:29 -0600 Subject: [PATCH] Refactor TestUrl call in apps.js. Updated UI to only have test buttons after a device is added. --- src/main/resources/public/scripts/app.js | 163 +++--------------- .../resources/public/views/editdevice.html | 8 - src/main/resources/public/views/editor.html | 8 - .../resources/public/views/veradevice.html | 8 - .../resources/public/views/verascene.html | 8 - 5 files changed, 27 insertions(+), 168 deletions(-) diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index 8ffd9c8..d28deb9 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -322,6 +322,31 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) { this.editDevice = function (id, name, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) { self.state.device = {id: id, name: name, onUrl: onUrl, offUrl: offUrl, httpVerb: httpVerb, contentType: contentType, contentBody: contentBody, contentBodyOff: contentBodyOff}; }; + + this.testUrl = function (device, type) { + if(type == "on") { + $http.put(this.state.huebase + "/test/lights/" + device.id + "/state", "{\"on\":true}").then( + function (response) { + $window.alert("Request Exceuted: " + response.statusText); + }, + function (error) { + $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); + } + ); + return; + } + else { + $http.put(this.state.huebase + "/test/lights/" + device.id + "/state", "{\"on\":false}").then( + function (response) { + $window.alert("Request Exceuted: " + response.statusText); + }, + function (error) { + $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); + } + ); + return; + } + }; }); app.controller('ViewingController', function ($scope, $location, $http, $window, bridgeService, BridgeSettings) { @@ -341,74 +366,7 @@ app.controller('ViewingController', function ($scope, $location, $http, $window, bridgeService.deleteDevice(device.id); }; $scope.testUrl = function (device, type) { - if(type == "on") { - if(device.deviceType == "activity" || device.deviceType == "button") { - $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":true}").then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - return; - } - - if(device.httpVerb == "PUT") - $http.put(device.onUrl, device.contentBody).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else if(device.httpVerb == "POST") - $http.post(device.onUrl, device.contentBody).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else - window.open(device.onUrl, "_blank"); - } - else { - if(device.deviceType == "activity" || device.deviceType == "button") { - $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":false}").then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - return; - } - - if(device.httpVerb == "PUT") - $http.put(device.offUrl, device.contentBodyOff).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else if(device.httpVerb == "POST") - $http.post(device.offUrl, device.contentBodyOff).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else - window.open(device.offUrl, "_blank"); - } + bridgeService.testUrl(device, type); }; $scope.setBridgeUrl = function (url) { bridgeService.state.base = url; @@ -524,74 +482,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer }; $scope.testUrl = function (device, type) { - if(type == "on") { - if(device.deviceType == "activity" || device.deviceType == "button") { - $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":true}").then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - return; - } - - if(device.httpVerb == "PUT") - $http.put(device.onUrl, device.contentBody).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else if(device.httpVerb == "POST") - $http.post(device.onUrl, device.contentBody).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else - window.open(device.onUrl, "_blank"); - } - else { - if(device.deviceType == "activity" || device.deviceType == "button") { - $http.put($scope.bridge.huebase + "/test/lights/" + device.id + "/state", "{\"on\":false}").then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - return; - } - - if(device.httpVerb == "PUT") - $http.put(device.offUrl, device.contentBodyOff).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else if(device.httpVerb == "POST") - $http.post(device.offUrl, device.contentBodyOff).then( - function (response) { - $window.alert("Request Exceuted: " + response.statusText); - }, - function (error) { - $window.alert("Request Error: " + error.statusText + ", with status: " + error.status + ", Pleae look in your console log."); - } - ); - else - window.open(device.offUrl, "_blank"); - } + bridgeService.testUrl(device, type); }; $scope.addDevice = function () { diff --git a/src/main/resources/public/views/editdevice.html b/src/main/resources/public/views/editdevice.html index 0971cb3..05b2ec6 100644 --- a/src/main/resources/public/views/editdevice.html +++ b/src/main/resources/public/views/editdevice.html @@ -35,10 +35,6 @@ -
- -
@@ -49,10 +45,6 @@
-
- -
diff --git a/src/main/resources/public/views/editor.html b/src/main/resources/public/views/editor.html index 872bf83..d2648be 100644 --- a/src/main/resources/public/views/editor.html +++ b/src/main/resources/public/views/editor.html @@ -98,10 +98,6 @@
-
- -
@@ -112,10 +108,6 @@
-
- -
diff --git a/src/main/resources/public/views/veradevice.html b/src/main/resources/public/views/veradevice.html index f04fd34..1d0a0b7 100644 --- a/src/main/resources/public/views/veradevice.html +++ b/src/main/resources/public/views/veradevice.html @@ -87,10 +87,6 @@
-
- -
@@ -101,10 +97,6 @@
-
- -
diff --git a/src/main/resources/public/views/verascene.html b/src/main/resources/public/views/verascene.html index a7809b5..7f58856 100644 --- a/src/main/resources/public/views/verascene.html +++ b/src/main/resources/public/views/verascene.html @@ -75,10 +75,6 @@ -
- -
@@ -89,10 +85,6 @@
-
- -