Checklist

Check-in [daf4f29f9b]
Login

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

Overview
Comment:Add the ability to edit the checklist using the /cklistedit page.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: daf4f29f9b34dc706a8a493d909b4eabcb68e101
User & Date: drh 2018-01-30 15:35:08
Context
2018-01-30
15:48
Fix a missing </b< in the 3080300.db database. check-in: 677b092f11 user: drh tags: trunk
15:35
Add the ability to edit the checklist using the /cklistedit page. check-in: daf4f29f9b user: drh tags: trunk
14:17
Show/hide history by clicking on the "(status user)" text. Set cursors on clickable text. check-in: 66716f8b1d user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to checklist.tcl.

136
137
138
139
140
141
142

143
144




145
146
147
148
149
150
151
...
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
...
641
642
643
644
645
646
647















































































648
649
650
651
652
653
654
  if {$write==0 && $this!="login"} {
    wapp-subst {<a href='login'>login</a>\n}
  }
  if {$write==1 && $this!="logout"} {
    wapp-subst {<a href='logout'>%html($user)-logout</a>\n}
  }
  set admin [wapp-param CKLIST_ADMIN 0]

  if {$admin && $this!="sql"} {
    wapp-subst {<a href='sql'>sql</a>\n}




  }
  wapp-subst {<a href='../listing'>catalog</a>\n}
  wapp-subst {</div>\n}
  return 0
}

# Close out a web page.  Close the database connection that was opened
................................................................................
  if {$update!=""} {
    checklist-verify-login
    if {[wapp-param CKLIST_WRITE 0] && [scan $update %x update]==1} {
      set status [wapp-param status]
      set comment [wapp-param comment]
      set owner [wapp-param CKLIST_USER]
      db eval {
         UPDATE ckitem
            SET mtime=julianday('now'),
                status=$status,
                owner=$owner,
                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} {
................................................................................
      wapp-subst {<tr><td>ERROR: %html($msg)\n}
    }
    wapp-subst {</table>}
  }
  db eval COMMIT
  checklist-common-footer 
}
















































































# This dispatch hook checks to see if the first element of the PATH_INFO
# is the name of a checklist database.  If it is, it makes that database
# the OBJECT and shifts a new method name out of PATH_INFO and into
# PATH_HEAD for dispatch.
#
# If the first element of PATH_INFO is not a valid checklist database name,







>
|
|
>
>
>
>







 







|
|
<
<
<
<







 







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







136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
521
522
523
524
525
526
527
528
529




530
531
532
533
534
535
536
...
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
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
  if {$write==0 && $this!="login"} {
    wapp-subst {<a href='login'>login</a>\n}
  }
  if {$write==1 && $this!="logout"} {
    wapp-subst {<a href='logout'>%html($user)-logout</a>\n}
  }
  set admin [wapp-param CKLIST_ADMIN 0]
  if {$admin} {
    if {$this!="sql"} {
      wapp-subst {<a href='sql'>sql</a>\n}
    }
    if {$this!="cklistedit"} {
      wapp-subst {<a href='cklistedit'>edit-checklist</a>\n}
    }
  }
  wapp-subst {<a href='../listing'>catalog</a>\n}
  wapp-subst {</div>\n}
  return 0
}

# Close out a web page.  Close the database connection that was opened
................................................................................
  if {$update!=""} {
    checklist-verify-login
    if {[wapp-param CKLIST_WRITE 0] && [scan $update %x update]==1} {
      set status [wapp-param status]
      set comment [wapp-param comment]
      set owner [wapp-param CKLIST_USER]
      db eval {
         REPLACE INTO ckitem(itemid,mtime,status,owner,comment)
          VALUES($update,julianday('now'),$status,$owner,$comment);




         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} {
................................................................................
      wapp-subst {<tr><td>ERROR: %html($msg)\n}
    }
    wapp-subst {</table>}
  }
  db eval COMMIT
  checklist-common-footer 
}

# Generate a text encoding of the checklist table
#
#    # (hash) top level item
#    ## (hash) second-level item
#    ## (hash) another second-level
#    # (hash) another top-level
#
proc checklist-as-text {} {
  set out {}
  db eval {SELECT seq, itemid, txt FROM checklist ORDER BY seq} {
    set id [format %x $itemid]
    regsub -all {\s+} [string trim $txt] { } txt
    if {($seq%100)==0} {
      append out "# ($id) $txt\n"
    } else {
      append out "## ($id) $txt\n"
    }
  }
  return $out
}

# Replace the content of the checklist table with a decoding
# of the text string given in the argument.  Throw an error and
# rollback the change if anything doesn't look right.
#
proc checklist-rebuild-from-text {txt} {
  set re {^(\#\#?) (\([0-9a-fA-F]+\) )?(.+)$}
  db transaction {
    db eval {DELETE FROM checklist}
    set i 0
    foreach line [split $txt \n] {
      set line [string trimright $line]
      if {$line==""} continue
      if {[regexp $re $line all a h t]} {
        if {$h==""} {unset h} {scan $h (%x) h}
        if {$a=="#"} {
          set i [expr {(int($i/100)+1)*100}]
        } elseif {$a=="##"} {
          if {$i==0} {error "\"##\" before any \"#\""}
          incr i
        } else {
          error "unknown line prefix: \"$a\""
        }
        db eval {INSERT INTO checklist(seq,itemid,txt)
                 VALUES($i,COALESCE($h,abs(random())),$t)}
      } else {
        error "illegal checklist line: \"$line\""
      }
    }
  }
}

# The /cklistedit page allows the administrator to edit the items on
# the checklist.
#
proc wapp-page-cklistedit {} {
  global wapp
  if {[checklist-common-header]} return
  if {![wapp-param CKLIST_ADMIN 0]} {
    wapp-redirect index
    return
  }
  set cklist [string trim [wapp-param cklist]]
  if {$cklist!=""} {
    checklist-rebuild-from-text $cklist
  }
  set x [checklist-as-text]
  wapp-trim {
    <form method="POST" action="cklistedit">
    <p>Edit checklist: <input type="submit" value="Install"><br>
    <textarea name="cklist" rows="40" cols="120">%html($x)</textarea>
    <br><input type="submit" value="Install">
    </form>
    </p>
  }
  catch {db eval COMMIT}
  checklist-common-footer 
}

# This dispatch hook checks to see if the first element of the PATH_INFO
# is the name of a checklist database.  If it is, it makes that database
# the OBJECT and shifts a new method name out of PATH_INFO and into
# PATH_HEAD for dispatch.
#
# If the first element of PATH_INFO is not a valid checklist database name,