← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jcsackett/launchpad/grackle-yui-module into lp:launchpad

 

j.c.sackett has proposed merging lp:~jcsackett/launchpad/grackle-yui-module into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/grackle-yui-module/+merge/90012

Summary
=======
This branch begins a YUI module for showing messages and message lists from
grackle, the new mail archiver/archiving service started in the Budapest Epic.

This is *very* basic--it allows the simplest of displays of a list of
messages. More involved processing/handling will be done in later branches.
This just starts getting things moving.

Preimp
======
Aaron Bentley, Curtis Hovey

Implementation
==============
A new module, team_mailinglists, is introduced as part of the registry
namespace. It defines a new class, MessageList, which can take a container
node and a list of messages either through ATTR or via the initial config. It
can also display those messages via a method, display_messages, which adds the
message HTML as child nodes to the container. In subsequent branches this will
probably be broken into separate classes--one to hold message data, and one as
a widget to display the data.

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

QA
==
None. The js is only included in the template when messages exist from
grackle. As grackle has not been integrated, this js is never currently
triggered within the team mailinglist archive template.

Lint
====
This branch is lint free.
-- 
https://code.launchpad.net/~jcsackett/launchpad/grackle-yui-module/+merge/90012
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/grackle-yui-module into lp:launchpad.
=== added file 'lib/lp/registry/javascript/team_mailinglists.js'
--- lib/lp/registry/javascript/team_mailinglists.js	1970-01-01 00:00:00 +0000
+++ lib/lp/registry/javascript/team_mailinglists.js	2012-01-24 23:10:33 +0000
@@ -0,0 +1,82 @@
+/* Copyright (c) 2012, Canonical Ltd. All rights reserved.
+ *
+ * Team mailinglists
+ *
+ * @module lp.registry.team.mailinglists
+ */
+
+YUI.add('lp.registry.team.mailinglists', function(Y) {
+
+var module = Y.namespace('lp.registry.team.mailinglists');
+
+function MessageList(config) {
+    MessageList.superclass.constructor.apply(this, arguments);
+}
+
+MessageList.NAME = "messageList";
+
+MessageList.ATTR = {
+    messages: {
+        value: []
+    },
+
+    container: {
+        value: null
+    }
+};
+
+Y.extend(MessageList, Y.Base, {
+
+    initializer: function (config) {
+        this.set('container', config.container);
+        if (config.messages !== undefined) {
+            this.set('messages', config.messages);
+        }
+    },
+
+    display_messages: function () {
+        var messages = this.get('messages');
+        var container = Y.one('#messagelist');
+        var i;
+        for (i = 0; i < messages.length; i++) {
+            var message_node = this._create_message_node(messages[i], 0);
+            container.appendChild(message_node);
+        }
+    },
+
+    _create_message_node: function(message, indent) {
+        var message_node = Y.Node.create('<li></li>');
+        var message_id = Y.DataType.Number.format(
+            message.message_id, {'prefix': 'message-'});
+        var subject_node = Y.Node.create('<a href="#"></a>')
+            .set('id', message_id)
+            .set('text', message.headers.Subject);
+
+        var info = message.headers.From + ', ' + message.headers.Date;
+        var info_node = Y.Node.create('<div></div>')
+            .set('text', info);
+        message_node.appendChild(subject_node);
+        message_node.appendChild(info_node);
+
+        if (message.nested_messages !== undefined) {
+            indent = indent + 10;
+            var nested_messages = Y.Node.create('<ul></ul>');
+            var indentation = Y.DataType.Number.format(
+                indent, {'suffix': 'px'});
+            var i;
+            nested_messages.setStyle('margin-left', indentation);
+
+            for (i = 0; i < message.nested_messages.length; i++) {
+                nested_node = _create_message_node(
+                    message.nested_messages[num], indent);
+                nested_messages.appendChild(nested_node);
+            }
+            message_node.appendChild(nested_messages);
+        }
+        return message_node;
+    }
+});
+module.MessageList = MessageList;
+
+
+}, '0.1', {requires: ['base', 'node', 'datatype']});

