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