Mathijs den Burger pushed to branch master at cms-community / 
hippo-addon-channel-manager


Commits:
8104b865 by Mathijs den Burger at 2016-10-12T14:48:13+02:00
CHANNELMGR-936 Don't reload page while loading an explicit one

A view-in-channel operation twiggers both a loadChannel call (to
load a specific page in a specific channel) and a reloadPage call
right after it (because the Channel Manager becomes active again).
Since the loadChannel call already reloads the page, the reloadPage
call is superfluous and logs a warning.

To prevent the warning, the selected channel is cleared until the
new channel has been set so the reloadPage call won't do anything.

- - - - -
9c32a81b by Mathijs den Burger at 2016-10-12T14:55:32+02:00
CHANNELMGR-936 Always load a page by settings the 'src' attribute

The code used to keep track of the loaded path in the iframe. When
the render path to load was equal to the already loaded path the
iframe's location was reloaded.

This does not work when the 'src' attribute of the iframe differs
from the URL of loaded page (e.g. when the user navigated inside the
iframe). In that case a reload of the iframe's location would
actually load the original location in the 'src' attribute.

To fix this, we always update the 'src' attribute when explicitly
loading a new page.

Also ensured 100% line coverage of the hippo iframe service.

- - - - -
8404e4e7 by Mathijs den Burger at 2016-10-12T15:42:42+02:00
CHANNELMGR-936 Reintegrate bugfix/CHANNELMGR-936

- - - - -


3 changed files:

- frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.js
- frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.spec.js
- 
frontend/src/main/resources/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.js


Changes:

=====================================
frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.js
=====================================
--- a/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.js
+++ b/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.js
@@ -38,22 +38,18 @@ export class HippoIframeService {
 
   load(renderPathInfo) {
     const targetPath = this.ChannelService.makePath(renderPathInfo);
-    if (targetPath !== this.loadedPath) {
-      this.pageLoaded = false;
-
-      if (targetPath !== this.src) {
-        // setting the src attribute of the iframe makes us go to the desired 
page.
-        this.src = targetPath;
-      } else if (this.iframeJQueryElement /* pro-forma check */) {
-        // we may have set the src attribute of the iframe to the targetPath 
before,
-        // but then navigated away from that location by following 
site-internal links.
-        // In order to get back to the location that already matches the 
iframe's src attribute
-        // value, we use jQuery's attr() method, which triggers a load of the 
specified src.
-        this.iframeJQueryElement.attr('src', this.src);
-      }
-    } else {
-      // we're already on the right page
-      this.reload();
+
+    this.pageLoaded = false;
+
+    if (targetPath !== this.src) {
+      // setting the src attribute of the iframe makes us go to the desired 
page.
+      this.src = targetPath;
+    } else if (this.iframeJQueryElement /* pro-forma check */) {
+      // we may have set the src attribute of the iframe to the targetPath 
before,
+      // but then navigated away from that location by following site-internal 
links.
+      // In order to get back to the location that already matches the 
iframe's src attribute
+      // value, we use jQuery's attr() method, which triggers a load of the 
specified src.
+      this.iframeJQueryElement.attr('src', this.src);
     }
   }
 
@@ -82,7 +78,7 @@ export class HippoIframeService {
 
   // called by the hippoIframe controller when the processing of the loaded 
page is completed.
   signalPageLoadCompleted() {
-    this._determineLoadedPathAndRenderPathInfo();
+    this.renderPathInfo = this._determineRenderPathInfo();
     this.pageLoaded = true;
 
     const deferred = this.deferredReload;
@@ -93,14 +89,13 @@ export class HippoIframeService {
     }
   }
 
-  _determineLoadedPathAndRenderPathInfo() {
+  _determineRenderPathInfo() {
     try {
-      this.loadedPath = 
this.iframeJQueryElement[0].contentWindow.location.pathname;
-      this.renderPathInfo = 
this.ChannelService.extractRenderPathInfo(this.loadedPath);
+      const loadedPath = 
this.iframeJQueryElement[0].contentWindow.location.pathname;
+      return this.ChannelService.extractRenderPathInfo(loadedPath);
     } catch (ignoredError) {
-      // if pathname is not found, reset loadedPath and renderPathInfo
-      this.loadedPath = undefined;
-      this.renderPathInfo = undefined;
+      // if pathname is not found, reset renderPathInfo
+      return undefined;
     }
   }
 }


=====================================
frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.spec.js
=====================================
--- a/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.spec.js
+++ b/frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.spec.js
@@ -54,6 +54,14 @@ describe('HippoIframeService', () => {
     iframe.attr('src', iframeSrc);
   }
 
+  it('knows when a page has been loaded', () => {
+    expect(HippoIframeService.isPageLoaded()).toBe(false);
+    HippoIframeService.load('dummy');
+    expect(HippoIframeService.isPageLoaded()).toBe(false);
+    HippoIframeService.signalPageLoadCompleted();
+    expect(HippoIframeService.isPageLoaded()).toBe(true);
+  });
+
   it('does not reload the iframe when no page has been loaded yet', (done) => {
     HippoIframeService.initialize(undefined); // undo initialization
 
@@ -135,16 +143,10 @@ describe('HippoIframeService', () => {
     expect(HippoIframeService.getCurrentRenderPathInfo()).toBe('dummy');
   });
 
-  it('triggers a reload when trying to load the current page', (done) => {
-    ChannelService.extractRenderPathInfo.and.returnValue('/target');
-    ChannelService.makePath.and.returnValue(iframeSrc);
-    spyOn(HippoIframeService, 'reload');
-    loadIframeFixture(() => { // give the iframe something to reload.
-      HippoIframeService.signalPageLoadCompleted();
-      HippoIframeService.load('dummy');
-      expect(HippoIframeService.reload).toHaveBeenCalled();
-      done();
-    });
+  it('resets the current renderPathInfo when the iframe path cannot be found', 
() => {
+    HippoIframeService.initialize(undefined); // undo initialization
+    HippoIframeService.signalPageLoadCompleted();
+    expect(HippoIframeService.getCurrentRenderPathInfo()).not.toBeDefined();
   });
 
   it('uses jQuery to trigger a reload if the src attribute matches the 
to-be-loaded path', () => {


=====================================
frontend/src/main/resources/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.js
=====================================
--- 
a/frontend/src/main/resources/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.js
+++ 
b/frontend/src/main/resources/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.js
@@ -59,12 +59,17 @@
     },
 
     loadChannel: function(channelId, initialPath) {
-      this.hostToIFrame.publish('clear-channel');
+      this._clearChannel();
       this._setChannel(channelId).when(function(channelRecord) {
         this.hostToIFrame.publish('load-channel', channelRecord.json, 
initialPath);
       }.bind(this));
     },
 
+    _clearChannel: function() {
+      this.selectedChannel = null;
+      this.hostToIFrame.publish('clear-channel');
+    },
+
     _reloadChannels: function() {
       return new Hippo.Future(function(success) {
         this.channelStoreFuture.when(function (config) {



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/38886519704013e843174a959cca89c705e0713d...8404e4e7ddc8163bb816a1bd8018e4e66c3dc135
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to