mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-06-30 18:14:45 +00:00
replace and clean up methods (#352)
This commit is contained in:
parent
3ca63b8433
commit
5dee937cf0
@ -8,7 +8,7 @@
|
||||
<button
|
||||
mat-icon-button
|
||||
color="primary"
|
||||
*ngIf="canPreviewFile(documentList.selection)"
|
||||
*ngIf="isFileSelected(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.VIEW' | translate }}"
|
||||
(click)="onNodeDoubleClick(documentList.selection[0]?.entry)">
|
||||
<mat-icon>open_in_browser</mat-icon>
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
<button mat-icon-button
|
||||
[color]="infoDrawerOpened ? 'accent' : 'primary'"
|
||||
*ngIf="documentList.selection.length"
|
||||
*ngIf="hasSelection(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.DETAILS' | translate }}"
|
||||
(click)="toggleSidebar()">
|
||||
<mat-icon>info_outline</mat-icon>
|
||||
|
@ -10,7 +10,7 @@
|
||||
<button
|
||||
color="primary"
|
||||
mat-icon-button
|
||||
*ngIf="canPreviewFile(documentList.selection)"
|
||||
*ngIf="isFileSelected(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.VIEW' | translate }}"
|
||||
(click)="showPreview(documentList.selection[0]?.entry)">
|
||||
<mat-icon>open_in_browser</mat-icon>
|
||||
@ -28,7 +28,8 @@
|
||||
<button
|
||||
color="primary"
|
||||
mat-icon-button
|
||||
*ngIf="canEditFolder(documentList.selection)"
|
||||
*ngIf="isFolderSelected(documentList.selection)
|
||||
&& permission.check(documentList.selection, ['update'])"
|
||||
[attr.title]="'APP.ACTIONS.EDIT' | translate"
|
||||
(error)="openSnackMessage($event)"
|
||||
[adf-edit-folder]="documentList.selection[0]?.entry">
|
||||
@ -37,7 +38,7 @@
|
||||
|
||||
<button mat-icon-button
|
||||
[color]="infoDrawerOpened ? 'accent' : 'primary'"
|
||||
*ngIf="documentList.selection.length"
|
||||
*ngIf="hasSelection(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.DETAILS' | translate }}"
|
||||
(click)="toggleSidebar()">
|
||||
<mat-icon>info_outline</mat-icon>
|
||||
@ -77,7 +78,7 @@
|
||||
|
||||
<button
|
||||
mat-menu-item
|
||||
*ngIf="canMove(documentList.selection)"
|
||||
*ngIf="permission.check(documentList.selection, ['delete'])"
|
||||
[acaMoveNode]="documentList.selection">
|
||||
<mat-icon color="primary">library_books</mat-icon>
|
||||
<span>{{ 'APP.ACTIONS.MOVE' | translate }}</span>
|
||||
@ -85,7 +86,7 @@
|
||||
|
||||
<button
|
||||
mat-menu-item
|
||||
*ngIf="canDelete(documentList.selection)"
|
||||
*ngIf="permission.check(documentList.selection, ['delete'])"
|
||||
[acaDeleteNode]="documentList.selection">
|
||||
<mat-icon color="primary">delete</mat-icon>
|
||||
<span>{{ 'APP.ACTIONS.DELETE' | translate }}</span>
|
||||
@ -190,8 +191,8 @@
|
||||
</div>
|
||||
|
||||
<adf-content-metadata-card
|
||||
[readOnly]="!canUpdate(documentList.selection)"
|
||||
[displayEmpty]="canUpdate(documentList.selection)"
|
||||
[readOnly]="!permission.check(nodeInfo.node, ['update'])"
|
||||
[displayEmpty]="permission.check(nodeInfo.node, ['update'])"
|
||||
[preset]="'custom'"
|
||||
[node]="infoInstance.node">
|
||||
</adf-content-metadata-card>
|
||||
|
@ -70,50 +70,6 @@ describe('PageComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('filesOnlySelected()', () => {
|
||||
it('return true if only files are selected', () => {
|
||||
const selected = [ { entry: { isFile: true } }, { entry: { isFile: true } } ];
|
||||
expect(component.filesOnlySelected(selected)).toBe(true);
|
||||
});
|
||||
|
||||
it('return false if selection contains others types', () => {
|
||||
const selected = [ { entry: { isFile: true } }, { entry: { isFolder: true } } ];
|
||||
expect(component.filesOnlySelected(selected)).toBe(false);
|
||||
});
|
||||
|
||||
it('return false if selection contains no files', () => {
|
||||
const selected = [ { entry: { isFolder: true } } ];
|
||||
expect(component.filesOnlySelected(selected)).toBe(false);
|
||||
});
|
||||
|
||||
it('return false no selection', () => {
|
||||
const selected = [];
|
||||
expect(component.filesOnlySelected(selected)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('foldersOnlySelected()', () => {
|
||||
it('return true if only folders are selected', () => {
|
||||
const selected = [ { entry: { isFolder: true } }, { entry: { isFolder: true } } ];
|
||||
expect(component.foldersOnlySelected(selected)).toBe(true);
|
||||
});
|
||||
|
||||
it('return false if selection contains others types', () => {
|
||||
const selected = [ { entry: { isFile: true } }, { entry: { isFolder: true } } ];
|
||||
expect(component.foldersOnlySelected(selected)).toBe(false);
|
||||
});
|
||||
|
||||
it('return false if selection contains no files', () => {
|
||||
const selected = [ { entry: { isFile: true } } ];
|
||||
expect(component.foldersOnlySelected(selected)).toBe(false);
|
||||
});
|
||||
|
||||
it('return false no selection', () => {
|
||||
const selected = [];
|
||||
expect(component.foldersOnlySelected(selected)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isFileSelected()', () => {
|
||||
it('returns true if selected node is file', () => {
|
||||
const selection = [ { entry: { isFile: true } } ];
|
||||
@ -131,135 +87,20 @@ describe('PageComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('canEditFolder()', () => {
|
||||
describe('isFolderSelected()', () => {
|
||||
it('returns true if selected node is folder', () => {
|
||||
const selection = [ { entry: { isFolder: true } } ];
|
||||
spyOn(component, 'nodeHasPermission').and.returnValue(true);
|
||||
|
||||
expect(component.canEditFolder(selection)).toBe(true);
|
||||
expect(component.isFolderSelected(selection)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if selected node is file', () => {
|
||||
const selection = [ { entry: { isFile: true } } ];
|
||||
expect(component.canEditFolder(selection)).toBe(false);
|
||||
expect(component.isFolderSelected(selection)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if there are more than one selections', () => {
|
||||
const selection = [ { entry: { isFolder: true } }, { entry: { isFolder: true } } ];
|
||||
expect(component.canEditFolder(selection)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false folder dows not have edit permission', () => {
|
||||
spyOn(component, 'nodeHasPermission').and.returnValue(false);
|
||||
const selection = [ { entry: { isFolder: true } } ];
|
||||
|
||||
expect(component.canEditFolder(selection)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canDelete()', () => {
|
||||
it('returns false if node has no delete permission', () => {
|
||||
const selection = [ { entry: { } } ];
|
||||
spyOn(component, 'nodeHasPermission').and.returnValue(false);
|
||||
|
||||
expect(component.canDelete(selection)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true if node has delete permission', () => {
|
||||
const selection = [ { entry: { } } ];
|
||||
spyOn(component, 'nodeHasPermission').and.returnValue(true);
|
||||
|
||||
expect(component.canDelete(selection)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canMove()', () => {
|
||||
it('returns true if node can be deleted', () => {
|
||||
const selection = [ { entry: { } } ];
|
||||
spyOn(component, 'canDelete').and.returnValue(true);
|
||||
|
||||
expect(component.canMove(selection)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if node can not be deleted', () => {
|
||||
const selection = [ { entry: { } } ];
|
||||
spyOn(component, 'canDelete').and.returnValue(false);
|
||||
|
||||
expect(component.canMove(selection)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canPreviewFile()', () => {
|
||||
it('it returns true if node is file', () => {
|
||||
const selection = [{ entry: { isFile: true } }];
|
||||
|
||||
expect(component.canPreviewFile(selection)).toBe(true);
|
||||
});
|
||||
|
||||
it('it returns false if node is folder', () => {
|
||||
const selection = [{ entry: { isFolder: true } }];
|
||||
|
||||
expect(component.canPreviewFile(selection)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canShareFile()', () => {
|
||||
it('it returns true if node is file', () => {
|
||||
const selection = [{ entry: { isFile: true } }];
|
||||
|
||||
expect(component.canShareFile(selection)).toBe(true);
|
||||
});
|
||||
|
||||
it('it returns false if node is folder', () => {
|
||||
const selection = [{ entry: { isFolder: true } }];
|
||||
|
||||
expect(component.canShareFile(selection)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canDownloadFile()', () => {
|
||||
it('it returns true if node is file', () => {
|
||||
const selection = [{ entry: { isFile: true } }];
|
||||
|
||||
expect(component.canDownloadFile(selection)).toBe(true);
|
||||
});
|
||||
|
||||
it('it returns false if node is folder', () => {
|
||||
const selection = [{ entry: { isFolder: true } }];
|
||||
|
||||
expect(component.canDownloadFile(selection)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('nodeHasPermission()', () => {
|
||||
it('returns true is has permission', () => {
|
||||
const node = { allowableOperations: ['some-operation'] };
|
||||
|
||||
expect(component.nodeHasPermission(node, 'some-operation')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true is has permission', () => {
|
||||
const node = { allowableOperations: ['other-operation'] };
|
||||
|
||||
expect(component.nodeHasPermission(node, 'some-operation')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('canUpdate()', () => {
|
||||
it('should return true if node can be edited', () => {
|
||||
const selection = [ { entry: {
|
||||
allowableOperations: ['update']
|
||||
} } ];
|
||||
|
||||
expect(component.canUpdate(selection)).toBe(true);
|
||||
});
|
||||
|
||||
it(`should return false if node cannot be edited`, () => {
|
||||
const selection = [ { entry: {
|
||||
allowableOperations: ['other-permission']
|
||||
} } ];
|
||||
|
||||
expect(component.canUpdate(selection)).toBe(false);
|
||||
expect(component.isFolderSelected(selection)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -49,20 +49,6 @@ export abstract class PageComponent {
|
||||
return selection && selection.length > 0;
|
||||
}
|
||||
|
||||
filesOnlySelected(selection: Array<MinimalNodeEntity>): boolean {
|
||||
if (this.hasSelection(selection)) {
|
||||
return selection.every(entity => entity.entry && entity.entry.isFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
foldersOnlySelected(selection: Array<MinimalNodeEntity>): boolean {
|
||||
if (this.hasSelection(selection)) {
|
||||
return selection.every(entity => entity.entry && entity.entry.isFolder);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isFileSelected(selection: Array<MinimalNodeEntity>): boolean {
|
||||
if (selection && selection.length === 1) {
|
||||
const entry = selection[0].entry;
|
||||
@ -74,58 +60,14 @@ export abstract class PageComponent {
|
||||
return false;
|
||||
}
|
||||
|
||||
canEditFolder(selection: Array<MinimalNodeEntity>): boolean {
|
||||
isFolderSelected(selection: Array<MinimalNodeEntity>): boolean {
|
||||
if (selection && selection.length === 1) {
|
||||
const entry = selection[0].entry;
|
||||
|
||||
if (entry && entry.isFolder) {
|
||||
return this.nodeHasPermission(entry, 'update');
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
canDelete(selection: Array<MinimalNodeEntity> = []): boolean {
|
||||
return selection.every(node => node.entry && this.nodeHasPermission(node.entry, 'delete'));
|
||||
}
|
||||
|
||||
canMove(selection: Array<MinimalNodeEntity>): boolean {
|
||||
return this.canDelete(selection);
|
||||
}
|
||||
|
||||
canUpdate(selection: Array<MinimalNodeEntity> = []): boolean {
|
||||
return selection.every(node => node.entry && this.nodeHasPermission(node.entry, 'update'));
|
||||
}
|
||||
|
||||
canPreviewFile(selection: Array<MinimalNodeEntity>): boolean {
|
||||
return this.isFileSelected(selection);
|
||||
}
|
||||
|
||||
canShareFile(selection: Array<MinimalNodeEntity>): boolean {
|
||||
return this.isFileSelected(selection);
|
||||
}
|
||||
|
||||
canDownloadFile(selection: Array<MinimalNodeEntity>): boolean {
|
||||
return this.isFileSelected(selection);
|
||||
}
|
||||
|
||||
canUpdateFile(selection: Array<MinimalNodeEntity>): boolean {
|
||||
return this.isFileSelected(selection) && this.nodeHasPermission(selection[0].entry, 'update');
|
||||
}
|
||||
|
||||
canManageVersions(selection: Array<MinimalNodeEntity>): boolean {
|
||||
return this.canUpdateFile(selection);
|
||||
}
|
||||
|
||||
nodeHasPermission(node: MinimalNodeEntryEntity, permission: string): boolean {
|
||||
if (node && permission) {
|
||||
const { allowableOperations = [] } = <any>(node || {});
|
||||
|
||||
if (allowableOperations.indexOf(permission) > -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
<button
|
||||
mat-icon-button
|
||||
color="primary"
|
||||
*ngIf="canPreviewFile(documentList.selection)"
|
||||
*ngIf="isFileSelected(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.VIEW' | translate }}"
|
||||
(click)="onNodeDoubleClick(documentList.selection[0]?.entry)">
|
||||
<mat-icon>open_in_browser</mat-icon>
|
||||
@ -25,7 +25,7 @@
|
||||
|
||||
<button mat-icon-button
|
||||
[color]="infoDrawerOpened ? 'accent' : 'primary'"
|
||||
*ngIf="documentList.selection.length"
|
||||
*ngIf="hasSelection(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.DETAILS' | translate }}"
|
||||
(click)="toggleSidebar()">
|
||||
<mat-icon>info_outline</mat-icon>
|
||||
@ -65,7 +65,7 @@
|
||||
|
||||
<button
|
||||
mat-menu-item
|
||||
*ngIf="canMove(documentList.selection)"
|
||||
*ngIf="permission.check(documentList.selection, ['delete'])"
|
||||
[acaMoveNode]="documentList.selection">
|
||||
<mat-icon color="primary">library_books</mat-icon>
|
||||
<span>{{ 'APP.ACTIONS.MOVE' | translate }}</span>
|
||||
@ -73,7 +73,7 @@
|
||||
|
||||
<button
|
||||
mat-menu-item
|
||||
*ngIf="canDelete(documentList.selection)"
|
||||
*ngIf="permission.check(documentList.selection, ['delete'])"
|
||||
[acaDeleteNode]="documentList.selection">
|
||||
<mat-icon color="primary">delete</mat-icon>
|
||||
<span>{{ 'APP.ACTIONS.DELETE' | translate }}</span>
|
||||
@ -177,8 +177,8 @@
|
||||
</div>
|
||||
|
||||
<adf-content-metadata-card
|
||||
[readOnly]="!canUpdate(documentList.selection)"
|
||||
[displayEmpty]="canUpdate(documentList.selection)"
|
||||
[readOnly]="!permission.check(nodeInfo.node, ['update'])"
|
||||
[displayEmpty]="permission.check(nodeInfo.node, ['update'])"
|
||||
[preset]="'custom'"
|
||||
[node]="infoInstance.node">
|
||||
</adf-content-metadata-card>
|
||||
|
@ -43,6 +43,7 @@ import { DocumentListService } from '@alfresco/adf-content-services';
|
||||
import { ContentManagementService } from '../../common/services/content-management.service';
|
||||
import { NodeInfoDirective } from '../../common/directives/node-info.directive';
|
||||
import { AppConfigPipe } from '../../common/pipes/app-config.pipe';
|
||||
import { NodePermissionService } from '../../common/services/node-permission.service';
|
||||
|
||||
import { RecentFilesComponent } from './recent-files.component';
|
||||
|
||||
@ -96,6 +97,7 @@ describe('RecentFiles Routed Component', () => {
|
||||
LogService,
|
||||
NotificationService,
|
||||
ContentManagementService,
|
||||
NodePermissionService,
|
||||
ContentService,
|
||||
NodesApiService,
|
||||
DocumentListService,
|
||||
|
@ -32,6 +32,7 @@ import { DocumentListComponent } from '@alfresco/adf-content-services';
|
||||
|
||||
import { ContentManagementService } from '../../common/services/content-management.service';
|
||||
import { PageComponent } from '../page.component';
|
||||
import { NodePermissionService } from '../../common/services/node-permission.service';
|
||||
|
||||
@Component({
|
||||
templateUrl: './recent-files.component.html'
|
||||
@ -49,6 +50,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private content: ContentManagementService,
|
||||
public permission: NodePermissionService,
|
||||
preferences: UserPreferencesService) {
|
||||
super(preferences);
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<button
|
||||
color="primary"
|
||||
mat-icon-button
|
||||
*ngIf="canPreviewFile(documentList.selection)"
|
||||
*ngIf="isFileSelected(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.VIEW' | translate }}"
|
||||
(click)="onNodeDoubleClick(documentList.selection[0]?.entry)">
|
||||
<mat-icon>open_in_browser</mat-icon>
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
<button mat-icon-button
|
||||
[color]="infoDrawerOpened ? 'accent' : 'primary'"
|
||||
*ngIf="documentList.selection.length"
|
||||
*ngIf="hasSelection(documentList.selection)"
|
||||
title="{{ 'APP.ACTIONS.DETAILS' | translate }}"
|
||||
(click)="toggleSidebar()">
|
||||
<mat-icon>info_outline</mat-icon>
|
||||
|
Loading…
x
Reference in New Issue
Block a user