]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: convert ``priorityAttrs`` from array to object
authorTatjana Dehler <tdehler@suse.com>
Tue, 11 Dec 2018 14:51:58 +0000 (15:51 +0100)
committerTatjana Dehler <tdehler@suse.com>
Wed, 23 Jan 2019 10:24:55 +0000 (11:24 +0100)
Convert ``priorityAttrs`` from array to object for better handling,
e.g. to get rid of unnecessary for-loops.

Signed-off-by: Tatjana Dehler <tdehler@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.ts

index 42934d711ea142cf47c444e93a71ae10eae4a851..79dc580a7563f97046c56c63e9f4f53e341ec574 100755 (executable)
           </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>
index f67b084e0d522c8227ae9cce80cd03dd7751b07e..7c679091a8715681800eacc71ddee0aa71133f86 100755 (executable)
@@ -183,11 +183,13 @@ describe('OsdRecvSpeedModalComponent', () => {
 
     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('');
         }
       });
     });
index b6e5ffbfa65924044a58459d089a3586d82c50c9..b8fd4897b29bc95bf741a4d8722c1f93cf8855ce 100755 (executable)
@@ -21,7 +21,7 @@ import { NotificationService } from '../../../../shared/services/notification.se
 export class OsdRecvSpeedModalComponent implements OnInit {
   osdRecvSpeedForm: CdFormGroup;
   priorities = [];
-  priorityAttrs = [];
+  priorityAttrs = {};
 
   constructor(
     public bsModalRef: BsModalRef,
@@ -35,32 +35,28 @@ export class OsdRecvSpeedModalComponent implements OnInit {
       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] })
       );
     });
@@ -68,8 +64,8 @@ export class OsdRecvSpeedModalComponent implements OnInit {
 
   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)
@@ -101,11 +97,7 @@ export class OsdRecvSpeedModalComponent implements OnInit {
   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;
       }
     });
   }
@@ -134,8 +126,8 @@ export class OsdRecvSpeedModalComponent implements OnInit {
   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',
@@ -180,8 +172,11 @@ export class OsdRecvSpeedModalComponent implements OnInit {
 
   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(