target_controls: { dataout_timeout: 2 }
}
];
- component.selection.update();
fixture.detectChanges();
});
it('should display old snapshot name', () => {
component.selection.selected = [{ name: 'oldname' }];
- component.selection.update();
component.openEditSnapshotModal();
expect(component.modalRef.content.snapName).toBe('oldname');
expect(component.modalRef.content.editing).toBeTruthy();
});
it('should call updateSelection', () => {
- const selection = new CdTableSelection();
- selection.selected = ['foo'];
- selection.update();
-
expect(component.selection.hasSelection).toBeFalsy();
- component.updateSelection(selection);
+ component.updateSelection(new CdTableSelection(['foo']));
expect(component.selection.hasSelection).toBeTruthy();
});
const setSelection = (selection: object[]) => {
component.selection.selected = selection;
- component.selection.update();
component.ngOnChanges();
};
hostname: 'localhost'
}
];
- component.selection.update();
});
it('should recognize a tabset child', () => {
it('should enable module', fakeAsync(() => {
spyOn(mgrModuleService, 'enable').and.returnValue(observableThrowError('y'));
spyOn(mgrModuleService, 'list').and.returnValues(observableThrowError('z'), observableOf([]));
- component.selection.selected.push({
+ component.selection.add({
name: 'foo',
enabled: false,
always_on: false
});
- component.selection.update();
component.updateModuleState();
tick(2000);
tick(2000);
it('should disable module', fakeAsync(() => {
spyOn(mgrModuleService, 'disable').and.returnValue(observableThrowError('x'));
spyOn(mgrModuleService, 'list').and.returnValue(observableOf([]));
- component.selection.selected.push({
+ component.selection.add({
name: 'bar',
enabled: true,
always_on: false
});
- component.selection.update();
component.updateModuleState();
tick(2000);
expect(mgrModuleService.disable).toHaveBeenCalledWith('bar');
name: 'dashboard'
}
];
- component.selection.update();
expect(component.isTableActionDisabled('enabled')).toBeTruthy();
});
always_on: true
}
];
- component.selection.update();
expect(component.isTableActionDisabled('enabled')).toBeTruthy();
});
});
// Table data and selection
component.selection = new CdTableSelection();
component.selection.selected = selection;
- component.selection.update();
component.osds = data;
component.permissions = fakeAuthStorageService.getPermissions();
};
});
describe('expire silence', () => {
- const setSelectedSilence = (silenceName: string) => {
- component.selection.selected = [{ id: silenceName }];
- component.selection.update();
- };
+ const setSelectedSilence = (silenceName: string) =>
+ (component.selection.selected = [{ id: silenceName }]);
const expireSilence = () => {
component.expireSilence();
state: 'LOADING'
}
];
- component.selection.update();
component.ngOnChanges();
fixture.detectChanges();
});
}
});
component.selection.selected = [newData];
- component.selection.update();
component.ngOnChanges();
expect(component.data).toEqual({
'Access Type': 'RW',
pool: 0
}
];
- poolDetailsComponent.selection.update();
});
it('should recognize a tabset child', () => {
tiers: []
}
];
- poolDetailsComponent.selection.update();
fixture.detectChanges();
const tabs = poolDetailsComponent.tabsetChild.tabs;
expect(tabs.length).toEqual(2);
describe('pool deletion', () => {
let taskWrapper: TaskWrapperService;
- const setSelectedPool = (poolName: string) => {
- component.selection.selected = [{ pool_name: poolName }];
- component.selection.update();
- };
+ const setSelectedPool = (poolName: string) =>
+ (component.selection.selected = [{ pool_name: poolName }]);
const callDeletion = () => {
component.deletePoolModal();
describe('getSelectionTiers', () => {
const setSelectionTiers = (tiers: number[]) => {
- component.selection.selected = [
- {
- tiers
- }
- ];
- component.selection.update();
+ component.selection.selected = [{ tiers }];
component.getSelectionTiers();
};
it('should create scopes permissions [1/2]', () => {
component.scopes = ['log', 'rgw'];
- component.selection = new CdTableSelection();
- component.selection.selected = [
+ component.selection = new CdTableSelection([
{
description: 'RGW Manager',
name: 'rgw-manager',
},
system: true
}
- ];
- component.selection.update();
+ ]);
expect(component.scopes_permissions.length).toBe(0);
component.ngOnChanges();
expect(component.scopes_permissions).toEqual([
it('should create scopes permissions [2/2]', () => {
component.scopes = ['cephfs', 'log', 'rgw'];
- component.selection = new CdTableSelection();
- component.selection.selected = [
+ component.selection = new CdTableSelection([
{
description: 'Test',
name: 'test',
},
system: false
}
- ];
- component.selection.update();
+ ]);
expect(component.scopes_permissions.length).toBe(0);
component.ngOnChanges();
expect(component.scopes_permissions).toEqual([
[cssClasses]="paginationClasses"
[selectionType]="selectionType"
[selected]="selection.selected"
- (select)="onSelect()"
+ (select)="onSelect($event)"
[sorts]="userConfig.sorts"
(sort)="changeSorting($event)"
[columns]="tableColumns"
return;
}
this.selection.selected = newSelected;
- this.onSelect();
+ this.onSelect(this.selection);
}
- onSelect() {
- this.selection.update();
+ onSelect($event) {
+ this.selection.selected = $event['selected'];
this.updateSelection.emit(_.clone(this.selection));
}
export class CdTableSelection {
- selected: any[] = [];
+ private _selected: any[] = [];
hasMultiSelection: boolean;
hasSingleSelection: boolean;
hasSelection: boolean;
- constructor() {
+ constructor(rows?: any[]) {
+ if (rows) {
+ this._selected = rows;
+ }
this.update();
}
* Recalculate the variables based on the current number
* of selected rows.
*/
- update() {
- this.hasSelection = this.selected.length > 0;
- this.hasSingleSelection = this.selected.length === 1;
- this.hasMultiSelection = this.selected.length > 1;
+ private update() {
+ this.hasSelection = this._selected.length > 0;
+ this.hasSingleSelection = this._selected.length === 1;
+ this.hasMultiSelection = this._selected.length > 1;
+ }
+
+ set selected(selection: any[]) {
+ this._selected = selection;
+ this.update();
+ }
+
+ get selected() {
+ return this._selected;
+ }
+
+ add(row: any) {
+ this._selected.push(row);
+ this.update();
}
/**
* @return {any | null}
*/
first() {
- return this.hasSelection ? this.selected[0] : null;
+ return this.hasSelection ? this._selected[0] : null;
}
}
setSelection(selection: object[]) {
this.tac.selection.selected = selection;
- this.tac.selection.update();
}
}