# All files / src/app/ceph/cluster/osd/osd-reweight-modal osd-reweight-modal.component.ts

100% Statements 20/20
72.73% Branches 8/11
100% Functions 5/5
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    467x
    7x

    7x

    7x
    7x

    7x
    2x

    2x
    2x
    2x

    8x

    7x
    2x

    7x
    1x

    1x

    7x
     import { Component, OnInit } from '@angular/core';
    import { Validators } from '@angular/forms';

    import { BsModalRef } from 'ngx-bootstrap/modal';

    import { OsdService } from '../../../../shared/api/osd.service';
    import { CdFormBuilder } from '../../../../shared/forms/cd-form-builder';
    import { CdFormGroup } from '../../../../shared/forms/cd-form-group';

    @Component({
      selector: 'cd-osd-reweight-modal',
      template: require('./osd-reweight-modal.component.html'),
      styles: []
    })
    export class OsdReweightModalComponent implements OnInit {
      currentWeight = 1;
      osdId: number;
      reweightForm: CdFormGroup;

      constructor(
        public bsModalRef: BsModalRef,
        private osdService: OsdService,
        private fb: CdFormBuilder
      ) {}

      get weight() {
        return this.reweightForm.get('weight');
      }

      ngOnInit() {
        this.reweightForm = this.fb.group({
          weight: this.fb.control(this.currentWeight, [
            Validators.required,
            Validators.max(1),
            Validators.min(0)
          ])
        });
      }

      reweight() {
        this.osdService
          .reweight(this.osdId, this.reweightForm.value.weight)
          .subscribe(() => this.bsModalRef.hide());
      }
    }