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
=== modified file 'app/models/charm.js'
--- app/models/charm.js 2013-09-24 18:56:05 +0000
+++ app/models/charm.js 2013-10-08 20:50:46 +0000
@@ -457,7 +457,46 @@
457 }457 }
458 },458 },
459 files: {459 files: {
460 value: []460 value: [],
461 /**
462 * Sort files when they are set.
463 *
464 * @method files.setter
465 */
466 setter: function(value) {
467 if (Y.Lang.isArray(value)) {
468 value.sort(function(a, b) {
469 var segments = [a, b].map(function(path) {
470 var segs = path.split('/');
471 if (segs.length === 1) {
472 segs.unshift('');
473 }
474 return segs;
475 });
476 var maxLength = Math.max(segments[0].length, segments[1].length);
477 for (var i = 0; i < maxLength; i += 1) {
478 var segmentA = segments[0][i];
479 var segmentB = segments[1][i];
480 if (segmentA === undefined) {
481 return -1;
482 } else if (segmentB === undefined) {
483 return 1;
484 } else {
485 var result = (
486 // Prefer case-insensitive sort, but honor case when
487 // string match in a case-insensitive comparison.
488 segmentA.localeCompare(
489 segmentB, undefined, {sensitivity: 'accent'}) ||
490 segmentA.localeCompare(segmentB));
491 if (result) {
492 return result;
493 }
494 }
495 }
496 return 0;
497 });
498 }
499 }
461 },500 },
462 full_name: {501 full_name: {
463 /**502 /**
464503
=== modified file 'app/subapps/browser/views/bundle.js'
--- app/subapps/browser/views/bundle.js 2013-10-07 20:45:48 +0000
+++ app/subapps/browser/views/bundle.js 2013-10-08 20:50:46 +0000
@@ -161,8 +161,11 @@
161161
162}, '', {162}, '', {
163 requires: [163 requires: [
164 'browser-overlay-indicator',
165 'juju-view-utils',
164 'view',166 'view',
165 'juju-env-fakebackend',167 'juju-env-fakebackend',
166 'juju-view-bundle'168 'juju-view-bundle',
169 'subapp-browser-entitybaseview'
167 ]170 ]
168});171});
169172
=== modified file 'app/subapps/browser/views/charm.js'
--- app/subapps/browser/views/charm.js 2013-10-02 17:37:08 +0000
+++ app/subapps/browser/views/charm.js 2013-10-08 20:50:46 +0000
@@ -331,6 +331,13 @@
331 tplData.isFullscreen = isFullscreen;331 tplData.isFullscreen = isFullscreen;
332 tplData.isLocal = tplData.scheme === 'local';332 tplData.isLocal = tplData.scheme === 'local';
333 tplData.forInspector = this.get('forInspector');333 tplData.forInspector = this.get('forInspector');
334 if (tplData.files) {
335 // Exclude svg files from the source view.
336 var regex = /\.svg$/;
337 tplData.files = tplData.files.filter(function(name) {
338 return !regex.test(name);
339 });
340 }
334 if (!tplData.forInspector) {341 if (!tplData.forInspector) {
335 tplData.sourceLink = this._getSourceLink();342 tplData.sourceLink = this._getSourceLink();
336 tplData.prettyCommits = this._formatCommitsForHtml(343 tplData.prettyCommits = this._formatCommitsForHtml(
337344
=== modified file 'test/test_browser_charm_details.js'
--- test/test_browser_charm_details.js 2013-10-02 16:26:20 +0000
+++ test/test_browser_charm_details.js 2013-10-08 20:50:46 +0000
@@ -211,6 +211,27 @@
211 view._getRevnoLink(url, 1));211 view._getRevnoLink(url, 1));
212 });212 });
213213
214 it('excludes source svg files from the source tab', function() {
215 view = new CharmView({
216 entity: new models.Charm({
217 files: [
218 'hooks/install',
219 'icon.svg',
220 'readme.rst'
221 ],
222 id: 'precise/ceph-9',
223 code_source: { location: 'lp:~foo'}
224 }),
225 container: utils.makeContainer()
226 });
227 view.render();
228 var options = Y.one('#bws-code').all('select option');
229 assert.equal(options.size(), 3);
230 assert.deepEqual(
231 options.get('text'),
232 ['Select --', 'readme.rst', 'hooks/install']);
233 });
234
214 it('can generate useful display data for commits', function() {235 it('can generate useful display data for commits', function() {
215 view = new CharmView({236 view = new CharmView({
216 entity: new models.Charm({237 entity: new models.Charm({
217238
=== modified file 'test/test_model.js'
--- test/test_model.js 2013-09-27 16:26:18 +0000
+++ test/test_model.js 2013-10-08 20:50:46 +0000
@@ -667,6 +667,32 @@
667 assert.isFalse(unapproved_without_icon.get('shouldShowIcon'));667 assert.isFalse(unapproved_without_icon.get('shouldShowIcon'));
668 });668 });
669669
670 it('sorts files', function() {
671 // Because we rely on localeCompare, and this has different
672 // implementations and capabilities across browsers, we don't include
673 // any capital letters in this test. They sort reliably within a given
674 // browser, but not across browsers.
675 instance = new models.Charm({
676 id: 'cs:precise/mysql-2',
677 files: [
678 'alpha/beta/gamma',
679 'alpha/beta',
680 'alpha/aardvark',
681 'zebra',
682 'yam'
683 ]
684 });
685 assert.deepEqual(
686 instance.get('files'),
687 [
688 'yam',
689 'zebra',
690 'alpha/aardvark',
691 'alpha/beta',
692 'alpha/beta/gamma'
693 ]);
694 });
695
670 it('tracks recent commits in the last 30 days', function() {696 it('tracks recent commits in the last 30 days', function() {
671 instance = new models.Charm(data.charm);697 instance = new models.Charm(data.charm);
672 var commits = instance.get('recent_commits'),698 var commits = instance.get('recent_commits'),

Subscribers

People subscribed via source and target branches