]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
ae35da6d6b5406d54010d895ab891fe09b76028a
[ceph.git] /
1 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2
3 import * as _ from 'lodash';
4 import { BsModalRef } from 'ngx-bootstrap/modal';
5
6 import { OsdService } from '../../../../shared/api/osd.service';
7 import { ActionLabelsI18n, URLVerbs } from '../../../../shared/constants/app.constants';
8 import { CdFormBuilder } from '../../../../shared/forms/cd-form-builder';
9 import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
10 import { FinishedTask } from '../../../../shared/models/finished-task';
11 import { TaskWrapperService } from '../../../../shared/services/task-wrapper.service';
12 import { DriveGroups } from '../osd-form/drive-groups.interface';
13
14 @Component({
15   selector: 'cd-osd-creation-preview-modal',
16   templateUrl: './osd-creation-preview-modal.component.html',
17   styleUrls: ['./osd-creation-preview-modal.component.scss']
18 })
19 export class OsdCreationPreviewModalComponent implements OnInit {
20   @Input()
21   driveGroups: DriveGroups = {};
22
23   @Output()
24   submitAction = new EventEmitter();
25
26   action: string;
27   formGroup: CdFormGroup;
28
29   constructor(
30     public bsModalRef: BsModalRef,
31     public actionLabels: ActionLabelsI18n,
32     private formBuilder: CdFormBuilder,
33     private osdService: OsdService,
34     private taskWrapper: TaskWrapperService
35   ) {
36     this.action = actionLabels.CREATE;
37     this.createForm();
38   }
39
40   ngOnInit() {}
41
42   createForm() {
43     this.formGroup = this.formBuilder.group({});
44   }
45
46   onSubmit() {
47     this.taskWrapper
48       .wrapTaskAroundCall({
49         task: new FinishedTask('osd/' + URLVerbs.CREATE, {
50           tracking_id: _.join(_.keys(this.driveGroups), ', ')
51         }),
52         call: this.osdService.create(this.driveGroups)
53       })
54       .subscribe(
55         undefined,
56         () => {
57           this.formGroup.setErrors({ cdSubmitButton: true });
58         },
59         () => {
60           this.submitAction.emit();
61           this.bsModalRef.hide();
62         }
63       );
64   }
65 }