src/app/ceph/block/iscsi-target-list/iscsi-target-list.component.ts
providers |
TaskListService
|
selector | cd-iscsi-target-list |
styleUrls | ./iscsi-target-list.component.scss |
templateUrl | ./iscsi-target-list.component.html |
Properties |
Methods |
constructor(authStorageService: AuthStorageService, i18n: I18n, iscsiService: IscsiService, taskListService: TaskListService, cephReleaseNamePipe: CephReleaseNamePipe, summaryservice: SummaryService, modalService: BsModalService, taskWrapper: TaskWrapperService)
|
|||||||||||||||||||||||||||
Parameters :
|
configureDiscoveryAuth |
configureDiscoveryAuth()
|
Returns :
void
|
deleteIscsiTargetModal |
deleteIscsiTargetModal()
|
Returns :
void
|
itemFilter | ||||||
itemFilter(entry, task)
|
||||||
Parameters :
Returns :
boolean
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onFetchError |
onFetchError()
|
Returns :
void
|
prepareResponse | ||||||
prepareResponse(resp: any)
|
||||||
Parameters :
Returns :
any[]
|
taskFilter | ||||
taskFilter(task)
|
||||
Parameters :
Returns :
any
|
updateSelection | ||||||
updateSelection(selection: CdTableSelection)
|
||||||
Parameters :
Returns :
void
|
available |
Type : boolean
|
Default value : undefined
|
builders |
Type : object
|
Default value : {
'iscsi/target/create': (metadata) => {
return {
target_iqn: metadata['target_iqn']
};
}
}
|
columns |
Type : CdTableColumn[]
|
docsUrl |
Type : string
|
modalRef |
Type : BsModalRef
|
permissions |
Type : Permissions
|
selection |
Default value : new CdTableSelection()
|
settings |
Type : any
|
status |
Type : string
|
summaryDataSubscription |
Type : Subscription
|
table |
Type : TableComponent
|
Decorators :
@ViewChild(TableComponent)
|
tableActions |
Type : CdTableAction[]
|
targets |
Type : []
|
Default value : []
|
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { I18n } from '@ngx-translate/i18n-polyfill';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { Subscription } from 'rxjs';
import { IscsiService } from '../../../shared/api/iscsi.service';
import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
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 { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { FinishedTask } from '../../../shared/models/finished-task';
import { Permissions } from '../../../shared/models/permissions';
import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { SummaryService } from '../../../shared/services/summary.service';
import { TaskListService } from '../../../shared/services/task-list.service';
import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
import { IscsiTargetDiscoveryModalComponent } from '../iscsi-target-discovery-modal/iscsi-target-discovery-modal.component';
@Component({
selector: 'cd-iscsi-target-list',
templateUrl: './iscsi-target-list.component.html',
styleUrls: ['./iscsi-target-list.component.scss'],
providers: [TaskListService]
})
export class IscsiTargetListComponent implements OnInit, OnDestroy {
@ViewChild(TableComponent)
table: TableComponent;
available: boolean = undefined;
columns: CdTableColumn[];
docsUrl: string;
modalRef: BsModalRef;
permissions: Permissions;
selection = new CdTableSelection();
settings: any;
status: string;
summaryDataSubscription: Subscription;
tableActions: CdTableAction[];
targets = [];
builders = {
'iscsi/target/create': (metadata) => {
return {
target_iqn: metadata['target_iqn']
};
}
};
constructor(
private authStorageService: AuthStorageService,
private i18n: I18n,
private iscsiService: IscsiService,
private taskListService: TaskListService,
private cephReleaseNamePipe: CephReleaseNamePipe,
private summaryservice: SummaryService,
private modalService: BsModalService,
private taskWrapper: TaskWrapperService
) {
this.permissions = this.authStorageService.getPermissions();
this.tableActions = [
{
permission: 'create',
icon: 'fa-plus',
routerLink: () => '/block/iscsi/targets/add',
name: this.i18n('Add')
},
{
permission: 'update',
icon: 'fa-pencil',
routerLink: () => `/block/iscsi/targets/edit/${this.selection.first().target_iqn}`,
name: this.i18n('Edit')
},
{
permission: 'delete',
icon: 'fa-times',
click: () => this.deleteIscsiTargetModal(),
name: this.i18n('Delete')
}
];
}
ngOnInit() {
this.columns = [
{
name: this.i18n('Target'),
prop: 'target_iqn',
flexGrow: 2,
cellTransformation: CellTemplate.executing
},
{
name: this.i18n('Portals'),
prop: 'cdPortals',
flexGrow: 2
},
{
name: this.i18n('Images'),
prop: 'cdImages',
flexGrow: 2
}
];
this.iscsiService.status().subscribe((result: any) => {
this.available = result.available;
if (result.available) {
this.taskListService.init(
() => this.iscsiService.listTargets(),
(resp) => this.prepareResponse(resp),
(targets) => (this.targets = targets),
() => this.onFetchError(),
this.taskFilter,
this.itemFilter,
this.builders
);
this.iscsiService.settings().subscribe((settings: any) => {
this.settings = settings;
});
} else {
const summary = this.summaryservice.getCurrentSummary();
const releaseName = this.cephReleaseNamePipe.transform(summary.version);
this.docsUrl = `http://docs.ceph.com/docs/${releaseName}/mgr/dashboard/#enabling-iscsi-management`;
this.status = result.message;
}
});
}
ngOnDestroy() {
if (this.summaryDataSubscription) {
this.summaryDataSubscription.unsubscribe();
}
}
prepareResponse(resp: any): any[] {
resp.forEach((element) => {
element.cdPortals = element.portals.map((portal) => `${portal.host}:${portal.ip}`);
element.cdImages = element.disks.map((disk) => `${disk.pool}/${disk.image}`);
});
return resp;
}
onFetchError() {
this.table.reset(); // Disable loading indicator.
}
itemFilter(entry, task) {
return entry.target_iqn === task.metadata['target_iqn'];
}
taskFilter(task) {
return ['iscsi/target/create', 'iscsi/target/edit', 'iscsi/target/delete'].includes(task.name);
}
updateSelection(selection: CdTableSelection) {
this.selection = selection;
}
deleteIscsiTargetModal() {
const target_iqn = this.selection.first().target_iqn;
this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
initialState: {
itemDescription: this.i18n('iSCSI'),
submitActionObservable: () =>
this.taskWrapper.wrapTaskAroundCall({
task: new FinishedTask('iscsi/target/delete', {
target_iqn: target_iqn
}),
call: this.iscsiService.deleteTarget(target_iqn)
})
}
});
}
configureDiscoveryAuth() {
this.modalService.show(IscsiTargetDiscoveryModalComponent, {});
}
}
<cd-iscsi-tabs></cd-iscsi-tabs>
<cd-info-panel *ngIf="available === false"
title="iSCSI Targets not available"
i18n-title>
<ng-container i18n>Please consult the <a href="{{docsUrl}}"
target="_blank">documentation</a>
on how to configure and enable the iSCSI Targets management functionality.</ng-container>
<ng-container *ngIf="status">
<br>
<span i18n>Available information:</span>
<pre>{{ status }}</pre>
</ng-container>
</cd-info-panel>
<cd-table #table
*ngIf="available === true"
[data]="targets"
columnMode="flex"
[columns]="columns"
identifier="target_iqn"
forceIdentifier="true"
selectionType="single"
(updateSelection)="updateSelection($event)">
<div class="table-actions btn-toolbar">
<cd-table-actions class="btn-group"
[permission]="permissions.iscsi"
[selection]="selection"
[tableActions]="tableActions">
</cd-table-actions>
<button class="btn btn-sm btn-default btn-label"
type="button"
(click)="configureDiscoveryAuth()">
<i class="fa fa-fw fa-key-modern"
aria-hidden="true">
</i>
<ng-container i18n>Set discovery authentication</ng-container>
</button>
</div>
<cd-iscsi-target-details cdTableDetail
*ngIf="selection.hasSingleSelection"
[selection]="selection"
[settings]="settings"></cd-iscsi-target-details>
</cd-table>
./iscsi-target-list.component.scss
::ng-deep tabset.tabset > ul {
border-bottom: 1px solid #ddd;
float: left;
display: block;
margin-right: 20px;
border-bottom: 0;
border-right: 1px solid #ddd;
padding-right: 15px;
}