Arthur Bogaart pushed to branch feature/cmng-psp1 at cms-community / hippo-addon-channel-manager
Commits: d4c7fd32 by Arthur Bogaart at 2016-03-08T12:50:45+01:00 CHANNELMGR-437 Add function to get the preview path of a channel - - - - - 3 changed files: - frontend-ng/src/angularjs/api/channel.service.js - frontend-ng/src/angularjs/api/channel.service.spec.js - frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js Changes: ===================================== frontend-ng/src/angularjs/api/channel.service.js ===================================== --- a/frontend-ng/src/angularjs/api/channel.service.js +++ b/frontend-ng/src/angularjs/api/channel.service.js @@ -47,15 +47,20 @@ export class ChannelService { }); } - getUrl(path) { - let url = this.channel.contextPath; - if (url === '/') { - url = ''; + getPreviewPath() { + let path = this.channel.contextPath; + if (path === '/') { + path = ''; } if (this.channel.cmsPreviewPrefix) { - url += '/' + this.channel.cmsPreviewPrefix; + path += '/' + this.channel.cmsPreviewPrefix; } + return path; + } + + getUrl(path) { + let url = this.getPreviewPath(); if (this.channel.mountPath) { url += this.channel.mountPath; ===================================== frontend-ng/src/angularjs/api/channel.service.spec.js ===================================== --- a/frontend-ng/src/angularjs/api/channel.service.spec.js +++ b/frontend-ng/src/angularjs/api/channel.service.spec.js @@ -88,34 +88,44 @@ describe('ChannelService', function () { expect(promiseSpy).toHaveBeenCalledWith(channelMock); }); - it('should return a url that starts with the contextPath', function () { - ChannelService.load({ contextPath: '/test' }); + it('should ignore the contextPath if it is /', function () { + ChannelService.load({ contextPath: '/' }); $rootScope.$digest(); - expect(ChannelService.getUrl('/optional/path')).toEqual('/test/optional/path'); - }); + expect(ChannelService.getPreviewPath()).toEqual(''); + expect(ChannelService.getUrl()).toEqual(''); - it('should return a url that ends with a slash if it equals the contextPath', function () { - ChannelService.load({ contextPath: '/test' }); + ChannelService.load({ contextPath: '/', cmsPreviewPrefix: 'cmsPreviewPrefix' }); $rootScope.$digest(); - expect(ChannelService.getUrl()).toEqual('/test/'); + expect(ChannelService.getPreviewPath()).toEqual('/cmsPreviewPrefix'); + expect(ChannelService.getUrl()).toEqual('/cmsPreviewPrefix'); }); - it('should return a url without the contextPath if it is root', function () { - ChannelService.load({ contextPath: '/' }); + it('should return a preview path that starts with the contextPath', function () { + ChannelService.load({ contextPath: '/contextPath' }); $rootScope.$digest(); - expect(ChannelService.getUrl()).toEqual(''); + expect(ChannelService.getPreviewPath()).toEqual('/contextPath'); + + ChannelService.load({ contextPath: '/contextPath', cmsPreviewPrefix: 'cmsPreviewPrefix' }); + $rootScope.$digest(); + expect(ChannelService.getPreviewPath()).toEqual('/contextPath/cmsPreviewPrefix'); }); - it('should return a url with the cmsPreviewPrefix appended after the contextPath with a slash', function () { - ChannelService.load({ contextPath: '/test', cmsPreviewPrefix: 'cmsPreviewPrefix' }); + it('should return a url that ends with a slash if it equals the contextPath', function () { + ChannelService.load({ contextPath: '/contextPath' }); $rootScope.$digest(); - expect(ChannelService.getUrl()).toEqual('/test/cmsPreviewPrefix'); + expect(ChannelService.getUrl()).toEqual('/contextPath/'); }); it('should return a url with the mountPath appended after the cmsPreviewPrefix', function () { - ChannelService.load({ contextPath: '/test', cmsPreviewPrefix: 'cmsPreviewPrefix', mountPath: '/mountPath' }); + ChannelService.load({ contextPath: '/contextPath', cmsPreviewPrefix: 'cmsPreviewPrefix', mountPath: '/mountPath' }); + $rootScope.$digest(); + expect(ChannelService.getUrl()).toEqual('/contextPath/cmsPreviewPrefix/mountPath'); + }); + + it('should append argument path to the url', function () { + ChannelService.load({ contextPath: '/contextPath', cmsPreviewPrefix: 'cmsPreviewPrefix', mountPath: '/mountPath' }); $rootScope.$digest(); - expect(ChannelService.getUrl()).toEqual('/test/cmsPreviewPrefix/mountPath'); + expect(ChannelService.getUrl('/optional/path')).toEqual('/contextPath/cmsPreviewPrefix/mountPath/optional/path'); }); it('should return the mountId of the current channel', function () { ===================================== frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js ===================================== --- a/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js +++ b/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.controller.js @@ -80,9 +80,9 @@ export class HippoIframeCtrl { _parseLinks() { const iframeDom = this.iframeJQueryElement.contents()[0]; - const internalLinkPrefix = `${iframeDom.location.protocol}//${iframeDom.location.host}${this.ChannelService.getUrl()}`; - - this.linkProcessorService.run(iframeDom, internalLinkPrefix); + const schemeAndHost = `${iframeDom.location.protocol}//${iframeDom.location.host}`; + const previewUrl = `${schemeAndHost}${this.ChannelService.getPreviewPath()}`; + this.linkProcessorService.run(iframeDom, previewUrl); } getContainers() { View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/d4c7fd32cde5ad97c8005b2863bc6715fc8cc70c
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn