]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
eb8ded17349bbb97477f7b65c9b26f755b0644ed
[ceph-ci.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
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 implements OnInit {
19   @Input()
20   driveGroups: Object[] = [];
21
22   @Output()
23   submitAction = new EventEmitter();
24
25   action: string;
26   formGroup: CdFormGroup;
27
28   constructor(
29     public bsModalRef: BsModalRef,
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   ngOnInit() {}
40
41   createForm() {
42     this.formGroup = this.formBuilder.group({});
43   }
44
45   onSubmit() {
46     this.taskWrapper
47       .wrapTaskAroundCall({
48         task: new FinishedTask('osd/' + URLVerbs.CREATE, {
49           tracking_id: _.join(_.map(this.driveGroups, 'service_id'), ', ')
50         }),
51         call: this.osdService.create(this.driveGroups)
52       })
53       .subscribe(
54         undefined,
55         () => {
56           this.formGroup.setErrors({ cdSubmitButton: true });
57         },
58         () => {
59           this.submitAction.emit();
60           this.bsModalRef.hide();
61         }
62       );
63   }
64 }