diff --git a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java index f0665b7..993fb0f 100644 --- a/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java +++ b/src/main/java/com/bwssystems/HABridge/dao/DeviceRepository.java @@ -3,6 +3,8 @@ package com.bwssystems.HABridge.dao; import java.io.IOException; import java.io.StringReader; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -106,7 +108,10 @@ public class DeviceRepository { } try { + Path target = FileSystems.getDefault().getPath("data", "device.db.old"); + Files.move(filePath, target); Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE); + Files.delete(target); } catch (IOException e) { log.error("Error writing the file: " + filePath + " message: " + e.getMessage(), e); } diff --git a/src/main/resources/public/scripts/app.js b/src/main/resources/public/scripts/app.js index c431c5b..fcd4be6 100644 --- a/src/main/resources/public/scripts/app.js +++ b/src/main/resources/public/scripts/app.js @@ -182,6 +182,8 @@ app.service('bridgeService', function ($http, BridgeSettings) { } ); } else { + if(type == null || type == "") + type = "switch"; return $http.post(this.state.base, { name: name, deviceType: type, @@ -241,14 +243,46 @@ app.controller('ViewingController', function ($scope, $location, $http, bridgeSe }; $scope.testUrl = function (device, type) { if(type == "on") { - if(device.httpVerb == "PUT" || device.httpVerb == "POST") - $http.put(device.onUrl, device.contentBody); + if(device.httpVerb == "PUT") + $http.put(device.onUrl, device.contentBody).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); + else if(device.httpVerb == "POST") + $http.post(device.onUrl, device.contentBody).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); else window.open(device.onUrl, "_blank"); } else { - if(device.httpVerb == "PUT" || device.httpVerb == "POST") - $http.put(device.offUrl, device.contentBodyOff); + if(device.httpVerb == "PUT") + $http.put(device.offUrl, device.contentBodyOff).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); + else if(device.httpVerb == "POST") + $http.post(device.offUrl, device.contentBody).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); else window.open(device.offUrl, "_blank"); } @@ -335,14 +369,46 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer $scope.testUrl = function (url) { if(type == "on") { - if(device.httpVerb == "PUT" || device.httpVerb == "POST") - $http.put(device.onUrl, device.contentBody); + if(device.httpVerb == "PUT") + $http.put(device.onUrl, device.contentBody).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); + else if(device.httpVerb == "POST") + $http.post(device.onUrl, device.contentBody).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); else window.open(device.onUrl, "_blank"); } else { - if(device.httpVerb == "PUT" || device.httpVerb == "POST") - $http.put(device.offUrl, device.contentBodyOff); + if(device.httpVerb == "PUT") + $http.put(device.offUrl, device.contentBodyOff).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); + else if(device.httpVerb == "POST") + $http.post(device.offUrl, device.contentBody).then( + function (response) { + $scope.responsedata = response.data; + }, + function (error) { + console.log(error); + } + ); else window.open(device.offUrl, "_blank"); }