278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
if( nTag>0 ){
int i;
for(i=0; i<nTag; i++){
@ <b>%s(azTag[i])%s(i==nTag-1?"":",")</b>
}
}
if( pGraph ){
int nParent = 0;
int aParent[32];
const char *zBr;
static Stmt qparent;
static Stmt qbranch;
db_static_prepare(&qparent,
"SELECT pid FROM plink WHERE cid=:rid ORDER BY isprim DESC"
);
db_static_prepare(&qbranch,
"SELECT value FROM tagxref WHERE tagid=%d AND tagtype>0 AND rid=:rid",
TAG_BRANCH
);
db_bind_int(&qparent, ":rid", rid);
while( db_step(&qparent)==SQLITE_ROW && nParent<32 ){
aParent[nParent++] = db_column_int(&qparent, 0);
}
db_reset(&qparent);
db_bind_int(&qbranch, ":rid", rid);
if( db_step(&qbranch)==SQLITE_ROW ){
zBr = db_column_text(&qbranch, 0);
}else{
zBr = "trunk";
}
graph_add_row(pGraph, rid, isLeaf, nParent, aParent, zBr);
db_reset(&qbranch);
}
}else if( (tmFlags & TIMELINE_ARTID)!=0 ){
hyperlink_to_uuid(zUuid);
}
db_column_blob(pQuery, commentColumn, &comment);
if( mxWikiLen>0 && blob_size(&comment)>mxWikiLen ){
Blob truncated;
blob_zero(&truncated);
|
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
@ </td></tr>
}
if( suppressCnt ){
@ <tr><td><td><td>
@ <small><i>... %d(suppressCnt) similar
@ event%s(suppressCnt>1?"s":"") omitted.</i></small></tr>
suppressCnt = 0;
}
if( pGraph ){
graph_finish(pGraph);
if( pGraph->nErr ){
graph_free(pGraph);
pGraph = 0;
}else{
@ <tr><td><td><div style="width:%d(pGraph->mxRail*20+30)px;"></div>
}
}
@ </table>
if( pGraph && pGraph->nErr==0 ){
GraphRow *pRow;
int i;
char cSep;
@ <script type="text/JavaScript">
cgi_printf("var rowinfo = [\n");
for(pRow=pGraph->pFirst; pRow; pRow=pRow->pNext){
cgi_printf("{id:\"m%d\",r:%d,d:%d,mo:%d,mu:%d,u:%d,au:",
pRow->rid,
pRow->iRail,
pRow->bDescender,
pRow->mergeOut,
pRow->mergeUpto,
pRow->aiRaiser[pRow->iRail]
);
cSep = '[';
for(i=0; i<GR_MAX_RAIL; i++){
if( i==pRow->iRail ) continue;
if( pRow->aiRaiser[i]>0 ){
cgi_printf("%c%d,%d", cSep, pGraph->railMap[i], pRow->aiRaiser[i]);
cSep = ',';
}
}
if( cSep=='[' ) cgi_printf("[");
cgi_printf("],mi:");
cSep = '[';
for(i=0; i<GR_MAX_RAIL; i++){
if( pRow->mergeIn & (1<<i) ){
cgi_printf("%c%d", cSep, pGraph->railMap[i]);
cSep = ',';
}
}
if( cSep=='[' ) cgi_printf("[");
cgi_printf("]}%s", pRow->pNext ? ",\n" : "];\n");
}
cgi_printf("var nrail = %d\n", pGraph->mxRail+1);
graph_free(pGraph);
@ var canvasDiv = document.getElementById("canvas");
@ function drawBox(color,x0,y0,x1,y1){
@ var n = document.createElement("div");
@ if( x0>x1 ){ var t=x0; x0=x1; x1=t; }
@ if( y0>y1 ){ var t=y0; y0=y1; y1=t; }
@ var w = x1-x0+1;
@ var h = y1-y0+1;
@ n.setAttribute("style",
@ "position:absolute;"+
@ "left:"+x0+"px;"+
@ "top:"+y0+"px;"+
@ "width:"+w+"px;"+
@ "height:"+h+"px;"+
@ "background-color:"+color+";"
@ );
@ canvasDiv.appendChild(n);
@ }
@ function absoluteY(id){
@ var obj = document.getElementById(id);
@ if( !obj ) return;
@ var top = 0;
@ if( obj.offsetParent ){
@ do{
@ top += obj.offsetTop;
@ }while( obj = obj.offsetParent );
@ }
@ return top;
@ }
@ function absoluteX(id){
@ var obj = document.getElementById(id);
@ if( !obj ) return;
@ var left = 0;
@ if( obj.offsetParent ){
@ do{
@ left += obj.offsetLeft;
@ }while( obj = obj.offsetParent );
@ }
@ return left;
@ }
@ function drawUpArrow(x,y0,y1){
@ drawBox("black",x,y0,x+1,y1);
@ if( y0+8>=y1 ){
@ drawBox("black",x-1,y0+1,x+2,y0+2);
@ drawBox("black",x-2,y0+3,x+3,y0+4);
@ }else{
@ drawBox("black",x-1,y0+2,x+2,y0+4);
@ drawBox("black",x-2,y0+5,x+3,y0+7);
@ }
@ }
@ function drawThinArrow(y,xFrom,xTo){
@ if( xFrom<xTo ){
@ drawBox("black",xFrom,y,xTo,y);
@ drawBox("black",xTo-4,y-1,xTo-2,y+1);
@ if( xTo>xFrom-8 ) drawBox("black",xTo-6,y-2,xTo-5,y+2);
@ }else{
@ drawBox("black",xTo,y,xFrom,y);
@ drawBox("black",xTo+2,y-1,xTo+4,y+1);
@ if( xTo+8<xFrom ) drawBox("black",xTo+5,y-2,xTo+6,y+2);
@ }
@ }
@ function drawThinLine(x0,y0,x1,y1){
@ drawBox("black",x0,y0,x1,y1);
@ }
@ function drawNode(p, left, btm){
@ drawBox("black",p.x-5,p.y-5,p.x+6,p.y+6);
@ drawBox("white",p.x-4,p.y-4,p.x+5,p.y+5);
@ if( p.u>0 ){
@ var u = rowinfo[p.u-1];
@ drawUpArrow(p.x, u.y+6, p.y-5);
@ }
@ if( p.d ){
@ drawUpArrow(p.x, p.y+6, btm);
@ }
@ if( p.mo>=0 ){
@ var x1 = p.mo*20 + left;
@ var y1 = p.y-3;
@ var x0 = x1>p.x ? p.x+7 : p.x-6;
@ var u = rowinfo[p.mu-1];
@ var y0 = u.y+5;
@ drawThinLine(x0,y1,x1,y1);
@ drawThinLine(x1,y0,x1,y1);
@ }
@ var n = p.au.length;
@ for(var i=0; i<n; i+=2){
@ var x1 = p.au[i]*20 + left;
@ var x0 = x1>p.x ? p.x+7 : p.x-6;
@ drawBox("black",x0,p.y,x1,p.y+1);
@ var u = rowinfo[p.au[i+1]-1];
@ drawUpArrow(x1, u.y+6, p.y);
@ }
@ for(var j in p.mi){
@ var y0 = p.y+5;
@ var mx = p.mi[j]*20 + left;
@ if( mx>p.x ){
@ drawThinArrow(y0,mx,p.x+5);
@ }else{
@ drawThinArrow(y0,mx,p.x-5);
@ }
@ }
@ }
@ function renderGraph(){
@ var canvasY = absoluteY("canvas");
@ var left = absoluteX(rowinfo[0].id) - absoluteX("canvas") + 15;
@ for(var i in rowinfo){
@ rowinfo[i].y = absoluteY(rowinfo[i].id) + 10 - canvasY;
@ rowinfo[i].x = left + rowinfo[i].r*20;
@ }
@ var btm = rowinfo[rowinfo.length-1].y + 20;
@ for(var i in rowinfo){
@ drawNode(rowinfo[i], left, btm);
@ }
@ }
@ renderGraph();
@ </script>
}
}
/*
** Create a temporary table suitable for storing timeline data.
*/
static void timeline_temp_table(void){
static const char zSql[] =
|
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
|
887
888
889
890
891
892
893
894
895
896
897
898
899
900
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
}
blob_zero(&sql);
db_prepare(&q, "SELECT * FROM timeline ORDER BY timestamp DESC");
@ <h2>%b(&desc)</h2>
blob_reset(&desc);
www_print_timeline(&q, tmFlags, 0);
db_finalize(&q);
@ <script>
@ var parentof = new Object();
@ var childof = new Object();
db_prepare(&q, "SELECT rid FROM seen");
while( db_step(&q)==SQLITE_ROW ){
int rid = db_column_int(&q, 0);
Stmt q2;
const char *zSep;
Blob *pOut = cgi_output_blob();
db_prepare(&q2, "SELECT pid FROM plink WHERE cid=%d", rid);
zSep = "";
blob_appendf(pOut, "parentof[\"m%d\"] = [", rid);
while( db_step(&q2)==SQLITE_ROW ){
int pid = db_column_int(&q2, 0);
blob_appendf(pOut, "%s\"m%d\"", zSep, pid);
zSep = ",";
}
db_finalize(&q2);
blob_appendf(pOut, "];\n");
db_prepare(&q2, "SELECT cid FROM plink WHERE pid=%d", rid);
zSep = "";
blob_appendf(pOut, "childof[\"m%d\"] = [", rid);
while( db_step(&q2)==SQLITE_ROW ){
int pid = db_column_int(&q2, 0);
blob_appendf(pOut, "%s\"m%d\"", zSep, pid);
zSep = ",";
}
db_finalize(&q2);
blob_appendf(pOut, "];\n");
}
db_finalize(&q);
@ function setall(value){
@ for(var x in parentof){
@ setone(x,value);
@ }
@ }
@ setall("#ffffff");
@ function setone(id, clr){
@ if( parentof[id]==null ) return 0;
@ var w = document.getElementById(id);
@ if( w.style.color==clr ){
@ return 0
@ }else{
@ w.style.color = clr
@ return 1
@ }
@ }
@ function xin(id) {
@ setall("#ffffff");
@ setone(id,"#ff0000");
@ set_children(id, "#b0b0b0");
@ set_parents(id, "#b0b0b0");
@ for(var x in parentof[id]){
@ var pid = parentof[id][x]
@ var w = document.getElementById(pid);
@ if( w!=null ){
@ w.style.color = "#000000";
@ }
@ }
@ for(var x in childof[id]){
@ var cid = childof[id][x]
@ var w = document.getElementById(cid);
@ if( w!=null ){
@ w.style.color = "#000000";
@ }
@ }
@ }
@ function xout(id) {
@ /* setall("#000000"); */
@ }
@ function set_parents(id, clr){
@ var plist = parentof[id];
@ if( plist==null ) return;
@ for(var x in plist){
@ var pid = plist[x];
@ if( setone(pid,clr)==1 ){
@ set_parents(pid,clr);
@ }
@ }
@ }
@ function set_children(id,clr){
@ var clist = childof[id];
@ if( clist==null ) return;
@ for(var x in clist){
@ var cid = clist[x];
@ if( setone(cid,clr)==1 ){
@ set_children(cid,clr);
@ }
@ }
@ }
@ </script>
style_footer();
}
/*
** The input query q selects various records. Print a human-readable
** summary of those records.
**
|