]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
e4df25d15ece467070499f8d3d1bab5da4f5dd29
[ceph-ci.git] /
1 import { Component, OnInit } from '@angular/core';
2
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4
5 import { Pool } from '~/app/ceph/pool/pool';
6 import { PoolService } from '~/app/shared/api/pool.service';
7 import { RbdService } from '~/app/shared/api/rbd.service';
8 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
9 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
10 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
11 import { FinishedTask } from '~/app/shared/models/finished-task';
12 import { Permission } from '~/app/shared/models/permissions';
13 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
14 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
15
16 @Component({
17   selector: 'cd-rbd-trash-purge-modal',
18   templateUrl: './rbd-trash-purge-modal.component.html',
19   styleUrls: ['./rbd-trash-purge-modal.component.scss']
20 })
21 export class RbdTrashPurgeModalComponent implements OnInit {
22   poolPermission: Permission;
23   purgeForm: CdFormGroup;
24   pools: any[];
25
26   constructor(
27     private authStorageService: AuthStorageService,
28     private rbdService: RbdService,
29     public activeModal: NgbActiveModal,
30     public actionLabels: ActionLabelsI18n,
31     private fb: CdFormBuilder,
32     private poolService: PoolService,
33     private taskWrapper: TaskWrapperService
34   ) {
35     this.poolPermission = this.authStorageService.getPermissions().pool;
36   }
37
38   createForm() {
39     this.purgeForm = this.fb.group({
40       poolName: ''
41     });
42   }
43
44   ngOnInit() {
45     if (this.poolPermission.read) {
46       this.poolService.list(['pool_name', 'application_metadata']).then((resp) => {
47         this.pools = resp
48           .filter((pool: Pool) => pool.application_metadata.includes('rbd'))
49           .map((pool: Pool) => pool.pool_name);
50       });
51     }
52
53     this.createForm();
54   }
55
56   purge() {
57     const poolName = this.purgeForm.getValue('poolName') || '';
58     this.taskWrapper
59       .wrapTaskAroundCall({
60         task: new FinishedTask('rbd/trash/purge', {
61           pool_name: poolName
62         }),
63         call: this.rbdService.purgeTrash(poolName)
64       })
65       .subscribe({
66         error: () => {
67           this.purgeForm.setErrors({ cdSubmitButton: true });
68         },
69         complete: () => {
70           this.activeModal.close();
71         }
72       });
73   }
74 }