annotate demo/more/grid1.ur @ 1034:a779402841f6

Hooks for measuring how much interesting proving is going on in elaboration
author Adam Chlipala <adamc@hcoop.net>
date Tue, 17 Nov 2009 12:44:14 -0500
parents fbc3a0eef45a
children 8d3aa6c7cee0
rev   line source
adamc@915 1 open Dbgrid
adamc@915 2
adamc@915 3 table t1 : {Id : int, A : string}
adamc@915 4 PRIMARY KEY Id
adamc@915 5
adamc@915 6 sequence s
adamc@931 7 table t : {Id : int, A : int, B : string, C : bool, D : int, E : option int, F : option int}
adamc@915 8 PRIMARY KEY Id,
adamc@915 9 CONSTRAINT Foreign FOREIGN KEY (D) REFERENCES t1(Id) ON DELETE CASCADE
adamc@915 10
adamc@932 11 fun page (n, s) = return <xml>A = {[n]}, B = {[s]}</xml>
adamc@915 12
adamc@915 13 open Make(struct
adamc@915 14 val tab = t
adamc@915 15 con key = [Id = _]
adamc@915 16
adamc@915 17 val raw = {Id = {New = nextval s,
adamc@915 18 Inj = _},
adamc@915 19 A = {New = return 0,
adamc@915 20 Inj = _},
adamc@915 21 B = {New = return "",
adamc@915 22 Inj = _},
adamc@915 23 C = {New = return False,
adamc@915 24 Inj = _},
adamc@915 25 D = {New = return 0,
adamc@930 26 Inj = _},
adamc@930 27 E = {New = return None,
adamc@931 28 Inj = _},
adamc@931 29 F = {New = return None,
adamc@915 30 Inj = _}}
adamc@915 31
adamc@915 32 structure F = Direct.Foreign(struct
adamc@915 33 con nm = #Id
adamc@915 34 val tab = t1
adamc@915 35 fun render r = r.A
adamc@915 36 end)
adamc@915 37
adamc@915 38 val cols = {Id = Direct.readOnly [#Id] ! "Id" Direct.int,
adamc@932 39 A = Direct.editable [#A] ! "A" Direct.int,
adamc@915 40 B = Direct.editable [#B] ! "B" Direct.string,
adamc@931 41 C = Direct.editable [#C] ! "C" Direct.bool,
adamc@932 42 D = Direct.editable [#D] ! "D" F.meta,
adamc@930 43 E = Direct.editable [#E] ! "E" (Direct.nullable Direct.int),
adamc@932 44 F = Direct.editable [#F] ! "F" (Direct.nullable F.meta),
adamc@915 45 DA = computed "2A" (fn r => 2 * r.A),
adamc@932 46 Link = computedHtml "Link" (fn r => <xml><a link={page (r.A, r.B)}>Go</a></xml>)}
adamc@935 47
adamc@937 48 val aggregates = {Dummy1 = {Initial = (),
adamc@937 49 Step = fn _ _ => (),
adamc@937 50 Display = fn _ => <xml/>},
adamc@937 51 Sum = {Initial = 0,
adamc@937 52 Step = fn r n => r.A + n,
adamc@937 53 Display = txt},
adamc@937 54 Dummy2 = {Initial = (),
adamc@937 55 Step = fn _ _ => (),
adamc@940 56 Display = fn _ => <xml/>},
adamc@937 57 And = {Initial = True,
adamc@937 58 Step = fn r b => r.C && b,
adamc@937 59 Display = txt}}
adamc@964 60
adamc@964 61 val pageLength = Some 10
adamc@915 62 end)
adamc@915 63
adamc@915 64 fun main () =
adamc@915 65 grid <- grid;
adamc@940 66 set (showSelection grid) True;
adamc@915 67 return <xml>
adamc@915 68 <head>
adamc@923 69 <link rel="stylesheet" type="text/css" href="../../grid.css"/>
adamc@915 70 </head>
adamc@915 71 <body onload={sync grid}>
adamc@915 72 {render grid}
adamc@940 73 <hr/>
adamc@941 74 <ccheckbox source={showSelection grid}/> Show selection<br/>
adamc@940 75 Selection: <dyn signal={ls <- selection grid;
adamc@940 76 return (List.mapX (fn r => <xml>{[r.Id]}; </xml>) ls)}/>
adamc@915 77 </body>
adamc@915 78 </xml>