Diff
Not logged in

Differences From:

File src/timeline.c part of check-in [5e2392307d] - Turn tags into properties. Allow properties to control background color on timelines. Still experimental. by drh on 2007-09-22 01:40:39. [view]

To:

File src/timeline.c part of check-in [9395aba4f4] - Timeline now responses to comment and user properties. by drh on 2007-09-22 12:38:05. [view]

@@ -76,9 +76,9 @@
 }
 
 /*
 ** Output a timeline in the web format given a query.  The query
-** should return 4 columns:
+** should return these columns:
 **
 **    0.  rid
 **    1.  UUID
 **    2.  Date/Time
@@ -190,8 +190,42 @@
   return 0;
 }
 
 /*
+** Return a pointer to a constant string that forms the basis
+** for a timeline query for the WWW interface.
+*/
+const char *timeline_query_for_www(void){
+  static const char zBaseSql[] =
+    @ SELECT
+    @   blob.rid,
+    @   uuid,
+    @   datetime(event.mtime,'localtime'),
+    @   coalesce((SELECT value FROM tagxref
+    @              WHERE rid=blob.rid
+    @                AND tagid=(SELECT tagid FROM tag WHERE tagname='comment')),
+    @            comment),
+    @   coalesce((SELECT value FROM tagxref
+    @              WHERE rid=blob.rid
+    @                AND tagid=(SELECT tagid FROM tag WHERE tagname='user')),
+    @            user),
+    @   (SELECT count(*) FROM plink WHERE pid=blob.rid AND isprim=1),
+    @   (SELECT count(*) FROM plink WHERE cid=blob.rid),
+    @   NOT EXISTS (SELECT 1 FROM plink WHERE pid=blob.rid),
+    @   (SELECT value FROM tagxref
+    @     WHERE rid=blob.rid
+    @       AND tagid=(SELECT tagid FROM tag WHERE tagname='bgcolor')
+    @    UNION ALL
+    @    SELECT value FROM tagxref
+    @     WHERE rid=blob.rid
+    @       AND tagid=(SELECT tagid FROM tag WHERE tagname='br-bgcolor'))
+    @  FROM event JOIN blob
+    @ WHERE blob.rid=event.objid
+  ;
+  return zBaseSql;
+}
+
+/*
 ** WEBPAGE: timeline
 **
 ** Query parameters:
 **
@@ -214,36 +248,23 @@
   int relatedEvents = P("r")!=0;
   int afterFlag = P("a")!=0;
   int firstEvent;
   int lastEvent;
-  int clr1, clr2;     /* Tag IDs for specifying background colors */
 
   /* To view the timeline, must have permission to read project data.
   */
   login_check_credentials();
   if( !g.okRead ){ login_needed(); return; }
 
   style_header("Timeline");
-  clr1 = db_int(0, "SELECT tagid FROM tag WHERE tagname='br-bg-color'");
-  clr2 = db_int(0, "SELECT tagid FROM tag WHERE tagname='bg-color'");
   if( !g.okHistory &&
       db_exists("SELECT 1 FROM user"
                 " WHERE login='anonymous'"
                 "   AND cap LIKE '%%h%%'") ){
     @ <p><b>Note:</b> You will be able to access <u>much</u> more
     @ historical information if <a href="%s(g.zBaseURL)/login">login</a>.</p>
   }
-  zSQL = mprintf(
-    "SELECT blob.rid, uuid, datetime(event.mtime,'localtime'), comment, user,"
-    "       (SELECT count(*) FROM plink WHERE pid=blob.rid AND isprim=1),"
-    "       (SELECT count(*) FROM plink WHERE cid=blob.rid),"
-    "       NOT EXISTS (SELECT 1 FROM plink WHERE pid=blob.rid),"
-    "       (SELECT value FROM tagxref WHERE rid=blob.rid AND tagid=%d"
-    "        UNION ALL"
-    "        SELECT value FROM tagxref WHERE rid=blob.rid AND tagid=%d)"
-    "  FROM event JOIN blob"
-    " WHERE event.type='ci' AND blob.rid=event.objid", clr2, clr1
-  );
+  zSQL = mprintf("%s", timeline_query_for_www());
   if( zUser ){
     zSQL = mprintf("%z AND event.user=%Q", zSQL, zUser);
   }
   if( objid ){
@@ -368,8 +389,17 @@
 ** The input query q selects various records.  Print a human-readable
 ** summary of those records.
 **
 ** Limit the number of entries printed to nLine.
+**
+** The query should return these columns:
+**
+**    0.  rid
+**    1.  uuid
+**    2.  Date/Time
+**    3.  Comment string and user
+**    4.  Number of non-merge children
+**    5.  Number of parents
 */
 void print_timeline(Stmt *q, int mxLine){
   int nLine = 0;
   char zPrevDate[20];
@@ -409,8 +439,36 @@
     }
     nLine += comment_print(zFree, 9, 79);
     sqlite3_free(zFree);
   }
+}
+
+/*
+** Return a pointer to a static string that forms the basis for
+** a timeline query for display on a TTY.
+*/
+const char *timeline_query_for_tty(void){
+  static const char zBaseSql[] =
+    @ SELECT
+    @   blob.rid,
+    @   uuid,
+    @   datetime(event.mtime,'localtime'),
+    @   coalesce((SELECT value FROM tagxref
+    @             WHERE rid=blob.rid
+    @             AND tagid=(SELECT tagid FROM tag WHERE tagname='comment')),
+    @            comment)
+    @     || ' (by ' ||
+    @     coalesce((SELECT value FROM tagxref
+    @               WHERE rid=blob.rid
+    @               AND tagid=(SELECT tagid FROM tag WHERE tagname='user')),
+    @              user)
+    @     || ')',
+    @   (SELECT count(*) FROM plink WHERE pid=blob.rid AND isprim),
+    @   (SELECT count(*) FROM plink WHERE cid=blob.rid)
+    @ FROM event, blob
+    @ WHERE blob.rid=event.objid
+  ;
+  return zBaseSql;
 }
 
 
 /*
@@ -493,17 +551,12 @@
       fossil_fatal("cannot compute descendents or ancestors of a date");
     }
     zDate = mprintf("(SELECT julianday(%Q, 'utc'))", zOrigin);
   }
-  zSQL = mprintf(
-    "SELECT blob.rid, uuid, datetime(event.mtime,'localtime'),"
-    "       comment || ' (by ' || user || ')',"
-    "       (SELECT count(*) FROM plink WHERE pid=blob.rid AND isprim),"
-    "       (SELECT count(*) FROM plink WHERE cid=blob.rid)"
-    "  FROM event, blob"
-    " WHERE event.type='ci' AND blob.rid=event.objid"
-    "   AND event.mtime %s %s",
-    (mode==1 || mode==4) ? "<=" : ">=", zDate
+  zSQL = mprintf("%s AND event.mtime %s %s",
+     timeline_query_for_tty(),
+     (mode==1 || mode==4) ? "<=" : ">=",
+     zDate
   );
   if( mode==3 || mode==4 ){
     db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
     if( mode==3 ){