← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jcsackett/launchpad/sharing-details-bugs-mustache into lp:launchpad

 

j.c.sackett has proposed merging lp:~jcsackett/launchpad/sharing-details-bugs-mustache into lp:launchpad with lp:~jcsackett/launchpad/sharing-details-branches-mustache as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/sharing-details-bugs-mustache/+merge/99619

Summary
=======
This branch adds bugs to the sharing details page.

Preimp
======
None, this is a continuation of the dependent branch, implementation was
already largely sorted.

Implementation
==============
The details widget now has a bug partial template; the branch template has
also been moved to a partial, and a final table body template stitches them
together.

The sharing-details view builds the view data for the mustache template and
loads it into the JSON cache.

A test has been added to check the rendering of the bugs.

Tests
=====
bin/test --vvct sharing_details --layer=YUI

QA
==
Set the feature flag.
Find a project sharing `Some` with a person. Verify that the sharingdetails
page for that person and project shows the bugs and branches appropriately.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/javascript/sharing/tests/test_sharing_details.js
  lib/lp/registry/templates/pillar-sharing-details.pt
  lib/lp/registry/javascript/sharing/tests/test_sharing_details.html
  lib/lp/registry/browser/pillar.py
  lib/lp/registry/browser/tests/test_pillar_sharing.py
  lib/lp/registry/services/sharingservice.py
  lib/lp/services/features/flags.py
  lib/lp/registry/javascript/sharing/sharingdetails.js
  lib/lp/registry/interfaces/sharingservice.py
-- 
https://code.launchpad.net/~jcsackett/launchpad/sharing-details-bugs-mustache/+merge/99619
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/sharing-details-bugs-mustache into lp:launchpad.
=== modified file 'lib/lp/registry/browser/pillar.py'
--- lib/lp/registry/browser/pillar.py	2012-03-26 21:23:40 +0000
+++ lib/lp/registry/browser/pillar.py	2012-03-27 21:15:25 +0000
@@ -379,6 +379,8 @@
 
         cache = IJSONRequestCache(self.request)
         branch_data = self._build_branch_template_data(self.branches)
+        bug_data = self._build_bug_template_data(self.bugs)
+        cache.objects['bugs'] = bug_data
         cache.objects['branches'] = branch_data
 
     def _loadSharedArtifacts(self):
@@ -388,9 +390,9 @@
                             self.pillar, self.person):
             concrete = artifact.concrete_artifact
             if IBug.providedBy(concrete):
-                bugs.append(artifact)
+                bugs.append(concrete)
             elif IBranch.providedBy(concrete):
-                branches.append(artifact)
+                branches.append(concrete)
 
         self.bugs = bugs
         self.branches = branches
@@ -405,3 +407,14 @@
                 branch_name=branch.unique_name,
                 branch_id=branch.id))
         return branch_data
+
+    def _build_bug_template_data(self, bugs):
+        bug_data = []
+        for bug in bugs:
+            importance = bug.default_bugtask.importance.title.lower()
+            bug_data.append(dict(
+                bug_link=canonical_url(bug),
+                bug_summary=bug.title,
+                bug_id=bug.id,
+                bug_importance=importance))
+        return bug_data

=== modified file 'lib/lp/registry/javascript/sharing/sharingdetails.js'
--- lib/lp/registry/javascript/sharing/sharingdetails.js	2012-03-27 15:09:59 +0000
+++ lib/lp/registry/javascript/sharing/sharingdetails.js	2012-03-27 21:15:25 +0000
@@ -1,7 +1,7 @@
 /* Copyright 2012 Canonical Ltd.  This software is licensed under the
  * GNU Affero General Public License version 3 (see the file LICENSE).
  *
- * Sharee table widget.
+ * Sharing details widget
  *
  * @module lp.registry.sharing.details
  */
@@ -19,6 +19,10 @@
 
 SharingDetailsTable.ATTRS = {
 
+    table_body_template: {
+        value: null
+    },
+
     bug_details_row_template: {
         value: null
     },
@@ -43,26 +47,71 @@
             this.set('branches', config.branches);
         }
 
+        if (Y.Lang.isValue(config.bugs)) {
+            this.set('bugs', config.bugs);
+        }
+
+        this.set(
+            'bug_details_row_template',
+            this._bug_details_row_template());
+
         this.set(
             'branch_details_row_template',
             this._branch_details_row_template());
+
+        this.set(
+            'table_body_template',
+            this._table_body_template());
     },
 
     renderUI: function() {
-        var template = this.get('branch_details_row_template');
         var branch_data = this.get('branches');
-        var html = Y.lp.mustache.to_html(template, {branches: branch_data});
+        var bug_data = this.get('bugs');
+        var partials = {
+            branch: this.get('branch_details_row_template'),
+            bug: this.get('bug_details_row_template')
+        };
+        var template = this.get('table_body_template');
+        var html = Y.lp.mustache.to_html(
+            template,
+            {branches: branch_data, bugs: bug_data},
+            partials);
         var table = Y.one('#sharing-table-body');
         table.set('innerHTML', html);
     },
 
