From b6018facac5e066db42a914be299cb5e33150d4c Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 3 Jan 2018 10:05:54 +0000 Subject: [PATCH] Revert "preview files child route (#170)" (#171) This reverts commit d768219bdbdf91006bb5972e1412d3185a938407. --- src/app/app.routes.ts | 84 +++++-------------- .../favorites/favorites.component.spec.ts | 2 +- .../favorites/favorites.component.ts | 5 +- .../components/files/files.component.spec.ts | 5 +- src/app/components/files/files.component.ts | 7 +- .../components/preview/preview.component.html | 6 +- .../components/preview/preview.component.ts | 25 +----- .../recent-files.component.spec.ts | 4 +- .../recent-files/recent-files.component.ts | 5 +- .../search/search.component.spec.ts | 5 +- src/app/components/search/search.component.ts | 2 +- .../shared-files.component.spec.ts | 2 +- .../shared-files/shared-files.component.ts | 5 +- 13 files changed, 42 insertions(+), 115 deletions(-) diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 8c66ca552..3a28d1cef 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -41,6 +41,13 @@ import { PreviewComponent } from './components/preview/preview.component'; import { GenericErrorComponent } from './components/generic-error/generic-error.component'; export const APP_ROUTES: Routes = [ + { + path: 'preview/:nodeId', + component: PreviewComponent, + data: { + i18nTitle: 'APP.PREVIEW.TITLE' + } + }, { path: 'login', component: LoginComponent, @@ -59,22 +66,10 @@ export const APP_ROUTES: Routes = [ }, { path: 'favorites', - children: [ - { - path: '', - component: FavoritesComponent, - data: { - i18nTitle: 'APP.BROWSE.FAVORITES.TITLE' - } - }, - { - path: 'preview/:nodeId', - component: PreviewComponent, - data: { - i18nTitle: 'APP.PREVIEW.TITLE' - } - } - ] + component: FavoritesComponent, + data: { + i18nTitle: 'APP.BROWSE.FAVORITES.TITLE' + } }, { path: 'libraries', @@ -90,15 +85,7 @@ export const APP_ROUTES: Routes = [ data: { i18nTitle: 'APP.BROWSE.LIBRARIES.TITLE' } - }, - { - path: ':id/preview/:nodeId', - component: PreviewComponent, - data: { - i18nTitle: 'APP.PREVIEW.TITLE' - } - } - ] + }] }, { path: 'personal-files', @@ -115,52 +102,21 @@ export const APP_ROUTES: Routes = [ data: { i18nTitle: 'APP.BROWSE.PERSONAL.TITLE' } - }, - { - path: ':id/preview/:nodeId', - component: PreviewComponent, - data: { - i18nTitle: 'APP.PREVIEW.TITLE' - } }] }, { path: 'recent-files', - children: [ - { - path: '', - component: RecentFilesComponent, - data: { - i18nTitle: 'APP.BROWSE.RECENT.TITLE' - } - }, - { - path: 'preview/:nodeId', - component: PreviewComponent, - data: { - i18nTitle: 'APP.PREVIEW.TITLE' - } - } - ] + component: RecentFilesComponent, + data: { + i18nTitle: 'APP.BROWSE.RECENT.TITLE' + } }, { path: 'shared', - children: [ - { - path: '', - component: SharedFilesComponent, - data: { - i18nTitle: 'APP.BROWSE.SHARED.TITLE' - } - }, - { - path: 'preview/:nodeId', - component: PreviewComponent, - data: { - i18nTitle: 'APP.PREVIEW.TITLE' - } - } - ] + component: SharedFilesComponent, + data: { + i18nTitle: 'APP.BROWSE.SHARED.TITLE' + } }, { path: 'trashcan', diff --git a/src/app/components/favorites/favorites.component.spec.ts b/src/app/components/favorites/favorites.component.spec.ts index 8a0c2a189..c121bd7ea 100644 --- a/src/app/components/favorites/favorites.component.spec.ts +++ b/src/app/components/favorites/favorites.component.spec.ts @@ -174,7 +174,7 @@ describe('Favorites Routed Component', () => { component.onNodeDoubleClick(node); - expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', 'folder-node']); + expect(router.navigate).toHaveBeenCalledWith(['/preview', node.id]); }); }); diff --git a/src/app/components/favorites/favorites.component.ts b/src/app/components/favorites/favorites.component.ts index 2626f5748..99b858404 100644 --- a/src/app/components/favorites/favorites.component.ts +++ b/src/app/components/favorites/favorites.component.ts @@ -24,7 +24,7 @@ */ import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; -import { Router, ActivatedRoute } from '@angular/router'; +import { Router } from '@angular/router'; import { Subscription } from 'rxjs/Rx'; import { MinimalNodeEntryEntity, MinimalNodeEntity, PathElementEntity, PathInfo } from 'alfresco-js-api'; @@ -46,7 +46,6 @@ export class FavoritesComponent extends PageComponent implements OnInit, OnDestr constructor( private router: Router, - private route: ActivatedRoute, private nodesApi: NodesApiService, private contentService: ContentService, private content: ContentManagementService, @@ -96,7 +95,7 @@ export class FavoritesComponent extends PageComponent implements OnInit, OnDestr } if (node.isFile) { - this.router.navigate(['./preview', node.id], { relativeTo: this.route }); + this.router.navigate(['/preview', node.id]); } } } diff --git a/src/app/components/files/files.component.spec.ts b/src/app/components/files/files.component.spec.ts index 70c7e4f75..884ee1a83 100644 --- a/src/app/components/files/files.component.spec.ts +++ b/src/app/components/files/files.component.spec.ts @@ -143,7 +143,7 @@ describe('FilesComponent', () => { fixture.detectChanges(); - expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['/personal-files', 'parent-id']); + expect(router.navigate).toHaveBeenCalledWith([ '/personal-files', 'parent-id' ]); }); }); @@ -315,7 +315,6 @@ describe('FilesComponent', () => { it('opens preview if node is file', () => { spyOn(router, 'navigate').and.stub(); node.isFile = true; - node.isFolder = false; const event: any = { detail: { @@ -326,7 +325,7 @@ describe('FilesComponent', () => { }; component.onNodeDoubleClick(event); - expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', node.id]); + expect(router.navigate).toHaveBeenCalledWith(['/preview', node.id]); }); it('navigate if node is folder', () => { diff --git a/src/app/components/files/files.component.ts b/src/app/components/files/files.component.ts index 7854a44e7..96926da40 100644 --- a/src/app/components/files/files.component.ts +++ b/src/app/components/files/files.component.ts @@ -80,10 +80,9 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { if (node.isFolder) { this.updateCurrentNode(node); } else { - this.router.navigate(['/personal-files', node.parentId], { replaceUrl: true }); + this.router.navigate(['/personal-files', node.parentId]); } }) - .skipWhile(node => !node.isFolder) .flatMap((node) => this.fetchNodes(node.id)) .subscribe( (page) => { @@ -155,7 +154,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { event.preventDefault(); } else if (node.isFile) { - this.router.navigate(['./preview', node.id], { relativeTo: this.route }); + this.router.navigate(['/preview', node.id]); } } @@ -165,7 +164,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { showPreview(node: MinimalNodeEntryEntity) { if (node) { if (node.isFile) { - this.router.navigate(['./preview', node.id], { relativeTo: this.route }); + this.router.navigate(['/preview', node.id]); } } } diff --git a/src/app/components/preview/preview.component.html b/src/app/components/preview/preview.component.html index 536b6ebdc..2592514c9 100644 --- a/src/app/components/preview/preview.component.html +++ b/src/app/components/preview/preview.component.html @@ -1,7 +1,3 @@ - - + diff --git a/src/app/components/preview/preview.component.ts b/src/app/components/preview/preview.component.ts index 6c42b3416..99d92bfe9 100644 --- a/src/app/components/preview/preview.component.ts +++ b/src/app/components/preview/preview.component.ts @@ -26,7 +26,6 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { AlfrescoApiService } from '@alfresco/adf-core'; -import { MinimalNodeEntryEntity } from 'alfresco-js-api'; @Component({ selector: 'app-preview', @@ -38,17 +37,12 @@ import { MinimalNodeEntryEntity } from 'alfresco-js-api'; }) export class PreviewComponent implements OnInit { - private node: MinimalNodeEntryEntity; - private previewLocation: string = null; - private routesSkipNavigation = [ '/shared', '/recent-files', '/favorites' ]; nodeId: string = null; constructor( private router: Router, private route: ActivatedRoute, - private apiService: AlfrescoApiService) { - this.previewLocation = this.router.url.substr(0, this.router.url.indexOf('/', 1)); - } + private apiService: AlfrescoApiService) {} ngOnInit() { this.route.params.subscribe(params => { @@ -56,29 +50,16 @@ export class PreviewComponent implements OnInit { if (id) { this.apiService.getInstance().nodes.getNodeInfo(id).then( (node) => { - this.node = node; - if (node && node.isFile) { this.nodeId = id; return; } - this.router.navigate([this.previewLocation, id]); + this.router.navigate(['/personal-files', id]); }, - () => this.router.navigate([this.previewLocation, id]) + () => this.router.navigate(['/personal-files', 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]); - } - } - } } diff --git a/src/app/components/recent-files/recent-files.component.spec.ts b/src/app/components/recent-files/recent-files.component.spec.ts index 7291b60b8..890c5a6f9 100644 --- a/src/app/components/recent-files/recent-files.component.spec.ts +++ b/src/app/components/recent-files/recent-files.component.spec.ts @@ -122,12 +122,12 @@ describe('RecentFiles Routed Component', () => { it('open preview if node is file', () => { spyOn(router, 'navigate').and.stub(); - const node: any = { id: 'node-id', isFile: true }; + const node: any = { isFile: true }; component.onNodeDoubleClick(node); fixture.detectChanges(); - expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', node.id]); + expect(router.navigate).toHaveBeenCalledWith(['/preview', node.id]); }); it('does not open preview if node is folder', () => { diff --git a/src/app/components/recent-files/recent-files.component.ts b/src/app/components/recent-files/recent-files.component.ts index c49048758..1e2617b36 100644 --- a/src/app/components/recent-files/recent-files.component.ts +++ b/src/app/components/recent-files/recent-files.component.ts @@ -25,7 +25,7 @@ import { Subscription } from 'rxjs/Rx'; import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; -import { Router, ActivatedRoute } from '@angular/router'; +import { Router } from '@angular/router'; import { MinimalNodeEntryEntity } from 'alfresco-js-api'; import { UserPreferencesService } from '@alfresco/adf-core'; import { DocumentListComponent } from '@alfresco/adf-content-services'; @@ -45,7 +45,6 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes constructor( private router: Router, - private route: ActivatedRoute, private content: ContentManagementService, preferences: UserPreferencesService) { super(preferences); @@ -68,7 +67,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes event.preventDefault(); } else if (node && node.isFile) { - this.router.navigate(['./preview', node.id], { relativeTo: this.route }); + this.router.navigate(['/preview', node.id]); } } diff --git a/src/app/components/search/search.component.spec.ts b/src/app/components/search/search.component.spec.ts index 910e25cb0..946c4d268 100644 --- a/src/app/components/search/search.component.spec.ts +++ b/src/app/components/search/search.component.spec.ts @@ -60,12 +60,11 @@ describe('SearchComponent', () => { describe('onItemClicked()', () => { it('opens preview if node is file', () => { spyOn(router, 'navigate').and.stub(); - const node = { entry: { isFile: true, id: 'node-id', parentId: 'parent-id' } }; + const node = { entry: { isFile: true, id: 'node-id' } }; component.onItemClicked(node); - expect(router.navigate['calls'].argsFor(0)[0]) - .toEqual([`/personal-files/${node.entry.parentId}/preview/`, node.entry.id]); + expect(router.navigate).toHaveBeenCalledWith(['/preview', node.entry.id]); }); it('navigates if node is folder', () => { diff --git a/src/app/components/search/search.component.ts b/src/app/components/search/search.component.ts index 10f1f5fec..e4f14405e 100644 --- a/src/app/components/search/search.component.ts +++ b/src/app/components/search/search.component.ts @@ -41,7 +41,7 @@ export class SearchComponent { onItemClicked(node: MinimalNodeEntity) { if (node && node.entry) { if (node.entry.isFile) { - this.router.navigate([`/personal-files/${node.entry.parentId}/preview/`, node.entry.id]); + this.router.navigate(['/preview', node.entry.id]); } else if (node.entry.isFolder) { this.router.navigate([ '/personal-files', node.entry.id ]); } diff --git a/src/app/components/shared-files/shared-files.component.spec.ts b/src/app/components/shared-files/shared-files.component.spec.ts index 064b4a9cd..86df66efd 100644 --- a/src/app/components/shared-files/shared-files.component.spec.ts +++ b/src/app/components/shared-files/shared-files.component.spec.ts @@ -126,7 +126,7 @@ describe('SharedFilesComponent', () => { component.onNodeDoubleClick(link); tick(); - expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['./preview', node.entry.id]); + expect(router.navigate).toHaveBeenCalledWith(['/preview', node.entry.id]); })); it('does nothing if node is folder', fakeAsync(() => { diff --git a/src/app/components/shared-files/shared-files.component.ts b/src/app/components/shared-files/shared-files.component.ts index 5c4c2bc4d..70265c61a 100644 --- a/src/app/components/shared-files/shared-files.component.ts +++ b/src/app/components/shared-files/shared-files.component.ts @@ -24,7 +24,7 @@ */ import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core'; -import { Router, ActivatedRoute } from '@angular/router'; +import { Router } from '@angular/router'; import { Subscription } from 'rxjs/Rx'; import { MinimalNodeEntity } from 'alfresco-js-api'; import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core'; @@ -45,7 +45,6 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes constructor( private router: Router, - private route: ActivatedRoute, private content: ContentManagementService, private apiService: AlfrescoApiService, preferences: UserPreferencesService) { @@ -69,7 +68,7 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes this.apiService.nodesApi.getNode(link.nodeId).then( (node: MinimalNodeEntity) => { if (node && node.entry && node.entry.isFile) { - this.router.navigate(['./preview', node.entry.id], { relativeTo: this.route }); + this.router.navigate(['/preview', node.entry.id]); } } );