Checklist

Check-in [ec491e5144]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Show individual change history on checklist items.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ec491e5144747e50c063bc359711ea1249e21672
User & Date: drh 2018-01-30 02:49:17
Context
2018-01-30
14:17
Show/hide history by clicking on the "(status user)" text. Set cursors on clickable text. check-in: 66716f8b1d user: drh tags: trunk
02:49
Show individual change history on checklist items. check-in: ec491e5144 user: drh tags: trunk
2018-01-29
22:38
Enable caching of javascript and CSS resources. check-in: d1e8bef86e user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to checklist.tcl.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
242
243
244
245
246
247
248

249
250
251
252
253
254
255
...
316
317
318
319
320
321
322



323
324
325
326
327
328
329
...
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
...
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

package require wapp

# Any unknown URL dispatches to this routine.  List all available
# checklists.
#
proc wapp-default {} {
  app-page-listing
}

# List all available checklists.
#
proc wapp-page-listing {} {
  global wapp DATADIR
  wapp-subst {<h1>Available Checklists</h1>\n}
................................................................................
      wapp-subst {</ol>\n}
      incr level -1
    }
    if {$level==1} {wapp-subst {<p>}}
    wapp-trim {
      <li id='item-%unsafe($itemid)'><span>%unsafe($txt)</span>
      <span class='ckuid' id='stat-%unsafe($itemid)'></span>

      <div class='ckcom' id='com-%unsafe($itemid)'></div></li>\n
    }
  }
  while {$level>0} {
    wapp-subst {</ol>\n}
    incr level -1
  }
................................................................................
      font-size: 80%;
      font-style: italic;
      white-space: pre;
    }
    span.ckuid {
      font-size: 80%;
    }



    div.mainmenu {
      text-align: center;
      border: 1px solid black;
      padding: 2ex;
    }
    div.mainmenu a {
      margin: 0 1.5ex;
................................................................................
        var x = jx[i];
        var name = "item-"+x.itemid
        var e = document.getElementById(name);
        if(!e) continue
        e.style.color = cklistClr(x.status);
        e = document.getElementById("stat-"+x.itemid);
        if(!e) continue;
        e.innerHTML = "(" + x.status + " by " + x.owner + ")";




        if( x.comment && x.comment.length>0 ){
          e = document.getElementById("com-"+x.itemid);
          e.innerHTML = x.comment;
        }
        if( editItem && editItem.id==name ){
          document.getElementById("editStatus").value = x.status;
          document.getElementById("editCom").value = x.comment;
        }
      }
    }
    cklistAjax('jstat',null,cklistApplyJstat);
    var userNode = document.getElementById("cklistUser");
    var userInfo = JSON.parse(userNode.textContent||userNode.innerText);
    if(userInfo.canWrite){



















      var editItem = null
      var editBox = document.getElementById("editBox");
      document.getElementById("mainCklist").onclick = function(event){
        var e = document.elementFromPoint(event.clientX,event.clientY);
        while(e && e.tagName!="LI"){

          if(e.id=="editForm") return false;










          if(e==editBox) return false;
          e = e.parentNode;
        }

        if(!e) return
        if(editItem) editItem.removeChild(editBox);
        if(e==editItem){
          editItem = null;
          return;
        }
        editBox.style.display = "block";
        editItem = e;

        editItem.appendChild(editBox);
        cklistAjax("jstat?itemid="+e.id.substr(5),null,cklistApplyJstat);
        document.getElementById("cancelBtn").onclick = function(event){
          event.stopPropagation();
          editItem.removeChild(editBox);
          editItem = null;
        }
        document.getElementById("applyBtn").onclick = function(event){
          var data = "update=" + editItem.id.substr(5);
          var e = document.getElementById("editStatus");
          data += "&status=" + escape(e.value);
          e = document.getElementById("editCom");
          data += "&comment=" + escape(e.value);
          cklistAjax("jstat",data,cklistApplyJstat);
          editItem.removeChild(editBox);
          editItem = null;
          event.stopPropagation();
        }
        document.getElementById("editForm").onsubmit = function(){
          return false;
        }
      }
    }
  }
  # wapp-subst {window.alert("Javascript loaded");\n}
}

