mirror of
https://github.com/bwssytems/ha-bridge.git
synced 2025-12-19 08:28:46 +00:00
Refactor TestUrl call in apps.js. Updated UI to only have test buttons
after a device is added.
This commit is contained in:
@@ -322,6 +322,31 @@ app.service('bridgeService', function ($http, $window, BridgeSettings) {
|
|||||||
this.editDevice = function (id, name, onUrl, offUrl, httpVerb, contentType, contentBody, contentBodyOff) {
|
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};
|
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) {
|
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);
|
bridgeService.deleteDevice(device.id);
|
||||||
};
|
};
|
||||||
$scope.testUrl = function (device, type) {
|
$scope.testUrl = function (device, type) {
|
||||||
if(type == "on") {
|
bridgeService.testUrl(device, type);
|
||||||
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");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
$scope.setBridgeUrl = function (url) {
|
$scope.setBridgeUrl = function (url) {
|
||||||
bridgeService.state.base = url;
|
bridgeService.state.base = url;
|
||||||
@@ -524,74 +482,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.testUrl = function (device, type) {
|
$scope.testUrl = function (device, type) {
|
||||||
if(type == "on") {
|
bridgeService.testUrl(device, type);
|
||||||
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");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addDevice = function () {
|
$scope.addDevice = function () {
|
||||||
|
|||||||
@@ -35,10 +35,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-on-url"
|
<textarea rows="3" class="form-control" id="device-on-url"
|
||||||
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'on')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -49,10 +45,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-off-url"
|
<textarea rows="3" class="form-control" id="device-off-url"
|
||||||
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'off')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -98,10 +98,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-on-url"
|
<textarea rows="3" class="form-control" id="device-on-url"
|
||||||
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'on')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -112,10 +108,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-off-url"
|
<textarea rows="3" class="form-control" id="device-off-url"
|
||||||
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'off')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -87,10 +87,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-on-url"
|
<textarea rows="3" class="form-control" id="device-on-url"
|
||||||
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'on')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -101,10 +97,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-off-url"
|
<textarea rows="3" class="form-control" id="device-off-url"
|
||||||
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'off')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -75,10 +75,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-on-url"
|
<textarea rows="3" class="form-control" id="device-on-url"
|
||||||
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
ng-model="device.onUrl" placeholder="URL to turn device on"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'on')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -89,10 +85,6 @@
|
|||||||
<textarea rows="3" class="form-control" id="device-off-url"
|
<textarea rows="3" class="form-control" id="device-off-url"
|
||||||
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
ng-model="device.offUrl" placeholder="URL to turn device off"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix visible-xs"></div>
|
|
||||||
<button class="col-xs-4 col-sm-2 btn btn-success" type="button"
|
|
||||||
ng-click="testUrl(device, 'off')">Test</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user