← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jcsackett/launchpad/consolidate-spam-js into lp:launchpad

 

j.c.sackett has proposed merging lp:~jcsackett/launchpad/consolidate-spam-js into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/consolidate-spam-js/+merge/61151


Summary
=======
There was a fair amount of duplication created as a result of the process of implementing the comment hiding functions now available in bug and question comments. A prior branch addressed some of that duplication; this branch address the remainder by consolidating the duplicated javascript.

Additionally, this addresses bug 782252 by updating the action from "Mark as spam" to "Hide comment."

Preimplemenation
================
No preimplemenation talks--the necessary work was well defined by what was duplicated.


Implementation
==============
lib/lp/app/javascript/hide_comment.js
lib/lp/app/javascript/tests/test_hide_comment.html
lib/lp/app/javascript/tests/test_hide_comment.js
------------------------------------------------
Consolidated bug_spam.js and question_spam.js into hide_comment.js; consolidated tests along with it.

lib/lp/answers/interfaces/questionmessage.py
lib/lp/answers/model/questionmessage.py
---------------------------------------
Added a "display_index" property to provide the 1-indexed message index for human reading.
Changed index to just provide the actual 0-indexed message index for everything else to use.

lib/lp/bugs/templates/bugtask-index.pt
lib/lp/answers/templates/question-index.pt
------------------------------------------
Changed the comment hiding js setup to use the new consolidated js file.

lib/lp/answers/templates/questionmessage-display.pt
lib/lp/bugs/templates/bugcomment-box.pt
---------------------------------------
Changed text from "Mark as spam" and "Mark as not spam" to "Hide comment" and "Unhide."

Tests
=====
bin/test -vvc -t questionmessage -t bugcomment
firefox lib/lp/app/javascript/tests/test_hide_comment.html

QA
==
Make sure that the comment hiding functions still work appropriately on a bug and question.
Make certain the link text for the control now says "Hide comment" and "Unhide comment"

Lint
====
= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/answers/interfaces/questionmessage.py
  lib/lp/answers/model/questionmessage.py
  lib/lp/answers/templates/question-index.pt
  lib/lp/answers/templates/questionmessage-display.pt
  lib/lp/app/javascript/hide_comment.js
  lib/lp/app/javascript/tests/test_hide_comment.html
  lib/lp/app/javascript/tests/test_hide_comment.js
  lib/lp/bugs/templates/bugcomment-box.pt
  lib/lp/bugs/templates/bugtask-index.pt

-- 
https://code.launchpad.net/~jcsackett/launchpad/consolidate-spam-js/+merge/61151
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/consolidate-spam-js into lp:launchpad.
=== modified file 'lib/lp/answers/interfaces/questionmessage.py'
--- lib/lp/answers/interfaces/questionmessage.py	2011-05-12 21:33:10 +0000
+++ lib/lp/answers/interfaces/questionmessage.py	2011-05-16 18:18:45 +0000
@@ -54,6 +54,11 @@
         description=_("The messages index in the question's list of "
         "messages."),
         readonly=True)
