changeset 171:33bed6f476ae

make the list view reflect a group selection in the sidebar
author Myk Melez <myk@mozilla.org>
date Wed, 16 Jul 2008 16:41:43 -0700
parents 52f9006fdbe3
children 3ec4ba145105
files extension/content/sidebar.js extension/content/snowl.js extension/modules/collection.js
diffstat 3 files changed, 48 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/extension/content/sidebar.js	Wed Jul 16 14:01:08 2008 -0700
+++ b/extension/content/sidebar.js	Wed Jul 16 16:41:43 2008 -0700
@@ -158,10 +158,10 @@
     else if (this._group == "person")
       this._model = SnowlPerson.getAll();
 */
-    let foo = new SnowlCollection();
-    foo.nameGroupField = "sources.name";
-    foo.uriGroupField = "sources.humanURI";
-    this._model = foo.groups;
+    this._collection = new SnowlCollection();
+    this._collection.nameGroupField = "sources.name";
+    this._collection.uriGroupField = "sources.humanURI";
+    this._model = this._collection.groups;
 
 /*
     this._model.unshift({ name: "All",
@@ -173,8 +173,8 @@
     if (this._tree.currentIndex == -1)
       return;
     
-    let id = this._model[this._tree.currentIndex].id;
-    gBrowserWindow.SnowlView.setGroupID(id);
+    let name = this._model[this._tree.currentIndex].name;
+    gBrowserWindow.SnowlView.setCollection(this._collection.getGroup(name));
   },
 
   onClick: function(aEvent) {
--- a/extension/content/snowl.js	Wed Jul 16 14:01:08 2008 -0700
+++ b/extension/content/snowl.js	Wed Jul 16 16:41:43 2008 -0700
@@ -210,6 +210,11 @@
     this._rebuildView();
   },
 
+  setCollection: function(collection) {
+    this._collection = collection;
+    this._rebuildView();
+  },
+
   _rebuildView: function() {
     // Since the number of rows might have changed, we rebuild the view
     // by reinitializing it instead of merely invalidating the box object
--- a/extension/modules/collection.js	Wed Jul 16 14:01:08 2008 -0700
+++ b/extension/modules/collection.js	Wed Jul 16 16:41:43 2008 -0700
@@ -32,6 +32,7 @@
   this._filter = aFilter;
   this._current = aCurrent;
   this._read = aRead;
+  this.conditions = [];
 }
 
 SnowlCollection.prototype = {
@@ -143,6 +144,12 @@
     return this._groups = groups;
   },
 
+  getGroup: function(name) {
+    let group = new SnowlCollection(this.sourceID, this.filter, this.current, this.read, this.authorID);
+    group.conditions.push({ column: this.nameGroupField, value: name });
+    return group;
+  },
+
   _generateGetGroupsStatement: function() {
     let query = 
       "SELECT DISTINCT(" + this.nameGroupField + ") AS name, " +
@@ -150,6 +157,29 @@
       "FROM sources JOIN messages ON sources.id = messages.sourceID " +
       "LEFT JOIN people AS authors ON messages.authorID = authors.id";
 
+    let conditions = this._generateConditions();
+    if (conditions.length > 0)
+      query += " WHERE " + conditions.join(" AND ");
+
+    query += " ORDER BY " + this.nameGroupField;
+
+    this._log.info("groups query: " + query);
+
+    let statement = SnowlDatastore.createStatement(query);
+
+    if (this.sourceID)
+      statement.params.sourceID = this.sourceID;
+
+    if (this.authorID)
+      statement.params.authorID = this.authorID;
+
+    if (this.filter)
+      statement.params.filter = this.filter;
+
+    return statement;
+  },
+
+  _generateConditions: function() {
     let conditions = [];
 
     if (this.sourceID)
@@ -169,25 +199,7 @@
     if (typeof this.read != "undefined")
       conditions.push("read = " + (this.read ? "1" : "0"));
 
-    if (conditions.length > 0)
-      query += " WHERE " + conditions.join(" AND ");
-
-    query += " ORDER BY " + this.nameGroupField;
-
-    this._log.info("groups query: " + query);
-
-    let statement = SnowlDatastore.createStatement(query);
-
-    if (this.sourceID)
-      statement.params.sourceID = this.sourceID;
-
-    if (this.authorID)
-      statement.params.authorID = this.authorID;
-
-    if (this.filter)
-      statement.params.filter = this.filter;
-
-    return statement;
+    return conditions;
   },
 
 
@@ -292,6 +304,12 @@
     if (typeof this.read != "undefined")
       conditions.push("read = " + (this.read ? "1" : "0"));
 
+    // FIXME: allow specification of the operator as well.
+    // FIXME: use parameter binding.
+    if (this.conditions)
+      for each (let condition in this.conditions)
+        conditions.push(condition.column + " = '" + condition.value + "'");
+
     if (conditions.length > 0)
       query += " WHERE " + conditions.join(" AND ");