1 import { Component, ViewChild } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import { BsModalService } from 'ngx-bootstrap/modal';
5 import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs';
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';
19 const BASE_URL = 'rgw/bucket';
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) }]
27 export class RgwBucketListComponent {
28 @ViewChild(TableComponent)
29 table: TableComponent;
31 permission: Permission;
32 tableActions: CdTableAction[];
33 columns: CdTableColumn[] = [];
34 buckets: object[] = [];
35 selection: CdTableSelection = new CdTableSelection();
38 private authStorageService: AuthStorageService,
39 private rgwBucketService: RgwBucketService,
40 private bsModalService: BsModalService,
42 private urlBuilder: URLBuilderService,
43 public actionLabels: ActionLabelsI18n
45 this.permission = this.authStorageService.getPermissions().rgw;
48 name: this.i18n('Name'),
53 name: this.i18n('Owner'),
58 const getBucketUri = () =>
59 this.selection.first() && `${encodeURIComponent(this.selection.first().bid)}`;
60 const addAction: CdTableAction = {
63 routerLink: () => this.urlBuilder.getCreate(),
64 name: this.actionLabels.CREATE
66 const editAction: CdTableAction = {
69 routerLink: () => this.urlBuilder.getEdit(getBucketUri()),
70 name: this.actionLabels.EDIT
72 const deleteAction: CdTableAction = {
75 click: () => this.deleteAction(),
76 name: this.actionLabels.DELETE
78 this.tableActions = [addAction, editAction, deleteAction];
81 getBucketList(context: CdTableFetchDataContext) {
82 this.rgwBucketService.list().subscribe(
92 updateSelection(selection: CdTableSelection) {
93 this.selection = selection;
97 this.bsModalService.show(CriticalConfirmationModalComponent, {
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.
106 this.selection.selected.map((bucket: any) => {
107 return this.rgwBucketService.delete(bucket.bid);
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();
119 // Notify the observer that we are done.
121 // Reload the data table content.
122 this.table.refreshBtn();