+    _table_body_template: function() {
+        return [
+        '{{#branches}}',
+        '{{> branch}}',
+        '{{/branches}}',
+        '{{#bugs}}',
+        '{{> bug}}',
+        '{{/bugs}}'
+        ].join(' ');
+    },
+
     _bug_details_row_template: function() {
-        return [].join(' ');
+        return [
+        '<tr>',
+        '    <td class="icon right">',
+        '        <span class="sprite bug-{{ bug_importance }}"></span>',
+        '    </td>',
+        '    <td class="amount">{{ bug_id }}</td>',
+        '    <td>',
+        '        <a href="{{ bug_link }}">{{ bug_summary }}</a>',
+        '    </td>',
+        '    <td>&mdash;</td>',
+        '    <td class="actions" id="remove-bug-{{ bug_id }}">',
+        '        <a class="sprite remove" href="#"',
+        '            title="Unshare this with the user"></a>',
+        '    </td>',
+        '</tr>'
+        ].join(' ');
     },
 
     _branch_details_row_template: function() {
         return [
-        '{{#branches}}',
         '<tr>',
         '    <td colspan="3">',
         '        <a class="sprite branch" href="{{ branch_link }}">',
@@ -70,12 +119,11 @@
         '        </a>',
         '    </td>',
         '    <td>&mdash;</td>',
-        '    <td class="actions" id="remove-button-{{ branch_id }}">',
+        '    <td class="actions" id="remove-branch-{{ branch_id }}">',
         '        <a class="sprite remove" href="#"',
         '            title="Unshare this with the user"></a>',
         '    </td>',
-        '</tr>',
-        '{{/branches}}'
+        '</tr>'
         ].join(' ');
     }
 });

=== modified file 'lib/lp/registry/javascript/sharing/tests/test_sharing_details.js'
--- lib/lp/registry/javascript/sharing/tests/test_sharing_details.js	2012-03-27 15:10:21 +0000
+++ lib/lp/registry/javascript/sharing/tests/test_sharing_details.js	2012-03-27 21:15:25 +0000
@@ -23,7 +23,7 @@
         tearDown: function() {
         },
 
-        test_render: function () {
+        test_render_branches: function () {
             var config = {
                 branches: [
                     {
@@ -33,15 +33,36 @@
                     }
                 ]
             };
-            table_constructor = Y.lp.registry.sharing.details.SharingDetailsTable;
+            details_module = Y.lp.registry.sharing.details;
+            table_constructor = details_module.SharingDetailsTable;
             var details_widget = new table_constructor(config);
             details_widget.render();
-            var expected = "lp:~someone/+junk/somebranch"
+            var expected = "lp:~someone/+junk/somebranch";
             var branch_link = Y.one('#sharing-table-body').one('a');
             var actual_text = branch_link.get('text').replace(/\s+/g, '');
             Assert.areEqual(expected, actual_text);
+        },
+
+        test_render_bugs: function () {
+            var config = {
+                bugs: [
+                    {
+                        bug_link:'/bugs/2',
+                        bug_id: '2',
+                        bug_importance: 'critical',
+                        bug_summary:'Everything is broken.'
+                    }
+                ]
+            };
+            details_module = Y.lp.registry.sharing.details;
+            table_constructor = details_module.SharingDetailsTable;
+            var details_widget = new table_constructor(config);
+            details_widget.render();
+            var expected = "Everythingisbroken.";
+            var bug_link = Y.one('#sharing-table-body').one('a');
+            var actual_text = bug_link.get('text').replace(/\s+/g, '');
+            Assert.areEqual(expected, actual_text);
         }
-
     }));
 
 

=== modified file 'lib/lp/registry/templates/pillar-sharing-details.pt'
--- lib/lp/registry/templates/pillar-sharing-details.pt	2012-03-26 20:49:13 +0000
+++ lib/lp/registry/templates/pillar-sharing-details.pt	2012-03-27 21:15:25 +0000
@@ -3,7 +3,7 @@
   xmlns:tal="http://xml.zope.org/namespaces/tal";
   xmlns:metal="http://xml.zope.org/namespaces/metal";
   xmlns:i18n="http://xml.zope.org/namespaces/i18n";
-  metal:use-macro="view/macro:page/main_only"
+  metal:use-macro="view/macro:page/main_side"
   i18n:domain="launchpad"
 >
 
@@ -13,8 +13,13 @@
             LPJS.use('base', 'node', 'event', 'lp.registry.sharing.details',
                 function(Y) {
             Y.on('domready', function() {
-                var config = {branches: LP.cache.branches};
-                var details_widget = new Y.lp.registry.sharing.details.SharingDetailsTable(config);
+                var config = {
+                    branches: LP.cache.branches,
+                    bugs: LP.cache.bugs
+                };
+                var details_module  = Y.lp.registry.sharing.details;
+                var details_widget = new details_module.SharingDetailsTable(
+                                                          config);
                 details_widget.render();
             });
           });