Merge lp:~makyo/juju-gui/center into lp:juju-gui/experimental

Proposed by Madison Scott-Clary
Status: Merged
Merged at revision: 1143
Proposed branch: lp:~makyo/juju-gui/center
Merge into: lp:juju-gui/experimental
Diff against target: 105 lines (+28/-28)
2 files modified
app/views/topology/service.js (+20/-12)
test/test_environment_view.js (+8/-16)
To merge this branch: bzr merge lp:~makyo/juju-gui/center
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+191681@code.launchpad.net

Description of the change

Fix initial centering of canvas in real env.

In a real environment with positioned services, this centers the services within the viewport, an artifact that was lost in a recent refactor. Also tests that the panToPoint event was fired when a positioned service is added (future designs will complicate this, as the inspector will have an arrow pointing to a service, if it's open; this will be prevented in app/views/topology/service.js:panToCenter() once that's implemented). Other tests in place already test finding and setting the centroid.

https://codereview.appspot.com/14771044/

To post a comment you must log in.
Revision history for this message
Madison Scott-Clary (makyo) wrote :
Download full text (4.8 KiB)

Reviewers: mp+191681_code.launchpad.net,

Message:
Please take a look.

Description:
Fix initial centering of canvas in real env.

In a real environment with positioned services, this centers the
services within the viewport, an artifact that was lost in a recent
refactor. Also tests that the panToPoint event was fired when a
positioned service is added (future designs will complicate this, as the
inspector will have an arrow pointing to a service, if it's open; this
will be prevented in app/views/topology/service.js:panToCenter() once
that's implemented). Other tests in place already test finding and
setting the centroid.

https://code.launchpad.net/~makyo/juju-gui/center/+merge/191681

(do not edit description out of merge proposal)

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

Affected files (+30, -28 lines):
   A [revision details]
   M app/views/topology/service.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_environment_view.js
=== modified file 'test/test_environment_view.js'
--- test/test_environment_view.js 2013-10-15 22:24:17 +0000
+++ test/test_environment_view.js 2013-10-17 16:54:10 +0000
@@ -586,7 +586,7 @@
            view.topo.service_boxes.wordpressb.center);
      });

