-import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@angular/core';
+import {
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ Input,
+ OnChanges,
+ OnInit,
+ TemplateRef,
+ ViewChild
+} from '@angular/core';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import moment from 'moment';
import { of } from 'rxjs';
import { RbdService } from '../../../shared/api/rbd.service';
+import { CdHelperClass } from '../../../shared/classes/cd-helper.class';
import { ConfirmationModalComponent } from '../../../shared/components/confirmation-modal/confirmation-modal.component';
import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
selector: 'cd-rbd-snapshot-list',
templateUrl: './rbd-snapshot-list.component.html',
styleUrls: ['./rbd-snapshot-list.component.scss'],
- providers: [TaskListService]
+ providers: [TaskListService],
+ changeDetection: ChangeDetectionStrategy.OnPush
})
export class RbdSnapshotListComponent implements OnInit, OnChanges {
@Input()
permission: Permission;
selection = new CdTableSelection();
tableActions: CdTableAction[];
+ rbdTableActions: RbdSnapshotActionsModel;
+ imageSpec: ImageSpec;
data: RbdSnapshotModel[];
private notificationService: NotificationService,
private summaryService: SummaryService,
private taskListService: TaskListService,
- private actionLabels: ActionLabelsI18n
+ private actionLabels: ActionLabelsI18n,
+ private cdr: ChangeDetectorRef
) {
this.permission = this.authStorageService.getPermissions().rbdImage;
}
pipe: this.cdDatePipe
}
];
- }
-
- ngOnChanges() {
- const imageSpec = new ImageSpec(this.poolName, this.namespace, this.rbdName);
- const actions = new RbdSnapshotActionsModel(
+ this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.rbdName);
+ this.rbdTableActions = new RbdSnapshotActionsModel(
this.actionLabels,
this.featuresName,
this.rbdService
);
- actions.create.click = () => this.openCreateSnapshotModal();
- actions.rename.click = () => this.openEditSnapshotModal();
- actions.protect.click = () => this.toggleProtection();
- actions.unprotect.click = () => this.toggleProtection();
+ this.rbdTableActions.create.click = () => this.openCreateSnapshotModal();
+ this.rbdTableActions.rename.click = () => this.openEditSnapshotModal();
+ this.rbdTableActions.protect.click = () => this.toggleProtection();
+ this.rbdTableActions.unprotect.click = () => this.toggleProtection();
const getImageUri = () =>
this.selection.first() &&
- `${imageSpec.toStringEncoded()}/${encodeURIComponent(this.selection.first().name)}`;
- actions.clone.routerLink = () => `/block/rbd/clone/${getImageUri()}`;
- actions.copy.routerLink = () => `/block/rbd/copy/${getImageUri()}`;
- actions.rollback.click = () => this.rollbackModal();
- actions.deleteSnap.click = () => this.deleteSnapshotModal();
- this.tableActions = actions.ordering;
+ `${this.imageSpec.toStringEncoded()}/${encodeURIComponent(this.selection.first().name)}`;
+ this.rbdTableActions.clone.routerLink = () => `/block/rbd/clone/${getImageUri()}`;
+ this.rbdTableActions.copy.routerLink = () => `/block/rbd/copy/${getImageUri()}`;
+ this.rbdTableActions.rollback.click = () => this.rollbackModal();
+ this.rbdTableActions.deleteSnap.click = () => this.deleteSnapshotModal();
+
+ this.tableActions = this.rbdTableActions.ordering;
const itemFilter = (entry: any, task: Task) => {
return entry.name === task.metadata['snapshot_name'];
return (
['rbd/snap/create', 'rbd/snap/delete', 'rbd/snap/edit', 'rbd/snap/rollback'].includes(
task.name
- ) && imageSpec.toString() === task.metadata['image_spec']
+ ) && this.imageSpec.toString() === task.metadata['image_spec']
);
};
this.taskListService.init(
() => of(this.snapshots),
null,
- (items) => (this.data = items),
- () => (this.data = this.snapshots),
+ (items) => {
+ const hasChanges = CdHelperClass.updateChanged(this, {
+ data: items
+ });
+ if (hasChanges) {
+ this.cdr.detectChanges();
+ this.data = [...this.data];
+ }
+ },
+ () => {
+ const hasChanges = CdHelperClass.updateChanged(this, {
+ data: this.snapshots
+ });
+ if (hasChanges) {
+ this.cdr.detectChanges();
+ this.data = [...this.data];
+ }
+ },
taskFilter,
itemFilter,
this.builders
);
}
+ ngOnChanges() {
+ if (this.columns) {
+ this.imageSpec = new ImageSpec(this.poolName, this.namespace, this.rbdName);
+ if (this.rbdTableActions) {
+ this.rbdTableActions.featuresName = this.featuresName;
+ }
+ this.taskListService.fetch();
+ }
+ }
+
private openSnapshotModal(taskName: string, snapName: string = null) {
this.modalRef = this.modalService.show(RbdSnapshotFormModalComponent);
this.modalRef.componentInstance.poolName = this.poolName;
const executingTask = new ExecutingTask();
executingTask.name = taskName;
executingTask.metadata = {
- image_name: this.rbdName,
- pool_name: this.poolName,
+ image_spec: this.imageSpec.toString(),
snapshot_name: snapshotName
};
this.summaryService.addRunningTask(executingTask);
- this.ngOnChanges();
});
}
executingTask.name = finishedTask.name;
executingTask.metadata = finishedTask.metadata;
this.summaryService.addRunningTask(executingTask);
- this.ngOnChanges();
this.taskManagerService.subscribe(
finishedTask.name,
finishedTask.metadata,
executingTask.metadata = finishedTask.metadata;
this.summaryService.addRunningTask(executingTask);
this.modalRef.close();
- this.ngOnChanges();
this.taskManagerService.subscribe(
executingTask.name,
executingTask.metadata,