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


Commits:
980acb57 by Mathijs den Burger at 2016-10-18T14:53:52+02:00
CHANNELMGR-937 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.

(cherry picked from commit 8104b865cf53db1cc67fb5af6eead1242d207256)

- - - - -
c5af88f6 by Mathijs den Burger at 2016-10-18T15:36:51+02:00
CHANNELMGR-937 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.

(cherry picked from commit 9c32a81b9e5a100c1d65abff29687925f2476319)

# Conflicts:
#       frontend-ng/src/angularjs/channel/hippoIframe/hippoIframe.service.js

- - - - -
fcdea407 by Mathijs den Burger at 2016-10-18T15:37:40+02:00
CHANNELMGR-937 Reintegrate bugfix/CHANNELMGR-937

- - - - -


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,8 +78,7 @@ export class HippoIframeService {
 
   // called by the hippoIframe controller when the processing of the loaded 
page is completed.
   signalPageLoadCompleted() {
-    this.loadedPath = 
this.iframeJQueryElement[0].contentWindow.location.pathname;
-    this.renderPathInfo = 
this.ChannelService.extractRenderPathInfo(this.loadedPath);
+    this.renderPathInfo = this._determineRenderPathInfo();
     this.pageLoaded = true;
 
     const deferred = this.deferredReload;
@@ -93,4 +88,14 @@ export class HippoIframeService {
       deferred.resolve();
     }
   }
+
+  _determineRenderPathInfo() {
+    try {
+      const loadedPath = 
this.iframeJQueryElement[0].contentWindow.location.pathname;
+      return this.ChannelService.extractRenderPathInfo(loadedPath);
+    } catch (ignoredError) {
+      // 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
@@ -58,12 +58,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/2b6b1d4207ceadf84bd6e2b64155092eadcd5fea...fcdea4077bb36ad0afb4d3fc1156c4101c878b55
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to