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
1=== modified file 'app/assets/javascripts/d3-components.js'
2--- app/assets/javascripts/d3-components.js 2012-12-11 15:35:25 +0000
3+++ app/assets/javascripts/d3-components.js 2012-12-14 16:41:29 +0000
4@@ -231,9 +231,12 @@
5 // Bind resolved event handlers as a group.
6 if (Y.Object.keys(resolvedHandler).length) {
7 Y.each(resolvedHandler, function(handler, name) {
8- subscriptions.push(Y[eventPhase](name,
9- handler.callback,
10- handler.context));
11+ // DOM and synthetic events are subscribed using Y.on with
12+ // this signature: Y.on(event, callback, target, context).
13+ // For this reason, it is not possible here to just pass the
14+ // context as third argument.
15+ var callback = Y.bind(handler.callback, handler.context);
16+ subscriptions.push(Y[eventPhase](name, callback));
17 });
18 }
19 });
20
21=== modified file 'test/test_d3_components.js'
22--- test/test_d3_components.js 2012-11-09 14:17:58 +0000
23+++ test/test_d3_components.js 2012-12-14 16:41:29 +0000
24@@ -129,6 +129,24 @@
25
26 });
27
28+ it('should correctly handle synthetic event bindings', function(done) {
29+ comp = new NS.Component();
30+ comp.setAttrs({container: container});
31+ modA = new TestModule();
32+ var resized = false;
33+ modA.windowResizeHandler = function(evt) {
34+ resized = true;
35+ };
36+ modA.events.yui.windowresize = 'windowResizeHandler';
37+ comp.addModule(modA);
38+ var subscription = Y.after('windowresize', function(evt) {
39+ subscription.detach();
40+ assert.isTrue(resized);
41+ done();
42+ });
43+ Y.one('window').simulate('resize');
44+ });
45+
46 it('should support basic rendering from all modules',
47 function() {
48 var modA = new TestModule(),
49
50=== modified file 'test/test_environment_view.js'
51--- test/test_environment_view.js 2012-12-05 18:37:01 +0000
52+++ test/test_environment_view.js 2012-12-14 16:41:29 +0000
53@@ -103,7 +103,7 @@
54 });
55
56 beforeEach(function(done) {
57- container = Y.Node.create('<div id="test-container" />');
58+ container = Y.Node.create('<div />').setStyle('visibility', 'hidden');
59 Y.one('body').prepend(container);
60 db = new models.Database();
61 db.on_delta({data: environment_delta});
62@@ -118,6 +118,22 @@
63 done();
64 });
65
66+ it('must handle the window resize event', function(done) {
67+ var view = new views.environment({container: container, db: db});
68+ view.render();
69+ var beforeResizeEventFired = false;
70+ Y.once('beforePageSizeRecalculation', function() {
71+ // This event must be fired by views.MegaModule.setSizesFromViewport.
72+ beforeResizeEventFired = true;
73+ });
74+ Y.once('afterPageSizeRecalculation', function() {
75+ // This event must be fired by views.MegaModule.setSizesFromViewport.
76+ assert.isTrue(beforeResizeEventFired);
77+ done();
78+ });
79+ Y.one('window').simulate('resize');
80+ });
81+
82 // Ensure the environment view loads properly
83 it('must be able to render service blocks and relations',
84 function() {

Subscribers

People subscribed via source and target branches