]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
aa43bd0e8db75721f25883d9c4cb6421544fcfa3
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2 import { FormControl } from '@angular/forms';
3
4 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
5
6 import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
7 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
8 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
9 import { FinishedTask } from '~/app/shared/models/finished-task';
10 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
11
12 @Component({
13   selector: 'cd-edit-site-mode-modal',
14   templateUrl: './edit-site-name-modal.component.html',
15   styleUrls: ['./edit-site-name-modal.component.scss']
16 })
17 export class EditSiteNameModalComponent implements OnInit {
18   siteName: string;
19
20   editSiteNameForm: CdFormGroup;
21
22   constructor(
23     public activeModal: NgbActiveModal,
24     public actionLabels: ActionLabelsI18n,
25     private rbdMirroringService: RbdMirroringService,
26     private taskWrapper: TaskWrapperService
27   ) {
28     this.createForm();
29   }
30
31   createForm() {
32     this.editSiteNameForm = new CdFormGroup({
33       siteName: new FormControl('', {})
34     });
35   }
36
37   ngOnInit() {
38     this.editSiteNameForm.get('siteName').setValue(this.siteName);
39     this.rbdMirroringService.getSiteName().subscribe((response: any) => {
40       this.editSiteNameForm.get('siteName').setValue(response.site_name);
41     });
42   }
43
44   update() {
45     const action = this.taskWrapper.wrapTaskAroundCall({
46       task: new FinishedTask('rbd/mirroring/site_name/edit', {}),
47       call: this.rbdMirroringService.setSiteName(this.editSiteNameForm.getValue('siteName'))
48     });
49
50     action.subscribe({
51       error: () => this.editSiteNameForm.setErrors({ cdSubmitButton: true }),
52       complete: () => {
53         this.rbdMirroringService.refresh();
54         this.activeModal.close();
55       }
56     });
57   }
58 }