]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.ts
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / nfs / nfs-list / nfs-list.component.ts
CommitLineData
11fdf7f2
TL
1import { Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
f67539c2
TL
3import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
4import _ from 'lodash';
11fdf7f2
TL
5import { Subscription } from 'rxjs';
6
f67539c2
TL
7import { NfsService } from '~/app/shared/api/nfs.service';
8import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
9import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
10import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
11import { TableComponent } from '~/app/shared/datatable/table/table.component';
12import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
13import { Icons } from '~/app/shared/enum/icons.enum';
14import { ViewCacheStatus } from '~/app/shared/enum/view-cache-status.enum';
15import { CdTableAction } from '~/app/shared/models/cd-table-action';
16import { CdTableColumn } from '~/app/shared/models/cd-table-column';
17import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
18import { FinishedTask } from '~/app/shared/models/finished-task';
19import { Permission } from '~/app/shared/models/permissions';
20import { Task } from '~/app/shared/models/task';
21import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
22import { ModalService } from '~/app/shared/services/modal.service';
23import { TaskListService } from '~/app/shared/services/task-list.service';
24import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
11fdf7f2
TL
25
26@Component({
27 selector: 'cd-nfs-list',
28 templateUrl: './nfs-list.component.html',
29 styleUrls: ['./nfs-list.component.scss'],
30 providers: [TaskListService]
31})
e306af50 32export class NfsListComponent extends ListWithDetails implements OnInit, OnDestroy {
f67539c2 33 @ViewChild('nfsState')
11fdf7f2 34 nfsState: TemplateRef<any>;
9f95a23c 35 @ViewChild('nfsFsal', { static: true })
11fdf7f2
TL
36 nfsFsal: TemplateRef<any>;
37
9f95a23c 38 @ViewChild('table', { static: true })
11fdf7f2
TL
39 table: TableComponent;
40
41 columns: CdTableColumn[];
42 permission: Permission;
43 selection = new CdTableSelection();
44 summaryDataSubscription: Subscription;
45 viewCacheStatus: any;
46 exports: any[];
47 tableActions: CdTableAction[];
48 isDefaultCluster = false;
49
f67539c2 50 modalRef: NgbModalRef;
11fdf7f2
TL
51
52 builders = {
9f95a23c 53 'nfs/create': (metadata: any) => {
11fdf7f2
TL
54 return {
55 path: metadata['path'],
56 cluster_id: metadata['cluster_id'],
57 fsal: metadata['fsal']
58 };
59 }
60 };
61
62 constructor(
63 private authStorageService: AuthStorageService,
f67539c2 64 private modalService: ModalService,
11fdf7f2
TL
65 private nfsService: NfsService,
66 private taskListService: TaskListService,
eafe8130
TL
67 private taskWrapper: TaskWrapperService,
68 public actionLabels: ActionLabelsI18n
11fdf7f2 69 ) {
e306af50 70 super();
11fdf7f2
TL
71 this.permission = this.authStorageService.getPermissions().nfs;
72 const getNfsUri = () =>
73 this.selection.first() &&
74 `${encodeURI(this.selection.first().cluster_id)}/${encodeURI(
75 this.selection.first().export_id
76 )}`;
77
eafe8130 78 const createAction: CdTableAction = {
11fdf7f2 79 permission: 'create',
9f95a23c 80 icon: Icons.add,
eafe8130 81 routerLink: () => '/nfs/create',
11fdf7f2 82 canBePrimary: (selection: CdTableSelection) => !selection.hasSingleSelection,
eafe8130 83 name: this.actionLabels.CREATE
11fdf7f2
TL
84 };
85
86 const editAction: CdTableAction = {
87 permission: 'update',
9f95a23c 88 icon: Icons.edit,
11fdf7f2 89 routerLink: () => `/nfs/edit/${getNfsUri()}`,
eafe8130 90 name: this.actionLabels.EDIT
11fdf7f2
TL
91 };
92
93 const deleteAction: CdTableAction = {
94 permission: 'delete',
9f95a23c 95 icon: Icons.destroy,
11fdf7f2 96 click: () => this.deleteNfsModal(),
eafe8130 97 name: this.actionLabels.DELETE
11fdf7f2
TL
98 };
99
eafe8130 100 this.tableActions = [createAction, editAction, deleteAction];
11fdf7f2
TL
101 }
102
103 ngOnInit() {
104 this.columns = [
105 {
f67539c2 106 name: $localize`Path`,
11fdf7f2
TL
107 prop: 'path',
108 flexGrow: 2,
109 cellTransformation: CellTemplate.executing
110 },
eafe8130 111 {
f67539c2 112 name: $localize`Pseudo`,
eafe8130
TL
113 prop: 'pseudo',
114 flexGrow: 2
115 },
11fdf7f2 116 {
f67539c2 117 name: $localize`Cluster`,
11fdf7f2
TL
118 prop: 'cluster_id',
119 flexGrow: 2
120 },
11fdf7f2 121 {
f67539c2 122 name: $localize`Storage Backend`,
11fdf7f2
TL
123 prop: 'fsal',
124 flexGrow: 2,
125 cellTemplate: this.nfsFsal
126 },
127 {
f67539c2 128 name: $localize`Access Type`,
11fdf7f2
TL
129 prop: 'access_type',
130 flexGrow: 2
131 }
132 ];
133
a4b75251
TL
134 this.taskListService.init(
135 () => this.nfsService.list(),
136 (resp) => this.prepareResponse(resp),
137 (exports) => (this.exports = exports),
138 () => this.onFetchError(),
139 this.taskFilter,
140 this.itemFilter,
141 this.builders
11fdf7f2
TL
142 );
143 }
144
145 ngOnDestroy() {
146 if (this.summaryDataSubscription) {
147 this.summaryDataSubscription.unsubscribe();
148 }
149 }
150
151 prepareResponse(resp: any): any[] {
9f95a23c
TL
152 let result: any[] = [];
153 resp.forEach((nfs: any) => {
11fdf7f2
TL
154 nfs.id = `${nfs.cluster_id}:${nfs.export_id}`;
155 nfs.state = 'LOADING';
156 result = result.concat(nfs);
157 });
158
159 return result;
160 }
161
162 onFetchError() {
163 this.table.reset(); // Disable loading indicator.
164 this.viewCacheStatus = { status: ViewCacheStatus.ValueException };
165 }
166
9f95a23c 167 itemFilter(entry: any, task: Task) {
11fdf7f2
TL
168 return (
169 entry.cluster_id === task.metadata['cluster_id'] &&
170 entry.export_id === task.metadata['export_id']
171 );
172 }
173
9f95a23c 174 taskFilter(task: Task) {
11fdf7f2
TL
175 return ['nfs/create', 'nfs/delete', 'nfs/edit'].includes(task.name);
176 }
177
178 updateSelection(selection: CdTableSelection) {
179 this.selection = selection;
180 }
181
182 deleteNfsModal() {
183 const cluster_id = this.selection.first().cluster_id;
184 const export_id = this.selection.first().export_id;
185
186 this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
f67539c2
TL
187 itemDescription: $localize`NFS export`,
188 itemNames: [`${cluster_id}:${export_id}`],
189 submitActionObservable: () =>
190 this.taskWrapper.wrapTaskAroundCall({
191 task: new FinishedTask('nfs/delete', {
192 cluster_id: cluster_id,
193 export_id: export_id
194 }),
195 call: this.nfsService.delete(cluster_id, export_id)
196 })
11fdf7f2
TL
197 });
198 }
199}