# The /jstat page returns JSON that describes the current
................................................................................
                comment=$comment
          WHERE itemid=$update;
         INSERT INTO history(itemid,mtime,status,owner,comment)
          VALUES($update,julianday('now'),$status,$owner,$comment);
      }
    }
  }


  set sql {
    SELECT json_group_array(
       json_object('itemid', printf('%016llx',itemid),
                   'mtime', strftime('%s',mtime)+0,
                   'status', status,
                   'owner', owner,
                   'comment', comment))


      FROM ckitem
  }
  set itemid [wapp-param itemid]
  if {$itemid!="" && [scan $itemid %x itemid]==1} {
    append sql { WHERE itemid=$itemid}














  }

  wapp [db one $sql]
  db eval COMMIT
  db close
  # puts "jstat from $dbfile"
}

































# The /sql page for doing arbitrary SQL on the database.
# This page is accessible to the administrator only.
#
proc wapp-page-sql {} {
  global wapp
  if {[checklist-common-header]} return







|







 







>







 







>
>
>







 







|
>
>
>
>













|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
>
|
>
>
>
>
>
>
>
>
>
>
|
|
|
>
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<







 







>
>
|
|
|
|
|
|
|
>
>
|
|
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
...
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
...
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
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

package require wapp

# Any unknown URL dispatches to this routine.  List all available
# checklists.
#
proc wapp-default {} {
  wapp-page-listing
}

# List all available checklists.
#
proc wapp-page-listing {} {
  global wapp DATADIR
  wapp-subst {<h1>Available Checklists</h1>\n}
................................................................................
      wapp-subst {</ol>\n}
      incr level -1
    }
    if {$level==1} {wapp-subst {<p>}}
    wapp-trim {
      <li id='item-%unsafe($itemid)'><span>%unsafe($txt)</span>
      <span class='ckuid' id='stat-%unsafe($itemid)'></span>
      <span class='ckcnt' id='cnt-%unsafe($itemid)'></span>
      <div class='ckcom' id='com-%unsafe($itemid)'></div></li>\n
    }
  }
  while {$level>0} {
    wapp-subst {</ol>\n}
    incr level -1
  }
................................................................................
      font-size: 80%;
      font-style: italic;
      white-space: pre;
    }
    span.ckuid {
      font-size: 80%;
    }
    span.ckcnt {
      font-size: 80%;
    }
    div.mainmenu {
      text-align: center;
      border: 1px solid black;
      padding: 2ex;
    }
    div.mainmenu a {
      margin: 0 1.5ex;
................................................................................
        var x = jx[i];
        var name = "item-"+x.itemid
        var e = document.getElementById(name);
        if(!e) continue
        e.style.color = cklistClr(x.status);
        e = document.getElementById("stat-"+x.itemid);
        if(!e) continue;
        e.innerHTML = "(" + x.status + " " + x.owner + ")";
        if( x.chngcnt>1 ){
          document.getElementById("cnt-"+x.itemid).innerHTML =
              "(" + x.chngcnt + " changes)";
        }
        if( x.comment && x.comment.length>0 ){
          e = document.getElementById("com-"+x.itemid);
          e.innerHTML = x.comment;
        }
        if( editItem && editItem.id==name ){
          document.getElementById("editStatus").value = x.status;
          document.getElementById("editCom").value = x.comment;
        }
      }
    }
    cklistAjax('jstat',null,cklistApplyJstat);
    var userNode = document.getElementById("cklistUser");
    var userInfo = JSON.parse(userNode.textContent||userNode.innerText);
    function historyOff(itemid){ 
      var e = document.getElementById("hist-"+itemid);
      if(e) e.parentNode.removeChild(e);
    }
    function historyOn(itemid){
      var req = new XMLHttpRequest
      req.open("GET","history?itemid="+itemid,true);
      req.onreadystatechange = function(){
        if(req.readyState!=4) return
        var lx = document.getElementById("item-"+itemid);
        var tx = document.createElement("DIV");
        tx.id = "hist-"+itemid;
        tx.style.borderWidth = 1
        tx.style.borderColor = "black"
        tx.style.borderStyle = "solid"
        tx.innerHTML = req.responseText;
        lx.appendChild(tx);
      }
      req.send();
    }
    var editItem = null
    var editBox = document.getElementById("editBox");
    document.getElementById("mainCklist").onclick = function(event){
      var e = document.elementFromPoint(event.clientX,event.clientY);
      while(e && e.tagName!="LI"){
        if(e.id){
          if(e.id=="editForm") return;
          if(e.id.substr(0,4)=="cnt-"){
            var id = e.id.substr(4);
            if( document.getElementById("hist-"+id) ){
              historyOff(id)
            }else{
              historyOn(id)
            }
            return;
          }
        }
        if(e==editBox) return;
        e = e.parentNode;
      }
      if(!userInfo.canWrite) return
      if(!e) return
      if(editItem) editItem.removeChild(editBox);
      if(e==editItem){
        editItem = null;
        return;
      }
      editBox.style.display = "block";
      editItem = e;
      historyOff(e.id.substr(5))
      editItem.appendChild(editBox);
      cklistAjax("jstat?itemid="+e.id.substr(5),null,cklistApplyJstat);
      document.getElementById("cancelBtn").onclick = function(event){
        event.stopPropagation();
        editItem.removeChild(editBox);
        editItem = null;
      }
      document.getElementById("applyBtn").onclick = function(event){
        var data = "update=" + editItem.id.substr(5);
        var e = document.getElementById("editStatus");
        data += "&status=" + escape(e.value);
        e = document.getElementById("editCom");
        data += "&comment=" + escape(e.value);
        cklistAjax("jstat",data,cklistApplyJstat);
        editItem.removeChild(editBox);
        editItem = null;
        event.stopPropagation();
      }
      document.getElementById("editForm").onsubmit = function(){
        return false;

      }
    }
  }
  # wapp-subst {window.alert("Javascript loaded");\n}
}

