mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACA-1066] Improved files preview (#173)
* preview files child route * fix previewing root files (personal)
This commit is contained in:
@@ -41,13 +41,6 @@ import { PreviewComponent } from './components/preview/preview.component';
|
|||||||
import { GenericErrorComponent } from './components/generic-error/generic-error.component';
|
import { GenericErrorComponent } from './components/generic-error/generic-error.component';
|
||||||
|
|
||||||
export const APP_ROUTES: Routes = [
|
export const APP_ROUTES: Routes = [
|
||||||
{
|
|
||||||
path: 'preview/:nodeId',
|
|
||||||
component: PreviewComponent,
|
|
||||||
data: {
|
|
||||||
i18nTitle: 'APP.PREVIEW.TITLE'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: 'login',
|
path: 'login',
|
||||||
component: LoginComponent,
|
component: LoginComponent,
|
||||||
@@ -66,10 +59,22 @@ export const APP_ROUTES: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'favorites',
|
path: 'favorites',
|
||||||
component: FavoritesComponent,
|
children: [
|
||||||
data: {
|
{
|
||||||
i18nTitle: 'APP.BROWSE.FAVORITES.TITLE'
|
path: '',
|
||||||
}
|
component: FavoritesComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.BROWSE.FAVORITES.TITLE'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'preview/:nodeId',
|
||||||
|
component: PreviewComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.PREVIEW.TITLE'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'libraries',
|
path: 'libraries',
|
||||||
@@ -85,38 +90,87 @@ export const APP_ROUTES: Routes = [
|
|||||||
data: {
|
data: {
|
||||||
i18nTitle: 'APP.BROWSE.LIBRARIES.TITLE'
|
i18nTitle: 'APP.BROWSE.LIBRARIES.TITLE'
|
||||||
}
|
}
|
||||||
}]
|
},
|
||||||
|
{
|
||||||
|
path: ':id/preview/:nodeId',
|
||||||
|
component: PreviewComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.PREVIEW.TITLE'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'personal-files',
|
path: 'personal-files',
|
||||||
children: [{
|
children: [
|
||||||
path: '',
|
{
|
||||||
component: FilesComponent,
|
path: '',
|
||||||
data: {
|
component: FilesComponent,
|
||||||
i18nTitle: 'APP.BROWSE.PERSONAL.TITLE',
|
data: {
|
||||||
defaultNodeId: '-my-'
|
i18nTitle: 'APP.BROWSE.PERSONAL.TITLE',
|
||||||
|
defaultNodeId: '-my-'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ':id',
|
||||||
|
component: FilesComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.BROWSE.PERSONAL.TITLE'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'preview/:nodeId',
|
||||||
|
component: PreviewComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.PREVIEW.TITLE'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ':id/preview/:nodeId',
|
||||||
|
component: PreviewComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.PREVIEW.TITLE'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, {
|
]
|
||||||
path: ':id',
|
|
||||||
component: FilesComponent,
|
|
||||||
data: {
|
|
||||||
i18nTitle: 'APP.BROWSE.PERSONAL.TITLE'
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'recent-files',
|
path: 'recent-files',
|
||||||
component: RecentFilesComponent,
|
children: [
|
||||||
data: {
|
{
|
||||||
i18nTitle: 'APP.BROWSE.RECENT.TITLE'
|
path: '',
|
||||||
}
|
component: RecentFilesComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.BROWSE.RECENT.TITLE'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'preview/:nodeId',
|
||||||
|
component: PreviewComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.PREVIEW.TITLE'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'shared',
|
path: 'shared',
|
||||||
component: SharedFilesComponent,
|
children: [
|
||||||
data: {
|
{
|
||||||
i18nTitle: 'APP.BROWSE.SHARED.TITLE'
|
path: '',
|
||||||
}
|
component: SharedFilesComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.BROWSE.SHARED.TITLE'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'preview/:nodeId',
|
||||||
|
component: PreviewComponent,
|
||||||
|
data: {
|
||||||
|
i18nTitle: 'APP.PREVIEW.TITLE'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'trashcan',
|
path: 'trashcan',
|
||||||
|
@@ -174,7 +174,7 @@ describe('Favorites Routed Component', () => {
|
|||||||
|
|
||||||
component.onNodeDoubleClick(node);
|
component.onNodeDoubleClick(node);
|
||||||
|
|
||||||
expect(router.navigate).toHaveBeenCalledWith(['/preview', node.id]);
|
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', 'folder-node']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core';
|
import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router, ActivatedRoute } from '@angular/router';
|
||||||
import { Subscription } from 'rxjs/Rx';
|
import { Subscription } from 'rxjs/Rx';
|
||||||
|
|
||||||
import { MinimalNodeEntryEntity, MinimalNodeEntity, PathElementEntity, PathInfo } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity, MinimalNodeEntity, PathElementEntity, PathInfo } from 'alfresco-js-api';
|
||||||
@@ -46,6 +46,7 @@ export class FavoritesComponent extends PageComponent implements OnInit, OnDestr
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
|
private route: ActivatedRoute,
|
||||||
private nodesApi: NodesApiService,
|
private nodesApi: NodesApiService,
|
||||||
private contentService: ContentService,
|
private contentService: ContentService,
|
||||||
private content: ContentManagementService,
|
private content: ContentManagementService,
|
||||||
@@ -95,7 +96,7 @@ export class FavoritesComponent extends PageComponent implements OnInit, OnDestr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (node.isFile) {
|
if (node.isFile) {
|
||||||
this.router.navigate(['/preview', node.id]);
|
this.router.navigate(['./preview', node.id], { relativeTo: this.route });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -143,7 +143,7 @@ describe('FilesComponent', () => {
|
|||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(router.navigate).toHaveBeenCalledWith([ '/personal-files', 'parent-id' ]);
|
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['/personal-files', 'parent-id']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -315,6 +315,7 @@ describe('FilesComponent', () => {
|
|||||||
it('opens preview if node is file', () => {
|
it('opens preview if node is file', () => {
|
||||||
spyOn(router, 'navigate').and.stub();
|
spyOn(router, 'navigate').and.stub();
|
||||||
node.isFile = true;
|
node.isFile = true;
|
||||||
|
node.isFolder = false;
|
||||||
|
|
||||||
const event: any = {
|
const event: any = {
|
||||||
detail: {
|
detail: {
|
||||||
@@ -325,7 +326,7 @@ describe('FilesComponent', () => {
|
|||||||
};
|
};
|
||||||
component.onNodeDoubleClick(event);
|
component.onNodeDoubleClick(event);
|
||||||
|
|
||||||
expect(router.navigate).toHaveBeenCalledWith(['/preview', node.id]);
|
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', node.id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('navigate if node is folder', () => {
|
it('navigate if node is folder', () => {
|
||||||
|
@@ -80,9 +80,10 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
|
|||||||
if (node.isFolder) {
|
if (node.isFolder) {
|
||||||
this.updateCurrentNode(node);
|
this.updateCurrentNode(node);
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/personal-files', node.parentId]);
|
this.router.navigate(['/personal-files', node.parentId], { replaceUrl: true });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.skipWhile(node => !node.isFolder)
|
||||||
.flatMap((node) => this.fetchNodes(node.id))
|
.flatMap((node) => this.fetchNodes(node.id))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(page) => {
|
(page) => {
|
||||||
@@ -154,7 +155,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
} else if (node.isFile) {
|
} else if (node.isFile) {
|
||||||
this.router.navigate(['/preview', node.id]);
|
this.router.navigate(['./preview', node.id], { relativeTo: this.route });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +165,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
|
|||||||
showPreview(node: MinimalNodeEntryEntity) {
|
showPreview(node: MinimalNodeEntryEntity) {
|
||||||
if (node) {
|
if (node) {
|
||||||
if (node.isFile) {
|
if (node.isFile) {
|
||||||
this.router.navigate(['/preview', node.id]);
|
this.router.navigate(['./preview', node.id], { relativeTo: this.route });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
<ng-container *ngIf="nodeId">
|
<ng-container *ngIf="nodeId">
|
||||||
<adf-viewer [fileNodeId]="nodeId"></adf-viewer>
|
<adf-viewer
|
||||||
|
[fileNodeId]="nodeId"
|
||||||
|
[overlayMode]="true"
|
||||||
|
(showViewerChange)="onShowChange($event)">
|
||||||
|
</adf-viewer>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||||
|
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-preview',
|
selector: 'app-preview',
|
||||||
@@ -37,12 +38,17 @@ import { AlfrescoApiService } from '@alfresco/adf-core';
|
|||||||
})
|
})
|
||||||
export class PreviewComponent implements OnInit {
|
export class PreviewComponent implements OnInit {
|
||||||
|
|
||||||
|
private node: MinimalNodeEntryEntity;
|
||||||
|
private previewLocation: string = null;
|
||||||
|
private routesSkipNavigation = [ '/shared', '/recent-files', '/favorites' ];
|
||||||
nodeId: string = null;
|
nodeId: string = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private apiService: AlfrescoApiService) {}
|
private apiService: AlfrescoApiService) {
|
||||||
|
this.previewLocation = this.router.url.substr(0, this.router.url.indexOf('/', 1));
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.params.subscribe(params => {
|
this.route.params.subscribe(params => {
|
||||||
@@ -50,16 +56,29 @@ export class PreviewComponent implements OnInit {
|
|||||||
if (id) {
|
if (id) {
|
||||||
this.apiService.getInstance().nodes.getNodeInfo(id).then(
|
this.apiService.getInstance().nodes.getNodeInfo(id).then(
|
||||||
(node) => {
|
(node) => {
|
||||||
|
this.node = node;
|
||||||
|
|
||||||
if (node && node.isFile) {
|
if (node && node.isFile) {
|
||||||
this.nodeId = id;
|
this.nodeId = id;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.router.navigate(['/personal-files', id]);
|
this.router.navigate([this.previewLocation, id]);
|
||||||
},
|
},
|
||||||
() => this.router.navigate(['/personal-files', id])
|
() => this.router.navigate([this.previewLocation, id])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onShowChange(isVisible) {
|
||||||
|
const shouldSkipNavigation = this.routesSkipNavigation.includes(this.previewLocation);
|
||||||
|
|
||||||
|
if (!isVisible) {
|
||||||
|
if ( !shouldSkipNavigation ) {
|
||||||
|
this.router.navigate([this.previewLocation, this.node.parentId ]);
|
||||||
|
} else {
|
||||||
|
this.router.navigate([this.previewLocation]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -122,12 +122,12 @@ describe('RecentFiles Routed Component', () => {
|
|||||||
|
|
||||||
it('open preview if node is file', () => {
|
it('open preview if node is file', () => {
|
||||||
spyOn(router, 'navigate').and.stub();
|
spyOn(router, 'navigate').and.stub();
|
||||||
const node: any = { isFile: true };
|
const node: any = { id: 'node-id', isFile: true };
|
||||||
|
|
||||||
component.onNodeDoubleClick(node);
|
component.onNodeDoubleClick(node);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(router.navigate).toHaveBeenCalledWith(['/preview', node.id]);
|
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', node.id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not open preview if node is folder', () => {
|
it('does not open preview if node is folder', () => {
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
import { Subscription } from 'rxjs/Rx';
|
import { Subscription } from 'rxjs/Rx';
|
||||||
import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core';
|
import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router, ActivatedRoute } from '@angular/router';
|
||||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
import { UserPreferencesService } from '@alfresco/adf-core';
|
import { UserPreferencesService } from '@alfresco/adf-core';
|
||||||
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
||||||
@@ -45,6 +45,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
|
private route: ActivatedRoute,
|
||||||
private content: ContentManagementService,
|
private content: ContentManagementService,
|
||||||
preferences: UserPreferencesService) {
|
preferences: UserPreferencesService) {
|
||||||
super(preferences);
|
super(preferences);
|
||||||
@@ -67,7 +68,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
} else if (node && node.isFile) {
|
} else if (node && node.isFile) {
|
||||||
this.router.navigate(['/preview', node.id]);
|
this.router.navigate(['./preview', node.id], { relativeTo: this.route });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,11 +60,12 @@ describe('SearchComponent', () => {
|
|||||||
describe('onItemClicked()', () => {
|
describe('onItemClicked()', () => {
|
||||||
it('opens preview if node is file', () => {
|
it('opens preview if node is file', () => {
|
||||||
spyOn(router, 'navigate').and.stub();
|
spyOn(router, 'navigate').and.stub();
|
||||||
const node = { entry: { isFile: true, id: 'node-id' } };
|
const node = { entry: { isFile: true, id: 'node-id', parentId: 'parent-id' } };
|
||||||
|
|
||||||
component.onItemClicked(node);
|
component.onItemClicked(node);
|
||||||
|
|
||||||
expect(router.navigate).toHaveBeenCalledWith(['/preview', node.entry.id]);
|
expect(router.navigate['calls'].argsFor(0)[0])
|
||||||
|
.toEqual([`/personal-files/${node.entry.parentId}/preview/`, node.entry.id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('navigates if node is folder', () => {
|
it('navigates if node is folder', () => {
|
||||||
|
@@ -41,7 +41,7 @@ export class SearchComponent {
|
|||||||
onItemClicked(node: MinimalNodeEntity) {
|
onItemClicked(node: MinimalNodeEntity) {
|
||||||
if (node && node.entry) {
|
if (node && node.entry) {
|
||||||
if (node.entry.isFile) {
|
if (node.entry.isFile) {
|
||||||
this.router.navigate(['/preview', node.entry.id]);
|
this.router.navigate([`/personal-files/${node.entry.parentId}/preview/`, node.entry.id]);
|
||||||
} else if (node.entry.isFolder) {
|
} else if (node.entry.isFolder) {
|
||||||
this.router.navigate([ '/personal-files', node.entry.id ]);
|
this.router.navigate([ '/personal-files', node.entry.id ]);
|
||||||
}
|
}
|
||||||
|
@@ -126,7 +126,7 @@ describe('SharedFilesComponent', () => {
|
|||||||
component.onNodeDoubleClick(link);
|
component.onNodeDoubleClick(link);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(router.navigate).toHaveBeenCalledWith(['/preview', node.entry.id]);
|
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', node.entry.id]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('does nothing if node is folder', fakeAsync(() => {
|
it('does nothing if node is folder', fakeAsync(() => {
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
|
import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router, ActivatedRoute } from '@angular/router';
|
||||||
import { Subscription } from 'rxjs/Rx';
|
import { Subscription } from 'rxjs/Rx';
|
||||||
import { MinimalNodeEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core';
|
import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core';
|
||||||
@@ -45,6 +45,7 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
|
private route: ActivatedRoute,
|
||||||
private content: ContentManagementService,
|
private content: ContentManagementService,
|
||||||
private apiService: AlfrescoApiService,
|
private apiService: AlfrescoApiService,
|
||||||
preferences: UserPreferencesService) {
|
preferences: UserPreferencesService) {
|
||||||
@@ -68,7 +69,7 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes
|
|||||||
this.apiService.nodesApi.getNode(link.nodeId).then(
|
this.apiService.nodesApi.getNode(link.nodeId).then(
|
||||||
(node: MinimalNodeEntity) => {
|
(node: MinimalNodeEntity) => {
|
||||||
if (node && node.entry && node.entry.isFile) {
|
if (node && node.entry && node.entry.isFile) {
|
||||||
this.router.navigate(['/preview', node.entry.id]);
|
this.router.navigate(['./preview', node.entry.id], { relativeTo: this.route });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user