+    display_index = Int(
+        title=_("Human readable Message index."),
+        description=_("The message's index in the question's list of "
+        "messages, meant for humans."),
+        readonly=True)
     visible = Bool(
         title=_("Message visibility."),
         description=_("Whether or not the message is visible."),

=== removed file 'lib/lp/answers/javascript/question_spam.js'
--- lib/lp/answers/javascript/question_spam.js	2011-05-09 21:41:44 +0000
+++ lib/lp/answers/javascript/question_spam.js	1970-01-01 00:00:00 +0000
@@ -1,73 +0,0 @@
-/* Copyright 2011 Canonical Ltd.  This software is licensed under the
- * GNU Affero General Public License version 3 (see the file LICENSE).
- *
- * Animation for IBugTask:+subscribe LaunchpadForm.
- * Also used in "Edit subscription" advanced overlay.
- *
- * @namespace Y.lp.answers.question_spam
- * @requires  dom, node, lazr.effects
- */
-YUI.add('lp.answers.question_spam', function(Y) {
-var namespace = Y.namespace('lp.answers.question_spam');
-
-var hidden_class = "adminHiddenComment";
-var spam_text = "Mark as spam";
-var not_spam_text = "Mark as not spam";
-
-function update_comment(link, comment) {
-    var text = link.get('text').trim();
-    if (text == spam_text) {
-        comment.removeClass(hidden_class);
-        link.set('text', not_spam_text);
-    } else {
-        comment.addClass(hidden_class);
-        link.set('text', spam_text);
-    }
-}
-
-function set_visibility(parameters, callbacks) {
-    var question = LP.cache.context;
-    var lp_client = new Y.lp.client.Launchpad();
-    var config = {
-        on: {
-            success: callbacks.success,
-            failure: callbacks.failure
-            },
-        parameters: parameters
-        }
-    lp_client.named_post(
-        question.self_link, 'setCommentVisibility', config);
-}
-
-function toggle_spam_setting(link) {
-    var comment = link.get('parentNode').get('parentNode');
-    var visible = comment.hasClass('adminHiddenComment');
-    var comment_number = parseInt(link.get('id').replace('mark-spam-', ''));
-    comment_number = comment_number - 1;
-    parameters = {
-        visible: visible,
-        comment_number: comment_number
-        };
-    set_visibility(parameters, {
-        // We use red flash on failure so admins no it didn't work.
-        // There's no green flash on success, b/c the change in bg
-        // color provides an immediate visual cue.
-        success: function () { 
-            update_comment(link, comment);
-            comment.toggleClass(hidden_class);
-            },
-        failure: function () {
-            Y.lazr.anim.red_flash({node:comment});
-            }
-        });
-}
-namespace.toggle_spam_setting = toggle_spam_setting;
-
-function setup_spam_links() {
-  Y.on('click', function(e) {
-      e.halt();
-      namespace.toggle_spam_setting(this);
-  }, '.mark-spam');
-}
-namespace.setup_spam_links = setup_spam_links
-}, "0.1", {"requires": ["dom", "node", "lazr.anim", "lp.client"]});

=== modified file 'lib/lp/answers/model/questionmessage.py'
--- lib/lp/answers/model/questionmessage.py	2011-05-12 21:33:10 +0000
+++ lib/lp/answers/model/questionmessage.py	2011-05-16 18:18:45 +0000
@@ -52,6 +52,10 @@
 
     @cachedproperty
     def index(self):
+        return list(self.question.messages).index(self)
+
+    @cachedproperty
+    def display_index(self):
         # Return the index + 1 so that messages appear 1-indexed in the UI.
         return list(self.question.messages).index(self) + 1
 

=== modified file 'lib/lp/answers/templates/question-index.pt'
--- lib/lp/answers/templates/question-index.pt	2011-05-09 13:03:50 +0000
+++ lib/lp/answers/templates/question-index.pt	2011-05-16 18:18:45 +0000
@@ -18,9 +18,10 @@
     </style>
     <script type="text/javascript">
         LPS.use('base', 'node', 'event',
-                'lp.answers.question_spam', function(Y) {
+                'lp.comments.hide', function(Y) {
         Y.on('domready', function() {
-            Y.lp.answers.question_spam.setup_spam_links();
+            LP.cache.comment_context = LP.cache.context;
+            Y.lp.comments.hide.setup_hide_controls();
         });
       });
     </script>

=== modified file 'lib/lp/answers/templates/questionmessage-display.pt'
--- lib/lp/answers/templates/questionmessage-display.pt	2011-05-05 14:44:18 +0000
+++ lib/lp/answers/templates/questionmessage-display.pt	2011-05-16 18:18:45 +0000
@@ -1,12 +1,11 @@
 <tal:root
   xmlns:tal="http://xml.zope.org/namespaces/tal";
   xmlns:metal="http://xml.zope.org/namespaces/metal";
-  define="index context/index"
   omit-tag="">
 <div
   tal:define="css_classes view/getBoardCommentCSSClass"
   tal:attributes="class string:${css_classes};
-                  id string:comment-${index}">
+                  id string:comment-${context/index}">
   <div class="boardCommentDetails">
     <tal:bestanswer condition="view/isBestAnswer">
       <img src="/@@/favourite-yes" style="float:right;" alt="Best"
@@ -21,7 +20,7 @@
       tal:content="context/datecreated/fmt:displaydate">Thursday
     13:21</span>:
     <span style="float:right;"
-       tal:content="string: #${context/index}" />
+       tal:content="string: #${context/display_index}" />
   </div>
 
   <div class="boardCommentBody"
@@ -47,14 +46,11 @@
   <div
     tal:condition="view/canSeeSpamControls"
     class="boardCommentFooter">
-    <a tal:attributes="id string:mark-spam-${index};"
+    <a tal:attributes="id string:mark-spam-${context/index};"
        class="js-action sprite edit mark-spam" href="#">
-         <tal:not-spam condition="not: context/visible">
-         Mark as not spam
-         </tal:not-spam>
-         <tal:spam condition="context/visible">
-         Mark as spam
-         </tal:spam>
+       <tal:not-spam
+         condition="not: context/visible">Unhide comment</tal:not-spam>
+       <tal:spam condition="context/visible">Hide comment</tal:spam>
     </a>
   </div>
 </div>

=== added file 'lib/lp/app/javascript/hide_comment.js'
--- lib/lp/app/javascript/hide_comment.js	1970-01-01 00:00:00 +0000
+++ lib/lp/app/javascript/hide_comment.js	2011-05-16 18:18:45 +0000
@@ -0,0 +1,71 @@
+/* Copyright 2011 Canonical Ltd.  This software is licensed under the
+ * GNU Affero General Public License version 3 (see the file LICENSE).
+ *
+ * @namespace Y.lp.comments.hide
+ * @requires dom, node, lazr.anim, lp.client
+ */
+YUI.add('lp.comments.hide', function(Y) {
+var namespace = Y.namespace('lp.comments.hide');
+
+var hidden_class = "adminHiddenComment";
+var hide_text = "Hide comment";
+var unhide_text = "Unhide comment";
+
+function update_comment(link, comment) {
+    var text = link.get('text').trim();
+    if (text == hide_text) {
+        comment.removeClass(hidden_class);
+        link.set('text', unhide_text);
+    } else {
+        comment.addClass(hidden_class);
+        link.set('text', hide_text);
+    }
+}
+
+function set_visibility(parameters, callbacks) {
+    // comment_context must be setup on pages using this js, and is the 
+    // context for a comment (e.g. bug).
+    var comment_context = LP.cache.comment_context;
+    var lp_client = new Y.lp.client.Launchpad();
+    var config = {
+        on: {
+            success: callbacks.success,
+            failure: callbacks.failure
+            },
+        parameters: parameters
+        }
+    lp_client.named_post(
+        comment_context.self_link, 'setCommentVisibility', config);
+}
+
+function toggle_hidden(link) {
+    var comment = link.get('parentNode').get('parentNode');
+    var visible = comment.hasClass('adminHiddenComment');
+    var comment_number = parseInt(link.get('id').replace('mark-spam-', ''));
+    parameters = {
+        visible: visible,
+        comment_number: comment_number
+        };
+    set_visibility(parameters, {
+        // We use red flash on failure so admins no it didn't work.
+        // There's no green flash on success, b/c the change in bg
+        // color provides an immediate visual cue.
+        success: function () { 
+            update_comment(link, comment);
+            comment.toggleClass(hidden_class);
+            },
+        failure: function () {
+            Y.lazr.anim.red_flash({node:comment});
+            }
+        });
+}
+namespace.toggle_hidden = toggle_hidden;
+
+function setup_hide_controls() {
+  Y.on('click', function(e) {
+      e.halt();
+      namespace.toggle_hidden(this);
+  }, '.mark-spam');
+}
+namespace.setup_hide_controls = setup_hide_controls
+}, "0.1", {"requires": ["dom", "node", "lazr.anim", "lp.client"]});

=== renamed file 'lib/lp/answers/javascript/tests/test_question_spam.html' => 'lib/lp/app/javascript/tests/test_hide_comment.html'
--- lib/lp/answers/javascript/tests/test_question_spam.html	2011-05-05 14:44:18 +0000
+++ lib/lp/app/javascript/tests/test_hide_comment.html	2011-05-16 18:18:45 +0000
@@ -1,6 +1,6 @@
 <html>
   <head>
-    <title>Launchpad Question Spam Controls</title>
+    <title>Launchpad Comment Hiding</title>
     <!-- YUI 3.0 Setup -->
     <script type="text/javascript" src="../../../../canonical/launchpad/icing/yui/yui/yui.js"></script>
     <script type="text/javascript"
@@ -16,63 +16,34 @@
     <script type="text/javascript" src="../../../app/javascript/client.js"></script>
     <script type="text/javascript" src="../../../app/javascript/lp.js"></script>
 
-    <!-- Additional module dependency setup -->
-    <script type="text/javascript">
-        var LP = {
-            cache: {
-                context: {
-                    self_link: 'http:example.com'
-                    }
-                }
-            };
-    </script>
-
     <!-- The module under test -->
-    <script type="text/javascript" src="../question_spam.js"></script>
+    <script type="text/javascript" src="../hide_comment.js"></script>
 
     <!-- The test suite -->
-    <script type="text/javascript" src="test_question_spam.js"></script>
+    <script type="text/javascript" src="test_hide_comment.js"></script>
   </head>
   <body class="yui-skin-sam">
 
     <!-- The example markup required by the script to run -->
-    <div id="expected-id">
     <div class="boardComment">
-      <div class="boardCommentDetails">
-        <a href="#" class="sprite person">TestyMcTest</a>
-        said
-        <span title="">2 hours ago</span>:
-        <span style="float:right;"> #1</span>
-      </div>
-
+      <div class="boardCommentDetails">Details</div>
       <div class="boardCommentBody"><p>Foo bar baz.</p></div>
-
       <div class="boardCommentFooter">
-        <a id="mark-spam-1" class="js-action sprite edit" href="#">
-            Mark as spam
-        </a>
-
+          <a id="mark-spam-0" class="js-action sprite edit" href="#"
+          >Hide comment</a>
       </div>
     </div>
 
     <div id="hidden-comment" class="boardComment adminHiddenComment">
-      <div class="boardCommentDetails">
-        <a href="#" class="sprite person">TestyMcTest</a>
-        said
-        <span title="">1 hours ago</span>:
-        <span style="float:right;"> #2</span>
-      </div>
-
+      <div class="boardCommentDetails">Details</div>
       <div class="boardCommentBody"><p>Click here for a diploma!</p></div>
-
       <div class="boardCommentFooter">
-        <a id="mark-spam-2" class="js-action sprite edit" href="#">
-            Mark as not spam
+        <a id="mark-spam-1" class="js-action sprite edit" href="#">
+            Unhide comment
         </a>
 
       </div>
     </div>
-    </div>
 
     <!-- The test output -->
     <div id="log"></div>

=== renamed file 'lib/lp/answers/javascript/tests/test_question_spam.js' => 'lib/lp/app/javascript/tests/test_hide_comment.js'
--- lib/lp/answers/javascript/tests/test_question_spam.js	2011-05-09 01:26:10 +0000
+++ lib/lp/app/javascript/tests/test_hide_comment.js	2011-05-16 18:18:45 +0000
@@ -7,12 +7,12 @@
     filter: 'raw', combine: false,
     fetchCSS: false,
     }).use('test', 'console', 'node', 'node-event-simulate',
-           'lp.answers.question_spam', function(Y) {
+           'lp.comments.hide', function(Y) {
 
-    var suite = new Y.Test.Suite("lp.answers.question_spam Tests");
+    var suite = new Y.Test.Suite("lp.comments.hide Tests");
 
     suite.add(new Y.Test.Case({
-        name: 'question_spam',
+        name: 'hide_comments',
 
         setUp: function() {
             // Monkeypatch LP to avoid network traffic and to allow
@@ -33,20 +33,20 @@
                     // success callback.
                     config.on.success();
                 };
-            LP.cache.context = {
-                self_link: 'https://launchpad.dev/api/devel/questions/fake'
+            LP.cache.comment_context = {
+                self_link: 'https://launchpad.dev/api/devel/some/comment/'
             };
         },
 
-        test_mark_as_spam: function () {
-            link = Y.one('#mark-spam-1');
+        test_hide: function () {
+            link = Y.one('#mark-spam-0');
             comment = Y.one('.boardComment');
-            Y.lp.answers.question_spam.toggle_spam_setting(link);
+            Y.lp.comments.hide.toggle_hidden(link);
             Y.Assert.isTrue(comment.hasClass('adminHiddenComment'));
-            Y.Assert.areEqual('Mark as not spam', link.get('text'),
-                'Link text should be \'Mark as not spam\'');
+            Y.Assert.areEqual('Unhide comment', link.get('text'),
+                'Link text should be \'Unhide comment\'');
             Y.Assert.areEqual(
-                'https://launchpad.dev/api/devel/questions/fake',
+                'https://launchpad.dev/api/devel/some/comment/',
                 LP.cache.call_data.called_url, 'Call with wrong url.');
             Y.Assert.areEqual(
                 'setCommentVisibility', LP.cache.call_data.called_func,
@@ -58,15 +58,15 @@
                 'Called with wrong wrong comment number.')
             },
         
-        test_mark_as_not_spam: function () {
-            link = Y.one('#mark-spam-2');
+        test_unhide: function () {
+            link = Y.one('#mark-spam-1');
             comment = Y.one('#hidden-comment');
-            Y.lp.answers.question_spam.toggle_spam_setting(link);
+            Y.lp.comments.hide.toggle_hidden(link);
             Y.Assert.isFalse(comment.hasClass('adminHiddenComment'));
-            Y.Assert.areEqual('Mark as spam', link.get('text'),
-                'Link text should be \'Mark as spam\'')
+            Y.Assert.areEqual('Hide comment', link.get('text'),
+                'Link text should be \'Hide comment\'')
             Y.Assert.areEqual(
-                'https://launchpad.dev/api/devel/questions/fake',
+                'https://launchpad.dev/api/devel/some/comment/',
                 LP.cache.call_data.called_url, 'Call with wrong url.');
             Y.Assert.areEqual(
                 'setCommentVisibility', LP.cache.call_data.called_func,

=== removed file 'lib/lp/bugs/javascript/bug_spam.js'
--- lib/lp/bugs/javascript/bug_spam.js	2011-05-09 21:59:06 +0000
+++ lib/lp/bugs/javascript/bug_spam.js	1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
-/* Copyright 2011 Canonical Ltd.  This software is licensed under the
- * GNU Affero General Public License version 3 (see the file LICENSE).
- *
- * Animation for IBugTask:+subscribe LaunchpadForm.
- * Also used in "Edit subscription" advanced overlay.
- *
- * @namespace Y.lp.answers.question_spam
- * @requires  dom, node, lazr.effects
- */
-YUI.add('lp.bugs.bug_spam', function(Y) {
-var namespace = Y.namespace('lp.bugs.bug_spam');
-
-var hidden_class = "adminHiddenComment";
-var spam_text = "Mark as spam";
-var not_spam_text = "Mark as not spam";
-
-function update_comment(link, comment) {
-    var text = link.get('text').trim();
-    if (text == spam_text) {
-        comment.removeClass(hidden_class);
-        link.set('text', not_spam_text);
-    } else {
-        comment.addClass(hidden_class);
-        link.set('text', spam_text);
-    }
-}
-
-function set_visibility(parameters, callbacks) {
-    var bug = LP.cache.bug;
-    var lp_client = new Y.lp.client.Launchpad();
-    var config = {
-        on: {
-            success: callbacks.success,
-            failure: callbacks.failure
-            },
-        parameters: parameters
-        }
-    lp_client.named_post(
-        bug.self_link, 'setCommentVisibility', config);
-}
-
-function toggle_spam_setting(link) {
-    var comment = link.get('parentNode').get('parentNode');
-    var visible = comment.hasClass('adminHiddenComment');
-    var comment_number = parseInt(link.get('id').replace('mark-spam-', ''));
-    parameters = {
-        visible: visible,
-        comment_number: comment_number
-        };
-    set_visibility(parameters, {
-        // We use red flash on failure so admins no it didn't work.
-        // There's no green flash on success, b/c the change in bg
-        // color provides an immediate visual cue.
-        success: function () { 
-            update_comment(link, comment);
-            comment.toggleClass(hidden_class);
-            },
-        failure: function () {
-            Y.lazr.anim.red_flash({node:comment});
-            }
-        });
-}
-namespace.toggle_spam_setting = toggle_spam_setting;
-
-function setup_spam_links() {
-  Y.on('click', function(e) {
-      e.halt();
-      namespace.toggle_spam_setting(this);
-  }, '.mark-spam');
-}
-namespace.setup_spam_links = setup_spam_links
-}, "0.1", {"requires": ["dom", "node", "lazr.anim", "lp.client"]});

=== removed file 'lib/lp/bugs/javascript/tests/test_bug_spam.html'
--- lib/lp/bugs/javascript/tests/test_bug_spam.html	2011-05-10 16:16:21 +0000
+++ lib/lp/bugs/javascript/tests/test_bug_spam.html	1970-01-01 00:00:00 +0000
@@ -1,94 +0,0 @@
-<html>
-  <head>
-    <title>Launchpad Question Spam Controls</title>
-    <!-- YUI 3.0 Setup -->
-    <script type="text/javascript" src="../../../../canonical/launchpad/icing/yui/yui/yui.js"></script>
-    <script type="text/javascript"
-      src="../../../../canonical/launchpad/icing/lazr/build/lazr.js"></script>
-    <link rel="stylesheet"
-      href="../../../../canonical/launchpad/icing/yui/cssreset/reset.css"/>
-    <link rel="stylesheet"
-      href="../../../../canonical/launchpad/icing/yui/cssfonts/fonts.css"/>
-    <link rel="stylesheet"
-      href="../../../../canonical/launchpad/icing/yui/cssbase/base.css"/>
-    <link rel="stylesheet"
-      href="../../../../canonical/launchpad/javascript/test.css" />
-    <script type="text/javascript" src="../../../app/javascript/client.js"></script>
-    <script type="text/javascript" src="../../../app/javascript/lp.js"></script>
-
-    <!-- The module under test -->
-    <script type="text/javascript" src="../bug_spam.js"></script>
-
-    <!-- The test suite -->
-    <script type="text/javascript" src="test_bug_spam.js"></script>
-  </head>
-  <body class="yui-skin-sam">
-
-    <!-- The example markup required by the script to run -->
-<div class="boardComment">
-  <div class="boardCommentDetails">
-    <table>
-      <tbody>
-        <tr>
-          <td>
-              <a href="https://launchpad.dev/~name12"; class="sprite person">
-                  Sample Person
-              </a>
-            wrote
-            <span title="2004-09-24 23:24:03 SAST">on 2004-09-24</span>:
-          </td>
-          <td class="bug-comment-index">
-            <a href="/firefox/+bug/1/comments/1"> #1</a>
-          </td>
-        </tr>
-      </tbody>
-    </table>
-  </div>
-
-  <div class="boardCommentBody">
-    <div class="bug-comment"><p>Good comment.</p></div>
-  </div>
-
-  <div class="boardCommentFooter">
-    <a class="js-action sprite edit mark-spam" href="#"
-       id="mark-spam-1">
-         Mark as spam
-    </a>
-  </div>
-</div>
-
-<div id="hidden-comment" class="boardComment adminHiddenComment">
-  <div class="boardCommentDetails">
-    <table>
-      <tbody>
-        <tr>
-          <td>
-              <a href="https://launchpad.dev/~name12"; class="sprite person">
-                  Sample Person
-              </a>
-            wrote
-            <span title="2004-09-24 23:24:03 SAST">on 2004-09-24</span>:
-          </td>
-          <td class="bug-comment-index">
-            <a href="/firefox/+bug/1/comments/1"> #1</a>
-          </td>
-        </tr>
-      </tbody>
-    </table>
-  </div>
-
-  <div class="boardCommentBody">
-    <div class="bug-comment"><p>Bad comment.</p></div>
-  </div>
-
-  <div class="boardCommentFooter">
-    <a class="js-action sprite edit mark-spam" href="#"
-       id="mark-spam-2">
-         Mark as not spam
-    </a>
-  </div>
-</div>
-    <!-- The test output -->
-    <div id="log"></div>
-  </body>
-</html>

=== removed file 'lib/lp/bugs/javascript/tests/test_bug_spam.js'
--- lib/lp/bugs/javascript/tests/test_bug_spam.js	2011-05-10 16:03:16 +0000
+++ lib/lp/bugs/javascript/tests/test_bug_spam.js	1970-01-01 00:00:00 +0000
@@ -1,93 +0,0 @@
-/* Copyright 2011 Canonical Ltd.  This software is licensed under the
- * GNU Affero General Public License version 3 (see the file LICENSE).
- */
-
-YUI({
-    base: '../../../../canonical/launchpad/icing/yui/',
-    filter: 'raw', combine: false,
-    fetchCSS: false,
-    }).use('test', 'console', 'node', 'node-event-simulate',
-           'lp.bugs.bug_spam', function(Y) {
-
-    var suite = new Y.Test.Suite("lp.bugs.bug_spam Tests");
-
-    suite.add(new Y.Test.Case({
-        name: 'bug_spam',
-
-        setUp: function() {
-            // Monkeypatch LP to avoid network traffic and to allow
-            // insertion of test data.
-            window.LP = {
-                links: {},
-                cache: {}
-            };
-            Y.lp.client.Launchpad = function() {};
-            Y.lp.client.Launchpad.prototype.named_post =
-                function(url, func, config) {
-                    LP.cache.call_data = {
-                        called_url: url, 
-                        called_func: func,
-                        called_config: config
-                    }
-                    // our setup assumes success, so we just do the
-                    // success callback.
-                    config.on.success();
-                };
-            LP.cache.bug = {
-                self_link: 'https://launchpad.dev/api/devel/bugs/fake'
-            };
-        },
-
-        test_mark_as_spam: function () {
-            link = Y.one('#mark-spam-1');
-            comment = Y.one('.boardComment');
-            Y.lp.bugs.bug_spam.toggle_spam_setting(link);
-            Y.Assert.isTrue(comment.hasClass('adminHiddenComment'));
-            Y.Assert.areEqual('Mark as not spam', link.get('text'),
-                'Link text should be \'Mark as not spam\'');
-            Y.Assert.areEqual(
-                'https://launchpad.dev/api/devel/bugs/fake',
-                LP.cache.call_data.called_url, 'Call with wrong url.');
-            Y.Assert.areEqual(
-                'setCommentVisibility', LP.cache.call_data.called_func,
-                'Call with wrong func.');
-            Y.Assert.isFalse(
-                LP.cache.call_data.called_config.parameters.visible);
-            Y.Assert.areEqual(
-                1, LP.cache.call_data.called_config.parameters.comment_number,
-                'Called with wrong wrong comment number.')
-            },
-        
-        test_mark_as_not_spam: function () {
-            link = Y.one('#mark-spam-2');
-            comment = Y.one('#hidden-comment');
-            Y.lp.bugs.bug_spam.toggle_spam_setting(link);
-            Y.Assert.isFalse(comment.hasClass('adminHiddenComment'));
-            Y.Assert.areEqual('Mark as spam', link.get('text'),
-                'Link text should be \'Mark as spam\'')
-            Y.Assert.areEqual(
-                'https://launchpad.dev/api/devel/bugs/fake',
-                LP.cache.call_data.called_url, 'Call with wrong url.');
-            Y.Assert.areEqual(
-                'setCommentVisibility', LP.cache.call_data.called_func,
-                'Call with wrong func.');
-            Y.Assert.isTrue(
-                LP.cache.call_data.called_config.parameters.visible);
-            Y.Assert.areEqual(
-                2, LP.cache.call_data.called_config.parameters.comment_number,
-                'Called with wrong wrong comment number.')
-            },
-
-        }));
-
-    // Lock, stock, and two smoking barrels.
-    Y.Test.Runner.add(suite);
-
-    var console = new Y.Console({newestOnTop: false});
-    console.render('#log');
-
-    Y.on('domready', function() {
-        Y.Test.Runner.run();
-        });
-});
-

=== modified file 'lib/lp/bugs/templates/bugcomment-box.pt'
--- lib/lp/bugs/templates/bugcomment-box.pt	2011-05-11 14:54:59 +0000
+++ lib/lp/bugs/templates/bugcomment-box.pt	2011-05-16 18:18:45 +0000
@@ -90,12 +90,10 @@
     <a tal:attributes="id string:mark-spam-${context/index};"
        tal:condition="view/show_spam_controls"
        class="js-action sprite edit mark-spam" href="#">
-         <tal:not-spam condition="not: context/visible">
-         Mark as not spam
-         </tal:not-spam>
-         <tal:spam condition="context/visible">
-         Mark as spam
-         </tal:spam>
+       <tal:not-spam condition="not: context/visible"
+       >Unhide comment</tal:not-spam>
+       <tal:spam condition="context/visible"
+       >Hide comment</tal:spam>
     </a>
     <tal:activity
         define="activity_list comment/activity"

=== modified file 'lib/lp/bugs/templates/bugtask-index.pt'
--- lib/lp/bugs/templates/bugtask-index.pt	2011-05-11 14:55:21 +0000
+++ lib/lp/bugs/templates/bugtask-index.pt	2011-05-16 18:18:45 +0000
@@ -44,7 +44,7 @@
       <script type="text/javascript">
         LPS.use('base', 'node', 'oop', 'event', 'lp.bugs.bugtask_index',
                   'lp.bugs.bugtask_index.portlets',
-                  'lp.code.branchmergeproposal.diff', 'lp.bugs.bug_spam',
+                  'lp.code.branchmergeproposal.diff', 'lp.comments.hide',
                   function(Y) {
             Y.lp.bugs.bugtask_index.portlets.use_advanced_subscriptions =
                 use_advanced_subscriptions;
@@ -53,7 +53,8 @@
                 Y.lp.code.branchmergeproposal.diff.connect_diff_links();
             }, window);
             Y.on('domready', function() {
-                Y.lp.bugs.bug_spam.setup_spam_links();
+                LP.cache.comment_context = LP.cache.bug;
+                Y.lp.comments.hide.setup_hide_controls();
             });
          });
       </script>

=== added directory 'lib/lp/services/comments/javascript'