- it('must be able to use position annotations', function() {
+ it('must be able to use position annotations', function(done) {
        var tmp_data = {
          op: 'delta',
          result: [
@@ -621,7 +621,13 @@
        match[1].should.eql('374.1');
        match[2].should.eql('211.2');

- // A positioned service will never be auto-positioned.
+ // A positioned service will never be auto-positioned. It will also
+ // center the canvas on itself.
+ view.topo.on('panToPoint', function() {
+ // Once we reach here, the view has been updated and the canvas
panned
+ // to the newly added/annotated service.
+ done();
+ });
        tmp_data = {
          op: 'delta',
          result: [
@@ -636,20 +642,6 @@
        };
        db.onDelta({ data: tmp_data });
        view.update();
-
- tmp_data = {
- op: 'delta',
- result: [
- ['service', 'add',
- {
- 'subordinate': false,
- 'charm': 'cs:precise/wordpress-6',
- 'id': 'wordpressb'
- }
- ]]
- };
- db.onDelta({ data: tmp_data });
- view.update();
      });

      it('must be able to use Landscape annotations', function() {

Index: app/views/topology/service.js
=== modified file 'app/views/topology/service.js'
--- app/views/topology/service.js 2013-10-15 19:39:05 +0000
+++ app/views/topology/service.js 2013-10-17 17:01:32 +0000
@@ -714,7 +714,7 @@
                    level: 'important'
                  });
                } else {
- console.log('import failed', file, result);
+ ...

Read more...

Revision history for this message
Madison Scott-Clary (makyo) wrote :

*** Submitted:

Fix initial centering of canvas in real env.

In a real environment with positioned services, this centers the
services within the viewport, an artifact that was lost in a recent
refactor. Also tests that the panToPoint event was fired when a
positioned service is added (future designs will complicate this, as the
inspector will have an arrow pointing to a service, if it's open; this
will be prevented in app/views/topology/service.js:panToCenter() once
that's implemented). Other tests in place already test finding and
setting the centroid.

R=
CC=
https://codereview.appspot.com/14771044

https://codereview.appspot.com/14771044/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/views/topology/service.js'
2--- app/views/topology/service.js 2013-10-15 19:39:05 +0000
3+++ app/views/topology/service.js 2013-10-17 17:08:07 +0000
4@@ -714,7 +714,7 @@
5 level: 'important'
6 });
7 } else {
8- console.log('import failed', file, result);
9+ console.warn('import failed', file, result);
10 notifications.add({
11 title: 'Import Environment Failed',
12 message: 'Import from "' + file.name +
13@@ -1000,12 +1000,20 @@
14 // and drop, or those who don't have position attributes/annotations.
15 var vertices = [];
16 Y.each(topo.service_boxes, function(boundingBox) {
17- var annotations = boundingBox.annotations;
18- if (annotations['gui-x'] && boundingBox.x === undefined) {
19- boundingBox.x = annotations['gui-x'];
20- }
21- if (annotations['gui-y'] && boundingBox.y === undefined) {
22- boundingBox.y = annotations['gui-y'];
23+ if (!boundingBox.model.get('pending')) {
24+ var annotations = boundingBox.annotations,
25+ addToVertices = 0;
26+ if (annotations['gui-x'] && boundingBox.x === undefined) {
27+ boundingBox.x = annotations['gui-x'];
28+ addToVertices += 1;
29+ }
30+ if (annotations['gui-y'] && boundingBox.y === undefined) {
31+ boundingBox.y = annotations['gui-y'];
32+ addToVertices += 1;
33+ }
34+ if (addToVertices === 2) {
35+ vertices.push([boundingBox.x, boundingBox.y]);
36+ }
37 }
38 });
39
40@@ -1073,11 +1081,11 @@
41 }
42 });
43 }
44- // Find the centroid of our hull of services and inform the
45- // topology.
46- if (vertices.length) {
47- this.findCentroid(vertices);
48- }
49+ }
50+ // Find the centroid of our hull of services and inform the
51+ // topology.
52+ if (vertices.length) {
53+ this.findCentroid(vertices);
54 }
55
56 // enter
57
58=== modified file 'test/test_environment_view.js'
59--- test/test_environment_view.js 2013-10-15 22:24:17 +0000
60+++ test/test_environment_view.js 2013-10-17 17:08:07 +0000
61@@ -586,7 +586,7 @@
62 view.topo.service_boxes.wordpressb.center);
63 });
64
65- it('must be able to use position annotations', function() {
66+ it('must be able to use position annotations', function(done) {
67 var tmp_data = {
68 op: 'delta',
69 result: [
70@@ -621,7 +621,13 @@
71 match[1].should.eql('374.1');
72 match[2].should.eql('211.2');
73
74- // A positioned service will never be auto-positioned.
75+ // A positioned service will never be auto-positioned. It will also
76+ // center the canvas on itself.
77+ view.topo.on('panToPoint', function() {
78+ // Once we reach here, the view has been updated and the canvas panned
79+ // to the newly added/annotated service.
80+ done();
81+ });
82 tmp_data = {
83 op: 'delta',
84 result: [
85@@ -636,20 +642,6 @@
86 };
87 db.onDelta({ data: tmp_data });
88 view.update();
89-
90- tmp_data = {
91- op: 'delta',
92- result: [
93- ['service', 'add',
94- {
95- 'subordinate': false,
96- 'charm': 'cs:precise/wordpress-6',
97- 'id': 'wordpressb'
98- }
99- ]]
100- };
101- db.onDelta({ data: tmp_data });
102- view.update();
103 });
104
105 it('must be able to use Landscape annotations', function() {

Subscribers

People subscribed via source and target branches