diff --git a/app/index.html b/app/index.html index 46f567f..3ec0f3f 100644 --- a/app/index.html +++ b/app/index.html @@ -99,6 +99,7 @@ + diff --git a/app/scripts/controllers/device-bodypart-run.js b/app/scripts/controllers/device-bodypart-run.js index 7a0a900..dc64b1e 100644 --- a/app/scripts/controllers/device-bodypart-run.js +++ b/app/scripts/controllers/device-bodypart-run.js @@ -22,7 +22,7 @@ .module('siteApp') .controller('RunDeviceBodyPartController', RunDeviceBodyPartController); - function RunDeviceBodyPartController($scope, $modalInstance, $filter, + function RunDeviceBodyPartController($scope, $modalInstance, getOptionValue, dataService, pluginInfo, deviceInfo, bodyPartInfo, settings) { var vm = this; @@ -42,22 +42,23 @@ // Populate default request field values angular.forEach(vm.plugin.request_fields, function(field) { // jshint ignore:line - if (!angular.isUndefined(field.default)) { - if ($filter('optionTypeToInputType')(field.type) === 'number') { - vm.requestFields[field.name] = parseInt(field.default); - } else { - vm.requestFields[field.name] = field.default; - } - } + vm.requestFields[field.name] = getOptionValue(field); }); //////////// function runBodyPart() { vm.runDisabled = true; + + var cleanRequestFields = {}; + angular.forEach(vm.plugin.request_fields, function(field) { // jshint ignore:line + cleanRequestFields[field.name] = field._values ? + vm.requestFields[field.name].value : vm.requestFields[field.name]; + }); + dataService.runBodyPart( 'localhost:' + vm.settings.services.api.options.rest.port, - vm.device.id, vm.bodyPart.name, vm.requestFields) + vm.device.id, vm.bodyPart.name, cleanRequestFields) .then(function(data) { vm.responseContent = data; vm.runDisabled = false; diff --git a/app/scripts/controllers/device-bodypart.js b/app/scripts/controllers/device-bodypart.js index 148a996..6fffa4c 100644 --- a/app/scripts/controllers/device-bodypart.js +++ b/app/scripts/controllers/device-bodypart.js @@ -23,39 +23,29 @@ .controller('DeviceBodyPartController', DeviceBodyPartController); function DeviceBodyPartController($scope, $modalInstance, $window, - extractNumberFromName, getBoardPins, initialState, pluginsList, deviceInfo, - boardInfo, editMode, wizardMode) { + extractNumberFromName, getBoardPins, getOptionValue, initialState, + pluginsList, deviceInfo, boardInfo, editMode, wizardMode) { var vm = this; vm.device = deviceInfo; vm.plugins = pluginsList; vm.item = initialState; + vm.itemOptions = {}; vm.boardPins = getBoardPins(boardInfo); vm.selectPlugin = {}; vm.wizardMode = wizardMode; - angular.forEach(vm.plugins, function(item) { - if (item.id === initialState.pluginId) { - vm.selectPlugin.selected = item; - } - }); - $scope.$watch('vm.selectPlugin.selected', function(newValue, oldValue) { - if (!angular.isObject(newValue) || newValue === oldValue) { + if (!angular.isObject(newValue)) { return; } - vm.item.peripheral = {}; - vm.item.options = {}; - - if (angular.isObject(vm.selectPlugin.selected.options)) { - angular.forEach(vm.selectPlugin.selected.options, function(item) { - if (!angular.isUndefined(item.default)) { - vm.item.options[item.name] = item.default; - } - }); - } + // Assigning default option values + angular.forEach(vm.selectPlugin.selected.options, function(option) { + vm.itemOptions[option.name] = getOptionValue( + option, vm.item.options[option.name]); + }); if (vm.wizardMode || !editMode || !vm.item.name) { vm.item.name = newValue.id; @@ -74,6 +64,12 @@ }); + angular.forEach(vm.plugins, function(item) { + if (item.id === initialState.pluginId) { + vm.selectPlugin.selected = item; + } + }); + // handlers vm.save = save; vm.cancel = cancel; @@ -89,6 +85,13 @@ } } } + + // Copy option values to item object + angular.forEach(vm.selectPlugin.selected.options, function(spec) { + vm.item.options[spec.name] = spec._values ? + vm.itemOptions[spec.name].value : vm.itemOptions[spec.name]; + }); + $modalInstance.close({ 'name': vm.item.name, 'pluginId': vm.selectPlugin.selected.id, diff --git a/app/scripts/controllers/device-bus.js b/app/scripts/controllers/device-bus.js index 230a152..eba116f 100644 --- a/app/scripts/controllers/device-bus.js +++ b/app/scripts/controllers/device-bus.js @@ -23,10 +23,10 @@ .module('siteApp') .controller('DeviceBusController', DeviceBusController); - function DeviceBusController($log, $scope, $filter, $modalInstance, - dataService, notifyUser, extractNumberFromName, getBoardPins, initialState, - deviceInfo, editMode, serialPortsList, transportsList, wizardMode, - boardInfo) { + function DeviceBusController($log, $scope, $modalInstance, dataService, + notifyUser, extractNumberFromName, getBoardPins, getOptionValue, + initialState, deviceInfo, editMode, serialPortsList, transportsList, + wizardMode, boardInfo) { var vm = this; @@ -146,21 +146,6 @@ } } - function getOptionValue(optionSpec, currentValue) { - var optionValue = currentValue || optionSpec.default; - if ('number' === $filter('optionTypeToInputType')(optionSpec.type)) { - optionValue = parseInt(optionValue); - } - if (optionSpec._values) { - angular.forEach(optionSpec._values, function(valueObj) { - if (valueObj.value === optionValue) { - optionValue = valueObj; - } - }); - } - return optionValue; - } - function hubMayBeAdded() { return !vm.editMode && vm.transport.id === 'serial'; } diff --git a/app/scripts/controllers/device-edit-bodyparts.js b/app/scripts/controllers/device-edit-bodyparts.js index 7867a1c..e45606d 100644 --- a/app/scripts/controllers/device-edit-bodyparts.js +++ b/app/scripts/controllers/device-edit-bodyparts.js @@ -41,7 +41,10 @@ //////////// function bodyPartModal(index) { - var state = {}; + var state = { + 'peripheral': {}, + 'options': {}, + }; if (index === undefined || index === null) { index = -1; } else { diff --git a/app/scripts/controllers/device-info.js b/app/scripts/controllers/device-info.js index 454b65c..f846094 100644 --- a/app/scripts/controllers/device-info.js +++ b/app/scripts/controllers/device-info.js @@ -167,7 +167,8 @@ } function runBodyPartDisabled(device) { - return !device.enabled || 2 === device.status; + return false; // _values support debug + // return !device.enabled || 2 === device.status; } function runBodyPartTooltipText(device) { diff --git a/app/scripts/factories/get-option-value.js b/app/scripts/factories/get-option-value.js new file mode 100644 index 0000000..d1f917b --- /dev/null +++ b/app/scripts/factories/get-option-value.js @@ -0,0 +1,42 @@ +/** + Copyright (C) 2015 OLogN Technologies AG + + This source file is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +(function() { + 'use strict'; + + angular + .module('siteApp') + .factory('getOptionValue', getOptionValue); + + function getOptionValue($filter) { + return function(optionSpec, currentValue) { + var optionValue = currentValue || optionSpec.default; + if ('number' === $filter('optionTypeToInputType')(optionSpec.type)) { + optionValue = parseInt(optionValue); + } + if (optionSpec._values) { + angular.forEach(optionSpec._values, function(valueObj) { + if (valueObj.value === optionValue) { + optionValue = valueObj; + } + }); + } + return optionValue; + }; + } + +})(); diff --git a/app/scripts/filters/option-input-utils.js b/app/scripts/filters/option-input-utils.js index a1848bf..6d8220b 100644 --- a/app/scripts/filters/option-input-utils.js +++ b/app/scripts/filters/option-input-utils.js @@ -57,7 +57,7 @@ } function _extractSize(string) { - return parseInt(/\[(\d+)\]/.exec(string)[1]); + return string ? parseInt(/\[(\d+)\]/.exec(string)[1]) : null; } function _isUnsigned(string) { diff --git a/app/views/device-bodypart-run.html b/app/views/device-bodypart-run.html index 479f7c6..3ec4fe2 100644 --- a/app/views/device-bodypart-run.html +++ b/app/views/device-bodypart-run.html @@ -10,23 +10,34 @@

Request fields:

- - +
+ + +
+
+ +
+
{{ vm.requestFields | json }}
+

Response:

{{ vm.responseContent | json }}
diff --git a/app/views/device-bodypart.html b/app/views/device-bodypart.html index a5c2b7f..14fa59e 100644 --- a/app/views/device-bodypart.html +++ b/app/views/device-bodypart.html @@ -40,25 +40,34 @@
-
+
- - +
+ + +
+
+ +