]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-bucket-list / rgw-bucket-list.component.ts
1 import { Component, ViewChild } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import { BsModalService } from 'ngx-bootstrap/modal';
5 import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs';
6
7 import { RgwBucketService } from '../../../shared/api/rgw-bucket.service';
8 import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
9 import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
10 import { TableComponent } from '../../../shared/datatable/table/table.component';
11 import { CdTableAction } from '../../../shared/models/cd-table-action';
12 import { CdTableColumn } from '../../../shared/models/cd-table-column';
13 import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
14 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
15 import { Permission } from '../../../shared/models/permissions';
16 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
17 import { URLBuilderService } from '../../../shared/services/url-builder.service';
18
19 const BASE_URL = 'rgw/bucket';
20
21 @Component({
22 selector: 'cd-rgw-bucket-list',
23 templateUrl: './rgw-bucket-list.component.html',
24 styleUrls: ['./rgw-bucket-list.component.scss'],
25 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
26 })
27 export class RgwBucketListComponent {
28 @ViewChild(TableComponent)
29 table: TableComponent;
30
31 permission: Permission;
32 tableActions: CdTableAction[];
33 columns: CdTableColumn[] = [];
34 buckets: object[] = [];
35 selection: CdTableSelection = new CdTableSelection();
36
37 constructor(
38 private authStorageService: AuthStorageService,
39 private rgwBucketService: RgwBucketService,
40 private bsModalService: BsModalService,
41 private i18n: I18n,
42 private urlBuilder: URLBuilderService,
43 public actionLabels: ActionLabelsI18n
44 ) {
45 this.permission = this.authStorageService.getPermissions().rgw;
46 this.columns = [
47 {
48 name: this.i18n('Name'),
49 prop: 'bid',
50 flexGrow: 1
51 },
52 {
53 name: this.i18n('Owner'),
54 prop: 'owner',
55 flexGrow: 1
56 }
57 ];
58 const getBucketUri = () =>
59 this.selection.first() && `${encodeURIComponent(this.selection.first().bid)}`;
60 const addAction: CdTableAction = {
61 permission: 'create',
62 icon: 'fa-plus',
63 routerLink: () => this.urlBuilder.getCreate(),
64 name: this.actionLabels.CREATE
65 };
66 const editAction: CdTableAction = {
67 permission: 'update',
68 icon: 'fa-pencil',
69 routerLink: () => this.urlBuilder.getEdit(getBucketUri()),
70 name: this.actionLabels.EDIT
71 };
72 const deleteAction: CdTableAction = {
73 permission: 'delete',
74 icon: 'fa-times',
75 click: () => this.deleteAction(),
76 name: this.actionLabels.DELETE
77 };
78 this.tableActions = [addAction, editAction, deleteAction];
79 }
80
81 getBucketList(context: CdTableFetchDataContext) {
82 this.rgwBucketService.list().subscribe(
83 (resp: object[]) => {
84 this.buckets = resp;
85 },
86 () => {
87 context.error();
88 }
89 );
90 }
91
92 updateSelection(selection: CdTableSelection) {
93 this.selection = selection;
94 }
95
96 deleteAction() {
97 this.bsModalService.show(CriticalConfirmationModalComponent, {
98 initialState: {
99 itemDescription: this.selection.hasSingleSelection
100 ? this.i18n('bucket')
101 : this.i18n('buckets'),
102 submitActionObservable: () => {
103 return new Observable((observer: Subscriber<any>) => {
104 // Delete all selected data table rows.
105 observableForkJoin(
106 this.selection.selected.map((bucket: any) => {
107 return this.rgwBucketService.delete(bucket.bid);
108 })
109 ).subscribe(
110 null,
111 (error) => {
112 // Forward the error to the observer.
113 observer.error(error);
114 // Reload the data table content because some deletions might
115 // have been executed successfully in the meanwhile.
116 this.table.refreshBtn();
117 },
118 () => {
119 // Notify the observer that we are done.
120 observer.complete();
121 // Reload the data table content.
122 this.table.refreshBtn();
123 }
124 );
125 });
126 }
127 }
128 });
129 }
130 }