changeset 322:3940ef5aa170

let users choose a period of time from which to see messages in the river view
author Myk Melez <myk@mozilla.org>
date Tue, 14 Oct 2008 11:34:46 -0700
parents 74793fa72460
children f395a054dd9c
files content/river.js content/river.xul locale/en-US/river.dtd modules/utils.js
diffstat 4 files changed, 95 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/content/river.js	Sun Oct 12 21:30:14 2008 -0700
+++ b/content/river.js	Tue Oct 14 11:34:46 2008 -0700
@@ -100,8 +100,58 @@
   },
 
   get _filterTextbox() {
-    delete this._filter;
-    return this._filter = document.getElementById("filterTextbox");
+    delete this._filterTextbox;
+    return this._filterTextbox = document.getElementById("filterTextbox");
+  },
+
+  get _periodMenu() {
+    delete this._periodMenu;
+    return this._periodMenu = document.getElementById("periodMenu");
+  },
+
+  get _periodMenuPopup() {
+    delete this._periodMenuPopup;
+    return this._periodMenuPopup = document.getElementById("periodMenuPopup");
+  },
+
+  get _periodStartTime() {
+    if (!this._periodMenu.selectedItem)
+      return 0;
+
+    switch (this._periodMenu.selectedItem.value) {
+      case "today":
+        return SnowlUtils.jsToJulianDate(SnowlUtils.today);
+      case "yesterday":
+        return SnowlUtils.jsToJulianDate(SnowlUtils.yesterday);
+      case "last7days":
+        return SnowlUtils.jsToJulianDate(SnowlUtils.sixDaysAgo.epoch);
+      case "last30days":
+        return SnowlUtils.jsToJulianDate(SnowlUtils.twentyNineDaysAgo.epoch);
+      case "all":
+      default:
+        return 0;
+    }
+  },
+
+  get _periodEndTime() {
+    if (!this._periodMenu.selectedItem)
+      return Number.MAX_VALUE;
+
+    switch (this._periodMenu.selectedItem.value) {
+      // Yesterday means only that day, but the rest of the periods are fairly
+      // open-ended, since they all include today, and in theory there shouldn't
+      // be any messages received after today.  I suppose we could exclude
+      // messages received in the future from these categories, but since that
+      // situation is exceptional, it's probably better to show those.
+      case "yesterday":
+        return SnowlUtils.jsToJulianDate(SnowlUtils.today);
+      case "today":
+      case "last7days":
+      case "last30days":
+      case "all":
+      default:
+        return Number.MAX_VALUE;
+    }
   },
 
   // The set of messages to display in the view.
@@ -246,6 +296,12 @@
     if ("filter" in this._params)
       document.getElementById("filterTextbox").value = this._params.filter;
 
+    if ("period" in this._params) {
+      let item = this._periodMenuPopup.getElementsByAttribute("value", this._params.period)[0];
+      if (item)
+        this._periodMenu.selectedItem = item;
+    }
+
     if ("columns" in this._params) {
       this._columnsButton.checked = true;
       // XXX This feels like the wrong place to do this, but I don't see
@@ -302,6 +358,11 @@
       filters.push({ expression: "messages.id IN (SELECT messageID FROM parts WHERE content MATCH :filter)",
                      parameters: { filter: this._filterTextbox.value } });
 
+    if (this._periodMenu.selectedItem)
+      filters.push({ expression: "received >= :startTime AND received < :endTime",
+                     parameters: { startTime: this._periodStartTime,
+                                     endTime: this._periodEndTime } });
+
     this._collection.filters = filters;
 
     this._collection.invalidate();
@@ -333,6 +394,11 @@
     
   },
 
+  onCommandPeriodMenu: function(event) {
+    this._updateURI();
+    this._applyFilters();
+  },
+
   _updateURI: function() {
     let params = [];
 
@@ -345,6 +411,8 @@
     if (this._columnsButton.checked)
       params.push("columns");
 
+    // FIXME: don't add the collection if it's the default All collection,
+    // but do add it if it's already in the list of params.
     if (this._collection.id)
       params.push("collection=" + this._collection.id);
     else if (this._collection.parent) {
@@ -355,6 +423,10 @@
     if (this._filterTextbox.value)
       params.push("filter=" + encodeURIComponent(this._filterTextbox.value));
 
+    // FIXME: do add the All period if it's already in the list of params.
+    if (this._periodMenu.selectedItem && this._periodMenu.selectedItem.value != "all")
+      params.push("period=" + encodeURIComponent(this._periodMenu.selectedItem.value));
+
     let gBrowserWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).
                          getInterface(Ci.nsIWebNavigation).
                          QueryInterface(Ci.nsIDocShellTreeItem).
--- a/content/river.xul	Sun Oct 12 21:30:14 2008 -0700
+++ b/content/river.xul	Tue Oct 14 11:34:46 2008 -0700
@@ -83,6 +83,16 @@
                     oncommand="SnowlMessageView.onCommandColumnsButton(event)"
                     tooltiptext="&columnsButton.tooltip;"/>
 
+        <menulist id="periodMenu" oncommand="SnowlMessageView.onCommandPeriodMenu(event)">
+          <menupopup id="periodMenuPopup">
+            <menuitem label="&periodAll.label;" value="all" selected="true"/>
+            <menuitem label="&periodToday.label;" value="today"/>
+            <menuitem label="&periodYesterday.label;" value="yesterday"/>
+            <menuitem label="&periodLast7Days.label;" value="last7days"/>
+            <menuitem label="&periodLast30Days.label;" value="last30days"/>
+          </menupopup>
+        </menulist>
+
         <spacer flex="1"/>
 
         <!-- FIXME: change type="timed" to type="search" once we no longer
--- a/locale/en-US/river.dtd	Sun Oct 12 21:30:14 2008 -0700
+++ b/locale/en-US/river.dtd	Tue Oct 14 11:34:46 2008 -0700
@@ -4,3 +4,9 @@
 <!ENTITY orderButton.tooltip          "Reverse the order of the messages.">
 <!ENTITY columnsButton.tooltip        "Show the messages in columns.">
 <!ENTITY filterTextbox.emptytext      "Search Messages">
+
+<!ENTITY periodAll.label              "All">
+<!ENTITY periodToday.label            "Today">
+<!ENTITY periodYesterday.label        "Yesterday">
+<!ENTITY periodLast7Days.label        "Last 7 Days">
+<!ENTITY periodLast30Days.label       "Last 30 Days">
--- a/modules/utils.js	Sun Oct 12 21:30:14 2008 -0700
+++ b/modules/utils.js	Tue Oct 14 11:34:46 2008 -0700
@@ -126,6 +126,11 @@
     get name() { return SnowlUtils.days[this.epoch.getDay()] }
   },
 
+  twentyNineDaysAgo: {
+    get epoch() { return new Date(SnowlUtils.today - (msInDay * 29)) },
+    get name() { return "Twenty Nine Days Ago" }
+  },
+
   /**
    * Formats a date for human consumption using the date formatting service
    * for locale-specific formatting along with some additional smarts for more