=== added file 'lib/lp/registry/javascript/tests/test_team_mailinglists.html'
--- lib/lp/registry/javascript/tests/test_team_mailinglists.html	1970-01-01 00:00:00 +0000
+++ lib/lp/registry/javascript/tests/test_team_mailinglists.html	2012-01-24 23:10:33 +0000
@@ -0,0 +1,30 @@
+<!--
+Copyright 2012 Canonical Ltd.  This software is licensed under the
+GNU Affero General Public License version 3 (see the file LICENSE).
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd";>
+<html>
+  <head>
+    <title>Launchpad test_team_mailinglists</title>
+    <!-- YUI and test setup -->
+    <script type="text/javascript"
+            src="../../../../canonical/launchpad/icing/yui/yui/yui.js">
+    </script>
+    <link rel="stylesheet" href="../../../app/javascript/testing/test.css" />
+    <script type="text/javascript"
+            src="../../../../app/javascript/testing/testrunner.js"></script>
+
+    <!-- The module under test -->
+    <script type="text/javascript" src="../team_mailinglists.js"></script>
+
+    <!-- The test suite -->
+    <script type="text/javascript" src="test_team_mailinglists.js"></script>
+  </head>
+  <body class="yui-skin-sam">
+
+    <!-- The example markup required by the script to run -->
+    <div id="messagelist">
+    </div>
+  </body>
+</html>
+

=== added file 'lib/lp/registry/javascript/tests/test_team_mailinglists.js'
--- lib/lp/registry/javascript/tests/test_team_mailinglists.js	1970-01-01 00:00:00 +0000
+++ lib/lp/registry/javascript/tests/test_team_mailinglists.js	2012-01-24 23:10:33 +0000
@@ -0,0 +1,71 @@
+/* Copyright (c) 2012, Canonical Ltd. All rights reserved. */
+YUI({
+    base: '../../../../canonical/launchpad/icing/yui/',
+    filter: 'raw',
+    combine: false,
+    fetchCSS: false
+}).use('event', 'lp.client', 'node', 'test', 'widget-stack',
+             'console', 'lp.registry.team.mailinglists', function(Y) {
+
+// Local aliases
+var Assert = Y.Assert,
+    ArrayAssert = Y.ArrayAssert;
+var team_mailinglists = Y.lp.registry.team.mailinglists;
+var suite = new Y.Test.Suite("team.mailinglists Tests");
+
+suite.add(new Y.Test.Case({
+
+    name: 'Team Mailinglists',
+
+    setUp: function() {
+        window.LP = {
+            links: {},
+            cache: {}
+        };
+    },
+
+    tearDown: function() {
+    },
+
+    test_render_message: function () {
+        var config = {
+            messages: [
+                {
+                    'message_id': 3,
+                    'headers': {
+                        'Subject': 'Please stop breaking things',
+                        'To': 'the_list@xxxxxxxxxx',
+                        'From': 'someone@xxxxxxxx',
+                        'Date': '2011-10-13'
+                    },
+                    'nested_messages': [],
+                    'attachments': []
+                }
+            ],
+            container: Y.one('#messagelist')
+        };
+        var message_list = new Y.lp.registry.team.mailinglists.MessageList(
+            config);
+        message_list.display_messages();
+        var message = Y.one("#message-3");
+        Assert.areEqual(message.get('text'), 'Please stop breaking things');
+    }
+}));
+
+
+var handle_complete = function(data) {
+    window.status = '::::' + JSON.stringify(data);
+    };
+Y.Test.Runner.on('complete', handle_complete);
+Y.Test.Runner.add(suite);
+
+var yconsole = new Y.Console({
+    newestOnTop: false
+});
+yconsole.render('#log');
+
+Y.on('domready', function() {
+    Y.Test.Runner.run();
+});
+
+});

=== modified file 'lib/lp/registry/templates/team-mailinglist-archive.pt'
--- lib/lp/registry/templates/team-mailinglist-archive.pt	2012-01-24 16:10:32 +0000
+++ lib/lp/registry/templates/team-mailinglist-archive.pt	2012-01-24 23:10:33 +0000
@@ -7,9 +7,30 @@
   i18n:domain="launchpad"
 >
 
+<head>
+  <tal:block metal:fill-slot="head_epilogue">
+    <tal:script condition="view/messages">
+        <!--We'll add this in later, for now it's a place holder because this is where
+        we bolt in the js module some day.-->
+        <script type="text/javascript">
+            LPS.use('lp.registry.team.mailinglists', function(Y) {
+              Y.on('domready', function() {
+                var config = {
+                  messages: LP.cache['mail'],
+                  container: Y.one('#messagelist')
+                };
+                var mailinglist_module = Y.lp.registry.team.mailinglists;
+                var message_list = new mailinglist_module.MessageList(config);
+              });
+            });
+        </script>
+    </tal:script>
+  </tal:block>
+</head>
+
 <body>
   <div metal:fill-slot="main">
-    
+
     <div id="messagelist">
       <tal:comment replace="nothing">
         The json loaded and manipulated messages go here.