Skip to content

Commit

Permalink
Merge cad9fbd into 2af37dd
Browse files Browse the repository at this point in the history
  • Loading branch information
mzazrivec committed Jul 21, 2020
2 parents 2af37dd + cad9fbd commit 1f07974
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/dialog-editor/components/field/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,26 @@
<!-- drop down list -->
<div ng-switch-when="DialogFieldDropDownList">
<div ng-if="!vm.fieldData.options.force_multi_value">
<select class="form-control" miq-select
<select class="form-control"
miq-select
ng-options="item[0] as item[1] for item in vm.sortedField()"
ng-model="vm.fieldData.default_value">
<option value="" translate>None</option>
<option ng-repeat="value in vm.fieldData.values" value="{{value[0]}}">{{value[1]}}</option>
</select>
</div>
<div ng-if="vm.fieldData.options.force_multi_value">
<select class="form-control" multiple miq-select
<select class="form-control"
multiple
miq-select
ng-options="item[0] as item[1] for item in vm.sortedField()"
ng-model="vm.fieldData.default_value">
<option ng-repeat="value in vm.fieldData.values" value="{{value[0]}}">{{value[1]}}</option>
</select>
</div>
</div>

<!-- radio button -->
<span ng-switch-when="DialogFieldRadioButton">
<label ng-repeat="option in vm.fieldData.values"
<label ng-repeat="option in vm.sortedField()"
class="radio-inline">
<input type="radio"
name="{{vm.fieldData.name}}"
Expand Down
36 changes: 36 additions & 0 deletions src/dialog-editor/components/field/fieldComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ class FieldController {
this.DialogEditor.updatePositions(this.getFields(tabId, boxId));
}

/**
* sort Field values if needed
* @memberof FieldController
* @function sortedField
* @returns {Array} of sorted field values
*/
public sortedField() {
if (this.fieldData.options.sort_by !== 'none') {
let tempValues = [...this.fieldData.values];
if (this.fieldData.data_type === 'integer') {
tempValues.forEach((item, index) => {
const val = parseInt(tempValues[index][1], 10);
if (!Number.isNaN(val)) {
tempValues[index][1] = val;
}
});
} else if (this.fieldData.data_type === 'string') {
tempValues.forEach((item, index) => {
tempValues[index][1] = tempValues[index][1].toString();
});
}
const sortBy = (this.fieldData.options.sort_by === 'value' ? 0 : 1);
let sortedValues = _.sortBy(tempValues, sortBy);
if (this.fieldData.options.sort_order !== 'ascending') {
sortedValues = sortedValues.reverse();
}
if (this.fieldData.data_type === 'integer') {
sortedValues.forEach((item, index) => {
sortedValues[index][1] = item[1].toString();
});
}
return sortedValues;
}
return this.fieldData.values;
}

/**
* Find fields at tabId and boxId.
* @memberof FieldController
Expand Down

0 comments on commit 1f07974

Please sign in to comment.