Merge lp:~frankban/juju-gui/bug-1090046-resize into lp:juju-gui/experimental

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 282
Proposed branch: lp:~frankban/juju-gui/bug-1090046-resize
Merge into: lp:juju-gui/experimental
Diff against target: 84 lines (+41/-4)
3 files modified
app/assets/javascripts/d3-components.js (+6/-3)
test/test_d3_components.js (+18/-0)
test/test_environment_view.js (+17/-1)
To merge this branch: bzr merge lp:~frankban/juju-gui/bug-1090046-resize
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+139959@code.launchpad.net

Description of the change

Fix GUI breakage on browser resizing.

Fixed how yui events are handled by the component framework.
Also added two tests:
- ensure that the module synthetic events binding works;
- ensure that the custom events 'beforePageSizeRecalculation'
  and 'afterPageSizeRecalculation' are correctly fired by
  the environment view when the browser is resized.

QA: resize the browser, open the charm panel, resize the
    browser again, close the charm panel, resize again,
    re-open the panel...

https://codereview.appspot.com/6941053/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :
Download full text (4.6 KiB)

Reviewers: mp+139959_code.launchpad.net,

Message:
Please take a look.

Description:
Fix GUI breakage on browser resizing.

Fixed how yui events are handled by the component framework.
Also added two tests:
- ensure that the module synthetic events binding works;
- ensure that the custom events 'beforePageSizeRecalculation'
   and 'afterPageSizeRecalculation' are correctly fired by
   the environment view when the browser is resized.

QA: resize the browser, open the charm panel, resize the
     browser again, close the charm panel, resize again,
     re-open the panel...

https://code.launchpad.net/~frankban/juju-gui/bug-1090046-resize/+merge/139959

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/6941053/

Affected files:
   A [revision details]
   M app/assets/javascripts/d3-components.js
   M test/test_d3_components.js
   M test/test_environment_view.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision:
<email address hidden>

Index: test/test_d3_components.js
=== modified file 'test/test_d3_components.js'
--- test/test_d3_components.js 2012-11-09 14:17:58 +0000
+++ test/test_d3_components.js 2012-12-14 15:25:55 +0000
@@ -129,6 +129,24 @@

       });

