This repository has been archived by the owner on May 23, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Services): Added interface to configure ESH services
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
- Loading branch information
Showing
15 changed files
with
423 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
/** | ||
* HABmin - Home Automation User and Administration Interface | ||
* Designed for openHAB (www.openhab.com) | ||
* | ||
* This software is copyright of Chris Jackson under the GPL license. | ||
* Note that this licence may be changed at a later date. | ||
* | ||
* (c) 2014-2016 Chris Jackson (chris@cd-jackson.com) | ||
*/ | ||
angular.module('Config.Services', [ | ||
'ui.router', | ||
'ui.bootstrap', | ||
'ngLocalize', | ||
'HABmin.configModel', | ||
'HABmin.serviceModel', | ||
'angular-growl', | ||
'ngInputModified', | ||
'ResizePanel' | ||
]) | ||
|
||
.config(function config($stateProvider) { | ||
$stateProvider.state('services', { | ||
url: '/services', | ||
views: { | ||
"main": { | ||
controller: 'ServicesConfigCtrl', | ||
templateUrl: 'configuration/servicesConfig.tpl.html' | ||
} | ||
}, | ||
data: {pageTitle: 'Services'}, | ||
resolve: { | ||
// Make sure the localisation files are resolved before the controller runs | ||
localisations: function (locale) { | ||
return locale.ready('services'); | ||
} | ||
} | ||
}); | ||
}) | ||
|
||
.controller('ServicesConfigCtrl', | ||
function ServicesConfigCtrl($scope, $timeout, locale, growl, ServiceModel, ConfigModel) { | ||
$scope.services = []; | ||
$scope.serviceTypes = []; | ||
$scope.typesCnt = -1; | ||
$scope.servicesCnt = -1; | ||
|
||
ServiceModel.getServices().then( | ||
function (services) { | ||
$scope.services = services; | ||
$scope.servicesCnt = services.length; | ||
|
||
// There's no service type list, so let's make one! | ||
for (var service in services) { | ||
var found = false; | ||
for (var serviceType in $scope.serviceTypes) { | ||
if ($scope.serviceTypes[serviceType].id == services[service].category) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (found == false) { | ||
$scope.serviceTypes.push({ | ||
id: services[service].category, | ||
label: services[service].category.toUpperCase() | ||
}); | ||
} | ||
} | ||
}, | ||
function (reason) { | ||
// Handle failure | ||
growl.warning(locale.getString("services.ErrorGettingServices")); | ||
} | ||
); | ||
|
||
/* | ||
ServiceModel.getTypes().then( | ||
function (serviceTypes) { | ||
$scope.serviceTypes = serviceTypes; | ||
$scope.typesCnt = serviceTypes.length; | ||
$scope.selectedType = $scope.serviceTypes[0]; | ||
}, | ||
function (reason) { | ||
// Handle failure | ||
growl.warning(locale.getString("services.ErrorGettingServices")); | ||
} | ||
); | ||
*/ | ||
|
||
$scope.selectService = function (service) { | ||
$scope.serviceConfig = null; | ||
$scope.serviceConfiguration = null; | ||
$scope.selectedService = service; | ||
|
||
$scope.configForm.reset(); | ||
$scope.formLoaded = false; | ||
|
||
if (service.configDescriptionURI != null) { | ||
// Get the configuration | ||
ConfigModel.getConfig(service.configDescriptionURI).then( | ||
function (cfg) { | ||
$scope.serviceConfig = cfg; | ||
}, | ||
function () { | ||
$scope.serviceConfig = null; | ||
} | ||
); | ||
|
||
ServiceModel.getServiceConfig(service).then( | ||
function (cfg) { | ||
$scope.serviceConfiguration = cfg; | ||
|
||
// Ensure the options are converted to a string for internal processing | ||
angular.forEach($scope.serviceConfiguration.parameters, function (parameter) { | ||
angular.forEach(parameter.options, function (option) { | ||
option.value = option.value.toString(); | ||
}); | ||
}); | ||
|
||
}, | ||
function () { | ||
} | ||
); | ||
} | ||
|
||
$timeout(function () { | ||
$scope.configForm.$setPristine(); | ||
$scope.formLoaded = true; | ||
}); | ||
}; | ||
|
||
$scope.configSave = function() { | ||
var cfgUpdated = false; | ||
|
||
var updatedCfg = {}; | ||
angular.forEach($scope.configForm.modifiedModels, function (model) { | ||
// Get the configuration description | ||
for (var cnt = 0; cnt < $scope.serviceConfig.parameters.length; cnt++) { | ||
if ($scope.serviceConfig.parameters[cnt].name == model.$name) { | ||
updatedCfg[model.$name] = | ||
ConfigModel.convertType($scope.serviceConfig.parameters[cnt].type, | ||
model.$modelValue, | ||
$scope.serviceConfig.parameters[cnt].multiple); | ||
} | ||
} | ||
}); | ||
|
||
ServiceModel.putServiceConfig($scope.selectedService, updatedCfg).then( | ||
function (cfg) { | ||
$scope.configForm.reset(); | ||
}, | ||
function () { | ||
} | ||
); | ||
}; | ||
|
||
$scope.hasUngroupedParams = function () { | ||
if ($scope.serviceConfig == null || $scope.serviceConfig.parameters == null) { | ||
return false; | ||
} | ||
|
||
for (var cnt = 0; cnt < $scope.serviceConfig.parameters.length; cnt++) { | ||
if ($scope.serviceConfig.parameters[cnt].groupName == null || | ||
$scope.serviceConfig.parameters[cnt].groupName === "" || | ||
$scope.serviceConfig.parameterGroups[$scope.serviceConfig.parameters[cnt].groupName] == null) { | ||
return true; | ||
} | ||
} | ||
}; | ||
|
||
$scope.configGroupFilter = function (config, group) { | ||
// Sanity check | ||
if (config == null) { | ||
return false; | ||
} | ||
|
||
// Are we looking for ungrouped parameters | ||
if (group == null) { | ||
if (config.groupName == null || config.groupName === "" || | ||
$scope.serviceConfig.parameterGroups[config.groupName] == null) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
if (config.groupName == group) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
}) | ||
|
||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<!-- Device List --> | ||
<div class="col-sm-4"> | ||
<div class="panel panel-default"> | ||
<!-- Header --> | ||
<div class="panel-heading"> | ||
<span i18n="services.Services"></span> | ||
</div> | ||
|
||
<!-- Body --> | ||
<div class="list-group habmin-list" resize-panel> | ||
<!-- SERVICES LIST --> | ||
<div ng-if="serviceTypes.length" ng-repeat="serviceType in serviceTypes | orderBy:'label'"> | ||
<div> | ||
<a role="presentation" class="list-group-item config-panel-title" | ||
ng-class="{'active': panelDisplayed=='SVC-{{serviceType.id}}'}" | ||
ng-click="panelDisplayed='SVC-{{serviceType.id}}'"> | ||
<span class="fa fa-fw fa-book"></span> {{serviceType.label}} | ||
</a> | ||
</div> | ||
<div collapse="panelDisplayed!='SVC-{{serviceType.id}}'"> | ||
<div ng-repeat="service in services | filter: {category: serviceType.id} | orderBy:'label'"> | ||
<a role="presentation" class="list-group-item" | ||
ng-class="{'active': service==selectedService}" | ||
ng-click="selectService(service)"> | ||
{{service.label}} | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Footer --> | ||
<div class="panel-footer panel-footer-none"> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- Service Information / Configuration --> | ||
<div class="col-sm-8"> | ||
<div class="panel panel-default"> | ||
<!-- Header --> | ||
<div class="panel-heading"> | ||
<button type="button" | ||
class="btn btn-default" ng-class="{'btn-success': formLoaded&&configForm.modified}" | ||
ng-click="configSave()" | ||
ng-disabled="!formLoaded || !configForm.modified"> | ||
<span class="fa fa-floppy-o"></span> | ||
<span class="hidden-xs hidden-sm" i18n="common.save"></span> | ||
</button> | ||
<button type="button" | ||
class="btn btn-default" | ||
ng-click="configForm.reset()" | ||
ng-disabled="!formLoaded || !configForm.modified"> | ||
<span class="fa fa-times"></span> | ||
<span class="hidden-xs hidden-sm" i18n="common.cancel"></span> | ||
</button> | ||
</div> | ||
|
||
<!-- Body --> | ||
<div class="list-group habmin-list" resize-panel> | ||
<form name="configForm" novalidate ng-show="selectedService" style="height:100%"> | ||
|
||
<!-- CONFIGURATION GROUPS --> | ||
<div ng-repeat="group in serviceConfig.parameterGroups"> | ||
<div> | ||
<a role="presentation" class="list-group-item list-group-item-heading" | ||
ng-class="{'active': cfgPanelDisplayed=='CONFIG-{{group.name}}'}" | ||
ng-click="cfgPanelDisplayed='CONFIG-{{group.name}}'" | ||
ng-if="configGroupAdvanced(group)||showAdvancedSettings"> | ||
<habmin-icon class="fa-fw" cfgcontext="{{group.context}}"></habmin-icon> | ||
<span>{{group.label}} {{cfgPanelDisplayed}}</span> | ||
</a> | ||
</div> | ||
<div collapse="$parent.cfgPanelDisplayed!='CONFIG-{{group.name}}'" | ||
class="panel-form"> | ||
<div ng-repeat="config in serviceConfig.parameters"> | ||
<div class="form-group" | ||
ng-if="configGroupFilter(config, group.name) && (!config.advanced||showAdvancedSettings)"> | ||
<ng-include | ||
ng-init="cfgType='CONFIG';cfgModel=serviceConfiguration[config.name]" | ||
src="'configuration/eshConfigParam.tpl.html'"></ng-include> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- CONFIGURATION UNGROUPED --> | ||
<div ng-if="hasUngroupedParams()"> | ||
<div> | ||
<a role="presentation" class="list-group-item list-group-item-heading" | ||
ng-class="{'active': cfgPanelDisplayed=='CONFIG-ungrouped'}" | ||
ng-click="cfgPanelDisplayed='CONFIG-ungrouped'"> | ||
<span class="fa fa-fw fa-wrench"></span> | ||
<span i18n="thing.Configuration"></span> | ||
</a> | ||
</div> | ||
<div collapse="cfgPanelDisplayed!='CONFIG-ungrouped'" | ||
class="panel-form"> | ||
<div ng-repeat="config in serviceConfig.parameters"> | ||
<div class="form-group" | ||
ng-if="configGroupFilter(config, null) && (!config.advanced||showAdvancedSettings)"> | ||
<ng-include | ||
ng-init="cfgType='CONFIG';cfgModel=serviceConfiguration[config.name]" | ||
src="'configuration/eshConfigParam.tpl.html'"></ng-include> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<!-- Footer --> | ||
<div class="panel-footer panel-footer-none"> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.