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