update ui components.

This commit is contained in:
Admin
2016-02-16 16:53:01 -06:00
parent 1d6a4c1432
commit 13fa5dea73
3 changed files with 926 additions and 893 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId>
<version>1.3.8e</version>
<version>1.3.8f</version>
<packaging>jar</packaging>
<name>HA Bridge</name>
@@ -33,7 +33,7 @@
<dependency>
<groupId>com.github.bwssytems</groupId>
<artifactId>nest-controller</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>

View File

@@ -41,38 +41,30 @@ app.run( function (bridgeService) {
app.service('bridgeService', function ($http, $window, ngToast) {
var self = this;
this.state = {base: window.location.origin + "/api/devices", systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: [], settings: [], olddevicename: "", error: "", showVera: false, showHarmony: false, showNest: false, habridgeversion: ""};
this.state = {base: window.location.origin + "/api/devices", bridgelocation: window.location.origin, systemsbase: window.location.origin + "/system", huebase: window.location.origin + "/api", configs: [], backups: [], devices: [], device: [], settings: [], myToastMsg: [], olddevicename: "", showVera: false, showHarmony: false, showNest: false, habridgeversion: ""};
this.viewDevices = function () {
this.state.error = "";
return $http.get(this.state.base).then(
function (response) {
self.state.devices = response.data;
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
} else {
self.state.error = "Some error occurred.";
}
console.log(error);
ngToast.create({
className: "warning",
content:"Cannot get devices from habridge: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.getHABridgeVersion = function () {
this.state.error = "";
return $http.get(this.state.systemsbase + "/habridge/version").then(
function (response) {
self.state.habridgeversion = response.data.version;
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
} else {
self.state.error = "cannot get version";
}
console.log(error);
ngToast.create({
className: "warning",
content:"Cannot get version" + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
@@ -96,9 +88,7 @@ app.service('bridgeService', function ($http, $window, ngToast) {
return;
}
this.loadBridgeSettings = function () {
this.state.error = "";
return $http.get(this.state.systemsbase + "/settings").then(
function (response) {
self.state.settings = response.data;
@@ -107,50 +97,40 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.updateShowNest();
},
function (error) {
if (error.data) {
$window.alert("Load Bridge Settings Error: " + error.data.message);
} else {
$window.alert("Load Bridge Settings Error: unknown");
}
console.log(error);
ngToast.create({
className: "warning",
content:"Load Bridge Settings Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.viewBackups = function () {
this.state.error = "";
return $http.get(this.state.base + "/backup/available").then(
function (response) {
self.state.backups = response.data;
},
function (error) {
if (error.data) {
$window.alert("Get Backups Error: " + error.data.message);
} else {
$window.alert("Get Backups Error: unknown");
}
ngToast.create({
className: "warning",
content:"Get Backups Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.viewConfigs = function () {
this.state.error = "";
return $http.get(this.state.systemsbase + "/backup/available").then(
function (response) {
self.state.configs = response.data;
},
function (error) {
if (error.data) {
$window.alert("Get Configs Error: " + error.data.message);
} else {
$window.alert("Get Configs Error: unknown");
}
ngToast.create({
className: "warning",
content:"Get Configs Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.viewNestItems = function () {
this.state.error = "";
if(!this.state.showNest)
return;
return $http.get(this.state.base + "/nest/items").then(
@@ -158,17 +138,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.state.nestitems = response.data;
},
function (error) {
if (error.data) {
$window.alert("Get Nest Items Error: " + error.data.message);
} else {
$window.alert("Get Nest Items Error: unknown");
}
ngToast.create({
className: "warning",
content:"Get Nest Items Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.viewVeraDevices = function () {
this.state.error = "";
if(!this.state.showVera)
return;
return $http.get(this.state.base + "/vera/devices").then(
@@ -176,17 +153,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.state.veradevices = response.data;
},
function (error) {
if (error.data) {
$window.alert("Get Vera Devices Error: " + error.data.message);
} else {
$window.alert("Get Vera Devices Error: unknown");
}
ngToast.create({
className: "warning",
content:"Get Vera Devices Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.viewVeraScenes = function () {
this.state.error = "";
if(!this.state.showVera)
return;
return $http.get(this.state.base + "/vera/scenes").then(
@@ -194,17 +168,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.state.verascenes = response.data;
},
function (error) {
if (error.data) {
$window.alert("Get Vera Scenes Error: " + error.data.message);
} else {
$window.alert("Get Vera Scenes Error: unknown");
}
ngToast.create({
className: "warning",
content:"Get Vera Scenes Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.viewHarmonyActivities = function () {
this.state.error = "";
if(!this.state.showHarmony)
return;
return $http.get(this.state.base + "/harmony/activities").then(
@@ -212,17 +183,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.state.harmonyactivities = response.data;
},
function (error) {
if (error.data) {
$window.alert("Get Harmony Activities Error: " + error.data.message);
} else {
$window.alert("Get Harmony Activities Error: unknown");
}
ngToast.create({
className: "warning",
content:"Get Harmony Activities Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.viewHarmonyDevices = function () {
this.state.error = "";
if(!this.state.showHarmony)
return;
return $http.get(this.state.base + "/harmony/devices").then(
@@ -230,11 +198,9 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.state.harmonydevices = response.data;
},
function (error) {
if (error.data) {
$window.alert("Get Harmony Devices Error: " + error.data.message);
} else {
$window.alert("Get Harmony Devices Error: unknown");
}
ngToast.create({
className: "warning",
content:"Get Harmony Devices Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
@@ -256,21 +222,18 @@ app.service('bridgeService', function ($http, $window, ngToast) {
};
this.bulkAddDevice = function (devices) {
this.state.error = "";
return $http.post(this.state.base, devices).then(
function (response) {
},
function (error) {
if (error.data) {
$window.alert("Bulk Add new Device Error: " + error.data.message);
}
self.state.error = "Bulk Add new Device Error: unknown";
ngToast.create({
className: "warning",
content:"Bulk Add new Device Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.addDevice = function (device) {
this.state.error = "";
if(device.httpVerb != null && device.httpVerb != "")
device.deviceType = "custom";
if(device.targetDevice == null || device.targetDevice == "")
@@ -294,10 +257,9 @@ app.service('bridgeService', function ($http, $window, ngToast) {
function (response) {
},
function (error) {
if (error.data) {
$window.alert("Edit Device Error: " + error.data.message);
}
$window.alert("Edit Device Error: unknown");
ngToast.create({
className: "warning",
content:"Edit Device Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
} else {
@@ -319,17 +281,15 @@ app.service('bridgeService', function ($http, $window, ngToast) {
function (response) {
},
function (error) {
if (error.data) {
$window.alert("Add new Device Error: " + error.data.message);
}
self.state.error = "Add new Device Error: unknown";
ngToast.create({
className: "warning",
content:"Add new Device Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
}
};
this.backupDeviceDb = function (afilename) {
this.state.error = "";
return $http.put(this.state.base + "/backup/create", {
filename: afilename
}).then(
@@ -337,16 +297,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.viewBackups();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Backup Device Db Error: unknown";
ngToast.create({
className: "warning",
content:"Backup Device Db Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.restoreBackup = function (afilename) {
this.state.error = "";
return $http.post(this.state.base + "/backup/restore", {
filename: afilename
}).then(
@@ -355,16 +313,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.viewDevices();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Backup Db Restore Error: unknown";
ngToast.create({
className: "warning",
content:"Backup Db Restore Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.deleteBackup = function (afilename) {
this.state.error = "";
return $http.post(this.state.base + "/backup/delete", {
filename: afilename
}).then(
@@ -372,32 +328,81 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.viewBackups();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
ngToast.create({
className: "warning",
content:"Delete Backup Db File Error:" + "unknown error" || error.data.message + " with status: " + error.status});
}
self.state.error = "Delete Backup Db File Error: unknown";
);
};
this.checkForBridge = function () {
return $http.get(this.state.bridgelocation + "/description.xml").then(
function (response) {
ngToast.dismiss(self.state.myToastMsg);
self.viewConfigs();
self.state.myToastMsg = null;
},
function (error) {
setTimeout(function(){
self.checkForBridge();
}, 2000);
}
);
};
this.stop = function() {
return $http.put(this.state.systemsbase + "/control/stop").then(
function (response) {
ngToast.create({
className: "danger",
dismissButton: true,
dismissOnTimeout: false,
content:"HABridge is now stopped. Restart must occur from the server."});
},
function (error) {
ngToast.create({
className: "warning",
content:"HABRidge Stop Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.reinit = function() {
return $http.put(this.state.systemsbase + "/control/reinit").then(
function (response) {
self.state.myToastMsg = ngToast.create({
className: "warning",
dismissButton: false,
dismissOnTimeout: false,
content:"HABridge is re-initializing, waiting for completion..."});
setTimeout(function(){
self.checkForBridge();
}, 2000);
},
function (error) {
ngToast.create({
className: "warning",
content:"HABRidge Reinit Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.saveSettings = function () {
this.state.error = "";
return $http.put(this.state.systemsbase + "/settings", this.state.settings).then(
function (response) {
self.viewConfigs();
self.reinit();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Save Settings Error: unknown";
ngToast.create({
className: "warning",
content:"Save Settings Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.backupSettings = function (afilename) {
this.state.error = "";
return $http.put(this.state.systemsbase + "/backup/create", {
filename: afilename
}).then(
@@ -405,16 +410,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.viewConfigs();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Backup Settings Error: unknown";
ngToast.create({
className: "warning",
content:"Backup Settings Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.restoreSettings = function (afilename) {
this.state.error = "";
return $http.post(this.state.systemsbase + "/backup/restore", {
filename: afilename
}).then(
@@ -423,16 +426,14 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.viewDevices();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Backup Settings Restore Error: unknown";
ngToast.create({
className: "warning",
content:"Backup Settings Restore Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.deleteSettingsBackup = function (afilename) {
this.state.error = "";
return $http.post(this.state.systemsbase + "/backup/delete", {
filename: afilename
}).then(
@@ -440,25 +441,22 @@ app.service('bridgeService', function ($http, $window, ngToast) {
self.viewConfigs();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Delete Backup Settings File Error: unknown";
ngToast.create({
className: "warning",
content:"Delete Backup Settings File Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
this.deleteDevice = function (id) {
this.state.error = "";
return $http.delete(this.state.base + "/" + id).then(
function (response) {
self.viewDevices();
},
function (error) {
if (error.data) {
self.state.error = error.data.message;
}
self.state.error = "Delete Device Error: unknown";
ngToast.create({
className: "warning",
content:"Delete Device Error: " + "unknown error" || error.data.message + " with status: " + error.status});
}
);
};
@@ -507,7 +505,7 @@ app.service('bridgeService', function ($http, $window, ngToast) {
return;
}
};
});
});
app.controller('SystemController', function ($scope, $location, $http, $window, bridgeService) {
bridgeService.viewConfigs();
@@ -521,8 +519,39 @@ app.controller('SystemController', function ($scope, $location, $http, $window,
if($scope.bridge.settings.veraddress == null) {
$scope.bridge.settings.veraddress = { devices: [] };
}
$scope.bridge.settings.veraaddress.devices.push("{" +"\"name\":\"" + newveraname +"\",\"ip\":\"" + newveraip + "\"}");
var newVera = {name: newveraname, ip: newveraip }
$scope.bridge.settings.veraaddress.devices.push(newVera);
$scope.newveraname = null;
$scope.newveraip = null;
};
$scope.removeVeratoSettings = function (veraname, veraip) {
for(var i = $scope.bridge.settings.veraaddress.devices.length - 1; i >= 0; i--) {
if($scope.bridge.settings.veraaddress.devices[i].name === veraname && $scope.bridge.settings.veraaddress.devices[i].ip === veraip) {
$scope.bridge.settings.veraaddress.devices.splice(i, 1);
}
}
};
$scope.addHarmonytoSettings = function (newharmonyname, newharmonyip) {
if($scope.bridge.settings.harmonyaddress == null) {
$scope.bridge.settings.harmonyaddress = { devices: [] };
}
var newharmony = {name: newharmonyname, ip: newharmonyip }
$scope.bridge.settings.harmonyaddress.devices.push(newharmony);
$scope.newharmonyname = null;
$scope.newharmonyip = null;
};
$scope.removeHarmonytoSettings = function (harmonyname, harmonyip) {
for(var i = $scope.bridge.settings.harmonyaddress.devices.length - 1; i >= 0; i--) {
if($scope.bridge.settings.harmonyaddress.devices[i].name === harmonyname && $scope.bridge.settings.harmonyaddress.devices[i].ip === harmonyip) {
$scope.bridge.settings.harmonyaddress.devices.splice(i, 1);
}
}
};
$scope.bridgeReinit = function () {
bridgeService.reinit();
};
$scope.bridgeStop = function () {
bridgeService.stop();
};
$scope.saveSettings = function() {
bridgeService.saveSettings();
@@ -608,7 +637,7 @@ app.controller('ViewingController', function ($scope, $location, $http, $window,
else
$scope.imgBkUrl = "glyphicon glyphicon-plus";
};
});
});
app.controller('AddingController', function ($scope, $location, $http, bridgeService) {
$scope.bridge = bridgeService.state;
@@ -650,7 +679,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
$scope.device.contentBodyOff = null;
$scope.bridge.olddevicename = "";
};
$scope.clearDevice();
$scope.buildUrlsUsingDevice = function (dim_control) {
if ($scope.vera.base.indexOf("http") < 0) {
$scope.vera.base = "http://" + $scope.vera.base;
@@ -720,7 +749,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
$scope.device.onUrl = "http://" + verascene.veraaddress + ":" + $scope.vera.port
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
+ verascene.id;
$scope.device.offUrl = "http://" + verascene.veraaddress + + ":" + $scope.vera.port
$scope.device.offUrl = "http://" + verascene.veraaddress + ":" + $scope.vera.port
+ "/data_request?id=action&output_format=json&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum="
+ verascene.id;
};
@@ -916,7 +945,7 @@ app.controller('AddingController', function ($scope, $location, $http, bridgeSer
bridgeService.deleteDeviceByMapId(id, mapType);
};
});
});
app.filter('availableHarmonyActivityId', function(bridgeService) {
return function(input) {
@@ -930,7 +959,7 @@ app.filter('availableHarmonyActivityId', function(bridgeService) {
}
return out;
}
});
});
app.filter('unavailableHarmonyActivityId', function(bridgeService) {
return function(input) {
@@ -961,7 +990,7 @@ app.filter('availableVeraDeviceId', function(bridgeService) {
});
app.filter('unavailableVeraDeviceId', function(bridgeService) {
return function(input) {
return function(input) {
var out = [];
if(input == null)
return out;
@@ -971,7 +1000,7 @@ return function(input) {
}
}
return out;
}
}
});
app.filter('availableVeraSceneId', function(bridgeService) {
@@ -989,7 +1018,7 @@ app.filter('availableVeraSceneId', function(bridgeService) {
});
app.filter('unavailableVeraSceneId', function(bridgeService) {
return function(input) {
return function(input) {
var out = [];
if(input == null)
return out;
@@ -999,7 +1028,7 @@ return function(input) {
}
}
return out;
}
}
});
app.filter('availableNestItemId', function(bridgeService) {
@@ -1017,7 +1046,7 @@ app.filter('availableNestItemId', function(bridgeService) {
});
app.filter('unavailableNestItemId', function(bridgeService) {
return function(input) {
return function(input) {
var out = [];
if(input == null)
return out;
@@ -1027,7 +1056,7 @@ return function(input) {
}
}
return out;
}
}
});
app.filter('configuredButtons', function() {
@@ -1047,7 +1076,7 @@ app.filter('configuredButtons', function() {
app.controller('ErrorsController', function ($scope, bridgeService) {
$scope.bridge = bridgeService.state;
});
});
app.controller('VersionController', function ($scope, bridgeService) {
$scope.bridge = bridgeService.state;

View File

@@ -44,6 +44,14 @@
ng-click="goBridgeUrl(bridge.base)">Go</button>
</div>
</form>
<p>
<button class="btn btn-success" type="submit"
ng-click="saveSettings()">Save</button>
<button class="btn btn-warning" type="submit"
ng-click="bridgeReinit()">Bridge Reinitialize</button>
<button class="btn btn-danger" type="submit"
ng-click="bridgeStop()">Bridge Stop</button>
</p>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
@@ -171,10 +179,6 @@
ng-true-value=true ng-false-value=false> {{bridge.settings.devmode}}</td>
</tr>
</table>
<p>
<button class="btn btn-success" type="submit"
ng-click="saveSettings()">Save</button>
</p>
</div>
</div>
<div class="panel panel-default backup">