# The /jstat page returns JSON that describes the current
................................................................................
                comment=$comment
          WHERE itemid=$update;
         INSERT INTO history(itemid,mtime,status,owner,comment)
          VALUES($update,julianday('now'),$status,$owner,$comment);
      }
    }
  }
  set itemid [wapp-param itemid]
  if {$itemid!="" && [scan $itemid %x itemid]==1} {
    set sql {
      SELECT json_group_array(
        json_object('itemid', printf('%016llx',itemid),
                    'mtime', strftime('%s',mtime)+0,
                    'status', status,
                    'owner', owner,
                    'comment', comment,
                    'chngcnt', (SELECT count(*) FROM history
                                WHERE itemid=$itemid)))
      FROM ckitem WHERE itemid=$itemid
    }



  } else {
    set sql {
      WITH chngcnt(cnt,itemid) AS (
         SELECT count(*), itemid FROM history GROUP BY itemid
      )
      SELECT json_group_array(
        json_object('itemid', printf('%016llx',itemid),
                    'mtime', strftime('%s',mtime)+0,
                    'status', status,
                    'owner', owner,
                    'comment', comment,
                    'chngcnt', COALESCE(chngcnt.cnt,0))
        )
        FROM ckitem LEFT JOIN chngcnt USING(itemid)
    }
  }
  wapp [db one $sql]
  db eval COMMIT
  db close
  # puts "jstat from $dbfile"
}

# The /history page returns an HTML table that shows the history of
# changes to a single checklist item.
#
#
proc wapp-page-history {} {
  global wapp
  set dbfile [wapp-param OBJECT]
  set itemid [wapp-param itemid]
  if {$dbfile=="" || $itemid=="" || [scan $itemid %x itemid]!=1} return
  wapp-mimetype text/text
  sqlite3 db $dbfile
  db eval BEGIN
  wapp-subst {<table border="0" cellspacing="4">\n}
  set date {}
  db eval {SELECT date(mtime) as dx, strftime('%H:%M',mtime) as tx,
                  owner, status, comment FROM history
                  WHERE itemid=$itemid
                  ORDER BY julianday(mtime) DESC} {
     if {$dx!=$date} {
       wapp-subst {<tr><td>%html($dx)<td><td>\n}
       set date $dx
     }
     wapp-trim {
        <tr><td align="right" valign="top">%html($tx)
            <td valign="top">%html($status) %html($owner)
            <td>%html($comment)</tr>\n
     }
  }
  wapp-subst {</table>\n}
}


# The /sql page for doing arbitrary SQL on the database.
# This page is accessible to the administrator only.
#
proc wapp-page-sql {} {
  global wapp
  if {[checklist-common-header]} return