+ it('should correctly handle synthetic event bindings', function(done) {
+ comp = new NS.Component();
+ comp.setAttrs({container: container});
+ modA = new TestModule();
+ var resized = false;
+ modA.windowResizeHandler = function(evt) {
+ resized = true;
+ };
+ modA.events.yui.windowresize = 'windowResizeHandler';
+ comp.addModule(modA);
+ var subscription = Y.after('windowresize', function(evt) {
+ subscription.detach();
+ assert.isTrue(resized);
+ done();
+ });
+ Y.one('window').simulate('resize');
+ });
+
    it('should support basic rendering from all modules',
       function() {
         var modA = new TestModule(),

Index: test/test_environment_view.js
=== modified file 'test/test_environment_view.js'
--- test/test_environment_view.js 2012-12-05 18:37:01 +0000
+++ test/test_environment_view.js 2012-12-14 15:25:55 +0000
@@ -103,7 +103,7 @@
      });

      beforeEach(function(done) {
- container = Y.Node.create('<div id="test-container" />');
+ container = Y.Node.create('<div
/>').setStyle('visibility', 'hidden');
        Y.one('body').prepend(container);
        db = new models.Database();
        db.on_delta({data: environment_delta});
@@ -118,6 +118,22 @@
        done();
      });

+ it('must handle the window resize event', function(done) {
+ var view = new views.environment({container: container, db: db});
+ view.render();
+ var beforeResizeEventFired = false;
+ Y.once('beforePageSizeRecalculation', function() {
+ // This event must be fired by
views.MegaModule.setSizesFromViewport.
+ beforeResizeEventFired = true;
+ });
+ Y.once('afterPageSizeRecalculati...

Read more...

Revision history for this message
Benjamin Saller (bcsaller) wrote :

Thanks,

This is a nice catch, a good fix and glad to see the additional tests.

+1 LGTM

https://codereview.appspot.com/6941053/diff/1/app/assets/javascripts/d3-components.js
File app/assets/javascripts/d3-components.js (right):

https://codereview.appspot.com/6941053/diff/1/app/assets/javascripts/d3-components.js#newcode238
app/assets/javascripts/d3-components.js:238: var callback =
Y.bind(handler.callback, handler.context);
This is a nice fix, thank you.

https://codereview.appspot.com/6941053/

Revision history for this message
Gary Poster (gary) wrote :

Land as is.

Thanks, Francesco! Great to have the user-facing fix and the general
event handling fix, and the branch has nice tests.

Gary

https://codereview.appspot.com/6941053/

Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Fix GUI breakage on browser resizing.

Fixed how yui events are handled by the component framework.
Also added two tests:
- ensure that the module synthetic events binding works;
- ensure that the custom events 'beforePageSizeRecalculation'
   and 'afterPageSizeRecalculation' are correctly fired by
   the environment view when the browser is resized.

QA: resize the browser, open the charm panel, resize the
     browser again, close the charm panel, resize again,
     re-open the panel...

R=benjamin.saller, gary.poster
CC=
https://codereview.appspot.com/6941053

https://codereview.appspot.com/6941053/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'app/assets/javascripts/d3-components.js'
--- app/assets/javascripts/d3-components.js 2012-12-11 15:35:25 +0000
+++ app/assets/javascripts/d3-components.js 2012-12-14 16:41:29 +0000
@@ -231,9 +231,12 @@
231 // Bind resolved event handlers as a group.231 // Bind resolved event handlers as a group.
232 if (Y.Object.keys(resolvedHandler).length) {232 if (Y.Object.keys(resolvedHandler).length) {
233 Y.each(resolvedHandler, function(handler, name) {233 Y.each(resolvedHandler, function(handler, name) {
234 subscriptions.push(Y[eventPhase](name,234 // DOM and synthetic events are subscribed using Y.on with
235 handler.callback,235 // this signature: Y.on(event, callback, target, context).
236 handler.context));236 // For this reason, it is not possible here to just pass the
237 // context as third argument.
238 var callback = Y.bind(handler.callback, handler.context);
239 subscriptions.push(Y[eventPhase](name, callback));
237 });240 });
238 }241 }
239 });242 });
240243
=== modified file 'test/test_d3_components.js'
--- test/test_d3_components.js 2012-11-09 14:17:58 +0000
+++ test/test_d3_components.js 2012-12-14 16:41:29 +0000
@@ -129,6 +129,24 @@
129129
130 });130 });
131131
132 it('should correctly handle synthetic event bindings', function(done) {
133 comp = new NS.Component();
134 comp.setAttrs({container: container});
135 modA = new TestModule();
136 var resized = false;
137 modA.windowResizeHandler = function(evt) {
138 resized = true;
139 };
140 modA.events.yui.windowresize = 'windowResizeHandler';
141 comp.addModule(modA);
142 var subscription = Y.after('windowresize', function(evt) {
143 subscription.detach();
144 assert.isTrue(resized);
145 done();
146 });
147 Y.one('window').simulate('resize');
148 });
149
132 it('should support basic rendering from all modules',150 it('should support basic rendering from all modules',
133 function() {151 function() {
134 var modA = new TestModule(),152 var modA = new TestModule(),
135153
=== modified file 'test/test_environment_view.js'
--- test/test_environment_view.js 2012-12-05 18:37:01 +0000
+++ test/test_environment_view.js 2012-12-14 16:41:29 +0000
@@ -103,7 +103,7 @@
103 });103 });
104104
105 beforeEach(function(done) {105 beforeEach(function(done) {
106 container = Y.Node.create('<div id="test-container" />');106 container = Y.Node.create('<div />').setStyle('visibility', 'hidden');
107 Y.one('body').prepend(container);107 Y.one('body').prepend(container);
108 db = new models.Database();108 db = new models.Database();
109 db.on_delta({data: environment_delta});109 db.on_delta({data: environment_delta});
@@ -118,6 +118,22 @@
118 done();118 done();
119 });119 });
120120
121 it('must handle the window resize event', function(done) {
122 var view = new views.environment({container: container, db: db});
123 view.render();
124 var beforeResizeEventFired = false;
125 Y.once('beforePageSizeRecalculation', function() {
126 // This event must be fired by views.MegaModule.setSizesFromViewport.
127 beforeResizeEventFired = true;
128 });
129 Y.once('afterPageSizeRecalculation', function() {
130 // This event must be fired by views.MegaModule.setSizesFromViewport.
131 assert.isTrue(beforeResizeEventFired);
132 done();
133 });
134 Y.one('window').simulate('resize');
135 });
136
121 // Ensure the environment view loads properly137 // Ensure the environment view loads properly
122 it('must be able to render service blocks and relations',138 it('must be able to render service blocks and relations',
123 function() {139 function() {

Subscribers

People subscribed via source and target branches