changeset 290:913ecc9089e1

primitive implementation of temporal grouping in the stream view
author Myk Melez <myk@mozilla.org>
date Thu, 25 Sep 2008 17:44:19 -0700
parents 1496b73c7308
children b61b4d5527bf
files content/stream.css content/stream.js modules/collection.js modules/utils.js
diffstat 4 files changed, 59 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/content/stream.css	Tue Sep 23 11:44:11 2008 -0700
+++ b/content/stream.css	Thu Sep 25 17:44:19 2008 -0700
@@ -104,6 +104,11 @@
   max-height: 24px;
 }
 
+.group {
+  background-color: darkgrey;
+  color: white;
+}
+
 /* Border styles to clarify the structure for debugging purposes. */
 
 /*
--- a/content/stream.js	Tue Sep 23 11:44:11 2008 -0700
+++ b/content/stream.js	Thu Sep 25 17:44:19 2008 -0700
@@ -314,9 +314,26 @@
     this._contentSandbox.messages =
       this._document.getElementById("contentBox");
 
+    let groups = [
+      { name: "The Future", epoch: Number.MAX_VALUE },
+      { name: "Today", epoch: SnowlUtils.today },
+      { name: "Yesterday", epoch: SnowlUtils.yesterday },
+      { name: "Older", epoch: 0 }
+    ];
+    let groupIndex = 0;
+
     for (let i = 0; i < this._collection.messages.length; ++i) {
       let message = this._collection.messages[i];
 
+      if (message.received < groups[groupIndex].epoch) {
+        ++groupIndex;
+        let desc = this._document.createElementNS(XUL_NS, "description");
+        desc.className = "group";
+        desc.setAttribute("crop", "end");
+        desc.setAttribute("value", groups[groupIndex].name);
+        contentBox.appendChild(desc);
+      }
+
       let messageBox = this._buildMessageView(message);
 
       this._contentSandbox.messageBox = messageBox;
--- a/modules/collection.js	Tue Sep 23 11:44:11 2008 -0700
+++ b/modules/collection.js	Thu Sep 25 17:44:19 2008 -0700
@@ -61,8 +61,12 @@
 Cu.import("resource://snowl/modules/message.js");
 Cu.import("resource://snowl/modules/utils.js");
 
+// FIXME: make SnowlCollection take a hash so it can have named parameters,
+// since the number of parameters it currently accepts, and the fact that they
+// are all optional, makes it unwieldy to pass them in the right order.
+
 /**
- * A group of messages.
+ * A set of messages.
  */
 function SnowlCollection(id, name, iconURL, constraints, parent, grouped,
                          groupIDColumn, groupNameColumn, groupHomeURLColumn,
@@ -307,12 +311,20 @@
   },
 
   _generateStatement: function() {
+    let columns = ["messages.id", "subject", "authors.name AS author", "link",
+                   "timestamp", "read", "authors.iconURL AS authorIcon",
+                   "received"];
+
+    if (this.groupIDColumn) {
+      columns.push(this.groupIDColumn + " AS groupID");
+      columns.push(this.groupNameColumn + " AS groupName");
+    }
+
     let query = 
       //"SELECT subject, author, link, timestamp, content \
       // FROM sources JOIN messages ON sources.id = messages.sourceID \
       // LEFT JOIN parts on messages.id = parts.messageID";
-      "SELECT messages.id, subject, authors.name AS author, link, timestamp, " +
-      "       read, authors.iconURL AS authorIcon, received " +
+      "SELECT " + columns.join(", ") + " " +
       "FROM sources JOIN messages ON sources.id = messages.sourceID " +
       "LEFT JOIN people AS authors ON messages.authorID = authors.id";
 
--- a/modules/utils.js	Tue Sep 23 11:44:11 2008 -0700
+++ b/modules/utils.js	Thu Sep 25 17:44:19 2008 -0700
@@ -64,6 +64,27 @@
                          getService(Ci.nsIScriptableDateFormat);
   },
 
+  get today() {
+    let sometimeToday = new Date();
+    return new Date(sometimeToday.getFullYear(),
+                    sometimeToday.getMonth(),
+                    sometimeToday.getDate());
+  },
+
+  get tomorrow() {
+    let sometimeTomorrow = new Date(new Date() + (1000 * 60 * 60 * 24));
+    return new Date(sometimeTomorrow.getFullYear(),
+                    sometimeTomorrow.getMonth(),
+                    sometimeTomorrow.getDate());
+  },
+
+  get yesterday() {
+    let sometimeYesterday = new Date(new Date() - (1000 * 60 * 60 * 24));
+    return new Date(sometimeYesterday.getFullYear(),
+                    sometimeYesterday.getMonth(),
+                    sometimeYesterday.getDate());
+  },
+
   /**
    * Formats a date for human consumption using the date formatting service
    * for locale-specific formatting along with some additional smarts for more
@@ -76,10 +97,7 @@
     let now = new Date();
     let today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
 
-    let yesterday = new Date(now - 1000 * 60 * 60 * 24);
-    yesterday = new Date(yesterday.getFullYear(),
-                         yesterday.getMonth(),
-                         yesterday.getDate());
+    let yesterday = this.yesterday;
 
     let sixDaysAgo = new Date(now - 1000 * 60 * 60 * 24 * 6);
     sixDaysAgo = new Date(sixDaysAgo.getFullYear(),