Extract groups from options when they are embedded

We return the actual embedded resource as allowedValues when they are available.
As there are drop-down lists where no embedded information is given
(e.g., assignee, responsible), we conditionally extract group
information from embedded resources.
pull/3780/head
Oliver Günther 9 years ago
parent 955c1194f2
commit c75f62ee0d
  1. 2
      frontend/app/components/inplace-edit/directives/field-edit/edit-drop-down/edit-drop-down.directive.html
  2. 32
      frontend/app/components/inplace-edit/directives/field-edit/edit-drop-down/edit-drop-down.directive.js
  3. 8
      frontend/app/components/inplace-edit/services/work-package-field.service.js
  4. 1
      frontend/tests/unit/tests/components/inplace-edit/directives/edit-drop-down.directive.test.js

@ -10,6 +10,6 @@
title="{{ fieldController.editTitle }}" title="{{ fieldController.editTitle }}"
class="inplace-edit-select form--select" class="inplace-edit-select form--select"
id="inplace-edit--write-value--{{::field.name}}" id="inplace-edit--write-value--{{::field.name}}"
ng-options="option.name group by customEditorController.optionGroup(option) for option in customEditorController.allowedValues track by option.hrefTracker"> ng-options="option.name group by option.group for option in customEditorController.allowedValues track by option.hrefTracker">
</select> </select>
</div> </div>

@ -65,13 +65,30 @@ function InplaceEditorDropDownController($q, $scope, I18n, WorkPackageFieldConfi
this.allowedValues = []; this.allowedValues = [];
function extractOptions(values) {
var options = values;
// Extract options and groups from embedded values only
if ($scope.field.allowedValuesEmbedded()) {
options = _.map(values, function(item) {
return _.extend({}, item._links.self, {
name: item._links.self.title,
group: WorkPackageFieldConfigurationService
.getDropDownOptionGroup($scope.field.name, item)
});
});
}
return options;
}
this.updateAllowedValues = function(field) { this.updateAllowedValues = function(field) {
var customEditorController = this; var customEditorController = this;
return $q(function(resolve) { return $q(function(resolve) {
$scope.field.getAllowedValues() $scope.field.getAllowedValues()
.then(function(values) { .then(function(values) {
var options;
var sorting = WorkPackageFieldConfigurationService var sorting = WorkPackageFieldConfigurationService
.getDropdownSortingStrategy(field); .getDropdownSortingStrategy(field);
@ -79,24 +96,21 @@ function InplaceEditorDropDownController($q, $scope, I18n, WorkPackageFieldConfi
values = _.sortBy(values, sorting); values = _.sortBy(values, sorting);
} }
options = extractOptions(values);
if (!$scope.field.isRequired()) { if (!$scope.field.isRequired()) {
values = addEmptyOption(values); options = addEmptyOption(options);
} }
addHrefTracker(values); addHrefTracker(options);
customEditorController.allowedValues = values; customEditorController.allowedValues = options;
resolve(); resolve();
}); });
}); });
}; };
this.optionGroup = function(option) {
return WorkPackageFieldConfigurationService
.getDropDownOptionGroup($scope.field.name, option);
};
var addEmptyOption = function(values) { var addEmptyOption = function(values) {
var emptyOption = { props: { href: null, var emptyOption = { props: { href: null,
name: $scope.field.placeholder } }; name: $scope.field.placeholder } };

@ -140,12 +140,7 @@ function WorkPackageFieldService($q, $http, $filter, I18n, WorkPackagesHelper,
function getEmbeddedAllowedValues(workPackage, field) { function getEmbeddedAllowedValues(workPackage, field) {
var options = []; var options = [];
var schema = getSchema(workPackage); var schema = getSchema(workPackage);
var allowedValues = schema.props[field]._embedded.allowedValues; return schema.props[field]._embedded.allowedValues;
options = _.map(allowedValues, function(item) {
return _.extend({}, item, { name: item.name || item.title });
});
return options;
} }
function getLinkedAllowedValues(workPackage, field) { function getLinkedAllowedValues(workPackage, field) {
@ -401,6 +396,7 @@ function WorkPackageFieldService($q, $http, $filter, I18n, WorkPackagesHelper,
getValue: getValue, getValue: getValue,
getLabel: getLabel, getLabel: getLabel,
getAllowedValues: getAllowedValues, getAllowedValues: getAllowedValues,
allowedValuesEmbedded: allowedValuesEmbedded,
format: format, format: format,
getInplaceEditStrategy: getInplaceEditStrategy, getInplaceEditStrategy: getInplaceEditStrategy,
getInplaceDisplayStrategy: getInplaceDisplayStrategy getInplaceDisplayStrategy: getInplaceDisplayStrategy

@ -58,6 +58,7 @@ describe('Inplace editor drop-down directive', function() {
scope.field = { scope.field = {
getAllowedValues: sinon.stub().returns(allowedValuePromise), getAllowedValues: sinon.stub().returns(allowedValuePromise),
allowedValuesEmbedded: sinon.stub().returns(false),
format: sinon.stub().returns({ props: { name: allowedValues[0].name } }), format: sinon.stub().returns({ props: { name: allowedValues[0].name } }),
isRequired: sinon.stub().returns(true), isRequired: sinon.stub().returns(true),
value: { props: { href: allowedValues[0].href } } value: { props: { href: allowedValues[0].href } }

Loading…
Cancel
Save