src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts
providers |
{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }
|
selector | cd-rgw-user-list |
styleUrls | ./rgw-user-list.component.scss |
templateUrl | ./rgw-user-list.component.html |
Properties |
Methods |
constructor(authStorageService: AuthStorageService, rgwUserService: RgwUserService, bsModalService: BsModalService, i18n: I18n, urlBuilder: URLBuilderService, actionLabels: ActionLabelsI18n)
|
|||||||||||||||||||||
Parameters :
|
deleteAction |
deleteAction()
|
Returns :
void
|
getUserList | ||||||
getUserList(context: CdTableFetchDataContext)
|
||||||
Parameters :
Returns :
void
|
updateSelection | ||||||
updateSelection(selection: CdTableSelection)
|
||||||
Parameters :
Returns :
void
|
Public actionLabels |
Type : ActionLabelsI18n
|
columns |
Type : CdTableColumn[]
|
Default value : []
|
permission |
Type : Permission
|
selection |
Type : CdTableSelection
|
Default value : new CdTableSelection()
|
table |
Type : TableComponent
|
Decorators :
@ViewChild(TableComponent)
|
tableActions |
Type : CdTableAction[]
|
users |
Type : object[]
|
Default value : []
|
import { Component, ViewChild } from '@angular/core';
import { I18n } from '@ngx-translate/i18n-polyfill';
import { BsModalService } from 'ngx-bootstrap/modal';
import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs';
import { RgwUserService } from '../../../shared/api/rgw-user.service';
import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
import { TableComponent } from '../../../shared/datatable/table/table.component';
import { CellTemplate } from '../../../shared/enum/cell-template.enum';
import { CdTableAction } from '../../../shared/models/cd-table-action';
import { CdTableColumn } from '../../../shared/models/cd-table-column';
import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { Permission } from '../../../shared/models/permissions';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { URLBuilderService } from '../../../shared/services/url-builder.service';
const BASE_URL = 'rgw/user';
@Component({
selector: 'cd-rgw-user-list',
templateUrl: './rgw-user-list.component.html',
styleUrls: ['./rgw-user-list.component.scss'],
providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
})
export class RgwUserListComponent {
@ViewChild(TableComponent)
table: TableComponent;
permission: Permission;
tableActions: CdTableAction[];
columns: CdTableColumn[] = [];
users: object[] = [];
selection: CdTableSelection = new CdTableSelection();
constructor(
private authStorageService: AuthStorageService,
private rgwUserService: RgwUserService,
private bsModalService: BsModalService,
private i18n: I18n,
private urlBuilder: URLBuilderService,
public actionLabels: ActionLabelsI18n
) {
this.permission = this.authStorageService.getPermissions().rgw;
this.columns = [
{
name: this.i18n('Username'),
prop: 'uid',
flexGrow: 1
},
{
name: this.i18n('Full name'),
prop: 'display_name',
flexGrow: 1
},
{
name: this.i18n('Email address'),
prop: 'email',
flexGrow: 1
},
{
name: this.i18n('Suspended'),
prop: 'suspended',
flexGrow: 1,
cellClass: 'text-center',
cellTransformation: CellTemplate.checkIcon
},
{
name: this.i18n('Max. buckets'),
prop: 'max_buckets',
flexGrow: 1
}
];
const getUserUri = () =>
this.selection.first() && `${encodeURIComponent(this.selection.first().uid)}`;
const addAction: CdTableAction = {
permission: 'create',
icon: 'fa-plus',
routerLink: () => this.urlBuilder.getCreate(),
name: this.actionLabels.CREATE
};
const editAction: CdTableAction = {
permission: 'update',
icon: 'fa-pencil',
routerLink: () => this.urlBuilder.getEdit(getUserUri()),
name: this.actionLabels.EDIT
};
const deleteAction: CdTableAction = {
permission: 'delete',
icon: 'fa-times',
click: () => this.deleteAction(),
name: this.actionLabels.DELETE
};
this.tableActions = [addAction, editAction, deleteAction];
}
getUserList(context: CdTableFetchDataContext) {
this.rgwUserService.list().subscribe(
(resp: object[]) => {
this.users = resp;
},
() => {
context.error();
}
);
}
updateSelection(selection: CdTableSelection) {
this.selection = selection;
}
deleteAction() {
this.bsModalService.show(CriticalConfirmationModalComponent, {
initialState: {
itemDescription: this.selection.hasSingleSelection ? this.i18n('user') : this.i18n('users'),
submitActionObservable: (): Observable<any> => {
return new Observable((observer: Subscriber<any>) => {
// Delete all selected data table rows.
observableForkJoin(
this.selection.selected.map((user: any) => {
return this.rgwUserService.delete(user.uid);
})
).subscribe(
null,
(error) => {
// Forward the error to the observer.
observer.error(error);
// Reload the data table content because some deletions might
// have been executed successfully in the meanwhile.
this.table.refreshBtn();
},
() => {
// Notify the observer that we are done.
observer.complete();
// Reload the data table content.
this.table.refreshBtn();
}
);
});
}
}
});
}
}
<cd-table #table
[autoReload]="false"
[data]="users"
[columns]="columns"
columnMode="flex"
selectionType="multi"
(updateSelection)="updateSelection($event)"
identifier="user_id"
(fetchData)="getUserList($event)">
<cd-table-actions class="table-actions"
[permission]="permission"
[selection]="selection"
[tableActions]="tableActions">
</cd-table-actions>
<cd-rgw-user-details cdTableDetail
[selection]="selection">
</cd-rgw-user-details>
</cd-table>
./rgw-user-list.component.scss