Merge lp:~gary/juju-gui/bug1203583 into lp:juju-gui/experimental

Proposed by Gary Poster
Status: Merged
Merged at revision: 1115
Proposed branch: lp:~gary/juju-gui/bug1203583
Merge into: lp:juju-gui/experimental
Diff against target: 155 lines (+98/-2)
5 files modified
app/models/charm.js (+40/-1)
app/subapps/browser/views/bundle.js (+4/-1)
app/subapps/browser/views/charm.js (+7/-0)
test/test_browser_charm_details.js (+21/-0)
test/test_model.js (+26/-0)
To merge this branch: bzr merge lp:~gary/juju-gui/bug1203583
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+189970@code.launchpad.net

Description of the change

Make the charm source tab work better

This was a quick hack I did that I wanted to land rather than throw away. Quick hacks are a lot less quick once you throw in tests. :-/

https://codereview.appspot.com/14565044/

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

Reviewers: mp+189970_code.launchpad.net,

Message:
Please take a look.

Description:
Make the charm source tab work better

This was a quick hack I did that I wanted to land rather than throw
away. Quick hacks are a lot less quick once you throw in tests. :-/

https://code.launchpad.net/~gary/juju-gui/bug1203583/+merge/189970

(do not edit description out of merge proposal)

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

Affected files (+100, -2 lines):
   A [revision details]
   M app/models/charm.js
   M app/subapps/browser/views/bundle.js
   M app/subapps/browser/views/charm.js
   M test/test_browser_charm_details.js
   M test/test_model.js

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

https://codereview.appspot.com/14565044/diff/1/app/subapps/browser/views/bundle.js
File app/subapps/browser/views/bundle.js (right):

https://codereview.appspot.com/14565044/diff/1/app/subapps/browser/views/bundle.js#newcode169
app/subapps/browser/views/bundle.js:169: 'subapp-browser-entitybaseview'
I discovered that the file needed these in order for some test files to
be run individually.

https://codereview.appspot.com/14565044/

Revision history for this message
Jeff Pihach (hatch) wrote :

LGTM QA OK with trivial

https://codereview.appspot.com/14565044/diff/1/app/models/charm.js
File app/models/charm.js (right):

