]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-trash-purge-modal/rbd-trash-purge-modal.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-trash-purge-modal / rbd-trash-purge-modal.component.ts
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
14 @Component({
15 selector: 'cd-rbd-trash-purge-modal',
16 templateUrl: './rbd-trash-purge-modal.component.html',
17 styleUrls: ['./rbd-trash-purge-modal.component.scss']
18 })
19 export class RbdTrashPurgeModalComponent implements OnInit {
20 poolPermission: Permission;
21 purgeForm: CdFormGroup;
22 pools: any[];
23
24 constructor(
25 private authStorageService: AuthStorageService,
26 private rbdService: RbdService,
27 public modalRef: BsModalRef,
28 private fb: CdFormBuilder,
29 private poolService: PoolService,
30 private taskWrapper: TaskWrapperService
31 ) {
32 this.poolPermission = this.authStorageService.getPermissions().pool;
33 }
34
35 createForm() {
36 this.purgeForm = this.fb.group({
37 poolName: ''
38 });
39 }
40
41 ngOnInit() {
42 if (this.poolPermission.read) {
43 this.poolService.list(['pool_name', 'application_metadata']).then((resp) => {
44 this.pools = resp
45 .filter((pool) => pool.application_metadata.includes('rbd'))
46 .map((pool) => pool.pool_name);
47 });
48 }
49
50 this.createForm();
51 }
52
53 purge() {
54 const poolName = this.purgeForm.getValue('poolName') || '';
55 this.taskWrapper
56 .wrapTaskAroundCall({
57 task: new FinishedTask('rbd/trash/purge', {
58 pool_name: poolName
59 }),
60 call: this.rbdService.purgeTrash(poolName)
61 })
62 .subscribe(
63 undefined,
64 () => {
65 this.purgeForm.setErrors({ cdSubmitButton: true });
66 },
67 () => {
68 this.modalRef.hide();
69 }
70 );
71 }
72 }