[ACA-1439] Resolve multi-select issues (#392)

* toolbar enhancements

* code cleanup
This commit is contained in:
Denys Vuika
2018-06-08 21:07:43 +01:00
committed by GitHub
parent f73f99ccf2
commit e33ddb38fd
5 changed files with 31 additions and 32 deletions

View File

@@ -8,9 +8,9 @@
<button
mat-icon-button
color="primary"
*ngIf="firstSelectedDocument"
*ngIf="selectedFile"
title="{{ 'APP.ACTIONS.VIEW' | translate }}"
(click)="showPreview(firstSelectedDocument)">
(click)="showPreview(selectedFile)">
<mat-icon>open_in_browser</mat-icon>
</button>
@@ -25,10 +25,10 @@
<button
mat-icon-button
color="primary"
*ngIf="firstSelectedFolder"
*ngIf="selectedFolder"
[attr.title]="'APP.ACTIONS.EDIT' | translate"
(error)="openSnackMessage($event)"
[adf-edit-folder]="firstSelectedFolder?.entry">
[adf-edit-folder]="selectedFolder?.entry">
<mat-icon>create</mat-icon>
</button>
@@ -81,8 +81,8 @@
<button
mat-menu-item
*ngIf="firstSelectedDocument"
[acaNodeVersions]="firstSelectedDocument">
*ngIf="selectedFile"
[acaNodeVersions]="selectedFile">
<mat-icon>history</mat-icon>
<span>{{ 'APP.ACTIONS.VERSIONS' | translate }}</span>
</button>

View File

@@ -10,9 +10,9 @@
<button
color="primary"
mat-icon-button
*ngIf="firstSelectedDocument"
*ngIf="selectedFile"
title="{{ 'APP.ACTIONS.VIEW' | translate }}"
(click)="showPreview(firstSelectedDocument)">
(click)="showPreview(selectedFile)">
<mat-icon>open_in_browser</mat-icon>
</button>
@@ -27,10 +27,10 @@
<button
color="primary"
mat-icon-button
*ngIf="firstSelectedFolder && permission.check(firstSelectedFolder, ['update'])"
*ngIf="selectedFolder && permission.check(selectedFolder, ['update'])"
[attr.title]="'APP.ACTIONS.EDIT' | translate"
(error)="openSnackMessage($event)"
[adf-edit-folder]="firstSelectedFolder?.entry">
[adf-edit-folder]="selectedFolder?.entry">
<mat-icon>create</mat-icon>
</button>
@@ -85,8 +85,8 @@
<button
mat-menu-item
*ngIf="firstSelectedDocument"
[acaNodeVersions]="firstSelectedDocument">
*ngIf="selectedFile"
[acaNodeVersions]="selectedFile">
<mat-icon>history</mat-icon>
<span>{{ 'APP.ACTIONS.VERSIONS' | translate }}</span>
</button>

View File

@@ -74,31 +74,31 @@ describe('PageComponent', () => {
});
});
describe('firstSelectedDocument', () => {
describe('selectedFile', () => {
it('returns true if selected node is file', () => {
const selection = [ { entry: { isFile: true } } ];
component.setSelection(selection);
expect(component.firstSelectedDocument).toBe(selection[0]);
expect(component.selectedFile).toBe(selection[0]);
});
it('returns false if selected node is folder', () => {
const selection = [ { entry: { isFile: false, isFolder: true } } ];
component.setSelection(selection);
expect(component.firstSelectedDocument).toBeFalsy();
expect(component.selectedFile).toBeFalsy();
});
});
describe('firstSelectedFolder', () => {
describe('selectedFolder', () => {
it('returns true if selected node is folder', () => {
const selection = [ { entry: { isFile: false, isFolder: true } } ];
component.setSelection(selection);
expect(component.firstSelectedFolder).toBe(selection[0]);
expect(component.selectedFolder).toBe(selection[0]);
});
it('returns false if selected node is file', () => {
const selection = [ { entry: { isFile: true, isFolder: false } } ];
component.setSelection(selection);
expect(component.firstSelectedFolder).toBeFalsy();
expect(component.selectedFolder).toBeFalsy();
});
});
});

View File

@@ -46,10 +46,10 @@ export abstract class PageComponent implements OnInit, OnDestroy {
infoDrawerOpened = false;
node: MinimalNodeEntryEntity;
selectedFolder: MinimalNodeEntity;
selectedFile: MinimalNodeEntity;
hasSelection = false;
firstSelectedDocument: MinimalNodeEntity;
firstSelectedFolder: MinimalNodeEntity;
firstSelectedNode: MinimalNodeEntity;
lastSelectedNode: MinimalNodeEntity;
selectedNodes: MinimalNodeEntity[];
@@ -86,16 +86,15 @@ export abstract class PageComponent implements OnInit, OnDestroy {
protected onSelectionChanged(selection: MinimalNodeEntity[] = []) {
this.selectedNodes = selection;
this.hasSelection = selection.length > 0;
this.selectedFolder = null;
this.selectedFile = null;
if (selection.length > 0) {
const firstNode = selection[0];
this.firstSelectedNode = firstNode;
this.firstSelectedDocument = selection.find(entity => entity.entry.isFile);
this.firstSelectedFolder = selection.find(entity => entity.entry.isFolder);
if (selection.length === 1) {
this.selectedFile = selection.find(entity => entity.entry.isFile);
this.selectedFolder = selection.find(entity => entity.entry.isFolder);
}
} else {
this.firstSelectedNode = null;
this.firstSelectedDocument = null;
this.firstSelectedFolder = null;
this.lastSelectedNode = null;
this.infoDrawerOpened = false;
}

View File

@@ -8,9 +8,9 @@
<button
mat-icon-button
color="primary"
*ngIf="firstSelectedDocument"
*ngIf="selectedFile"
title="{{ 'APP.ACTIONS.VIEW' | translate }}"
(click)="showPreview(firstSelectedDocument)">
(click)="showPreview(selectedFile)">
<mat-icon>open_in_browser</mat-icon>
</button>
@@ -73,8 +73,8 @@
<button
mat-menu-item
*ngIf="firstSelectedDocument"
[acaNodeVersions]="firstSelectedDocument">
*ngIf="selectedFile"
[acaNodeVersions]="selectedFile">
<mat-icon>history</mat-icon>
<span>{{ 'APP.ACTIONS.VERSIONS' | translate }}</span>
</button>