1 import { Component, OnInit } from '@angular/core';
2 import { Observable, BehaviorSubject, of } from 'rxjs';
3 import { switchMap, catchError } from 'rxjs/operators';
4 import { SmbService } from '~/app/shared/api/smb.service';
5 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
6 import { CdTableAction } from '~/app/shared/models/cd-table-action';
7 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
8 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
9 import { Permission } from '~/app/shared/models/permissions';
10 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
11 import { SMBJoinAuth } from '../smb.model';
12 import { Router } from '@angular/router';
13 import { Icons } from '~/app/shared/enum/icons.enum';
14 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
15 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
16 import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component';
17 import { ModalCdsService } from '~/app/shared/services/modal-cds.service';
18 import { FinishedTask } from '~/app/shared/models/finished-task';
19 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
21 export const JOINAUTH_URL = '/cephfs/smb/ad';
24 selector: 'cd-smb-join-auth-list',
25 templateUrl: './smb-join-auth-list.component.html',
26 styleUrls: ['./smb-join-auth-list.component.scss'],
27 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(JOINAUTH_URL) }]
29 export class SmbJoinAuthListComponent implements OnInit {
30 columns: CdTableColumn[];
31 permission: Permission;
32 tableActions: CdTableAction[];
33 context: CdTableFetchDataContext;
35 joinAuth$: Observable<SMBJoinAuth[]>;
36 subject$ = new BehaviorSubject<SMBJoinAuth[]>([]);
37 selection: CdTableSelection = new CdTableSelection();
40 private router: Router,
41 private urlBuilder: URLBuilderService,
42 private authStorageService: AuthStorageService,
43 public actionLabels: ActionLabelsI18n,
44 private smbService: SmbService,
45 private modalService: ModalCdsService,
46 private taskWrapper: TaskWrapperService
48 this.permission = this.authStorageService.getPermissions().smb;
54 name: $localize`Name`,
59 name: $localize`Username`,
60 prop: 'auth.username',
64 name: $localize`Linked to cluster`,
65 prop: 'linked_to_cluster',
72 name: `${this.actionLabels.CREATE} AD`,
75 click: () => this.router.navigate([this.urlBuilder.getCreate()]),
76 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
79 name: this.actionLabels.EDIT,
83 this.router.navigate([this.urlBuilder.getEdit(String(this.selection.first().auth_id))])
86 name: this.actionLabels.DELETE,
89 click: () => this.openDeleteModal()
93 this.joinAuth$ = this.subject$.pipe(
95 this.smbService.listJoinAuths().pipe(
106 this.subject$.next([]);
110 const authId = this.selection.first().auth_id;
112 this.modalService.show(DeleteConfirmationModalComponent, {
113 itemDescription: $localize`Active directory access resource`,
115 submitActionObservable: () =>
116 this.taskWrapper.wrapTaskAroundCall({
117 task: new FinishedTask('smb/ad/remove', {
120 call: this.smbService.deleteJoinAuth(authId)
125 updateSelection(selection: CdTableSelection) {
126 this.selection = selection;