File

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

Implements

OnInit

Metadata

selector cd-osd-reweight-modal
styleUrls ./osd-reweight-modal.component.scss
templateUrl ./osd-reweight-modal.component.html

Index

Properties
Methods
Accessors

Constructor

constructor(bsModalRef: BsModalRef, osdService: OsdService, fb: CdFormBuilder)
Parameters :
Name Type Optional
bsModalRef BsModalRef No
osdService OsdService No
fb CdFormBuilder No

Methods

ngOnInit
ngOnInit()
Returns : void
reweight
reweight()
Returns : void

Properties

Public bsModalRef
Type : BsModalRef
currentWeight
Type : number
Default value : 1
osdId
Type : number
reweightForm
Type : CdFormGroup

Accessors

weight
getweight()
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',
  templateUrl: './osd-reweight-modal.component.html',
  styleUrls: ['./osd-reweight-modal.component.scss']
})
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());
  }
}
<cd-modal [modalRef]="bsModalRef">
  <ng-container class="modal-title"
                i18n>Reweight OSD</ng-container>

  <ng-container class="modal-content">
    <form class="form-horizontal"
          [formGroup]="reweightForm">
      <div class="modal-body" [ngClass]="{'has-error': weight.errors}">
        <div class="row">
          <label for="weight" class="col-sm-2 control-label">Weight</label>
          <div class="col-sm-10">
            <input id="weight" class="form-control" type="number"
                   step="0.1" formControlName="weight" min="0" max="1"
                   [value]="currentWeight">
            <span class="help-block"
                  *ngIf="weight.errors">
              <span *ngIf="weight.errors?.required"
                    i18n>This field is required.</span>
              <span *ngIf="weight.errors?.max || weight.errors?.min"
                    i18n>The value needs to be between 0 and 1.</span>
            </span>
          </div>
        </div>
      </div>

      <div class="modal-footer">
        <cd-submit-button (submitAction)="reweight()"
                          [form]="reweightForm"
                          [disabled]="reweightForm.invalid"
                          i18n>Reweight</cd-submit-button>
        <cd-back-button [back]="bsModalRef.hide"
                        name="Cancel"
                        i18n-name>
        </cd-back-button>
      </div>
    </form>
  </ng-container>
</cd-modal>

./osd-reweight-modal.component.scss

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""