[Zope-CVS] CVS: Packages/Moztop/moztop/content/StatusBar - LogManager.js:1.2 TaskManager.js:1.8 TasksOverlay.xul:1.4

Stephan Richter srichter@cbu.edu
Sat, 15 Mar 2003 12:15:51 -0500


Update of /cvs-repository/Packages/Moztop/moztop/content/StatusBar
In directory cvs.zope.org:/tmp/cvs-serv17198/moztop/content/StatusBar

Modified Files:
	LogManager.js TaskManager.js TasksOverlay.xul 
Log Message:
- Cleaned up LogManager a bit more.
- Reimplemented TaskManager based on LogManager
- Implemented dump() function, so that the logmanager gets them, since the
  default dump() implementation does not work for me and Sidnei.


=== Packages/Moztop/moztop/content/StatusBar/LogManager.js 1.1 => 1.2 ===
--- Packages/Moztop/moztop/content/StatusBar/LogManager.js:1.1	Sat Mar 15 11:28:23 2003
+++ Packages/Moztop/moztop/content/StatusBar/LogManager.js	Sat Mar 15 12:15:50 2003
@@ -68,8 +68,8 @@
     logmessages.builder.rebuild();
     
     // Create a log message on startup
-    this.addMessage("startup","TaskManager.attachDataSource", 
-                    "Moztop started");
+    this.addMessage("Init Log Manager","LogManager.attachDataSource", 
+                    "Initializing Log Manager.");
     return;
 }
 
@@ -121,6 +121,18 @@
 		      "viewlogmessage", "chrome", msg.getValue());
 }
 
+function dump(msg) {
+    /* Convinience function to allow dump calls to be redirected to the Log
+    Manager. */
+    var MAXTITLELENGTH = 40;
+    if (msg.length < MAXTITLELENGTH) 
+	title = msg;
+    else
+	title = msg.slice(0, MAXTITLELENGTH)+"..."
+
+    logmanager.addMessage(title, "", msg);
+}
+
 
 /* Initialize the data in the tree object. */
 function initLogManager() {
@@ -128,3 +140,4 @@
     logmanager = LogManager();
     logmanager.attachDataSource();
 }
+


=== Packages/Moztop/moztop/content/StatusBar/TaskManager.js 1.7 => 1.8 ===
--- Packages/Moztop/moztop/content/StatusBar/TaskManager.js:1.7	Sat Mar 15 11:28:23 2003
+++ Packages/Moztop/moztop/content/StatusBar/TaskManager.js	Sat Mar 15 12:15:50 2003
@@ -17,71 +17,121 @@
 
 ******************************************************************************/
 
-/* Initialize Tasks datasource. */
-var tasks_source =
-  Components
-  .classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"]
-  .createInstance(Components.interfaces.nsIRDFDataSource);
+/* Now subclass, then add methods */
+TaskManager.prototype = new DataSourceManager();
+TaskManager.prototype.constructor = TaskManager;
+TaskManager.superclass = DataSourceManager;
+
+function TaskManager () {
+
+    /* This prototype manages interaction with the log viewer.  
+       It creates an RDFDataSource from rdfds.js, grabs the 
+       existing datasource from the logmessages-tree.  It also 
+       knows how to add messages and view the selected message.
+       Finally, it has a method for viewing the RDF contents in 
+       a popup text box. */
+
+    // Initialization preocess
+    if( !(this instanceof TaskManager) )
+	return new TaskManager( );
+    DataSourceManager.call(this);
+
+    this.id = 0
+
+    // Grep the right resource URL for storing it at the right place
+    this.profileurl = this.getProfileDirURL();
+
+    // Initialize RDF data source
+    this.elementid = "tasks-tree";
+    this.ds = new RDFDataSource();
+    this.urn = "urn:moztop:tasks";
+
+    // Define namespaces required for this RDF graph
+    this.dcns = "http://www.purl.org/dc/1.1#";
+    this.zoperdfns = "http://www.zope.org/rdf#";
+    this.ncns ="http://home.netscape.com/NC-rdf#";
+
+    // Setup tasks property names
+    this.idprop = this.dcns + "id";
+    this.titleprop = this.dcns + "title";
+    this.descriptionprop = this.dcns + "description";
+    this.timeprop = this.zoperdfns + "time";
+    this.statusprop = this.zoperdfns + "status";
+}
+
+
+TaskManager.prototype.attachDataSource = function()  {
+    /* Called once when tasks manager is first loaded */
+    var lms = this.ds.getNode(this.urn);
+    lms.makeSeq();
+    
+    // Now attach the datasource
+    var tasks = document.getElementById(this.elementid);
+    tasks.database.AddDataSource(this.ds.getRawDataSource());
+    tasks.builder.rebuild();
+    
+    // Create a log message on startup
+    logmanager.addMessage("Init Task Manager","TaskManager.attachDataSource", 
+                          "Task Manager has been initialized.");
+}
+
+
+TaskManager.prototype.addTask = function(title, description, status) {
+    /* Add a task to the manager; description and status is optional. 
+    */
+    // Create id of task
+    id++;
+    id = this.id;
+
+    // Create task start date
+    var date = new Date();
+    var now = date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
+
+    // If there was no status passed, make it "In progress"
+    if (!status)
+	status = "In progress";
+
+    // Create new RDF message node in graph
+    var rootnode = this.ds.getNode(this.urn);
+    var task = this.ds.getNode(this.urn + ":" + id);
+
+    // Add a new log message to the RDF graph.
+    rootnode.addChild(task);
+    task.addTarget(this.idprop, id);
+    task.addTarget(this.titleprop, title);
+    task.addTarget(this.descriptionprop, description);
+    task.addTarget(this.status, status);
+    task.addTarget(this.timeprop, now);
+}
+
+
+TaskManager.prototype.deleteTask = function(id) {
+    this.ds.deleteRecursive(this.urn + ":" + id);
+}
+
+
+TaskManager.prototype.viewSelectedTask = function() {
+    /* When a user doubleclicks on a task in the tree, this 
+       is called.  It finds the selected item in the tree 
+       and pops up a dialog box with the contents of the task. */
+
+    var tree = document.getElementById(this.elementid);
+    var index = tree.view.selection.currentIndex;
+    var rdf = tree.view.getItemAtIndex(index).resource;
+    
+    // Grab the RDF value and popup a dialog window
+    var node = this.ds.getNode(rdf.Value);
+    var task = node.getTarget(this.messageprop);
+    window.openDialog("chrome://moztop/content/StatusBar/LogMessageDialog.xul",
+		      "viewtask", "chrome", task.getValue());
+}
+
 
 /* Initialize the data in the tree object. */
