]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-clients/cephfs-clients.component.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cephfs / cephfs-clients / cephfs-clients.component.ts
CommitLineData
9f95a23c 1import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
11fdf7f2
TL
2
3import { I18n } from '@ngx-translate/i18n-polyfill';
9f95a23c 4import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
11fdf7f2
TL
5
6import { CephfsService } from '../../../shared/api/cephfs.service';
9f95a23c
TL
7import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
8import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
9import { Icons } from '../../../shared/enum/icons.enum';
10import { NotificationType } from '../../../shared/enum/notification-type.enum';
11fdf7f2 11import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
9f95a23c
TL
12import { CdTableAction } from '../../../shared/models/cd-table-action';
13import { CdTableColumn } from '../../../shared/models/cd-table-column';
14import { CdTableSelection } from '../../../shared/models/cd-table-selection';
15import { Permission } from '../../../shared/models/permissions';
16import { AuthStorageService } from '../../../shared/services/auth-storage.service';
17import { NotificationService } from '../../../shared/services/notification.service';
11fdf7f2
TL
18
19@Component({
20 selector: 'cd-cephfs-clients',
21 templateUrl: './cephfs-clients.component.html',
22 styleUrls: ['./cephfs-clients.component.scss']
23})
24export class CephfsClientsComponent implements OnInit {
25 @Input()
26 id: number;
27
9f95a23c
TL
28 @Input()
29 clients: {
30 data: any[];
31 status: ViewCacheStatus;
32 };
11fdf7f2 33
9f95a23c
TL
34 @Output()
35 triggerApiUpdate = new EventEmitter();
11fdf7f2 36
9f95a23c
TL
37 columns: CdTableColumn[];
38
39 permission: Permission;
40 tableActions: CdTableAction[];
41 modalRef: BsModalRef;
42
43 selection = new CdTableSelection();
44
45 constructor(
46 private cephfsService: CephfsService,
47 private modalService: BsModalService,
48 private notificationService: NotificationService,
49 private authStorageService: AuthStorageService,
50 private i18n: I18n,
51 private actionLabels: ActionLabelsI18n
52 ) {
53 this.permission = this.authStorageService.getPermissions().cephfs;
54 const evictAction: CdTableAction = {
55 permission: 'update',
56 icon: Icons.signOut,
57 click: () => this.evictClientModal(),
58 name: this.actionLabels.EVICT
11fdf7f2 59 };
9f95a23c
TL
60 this.tableActions = [evictAction];
61 }
62
63 ngOnInit() {
64 this.columns = [
65 { prop: 'id', name: this.i18n('id') },
66 { prop: 'type', name: this.i18n('type') },
67 { prop: 'state', name: this.i18n('state') },
68 { prop: 'version', name: this.i18n('version') },
69 { prop: 'hostname', name: this.i18n('Host') },
70 { prop: 'root', name: this.i18n('root') }
71 ];
72 }
73
74 updateSelection(selection: CdTableSelection) {
75 this.selection = selection;
76 }
11fdf7f2 77
9f95a23c
TL
78 evictClient(clientId: number) {
79 this.cephfsService.evictClient(this.id, clientId).subscribe(
80 () => {
81 this.triggerApiUpdate.emit();
82 this.modalRef.hide();
83 this.notificationService.show(
84 NotificationType.success,
85 this.i18n('Evicted client "{{clientId}}"', { clientId: clientId })
86 );
87 },
88 () => {
89 this.modalRef.content.stopLoadingSpinner();
90 }
91 );
11fdf7f2
TL
92 }
93
9f95a23c
TL
94 evictClientModal() {
95 const clientId = this.selection.first().id;
96 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
97 initialState: {
98 itemDescription: 'client',
99 itemNames: [clientId],
100 actionDescription: 'evict',
101 submitAction: () => this.evictClient(clientId)
102 }
11fdf7f2
TL
103 });
104 }
105}