-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsmartsheetDemo.ur
116 lines (104 loc) · 4.23 KB
/
smartsheetDemo.ur
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(* For this demo, it's necessary to create smartsheetSecrets.ur,
* defining [api_token]. *)
structure S = Smartsheet.Make(Smartsheet.TwoLegged(SmartsheetSecrets))
fun create tid wid r =
sid <- S.Sheets.createInWorkspace wid ({Nam = r.Nam} ++ Api.optionals {FromId = tid});
return <xml><body>
I created sheet #{[sid]}.
</body></xml>
fun workspace tid wid =
return <xml><body>
<form>
New sheet name: <textbox{#Nam}/><br/>
<submit action={create tid wid}/>
</form>
</body></xml>
fun template tid =
ws <- S.Workspaces.list;
return <xml><body>
<h2>Workspaces</h2>
<ul>
{List.mapX (fn r =>
case r.Id of
None => error <xml>No ID returned for workspace</xml>
| Some wid => <xml><li><a link={workspace tid wid}>{[r.Nam]}</a></li></xml>) ws}
</ul>
</body></xml>
datatype input_widget = StringWidget of source string | BoolWidget of source bool
fun addRow sid cs =
Monad.ignore (S.Rows.add sid (Api.optionals {Cells = cs} :: []))
fun sheet sid =
sh <- S.Sheets.get sid;
ws <- List.mapM (fn c =>
case (c.Id, c.Title) of
(Some cid, Some ttl) =>
(case c.Typ of
Some Smartsheet.CHECKBOX =>
s <- source False;
return (cid, ttl, BoolWidget s)
| _ =>
s <- source "";
return (cid, ttl, StringWidget s))
| _ => error <xml>Missing column info</xml>) (Option.get [] sh.Columns);
return <xml><body>
<h2>Columns</h2>
<table>
<tr> <th>Name</th> <th>Type</th> </tr>
{List.mapX (fn c => <xml><tr>
<td>{[c.Title]}</td>
<td>{[case c.Typ of
Some Smartsheet.TEXT_NUMBER => "default"
| Some Smartsheet.CHECKBOX => "bool"
| _ => "other"]}</td>
</tr></xml>) (Option.get [] sh.Columns)}
</table>
<h2>Rows</h2>
<table>
{List.mapX (fn r => <xml><tr>
{List.mapX (fn c => <xml><td>{[c.Value]}</td></xml>) (Option.get [] r.Cells)}
</tr></xml>) (Option.get [] sh.Rows)}
</table>
<h2>New row</h2>
<table>
{List.mapX (fn (_, ttl, w) => <xml><tr>
<th>{[ttl]}</th>
<td>{case w of
StringWidget s => <xml><ctextbox source={s}/></xml>
| BoolWidget s => <xml><ccheckbox source={s}/></xml>}</td>
</tr></xml>) ws}
</table>
<button value="Create"
onclick={fn _ =>
cs <- List.mapM (fn (cid, _, w) =>
v <- (case w of
StringWidget s =>
v <- get s;
return (Json.String v)
| BoolWidget s =>
v <- get s;
return (Json.Bool v));
return (Api.optionals {ColumnId = cid,
Value = v})) ws;
rpc (addRow sid cs)}/>
</body></xml>
val main =
shs <- S.Sheets.list;
ts <- S.Templates.list;
return <xml><body>
<h2>Sheets</h2>
<ul>
{List.mapX (fn r =>
case r.Id of
None => error <xml>No ID returned for sheet</xml>
| Some sid => <xml><li><a link={sheet sid}>{[r.Nam]}</a>{case r.Source of
None => <xml></xml>
| Some s => <xml> (from {[s.Id]})</xml>}</li></xml>) shs}
</ul>
<h2>Templates</h2>
<ul>
{List.mapX (fn r =>
case r.Id of
None => error <xml>No ID returned for template</xml>
| Some tid => <xml><li><a link={template tid}>{[r.Nam]}</a></li></xml>) ts}
</ul>
</body></xml>