Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
feat(Services): Added interface to configure ESH services
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
  • Loading branch information
cdjackson committed May 28, 2016
1 parent 10f4537 commit 3e46f6c
Show file tree
Hide file tree
Showing 15 changed files with 423 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ angular.module('HABmin', [
'ZWaveLogViewer',
'ZWaveNetwork',
'Config.Extensions',
'Config.Services',
'Config.Bindings',
'Config.Things',
'Config.Items',
Expand Down
1 change: 0 additions & 1 deletion src/app/configuration/bindingConfig.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ <h3 class="panel-title pull-left">
</div>
</div>


<!-- CONFIGURATION GROUPS -->
<div ng-repeat="group in bindingConfig.parameterGroups">
<div>
Expand Down
3 changes: 1 addition & 2 deletions src/app/configuration/eshConfigParam.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
name="{{config.name}}"
search-enabled="false"
ng-disabled="config.readOnly"
on-keypress="onComboKeypress"
>
on-keypress="onComboKeypress">
<ui-select-match>
{{$select.selected.label}}
</ui-select-match>
Expand Down
6 changes: 3 additions & 3 deletions src/app/configuration/extensionsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ angular.module('Config.Extensions', [
})

.controller('ExtensionsConfigCtrl',
function BindingConfigCtrl($scope, locale, growl, $timeout, $window, $http, $interval, UserService, ExtensionModel) {
$scope.extensions = null;
$scope.extensionTypes = null;
function ExtensionsConfigCtrl($scope, locale, growl, $timeout, $window, $http, $interval, UserService, ExtensionModel) {
$scope.extensions = [];
$scope.extensionTypes = [];
$scope.typesCnt = -1;
$scope.extensionsCnt = -1;

Expand Down
2 changes: 1 addition & 1 deletion src/app/configuration/extensionsConfig.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
</div>

<!-- Binding Information / Configuration -->
<!-- Service Information / Configuration -->
<div class="col-sm-8">
<div class="panel panel-default">
<!-- Header -->
Expand Down
194 changes: 194 additions & 0 deletions src/app/configuration/servicesConfig.js
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;
};
})

;
116 changes: 116 additions & 0 deletions src/app/configuration/servicesConfig.tpl.html
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>
1 change: 0 additions & 1 deletion src/app/configuration/thingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ angular.module('Config.Things', [
)
};


$scope.getChannelItems = function (channel) {
if ($scope.selectedThing == null || $scope.selectedThing.channels == null) {
return [];
Expand Down
9 changes: 9 additions & 0 deletions src/app/models/configModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ angular.module('HABmin.configModel', [
function (url) {
$http.get(url + "/" + uri)
.success(function (data) {
angular.forEach(data.parameters, function (param) {
if (param.type == "BOOLEAN" && (param.options == null || param.options.length == 0)) {
param.options = [
{label: "true", value: "true"},
{label: "false", value: "false"}
];
}
});

deferred.resolve(data);
})
.error(function (data, status) {
Expand Down
Loading

0 comments on commit 3e46f6c

Please sign in to comment.