]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
979dcc3411fb55ed59b1e2f75107fb4cd3e167ee
[ceph.git] /
1 import { Component, EventEmitter, Input, Output } from '@angular/core';
2
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import _ from 'lodash';
5
6 import { OsdService } from '~/app/shared/api/osd.service';
7 import { ActionLabelsI18n, URLVerbs } 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 import { FinishedTask } from '~/app/shared/models/finished-task';
11 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
12
13 @Component({
14   selector: 'cd-osd-creation-preview-modal',
15   templateUrl: './osd-creation-preview-modal.component.html',
16   styleUrls: ['./osd-creation-preview-modal.component.scss']
17 })
18 export class OsdCreationPreviewModalComponent {
19   @Input()
20   driveGroups: Object[] = [];
21
22   @Output()
23   submitAction = new EventEmitter();
24
25   action: string;
26   formGroup: CdFormGroup;
27
28   constructor(
29     public activeModal: NgbActiveModal,
30     public actionLabels: ActionLabelsI18n,
31     private formBuilder: CdFormBuilder,
32     private osdService: OsdService,
33     private taskWrapper: TaskWrapperService
34   ) {
35     this.action = actionLabels.CREATE;
36     this.createForm();
37   }
38
39   createForm() {
40     this.formGroup = this.formBuilder.group({});
41   }
42
43   onSubmit() {
44     this.taskWrapper
45       .wrapTaskAroundCall({
46         task: new FinishedTask('osd/' + URLVerbs.CREATE, {
47           tracking_id: _.join(_.map(this.driveGroups, 'service_id'), ', ')
48         }),
49         call: this.osdService.create(this.driveGroups)
50       })
51       .subscribe({
52         error: () => {
53           this.formGroup.setErrors({ cdSubmitButton: true });
54         },
55         complete: () => {
56           this.submitAction.emit();
57           this.activeModal.close();
58         }
59       });
60   }
61 }