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

View File

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

View File

@@ -74,31 +74,31 @@ describe('PageComponent', () => {
}); });
}); });
describe('firstSelectedDocument', () => { describe('selectedFile', () => {
it('returns true if selected node is file', () => { it('returns true if selected node is file', () => {
const selection = [ { entry: { isFile: true } } ]; const selection = [ { entry: { isFile: true } } ];
component.setSelection(selection); component.setSelection(selection);
expect(component.firstSelectedDocument).toBe(selection[0]); expect(component.selectedFile).toBe(selection[0]);
}); });
it('returns false if selected node is folder', () => { it('returns false if selected node is folder', () => {
const selection = [ { entry: { isFile: false, isFolder: true } } ]; const selection = [ { entry: { isFile: false, isFolder: true } } ];
component.setSelection(selection); component.setSelection(selection);
expect(component.firstSelectedDocument).toBeFalsy(); expect(component.selectedFile).toBeFalsy();
}); });
}); });
describe('firstSelectedFolder', () => { describe('selectedFolder', () => {
it('returns true if selected node is folder', () => { it('returns true if selected node is folder', () => {
const selection = [ { entry: { isFile: false, isFolder: true } } ]; const selection = [ { entry: { isFile: false, isFolder: true } } ];
component.setSelection(selection); component.setSelection(selection);
expect(component.firstSelectedFolder).toBe(selection[0]); expect(component.selectedFolder).toBe(selection[0]);
}); });
it('returns false if selected node is file', () => { it('returns false if selected node is file', () => {
const selection = [ { entry: { isFile: true, isFolder: false } } ]; const selection = [ { entry: { isFile: true, isFolder: false } } ];
component.setSelection(selection); 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; infoDrawerOpened = false;
node: MinimalNodeEntryEntity; node: MinimalNodeEntryEntity;
selectedFolder: MinimalNodeEntity;
selectedFile: MinimalNodeEntity;
hasSelection = false; hasSelection = false;
firstSelectedDocument: MinimalNodeEntity;
firstSelectedFolder: MinimalNodeEntity;
firstSelectedNode: MinimalNodeEntity;
lastSelectedNode: MinimalNodeEntity; lastSelectedNode: MinimalNodeEntity;
selectedNodes: MinimalNodeEntity[]; selectedNodes: MinimalNodeEntity[];
@@ -86,16 +86,15 @@ export abstract class PageComponent implements OnInit, OnDestroy {
protected onSelectionChanged(selection: MinimalNodeEntity[] = []) { protected onSelectionChanged(selection: MinimalNodeEntity[] = []) {
this.selectedNodes = selection; this.selectedNodes = selection;
this.hasSelection = selection.length > 0; this.hasSelection = selection.length > 0;
this.selectedFolder = null;
this.selectedFile = null;
if (selection.length > 0) { if (selection.length > 0) {
const firstNode = selection[0]; if (selection.length === 1) {
this.firstSelectedNode = firstNode; this.selectedFile = selection.find(entity => entity.entry.isFile);
this.firstSelectedDocument = selection.find(entity => entity.entry.isFile); this.selectedFolder = selection.find(entity => entity.entry.isFolder);
this.firstSelectedFolder = selection.find(entity => entity.entry.isFolder); }
} else { } else {
this.firstSelectedNode = null;
this.firstSelectedDocument = null;
this.firstSelectedFolder = null;
this.lastSelectedNode = null; this.lastSelectedNode = null;
this.infoDrawerOpened = false; this.infoDrawerOpened = false;
} }

View File

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