]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
4f884d1bdef4c7635265bac0ef64e4aa5443acb7
[ceph-ci.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { Validators } from '@angular/forms';
3
4 import { BsModalRef } from 'ngx-bootstrap/modal';
5
6 import { OsdService } from '../../../../shared/api/osd.service';
7 import { CdFormBuilder } from '../../../../shared/forms/cd-form-builder';
8 import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
9
10 @Component({
11   selector: 'cd-osd-reweight-modal',
12   templateUrl: './osd-reweight-modal.component.html',
13   styleUrls: ['./osd-reweight-modal.component.scss']
14 })
15 export class OsdReweightModalComponent implements OnInit {
16   currentWeight = 1;
17   osdId: number;
18   reweightForm: CdFormGroup;
19
20   constructor(
21     public bsModalRef: BsModalRef,
22     private osdService: OsdService,
23     private fb: CdFormBuilder
24   ) {}
25
26   get weight() {
27     return this.reweightForm.get('weight');
28   }
29
30   ngOnInit() {
31     this.reweightForm = this.fb.group({
32       weight: this.fb.control(this.currentWeight, [
33         Validators.required,
34         Validators.max(1),
35         Validators.min(0)
36       ])
37     });
38   }
39
40   reweight() {
41     this.osdService
42       .reweight(this.osdId, this.reweightForm.value.weight)
43       .subscribe(() => this.bsModalRef.hide());
44   }
45 }