-function initTaskList() {
-    var tree = document.getElementById("tasks-tree");
-    tree.database.AddDataSource(tasks_source);
-    tree.setAttribute("ref", "urn:tasks:data");
-    addTask('init', 'Initial Task', 'done');
-}
-
-/* This will remember the index of the last child we've added. */
-var taskCount = 0;
-
-/* Add a task to the manager. */
-function addTask(name, descr, status) {
-    tasks_source.Assert(RDF.GetResource("urn:tasks:task" + taskCount),
-              RDF.GetResource("http://www.zope.org/rdf/task#id"),
-              RDF.GetLiteral(taskCount),
-              true);
-
-    tasks_source.Assert(RDF.GetResource("urn:tasks:task" + taskCount),
-              RDF.GetResource("http://www.zope.org/rdf/task#name"),
-              RDF.GetLiteral(name),
-              true);
-
-    tasks_source.Assert(RDF.GetResource("urn:tasks:task" + taskCount),
-              RDF.GetResource("http://www.zope.org/rdf/task#descr"),
-              RDF.GetLiteral(descr),
-              true);
-
-    tasks_source.Assert(RDF.GetResource("urn:tasks:task" + taskCount),
-              RDF.GetResource("http://www.zope.org/rdf/task#status"),
-              RDF.GetLiteral(status),
-              true);
-
-    tasks_source.Assert(RDF.GetResource("urn:tasks:data"),
-              RDF.GetResource("http://www.zope.org/rdf/task#child"),
-              RDF.GetResource("urn:tasks:task" + taskCount),
-              true);
-
-    ++taskCount;
-}
-
-/* Delete a task from the manager. */
-function deleteSelectedTask() {
-    var tree = document.getElementById("tasks-tree");
-    var start = new Object();
-    var end = new Object();
-    var source = new Object();
-    var numRanges = tree.view.selection.getRangeCount();
-
-    for (var t=0; t<numRanges; t++){
-        tree.view.selection.getRangeAt(t,start,end);
-        for (var v = start.value; v <= end.value; v++){
-	    var builder = tree.builder.QueryInterface(
-                              Components.interfaces.nsIXULTreeBuilder)
-            rdf = builder.getResourceAtIndex(v)
-            tasks_source.Unassert(RDF.GetResource("urn:tasks:data"),
-                        RDF.GetResource("http://www.zope.org/rdf/task#child"),
-                        RDF.GetResource(rdf.Value));
-        }
-    }
+function initTaskManager() {
+    // Remember that logmanager was defined globally, but not initialized.
+    taskmanager = TaskManager();
+    taskmanager.attachDataSource();
 }
+
 


=== Packages/Moztop/moztop/content/StatusBar/TasksOverlay.xul 1.3 => 1.4 ===
--- Packages/Moztop/moztop/content/StatusBar/TasksOverlay.xul:1.3	Sat Feb 15 06:01:59 2003
+++ Packages/Moztop/moztop/content/StatusBar/TasksOverlay.xul	Sat Mar 15 12:15:50 2003
@@ -24,7 +24,7 @@
             <treerow>
               <treecell label="rdf:http://www.zope.org/rdf/task#id"/>
               <treecell label="rdf:http://www.zope.org/rdf/task#name"/>
-              <treecell label="rdf:http://www.zope.org/rdf/task#descr"/>
+              <treecell label="rdf:http://www.zope.org/rdf/task#description"/>
               <treecell label="rdf:http://www.zope.org/rdf/task#status"/>
             </treerow>
           </treeitem>