[ACA-1426] Search - back from preview breaks view (#376)

* build url from string

* fix tests
This commit is contained in:
Cilibiu Bogdan 2018-06-01 13:48:56 +03:00 committed by Denys Vuika
parent f2cc8e260b
commit f21ddee491
2 changed files with 21 additions and 5 deletions

View File

@ -205,7 +205,7 @@ describe('PreviewComponent', () => {
component.onVisibilityChanged(false);
expect(router.navigate).toHaveBeenCalledWith(
['libraries']
['libraries', {}]
);
});
@ -219,7 +219,7 @@ describe('PreviewComponent', () => {
component.onVisibilityChanged(false);
expect(router.navigate).toHaveBeenCalledWith(
['libraries', 'site1']
['libraries', {}, 'site1']
);
});
@ -233,7 +233,7 @@ describe('PreviewComponent', () => {
component.onVisibilityChanged(false);
expect(router.navigate).toHaveBeenCalledWith(
['shared']
['shared', {}]
);
});

View File

@ -24,7 +24,7 @@
*/
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRoute, Router, UrlTree, UrlSegmentGroup, UrlSegment, PRIMARY_OUTLET } from '@angular/router';
import { AlfrescoApiService, UserPreferencesService, ObjectUtils } from '@alfresco/adf-core';
import { Node, MinimalNodeEntity } from 'alfresco-js-api';
import { NodePermissionService } from '../../common/services/node-permission.service';
@ -124,7 +124,7 @@ export class PreviewComponent implements OnInit {
const shouldSkipNavigation = this.routesSkipNavigation.includes(this.previewLocation);
if (!isVisible) {
const route = [this.previewLocation];
const route = this.getNavigationCommands(this.previewLocation);
if ( !shouldSkipNavigation && this.folderId ) {
route.push(this.folderId);
@ -333,4 +333,20 @@ export class PreviewComponent implements OnInit {
} catch {
}
}
private getNavigationCommands(url: string): any[] {
const urlTree: UrlTree = this.router.parseUrl(url);
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
if (!urlSegmentGroup) {
return [url];
}
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
return urlSegments.reduce(function(acc, item) {
acc.push(item.path, item.parameters);
return acc;
}, []);
}
}