Diff
Not logged in

Differences From:

File src/timeline.c part of check-in [4d03017923] - Put a colored asterisk beside entries of interest in the timeline, rather than doing lots of annoying text color and background changes. by drh on 2007-08-30 21:37:42. [view]

To:

File src/timeline.c part of check-in [e15fe43153] - A new decendent finding algorithm is (hopefully) faster. Changes to the timeline are in process and might not yet work. by drh on 2007-08-31 20:14:33. [view]

@@ -88,14 +88,20 @@
 **    7.  True if is a leaf
 */
 void www_print_timeline(
   Stmt *pQuery,
-  char *zLastDate,
+  int *pFirstEvent,
+  int *pLastEvent,
   int (*xCallback)(int, Blob*),
   Blob *pArg
  ){
   char zPrevDate[20];
   zPrevDate[0] = 0;
+  int cnt = 0;
+  db_multi_exec(
+     "CREATE TEMP TABLE IF NOT EXISTS seen(rid INTEGER PRIMARY KEY);"
+     "DELETE FROM seen;"
+  );
   @ <table cellspacing=0 border=0 cellpadding=0>
   while( db_step(pQuery)==SQLITE_ROW ){
     int rid = db_column_int(pQuery, 0);
     const char *zUuid = db_column_text(pQuery, 1);
@@ -102,8 +108,15 @@
     int nPChild = db_column_int(pQuery, 5);
     int nParent = db_column_int(pQuery, 6);
     int isLeaf = db_column_int(pQuery, 7);
     const char *zDate = db_column_text(pQuery, 2);
+    if( cnt==0 && pFirstEvent ){
+      *pFirstEvent = rid;
+    }
+    if( pLastEvent ){
+      *pLastEvent = rid;
+    }
+    db_multi_exec("INSERT OR IGNORE INTO seen VALUES(%d)", rid);
     if( xCallback ){
       xCallback(rid, pArg);
     }
     if( memcmp(zDate, zPrevDate, 10) ){
@@ -133,11 +146,8 @@
       @ <b>Leaf</b>
     }
     @ %h(db_column_text(pQuery,3))
     @ (by %h(db_column_text(pQuery,4)))</td></tr>
-    if( zLastDate ){
-      strcpy(zLastDate, zDate);
-    }
   }
   @ </table>
 }
 
@@ -173,16 +183,31 @@
 }
 
 /*
 ** WEBPAGE: timeline
+**
+** Query parameters:
+**
+**    d=STARTDATE    date in iso8601 notation.          dflt: newest event
+**    n=INTEGER      number of events to show.          dflt: 25
+**    e=INTEGER      starting event id.                 dflt: nil
+**    u=NAME         show only events from user.        dflt: nil
+**    a              show events after and including.   dflt: false
+**    r              show only related events.          dflt: false
 */
 void page_timeline(void){
   Stmt q;
   char *zSQL;
   Blob scriptInit;
   char zDate[100];
   const char *zStart = P("d");
-  int nEntry = atoi(PD("n","25"));
+  int nEntry = atoi(PD("n","20"));
+  const char *zUser = P("u");
+  int objid = atoi(PD("e","0"));
+  int relatedEvents = P("r")!=0;
+  int afterFlag = P("a")!=0;
+  int firstEvent;
+  int lastEvent;
 
   /* To view the timeline, must have permission to read project data.
   */
   login_check_credentials();
@@ -203,21 +228,33 @@
     "       NOT EXISTS (SELECT 1 FROM plink WHERE pid=blob.rid)"
     "  FROM event, blob"
     " WHERE event.type='ci' AND blob.rid=event.objid"
   );
+  if( zUser ){
+    zSQL = mprintf("%z AND event.user=%Q", zSQL, zUser);
+  }
+  if( objid ){
+    char *z = db_text(0, "SELECT datetime(event.mtime) FROM event"
+                         " WHERE objid=%d", objid);
+    if( z ){
+      zStart = z;
+    }
+  }
   if( zStart ){
     while( isspace(zStart[0]) ){ zStart++; }
     if( zStart[0] ){
-      zSQL = mprintf("%z AND event.mtime<=julianday(%Q, 'localtime')",
-                      zSQL, zStart);
+      zSQL = mprintf("%z AND event.mtime %s julianday(%Q, 'localtime')",
+                      zSQL, afterFlag ? ">=" : "<=", zStart);
     }
   }
   zSQL = mprintf("%z ORDER BY event.mtime DESC LIMIT %d", zSQL, nEntry);
   db_prepare(&q, zSQL);
   free(zSQL);
   zDate[0] = 0;
   blob_zero(&scriptInit);
-  www_print_timeline(&q, zDate, save_parentage_javascript, &scriptInit);
+  zDate[0] = 0;
+  www_print_timeline(&q, &firstEvent, &lastEvent,
+                     save_parentage_javascript, &scriptInit);
   db_finalize(&q);
   if( zStart==0 ){
     zStart = zDate;
   }