</div>
</div>
<!-- Priority values -->
- <div class="form-group" *ngFor="let attr of priorityAttrs"
+ <div class="form-group" *ngFor="let attr of priorityAttrs | keyvalue"
[ngClass]="{'has-error': osdRecvSpeedForm.getValue('customizePriority') &&
- osdRecvSpeedForm.showError(attr.name, formDir)}">
+ osdRecvSpeedForm.showError(attr.key, formDir)}">
<label class="control-label col-sm-6"
- [for]="attr.name">{{ attr.text }}
- <cd-helper *ngIf="attr.desc">{{ attr.desc }}</cd-helper>
+ [for]="attr.key">{{ attr.value.text }}
+ <cd-helper *ngIf="attr.value.desc">{{ attr.value.desc }}</cd-helper>
<span class="required" *ngIf="osdRecvSpeedForm.getValue('customizePriority')"></span>
</label>
<div class="col-sm-6">
<input class="form-control"
type="number"
- [id]="attr.name"
- [formControlName]="attr.name"
+ [id]="attr.key"
+ [formControlName]="attr.key"
[readonly]="!osdRecvSpeedForm.getValue('customizePriority')">
<span class="help-block"
*ngIf="osdRecvSpeedForm.getValue('customizePriority') &&
- osdRecvSpeedForm.showError(attr.name, formDir, 'required')"
+ osdRecvSpeedForm.showError(attr.key, formDir, 'required')"
i18n>This field is required!</span>
</div>
</div>
it('should set the description if one is given', () => {
component.setDescription(configOptions);
- component.priorityAttrs.forEach((p) => {
- if (p.name === 'osd_recovery_sleep') {
- expect(p.desc).toBe('Time in seconds to sleep before next recovery or backfill op');
+ Object.keys(component.priorityAttrs).forEach((configOptionName) => {
+ if (configOptionName === 'osd_recovery_sleep') {
+ expect(component.priorityAttrs[configOptionName].desc).toBe(
+ 'Time in seconds to sleep before next recovery or backfill op'
+ );
} else {
- expect(p.desc).toBe('');
+ expect(component.priorityAttrs[configOptionName].desc).toBe('');
}
});
});
export class OsdRecvSpeedModalComponent implements OnInit {
osdRecvSpeedForm: CdFormGroup;
priorities = [];
- priorityAttrs = [];
+ priorityAttrs = {};
constructor(
public bsModalRef: BsModalRef,
priority: new FormControl(null, { validators: [Validators.required] }),
customizePriority: new FormControl(false)
});
- this.priorityAttrs = [
- {
- name: 'osd_max_backfills',
+ this.priorityAttrs = {
+ osd_max_backfills: {
text: this.i18n('Max Backfills'),
desc: ''
},
- {
- name: 'osd_recovery_max_active',
+ osd_recovery_max_active: {
text: this.i18n('Recovery Max Active'),
desc: ''
},
- {
- name: 'osd_recovery_max_single_start',
+ osd_recovery_max_single_start: {
text: this.i18n('Recovery Max Single Start'),
desc: ''
},
- {
- name: 'osd_recovery_sleep',
+ osd_recovery_sleep: {
text: this.i18n('Recovery Sleep'),
desc: ''
}
- ];
+ };
- this.priorityAttrs.forEach((attr) => {
+ Object.keys(this.priorityAttrs).forEach((configOptionName) => {
this.osdRecvSpeedForm.addControl(
- attr.name,
+ configOptionName,
new FormControl(null, { validators: [Validators.required] })
);
});
ngOnInit() {
const observables = [];
- this.priorityAttrs.forEach((configName) => {
- observables.push(this.configService.get(configName.name));
+ Object.keys(this.priorityAttrs).forEach((configOptionName) => {
+ observables.push(this.configService.get(configOptionName));
});
observableForkJoin(observables)
setDescription(configOptions: Array<any>) {
configOptions.forEach((configOption) => {
if (configOption.desc !== '') {
- this.priorityAttrs.forEach((p) => {
- if (p.name === configOption.name) {
- p['desc'] = configOption.desc;
- }
- });
+ this.priorityAttrs[configOption.name].desc = configOption.desc;
}
});
}
onCustomizePriorityChange() {
if (this.osdRecvSpeedForm.getValue('customizePriority')) {
const values = {};
- this.priorityAttrs.forEach((attr) => {
- values[attr.name] = this.osdRecvSpeedForm.getValue(attr.name);
+ Object.keys(this.priorityAttrs).forEach((configOptionName) => {
+ values[configOptionName] = this.osdRecvSpeedForm.getValue(configOptionName);
});
const customPriority = {
name: 'custom',
submitAction() {
const options = {};
- this.priorityAttrs.forEach((attr) => {
- options[attr.name] = { section: 'osd', value: this.osdRecvSpeedForm.getValue(attr.name) };
+ Object.keys(this.priorityAttrs).forEach((configOptionName) => {
+ options[configOptionName] = {
+ section: 'osd',
+ value: this.osdRecvSpeedForm.getValue(configOptionName)
+ };
});
this.configService.bulkCreate({ options: options }).subscribe(