https://codereview.appspot.com/14565044/diff/1/app/models/charm.js#newcode466
app/models/charm.js:466: setter: function(value) {
you can quote this instead of commenting it if you like.

https://codereview.appspot.com/14565044/diff/1/app/models/charm.js#newcode468
app/models/charm.js:468: value.sort(function(a, b) {
This all looks great but I'm curious what this sort method gets you over
the standard lexicographic sort. You may also want to add this comment
to the code so others know when looking at this.

https://codereview.appspot.com/14565044/

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

*** Submitted:

Make the charm source tab work better

This was a quick hack I did that I wanted to land rather than throw
away. Quick hacks are a lot less quick once you throw in tests. :-/

R=jeff.pihach
CC=
https://codereview.appspot.com/14565044

https://codereview.appspot.com/14565044/

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

On 2013/10/08 21:03:10, jeff.pihach wrote:
> LGTM QA OK with trivial

> https://codereview.appspot.com/14565044/diff/1/app/models/charm.js
> File app/models/charm.js (right):

https://codereview.appspot.com/14565044/diff/1/app/models/charm.js#newcode466
> app/models/charm.js:466: setter: function(value) {
> you can quote this instead of commenting it if you like.

https://codereview.appspot.com/14565044/diff/1/app/models/charm.js#newcode468
> app/models/charm.js:468: value.sort(function(a, b) {
> This all looks great but I'm curious what this sort method gets you
over the
> standard lexicographic sort. You may also want to add this comment to
the code
> so others know when looking at this.

Thank you for the review and comments, Jeff. I added the following
explanation to the code.

             // This sort has several properties that are different than
a
             // standard lexicographic sort.
             // * Filenames in the root are grouped together, rather than
             // sorted along with the names of directories.
             // * Sort ignores case, unless case is the only way to
             // distinguish between values, in which case it is honored
             // per-directory. For example, this is sorted: "a", "b/c",
             // "b/d", "B/b", "B/c", "e/f". Notice that "b" directory
values
             // and "B" directory values are grouped together, where
they
             // would not necessarily be in a simpler case-insensitive
             // lexicographic sort.
             // If you rip this out for something different and simpler,
that's
             // fine; just don't tell me about it. :-) This seemed like
a good
             // approach at the time.

https://codereview.appspot.com/14565044/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/models/charm.js'
2--- app/models/charm.js 2013-09-24 18:56:05 +0000
3+++ app/models/charm.js 2013-10-08 20:50:46 +0000
4@@ -457,7 +457,46 @@
5 }
6 },
7 files: {
8- value: []
9+ value: [],
10+ /**
11+ * Sort files when they are set.
12+ *
13+ * @method files.setter
14+ */
15+ setter: function(value) {
16+ if (Y.Lang.isArray(value)) {
17+ value.sort(function(a, b) {
18+ var segments = [a, b].map(function(path) {
19+ var segs = path.split('/');
20+ if (segs.length === 1) {
21+ segs.unshift('');
22+ }
23+ return segs;
24+ });
25+ var maxLength = Math.max(segments[0].length, segments[1].length);
26+ for (var i = 0; i < maxLength; i += 1) {
27+ var segmentA = segments[0][i];
28+ var segmentB = segments[1][i];
29+ if (segmentA === undefined) {
30+ return -1;
31+ } else if (segmentB === undefined) {
32+ return 1;
33+ } else {
34+ var result = (
35+ // Prefer case-insensitive sort, but honor case when
36+ // string match in a case-insensitive comparison.
37+ segmentA.localeCompare(
38+ segmentB, undefined, {sensitivity: 'accent'}) ||
39+ segmentA.localeCompare(segmentB));
40+ if (result) {
41+ return result;
42+ }
43+ }
44+ }
45+ return 0;
46+ });
47+ }
48+ }
49 },
50 full_name: {
51 /**
52
53=== modified file 'app/subapps/browser/views/bundle.js'
54--- app/subapps/browser/views/bundle.js 2013-10-07 20:45:48 +0000
55+++ app/subapps/browser/views/bundle.js 2013-10-08 20:50:46 +0000
56@@ -161,8 +161,11 @@
57
58 }, '', {
59 requires: [
60+ 'browser-overlay-indicator',
61+ 'juju-view-utils',
62 'view',
63 'juju-env-fakebackend',
64- 'juju-view-bundle'
65+ 'juju-view-bundle',
66+ 'subapp-browser-entitybaseview'
67 ]
68 });
69
70=== modified file 'app/subapps/browser/views/charm.js'
71--- app/subapps/browser/views/charm.js 2013-10-02 17:37:08 +0000
72+++ app/subapps/browser/views/charm.js 2013-10-08 20:50:46 +0000
73@@ -331,6 +331,13 @@
74 tplData.isFullscreen = isFullscreen;
75 tplData.isLocal = tplData.scheme === 'local';
76 tplData.forInspector = this.get('forInspector');
77+ if (tplData.files) {
78+ // Exclude svg files from the source view.
79+ var regex = /\.svg$/;
80+ tplData.files = tplData.files.filter(function(name) {
81+ return !regex.test(name);
82+ });
83+ }
84 if (!tplData.forInspector) {
85 tplData.sourceLink = this._getSourceLink();
86 tplData.prettyCommits = this._formatCommitsForHtml(
87
88=== modified file 'test/test_browser_charm_details.js'
89--- test/test_browser_charm_details.js 2013-10-02 16:26:20 +0000
90+++ test/test_browser_charm_details.js 2013-10-08 20:50:46 +0000
91@@ -211,6 +211,27 @@
92 view._getRevnoLink(url, 1));
93 });
94
95+ it('excludes source svg files from the source tab', function() {
96+ view = new CharmView({
97+ entity: new models.Charm({
98+ files: [
99+ 'hooks/install',
100+ 'icon.svg',
101+ 'readme.rst'
102+ ],
103+ id: 'precise/ceph-9',
104+ code_source: { location: 'lp:~foo'}
105+ }),
106+ container: utils.makeContainer()
107+ });
108+ view.render();
109+ var options = Y.one('#bws-code').all('select option');
110+ assert.equal(options.size(), 3);
111+ assert.deepEqual(
112+ options.get('text'),
113+ ['Select --', 'readme.rst', 'hooks/install']);
114+ });
115+
116 it('can generate useful display data for commits', function() {
117 view = new CharmView({
118 entity: new models.Charm({
119
120=== modified file 'test/test_model.js'
121--- test/test_model.js 2013-09-27 16:26:18 +0000
122+++ test/test_model.js 2013-10-08 20:50:46 +0000
123@@ -667,6 +667,32 @@
124 assert.isFalse(unapproved_without_icon.get('shouldShowIcon'));
125 });
126
127+ it('sorts files', function() {
128+ // Because we rely on localeCompare, and this has different
129+ // implementations and capabilities across browsers, we don't include
130+ // any capital letters in this test. They sort reliably within a given
131+ // browser, but not across browsers.
132+ instance = new models.Charm({
133+ id: 'cs:precise/mysql-2',
134+ files: [
135+ 'alpha/beta/gamma',
136+ 'alpha/beta',
137+ 'alpha/aardvark',
138+ 'zebra',
139+ 'yam'
140+ ]
141+ });
142+ assert.deepEqual(
143+ instance.get('files'),
144+ [
145+ 'yam',
146+ 'zebra',
147+ 'alpha/aardvark',
148+ 'alpha/beta',
149+ 'alpha/beta/gamma'
150+ ]);
151+ });
152+
153 it('tracks recent commits in the last 30 days', function() {
154 instance = new models.Charm(data.charm);
155 var commits = instance.get('recent_commits'),

Subscribers

People subscribed via source and target branches