forked from urweb/upo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplorer.ur
2555 lines (2467 loc) · 197 KB
/
explorer.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
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
521
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
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
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
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
open Bootstrap
type t1 (full :: {Type}) (p :: (Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)) =
{Title : string,
Extra : transaction xbody,
Table : sql_table p.2 p.4,
Insert : $p.2 -> p.7 -> transaction unit,
Update : p.1 -> $p.2 -> p.7 -> transaction unit,
Delete : p.1 -> transaction unit,
List : sql_exp [Tab = p.2] [] [] bool -> transaction (list p.1),
KeyIs : nm :: Name -> p.1 -> sql_exp [nm = p.2] [] [] bool,
Show : show p.1,
Eq : eq p.1,
Ord : ord p.1,
Config : transaction p.5,
Auxiliary : p.1 -> $p.2 -> transaction p.7,
Render : (variant full -> string -> xbody) -> p.7 -> $p.2 -> xtable,
FreshWidgets : p.5 -> transaction p.6,
WidgetsFrom : p.5 -> $p.2 -> p.7 -> transaction p.6,
RenderWidgets : option p.1 -> p.5 -> p.6 -> xbody,
ReadWidgets : p.6 -> signal ($p.3 * p.7 * option string (* Error message, if something is amiss *)),
KeyOf : $p.2 -> p.1,
ForIndex : transaction (list (p.1 * xbody))}
type t (full :: {Type}) (tables :: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}) =
$(map (t1 full) tables)
type base1 = unit
type base2 = unit
type base3 = unit
val none [full ::: {Type}] = {}
datatype index_style exp row =
Default of exp
| Custom of transaction (list row)
fun one [full ::: {Type}]
[tname :: Name] [key :: Name] [keyT ::: Type] [rest ::: {Type}] [cstrs ::: {{Unit}}]
[old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[key] ~ rest] [[tname] ~ old]
(tab : sql_table ([key = keyT] ++ rest) cstrs) (title : string) (extra : transaction xbody)
(isty : index_style (sql_exp [Tab = [key = keyT] ++ rest] [] [] bool) (keyT * xbody))
(sh : show keyT) (eq : eq keyT) (ord : ord keyT) (inj : sql_injectable keyT) (injs : $(map sql_injectable rest))
(fl : folder rest) (ofl : folder old) (old : t full old) =
{tname = {Title = title,
Extra = extra,
Table = tab,
Insert = fn r () => @@Sql.easy_insert [[key = _] ++ rest] [_] ({key = inj} ++ injs) (@Folder.cons [_] [_] ! fl) tab r,
Update = fn k r () => @@Sql.easy_update' [[key = _]] [rest] [_] ! {key = inj} injs _ fl tab {key = k} r (WHERE TRUE),
Delete = fn _ => return (),
List = fn wher => List.mapQuery (SELECT tab.{key}
FROM tab
WHERE {wher}
ORDER BY tab.{key})
(fn {Tab = r} => r.key),
KeyIs = fn [nm ::_] v => (WHERE {{nm}}.{key} = {[v]}),
Show = sh,
Eq = eq,
Ord = ord,
Config = return (),
Auxiliary = fn _ _ => return (),
Render = fn _ _ _ => <xml></xml>,
FreshWidgets = fn () => return (),
WidgetsFrom = fn () _ _ => return (),
RenderWidgets = fn _ () () => <xml></xml>,
ReadWidgets = fn () => return ((), (), None),
KeyOf = fn r => r.key,
ForIndex = case isty of
Default fltr => List.mapQuery (SELECT tab.{key}
FROM tab
WHERE {fltr}
ORDER BY tab.{key})
(fn {Tab = r} => (r.key, txt r.key))
| Custom xa => xa}} ++ old
fun two [full ::: {Type}]
[tname :: Name] [key1 :: Name] [key2 :: Name] [keyT1 ::: Type] [keyT2 ::: Type]
[rest ::: {Type}] [cstrs ::: {{Unit}}] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[key1] ~ [key2]] [[key1, key2] ~ rest] [[tname] ~ old]
(tab: sql_table ([key1 = keyT1, key2 = keyT2] ++ rest) cstrs) (title : string) (extra : transaction xbody)
(isty : index_style (sql_exp [Tab = [key1 = keyT1, key2 = keyT2] ++ rest] [] [] bool) (keyT1 * keyT2 * xbody))
(sh : show (keyT1 * keyT2)) (eq : eq (keyT1 * keyT2)) (ord : ord (keyT1 * keyT2)) (inj1 : sql_injectable keyT1) (inj2 : sql_injectable keyT2)
(injs : $(map sql_injectable rest)) (fl : folder rest) (ofl : folder old)
(old : t full old) =
{tname = {Title = title,
Extra = extra,
Table = tab,
Insert = fn r () => @@Sql.easy_insert [[key1 = _, key2 = _] ++ rest] [_] ({key1 = inj1, key2 = inj2} ++ injs) (@Folder.cons [_] [_] ! (@Folder.cons [_] [_] ! fl)) tab r,
Update = fn (k1, k2) r () => @@Sql.easy_update' [[key1 = _, key2 = _]] [rest] [_] ! {key1 = inj1, key2 = inj2} injs _ fl tab {key1 = k1, key2 = k2} r (WHERE TRUE),
Delete = fn _ => return (),
List = fn wher => List.mapQuery (SELECT tab.{key1}, tab.{key2}
FROM tab
WHERE {wher}
ORDER BY tab.{key1}, tab.{key2})
(fn {Tab = r} => (r.key1, r.key2)),
KeyIs = fn [nm ::_] (v1, v2) => (WHERE {{nm}}.{key1} = {[v1]}
AND {{nm}}.{key2} = {[v2]}),
Show = sh,
Eq = eq,
Ord = ord,
Config = return (),
Auxiliary = fn _ _ => return (),
Render = fn _ _ _ => <xml></xml>,
FreshWidgets = fn () => return (),
WidgetsFrom = fn () _ _ => return (),
RenderWidgets = fn _ () () => <xml></xml>,
ReadWidgets = fn () => return ((), (), None),
KeyOf = fn r => (r.key1, r.key2),
ForIndex = case isty of
Default fltr => List.mapQuery (SELECT tab.{key1}, tab.{key2}
FROM tab
WHERE {fltr}
ORDER BY tab.{key1}, tab.{key2})
(fn {Tab = r} => ((r.key1, r.key2), txt (r.key1, r.key2)))
| Custom xa =>
ls <- xa;
return (List.mp (fn (k1, k2, b) => ((k1, k2), b)) ls)}} ++ old
type text1 t = t
type text2 t = source string * t
type text3 t = t
fun text [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name] [colT ::: Type]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old]
(lab : string) (_ : show colT) (_ : read colT)
(old : t full ([tname = (key, [col = colT] ++ cols, colsDone, cstrs, impl1, impl2, impl3)] ++ old)) =
old -- tname
++ {tname = old.tname
-- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Render = fn entry aux r =>
<xml>
{old.tname.Render entry aux r}
<tr>
<th style="width: 25%">{[lab]}</th>
<td>{[r.col]}</td>
</tr>
</xml>,
FreshWidgets = fn cfg =>
s <- source "";
ws <- old.tname.FreshWidgets cfg;
return (s, ws),
WidgetsFrom = fn cfg r aux =>
s <- source (show r.col);
ws <- old.tname.WidgetsFrom cfg r aux;
return (s, ws),
RenderWidgets = fn k cfg (s, ws) =>
<xml>
{old.tname.RenderWidgets k cfg ws}
<div class="form-group">
<label class="control-label">{[lab]}</label>
<ctextbox class="form-control" source={s}/>
</div>
</xml>,
ReadWidgets = fn (s, ws) =>
v <- signal s;
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = readError v} ++ wsv, aux, err)}}
fun ignored [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name] [colT ::: Type]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old] (v : colT)
(old : t full ([tname = (key, [col = colT] ++ cols, colsDone, cstrs, impl1, impl2, impl3)] ++ old)) =
old -- tname
++ {tname = old.tname -- #ReadWidgets
++ {ReadWidgets = fn ws =>
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = v} ++ wsv, aux, err)}}
fun hyperref [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name] [colT ::: Type]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old]
(lab : string) (_ : show colT) (_ : read colT)
(old : t full ([tname = (key, [col = colT] ++ cols, colsDone, cstrs, impl1, impl2, impl3)] ++ old)) =
old -- tname
++ {tname = old.tname
-- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Render = fn entry aux r =>
<xml>
{old.tname.Render entry aux r}
{case checkUrl (show r.col) of
None => <xml></xml>
| Some url => <xml><tr>
<th style="width: 25%">{[lab]}</th>
<td><a href={url}><tt>{[r.col]}</tt></a></td>
</tr></xml>}
</xml>,
FreshWidgets = fn cfg =>
s <- source "";
ws <- old.tname.FreshWidgets cfg;
return (s, ws),
WidgetsFrom = fn cfg r aux =>
s <- source (show r.col);
ws <- old.tname.WidgetsFrom cfg r aux;
return (s, ws),
RenderWidgets = fn k cfg (s, ws) =>
<xml>
{old.tname.RenderWidgets k cfg ws}
<div class="form-group">
<label class="control-label">{[lab]}</label>
<ctextbox class="form-control" source={s}/>
</div>
</xml>,
ReadWidgets = fn (s, ws) =>
v <- signal s;
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = readError v} ++ wsv, aux, err)}}
fun image [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name] [colT ::: Type]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old]
(lab : string) (_ : show colT) (_ : read colT) (cls : css_class)
(old : t full ([tname = (key, [col = colT] ++ cols, colsDone, cstrs, impl1, impl2, impl3)] ++ old)) =
old -- tname
++ {tname = old.tname
-- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Render = fn entry aux r =>
<xml>
{old.tname.Render entry aux r}
{case checkUrl (show r.col) of
None => <xml></xml>
| Some url => <xml><tr>
<th style="width: 25%">{[lab]}</th>
<td><img src={url} class={cls}/></td>
</tr></xml>}
</xml>,
FreshWidgets = fn cfg =>
s <- source "";
ws <- old.tname.FreshWidgets cfg;
return (s, ws),
WidgetsFrom = fn cfg r aux =>
s <- source (show r.col);
ws <- old.tname.WidgetsFrom cfg r aux;
return (s, ws),
RenderWidgets = fn k cfg (s, ws) =>
<xml>
{old.tname.RenderWidgets k cfg ws}
<div class="form-group">
<label class="control-label">{[lab]}</label>
<ctextbox class="form-control" source={s}/>
</div>
</xml>,
ReadWidgets = fn (s, ws) =>
v <- signal s;
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = readError v} ++ wsv, aux, err)}}
fun textOpt [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name] [colT ::: Type]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old]
(lab : string) (_ : show colT) (_ : read colT)
(old : t full ([tname = (key, [col = option colT] ++ cols, colsDone, cstrs, impl1, impl2, impl3)] ++ old)) =
old -- tname
++ {tname = old.tname
-- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Render = fn entry aux r =>
<xml>
{old.tname.Render entry aux r}
<tr>
<th style="width: 25%">{[lab]}</th>
<td>{[r.col]}</td>
</tr>
</xml>,
FreshWidgets = fn cfg =>
s <- source "";
ws <- old.tname.FreshWidgets cfg;
return (s, ws),
WidgetsFrom = fn cfg r aux =>
s <- source (show r.col);
ws <- old.tname.WidgetsFrom cfg r aux;
return (s, ws),
RenderWidgets = fn k cfg (s, ws) =>
<xml>
{old.tname.RenderWidgets k cfg ws}
<div class="form-group">
<label class="control-label">{[lab]}</label>
<ctextbox class="form-control" source={s}/>
</div>
</xml>,
ReadWidgets = fn (s, ws) =>
v <- signal s;
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = case v of
"" => None
| _ => Some (readError v)} ++ wsv, aux, err)}}
type checkbox1 t = t
type checkbox2 t = source bool * t
type checkbox3 t = t
fun checkbox [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old]
(lab : string)
(old : t full ([tname = (key, [col = bool] ++ cols, colsDone, cstrs, impl1, impl2, impl3)] ++ old)) =
old -- tname
++ {tname = old.tname
-- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Render = fn entry aux r =>
<xml>
{old.tname.Render entry aux r}
<tr>
<th style="width: 25%">{[lab]}</th>
<td>{[r.col]}</td>
</tr>
</xml>,
FreshWidgets = fn cfg =>
s <- source False;
ws <- old.tname.FreshWidgets cfg;
return (s, ws),
WidgetsFrom = fn cfg r aux =>
s <- source r.col;
ws <- old.tname.WidgetsFrom cfg r aux;
return (s, ws),
RenderWidgets = fn k cfg (s, ws) =>
<xml>
{old.tname.RenderWidgets k cfg ws}
<div class="form-group">
<label class="control-label">{[lab]}</label>
<ccheckbox class="form-control" source={s}/>
</div>
</xml>,
ReadWidgets = fn (s, ws) =>
v <- signal s;
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = v} ++ wsv, aux, err)}}
type htmlbox1 t = t
type htmlbox2 t = Widget.htmlbox * t
type htmlbox3 t = t
fun htmlbox [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type] [old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old]
(lab : string)
(old : t full ([tname = (key, [col = string] ++ cols, colsDone, cstrs, impl1, impl2, impl3)] ++ old)) =
old -- tname
++ {tname = old.tname
-- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Render = fn entry aux r =>
<xml>
{old.tname.Render entry aux r}
<tr>
<th style="width: 25%">{[lab]}</th>
<td>{Widget.html r.col}</td>
</tr>
</xml>,
FreshWidgets = fn cfg =>
s <- @Widget.create Widget.htmlbox ();
ws <- old.tname.FreshWidgets cfg;
return (s, ws),
WidgetsFrom = fn cfg r aux =>
s <- @Widget.initialize Widget.htmlbox () r.col;
ws <- old.tname.WidgetsFrom cfg r aux;
return (s, ws),
RenderWidgets = fn k cfg (s, ws) =>
<xml>
{old.tname.RenderWidgets k cfg ws}
<div class="form-group">
<label class="control-label">{[lab]}</label>
{@Widget.asWidget Widget.htmlbox s None}
</div>
</xml>,
ReadWidgets = fn (s, ws) =>
v <- @Widget.value Widget.htmlbox s;
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = v} ++ wsv, aux, err)}}
type foreignize (t1 :: Type) (t2 :: Type) = {
Nullable : bool,
Inject : t2 -> t1,
Unject : t1 -> option t2
}
val foreignize_same [t] = {Nullable = False,
Inject = fn x => x,
Unject = Some}
val foreignize_nullable [t] = {Nullable = True,
Inject = Some,
Unject = fn x => x}
type foreign1 t key fcolT = list fcolT * t
type foreign2 t key fcolT = source string * t
type foreign3 t key fcolT = list key * t
fun foreign [full ::: {Type}]
[tname :: Name] [key ::: Type] [col :: Name] [colT ::: Type] [fcolT ::: Type]
[cols ::: {Type}] [colsDone ::: {Type}] [cstrs ::: {{Unit}}]
[impl1 ::: Type] [impl2 ::: Type] [impl3 ::: Type]
[ftname :: Name] [fcol :: Name]
[fcols ::: {Type}] [fcolsDone ::: {Type}] [fcstrs ::: {{Unit}}]
[fimpl1 ::: Type] [fimpl2 ::: Type] [fimpl3 ::: Type]
[old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[[col] ~ cols] [[col] ~ colsDone] [[tname] ~ old]
[[fcol] ~ fcols] [[ftname] ~ old]
[[tname] ~ [ftname]] [[tname, ftname] ~ full]
(lab : string) (clab : string) (fize : foreignize colT fcolT)
(_ : show colT) (_ : read colT) (_ : sql_injectable colT)
(_ : show fcolT) (_ : read fcolT) (_ : sql_injectable fcolT)
(old : t ([tname = key, ftname = fcolT] ++ full)
([tname = (key, [col = colT] ++ cols, colsDone, cstrs, impl1, impl2, impl3),
ftname = (fcolT, [fcol = fcolT] ++ fcols, fcolsDone, fcstrs, fimpl1, fimpl2, fimpl3)] ++ old)) =
old -- tname -- ftname
++ {tname = old.tname
-- #Config -- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Config =
let
val tab = old.ftname.Table
in
keys <- List.mapQuery (SELECT DISTINCT tab.{fcol}
FROM tab
ORDER BY tab.{fcol})
(fn r => r.Tab.fcol);
cfg <- old.tname.Config;
return (keys, cfg)
end,
Render = fn entry aux r =>
<xml>
{old.tname.Render entry aux r}
<tr>
<th style="width: 25%">{[lab]}</th>
<td>{case fize.Unject r.col of
None => <xml>—</xml>
| Some v => entry (make [ftname] v) (show v)}</td>
</tr>
</xml>,
FreshWidgets = fn (_, cfg) =>
s <- source "";
ws <- old.tname.FreshWidgets cfg;
return (s, ws),
WidgetsFrom = fn (_, cfg) r aux =>
s <- source (show r.col);
ws <- old.tname.WidgetsFrom cfg r aux;
return (s, ws),
RenderWidgets = fn k (cfg1, cfg2) (s, ws) =>
<xml>
{old.tname.RenderWidgets k cfg2 ws}
<div class="form-group">
<label class="control-label">{[lab]}</label>
<cselect class="form-select" source={s}>
{if fize.Nullable then
<xml><coption/></xml>
else
<xml></xml>}
{List.mapX (fn s => <xml><coption>{[s]}</coption></xml>) cfg1}
</cselect>
</div>
</xml>,
ReadWidgets = fn (s, ws) =>
v <- signal s;
(wsv, aux, err) <- old.tname.ReadWidgets ws;
return ({col = readError v} ++ wsv, aux, err)},
ftname = old.ftname
-- #Insert -- #Update -- #Auxiliary -- #Render -- #ReadWidgets -- #WidgetsFrom
++ {Insert = fn r (_, aux) => old.ftname.Insert r aux,
Update = fn k r (_, aux) => old.ftname.Update k r aux,
Auxiliary = fn fkey row =>
let
val tab = old.tname.Table
in
keys <- old.tname.List (WHERE tab.{col} = {[fize.Inject fkey]});
aux <- old.ftname.Auxiliary fkey row;
return (keys, aux)
end,
Render = fn entry (children, aux) r =>
let
val _ : show key = old.tname.Show
in
<xml>
{old.ftname.Render entry aux r}
<tr>
<th style="width: 25%">{[clab]}</th>
<td>{List.mapX (fn key => <xml>{entry (make [tname] key) (show key)}<br/></xml>) children}</td>
</tr>
</xml>
end,
ReadWidgets = fn w =>
(v, aux, err) <- old.ftname.ReadWidgets w;
return (v, ([], aux), err),
WidgetsFrom = fn cfg r (_, aux) => old.ftname.WidgetsFrom cfg r aux}}
type manyToMany11 t key1 key2 others = $(map thd3 others) * list key2 * t
type manyToMany12 t key1 key2 others = source string * $(map snd3 others) * source (list (key2 * source ($(map fst3 others)) * source (option ($(map snd3 others))))) * source bool (* dropdown changed since last button push? *) * t
type manyToMany13 t key1 key2 others = list (key2 * $(map fst3 others)) * t
type manyToMany21 t key1 key2 others = $(map thd3 others) * list key1 * t
type manyToMany22 t key1 key2 others = source string * $(map snd3 others) * source (list (key1 * source ($(map fst3 others)) * source (option ($(map snd3 others))))) * source bool * t
type manyToMany23 t key1 key2 others = list (key1 * $(map fst3 others)) * t
fun manyToMany [full ::: {Type}] [tname1 :: Name] [key1 ::: Type] [col1 :: Name] [colR1 :: Name]
[cols1 ::: {Type}] [colsDone1 ::: {Type}] [cstrs1 ::: {{Unit}}]
[impl11 ::: Type] [impl12 ::: Type] [impl13 ::: Type]
[tname2 :: Name] [key2 ::: Type] [col2 :: Name] [colR2 :: Name]
[cols2 ::: {Type}] [colsDone2 ::: {Type}] [cstrs2 ::: {{Unit}}]
[impl21 ::: Type] [impl22 ::: Type] [impl23 ::: Type]
[cstrs ::: {{Unit}}]
[old ::: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}]
[others ::: {(Type * Type * Type)}]
[[tname1] ~ [tname2]] [[tname1, tname2] ~ old] [[tname1, tname2] ~ full]
[[col1] ~ cols1] [[col2] ~ cols2] [[col1] ~ [col2]] [[colR1] ~ [colR2]]
[others ~ [colR1, colR2]]
(rel : sql_table ([colR1 = key1, colR2 = key2] ++ map fst3 others) cstrs)
(lab1 : string) (lab2 : string)
(_ : eq key1) (_ : ord key1) (_ : show key1) (_ : read key1) (_ : sql_injectable key1)
(_ : eq key2) (_ : ord key2) (_ : show key2) (_ : read key2) (_ : sql_injectable key2)
(fl : folder others) (ws : $(map Widget.t' others)) (injs : $(map (fn p => sql_injectable p.1) others)) (labels : $(map (fn _ => string) others))
(old : t ([tname1 = key1, tname2 = key2] ++ full)
([tname1 = (key1, [col1 = key1] ++ cols1, colsDone1, cstrs1, impl11, impl12, impl13),
tname2 = (key2, [col2 = key2] ++ cols2, colsDone2, cstrs2, impl21, impl22, impl23)] ++ old)) =
old -- tname1 -- tname2
++ {tname1 = old.tname1
-- #Insert -- #Update -- #Delete -- #Config -- #Auxiliary -- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Insert =
fn r (k2s, aux) =>
old.tname1.Insert r aux;
List.app (fn (k2, others) =>
@Sql.easy_insert ({colR1 = _, colR2 = _} ++ injs)
(@Folder.cons [colR1] [_] !
(@Folder.cons [colR2] [_] !
(@Folder.mp fl)))
rel ({colR1 = r.col1, colR2 = k2} ++ others)) k2s,
Update =
fn k r (k2s, aux) =>
old.tname1.Update k r aux;
dml (DELETE FROM rel
WHERE t.{colR1} = {[r.col1]});
List.app (fn (k2, others) =>
@Sql.easy_insert ({colR1 = _, colR2 = _} ++ injs)
(@Folder.cons [colR1] [_] !
(@Folder.cons [colR2] [_] !
(@Folder.mp fl)))
rel ({colR1 = r.col1, colR2 = k2} ++ others)) k2s,
Delete = fn k1 => dml (DELETE FROM rel WHERE t.{colR1} = {[k1]}),
Config =
let
val tab = old.tname2.Table
in
keys <- List.mapQuery (SELECT DISTINCT tab.{col2}
FROM tab
ORDER BY tab.{col2})
(fn r => r.Tab.col2);
wcfg <- @Monad.mapR _ [Widget.t'] [thd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) => @Widget.configure w)
fl ws;
cfg <- old.tname1.Config;
return (wcfg, keys, cfg)
end,
Auxiliary = fn k1 row =>
keys <- List.mapQuery (SELECT rel.{colR2}, rel.{{map fst3 others}}
FROM rel
WHERE rel.{colR1} = {[k1]}
ORDER BY rel.{colR2})
(fn r => (r.Rel.colR2, r.Rel -- colR2));
aux <- old.tname1.Auxiliary k1 row;
return (keys, aux),
Render = fn entry (k2s, aux) r =>
<xml>
{old.tname1.Render entry aux r}
<tr>
<th style="width: 25%">{[lab1]}</th>
<td>{List.mapX (fn (k2, others) => <xml>{entry (make [tname2] k2) (show k2)}
{@mapX3 [fn _ => string] [Widget.t'] [fst3] [body]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (label : string) (w : Widget.t' p) (v : p.1) =>
<xml> - {[label]}: {[@Widget.asValue w v]}</xml>) fl labels ws others}
<br/></xml>) k2s}</td>
</tr>
</xml>,
FreshWidgets = fn (cfg0, _, cfg) =>
s <- source "";
ws0 <- @Monad.mapR2 _ [Widget.t'] [thd3] [snd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (cfg : p.3) => @Widget.create w cfg)
fl ws cfg0;
sl <- source [];
changed <- source False;
ws <- old.tname1.FreshWidgets cfg;
return (s, ws0, sl, changed, ws),
WidgetsFrom = fn (cfg0, _, cfg) r (keys, aux) =>
s <- source "";
ws0 <- @Monad.mapR2 _ [Widget.t'] [thd3] [snd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (cfg : p.3) => @Widget.create w cfg)
fl ws cfg0;
keys <- List.mapM (fn (k, vs) => vs <- source vs; notEditing <- source None; return (k, vs, notEditing)) keys;
sl <- source keys;
changed <- source False;
ws <- old.tname1.WidgetsFrom cfg r aux;
return (s, ws0, sl, changed, ws),
RenderWidgets = fn k (cfgs, cfg1, cfg2) (s, ws0, sl, changed, wso) =>
<xml>
{old.tname1.RenderWidgets k cfg2 wso}
<div class="form-group">
<label class="control-label">{[lab1]}</label>
<div class="input-group">
{@mapX3 [fn _ => string] [Widget.t'] [snd3] [body]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (label : string) (w : Widget.t' p) (s : p.2) =>
<xml>{[label]}: {@Widget.asWidget w s None}</xml>)
fl labels ws ws0}
</div>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-secondary"
onclick={fn _ =>
sv <- get s;
if sv = "" then
return ()
else
set changed False;
sv <- return (readError sv);
slv <- get sl;
if List.exists (fn (sv', _, _) => sv' = sv) slv then
return ()
else
vs <- @Monad.mapR2 _ [Widget.t'] [snd3] [fst3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (s : p.2) =>
current (@Widget.value w s))
fl ws ws0;
vs <- source vs;
notEditing <- source None;
set sl (List.sort (fn x y => x.1 > y.1) ((sv, vs, notEditing) :: slv))}>Select:</button>
</span>
<cselect class="form-select" source={s} onchange={set changed True}>
<coption/>
{List.mapX (fn s => <xml><coption>{[s]}</coption></xml>) cfg1}
</cselect>
</div>
<table>
<thead><tr><td/>
{@mapX [fn _ => string] [tr]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (label : string) =>
<xml><th>{[label]}</th></xml>)
fl labels}
<td/></tr></thead>
<tbody>
<dyn signal={slv <- signal sl;
return (List.mapX (fn (k2, vs, ws0) => <xml>
<dyn signal={vals <- signal vs;
wids <- signal ws0;
case wids of
None => return <xml>
<tr>
<td>{[k2]}</td>
{@mapX2 [Widget.t'] [fst3] [tr]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (w : Widget.t' p) (v : p.1) =>
<xml><td>{[@Widget.asValue w v]}</td></xml>)
fl ws vals}
{if @Row.isEmpty fl then
<xml></xml>
else <xml>
<td><button class="btn btn-secondary"
onclick={fn _ =>
wids <- @Monad.mapR3 _ [Widget.t'] [thd3] [fst3] [snd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (cfg : p.3) (v : p.1) =>
@Widget.initialize w cfg v)
fl ws cfgs vals;
set ws0 (Some wids)}>
<span class="glyphicon glyphicon-pencil-alt"/>
</button></td>
<td><button class="btn btn-secondary"
onclick={fn _ => set sl (List.filter (fn (k2', _, _) => k2' <> k2) slv)}>
<span class="glyphicon glyphicon-trash"/>
</button></td>
</xml>}
</tr>
</xml>
| Some wids => return <xml>
<tr>
<td>{[k2]}</td>
{@mapX2 [Widget.t'] [snd3] [tr]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (w : Widget.t' p) (s : p.2) =>
<xml><td>{@Widget.asWidget w s None}</td></xml>)
fl ws wids}
<td><button class="btn btn-secondary"
onclick={fn _ =>
vsv <- @Monad.mapR2 _ [Widget.t'] [snd3] [fst3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (s : p.2) =>
current (@Widget.value w s))
fl ws wids;
set vs vsv;
set ws0 None}>
<span class="glyphicon glyphicon-check"/>
</button></td>
<td><button class="btn btn-secondary"
onclick={fn _ => set ws0 None}>
<span class="glyphicon glyphicon-trash"/>
</button></td>
</tr>
</xml>}/>
</xml>) slv)}/>
</tbody>
</table>
</div>
</xml>,
ReadWidgets = fn (s, _, sl, changed, ws) =>
slv <- signal sl;
slv <- List.mapM (fn (k2, vs, _) => vs <- signal vs; return (k2, vs)) slv;
chd <- signal changed;
(wsv, aux, err) <- old.tname1.ReadWidgets ws;
return (wsv, (slv, aux),
if chd then
let
val msg = "The dropdown for \"" ^ lab1 ^ "\" has changed, but the new value hasn't been selected by pushing the adjacent button."
in
case err of
None => Some msg
| Some err => Some (err ^ "\n" ^ msg)
end
else
err)},
tname2 = old.tname2
-- #Insert -- #Update -- #Delete -- #Config -- #Auxiliary -- #Render -- #FreshWidgets -- #WidgetsFrom -- #RenderWidgets -- #ReadWidgets
++ {Insert =
fn r (k1s, aux) =>
old.tname2.Insert r aux;
List.app (fn (k1, others) =>
@Sql.easy_insert ({colR1 = _, colR2 = _} ++ injs)
(@Folder.cons [colR1] [_] !
(@Folder.cons [colR2] [_] !
(@Folder.mp fl)))
rel ({colR1 = k1, colR2 = r.col2} ++ others)) k1s,
Update =
fn k r (k1s, aux) =>
old.tname2.Update k r aux;
dml (DELETE FROM rel
WHERE t.{colR2} = {[r.col2]});
List.app (fn (k1, others) =>
@Sql.easy_insert ({colR1 = _, colR2 = _} ++ injs)
(@Folder.cons [colR1] [_] !
(@Folder.cons [colR2] [_] !
(@Folder.mp fl)))
rel ({colR1 = k1, colR2 = r.col2} ++ others)) k1s,
Delete = fn k2 => dml (DELETE FROM rel WHERE t.{colR2} = {[k2]}),
Config =
let
val tab = old.tname1.Table
in
keys <- List.mapQuery (SELECT DISTINCT tab.{col1}
FROM tab
ORDER BY tab.{col1})
(fn r => r.Tab.col1);
wcfg <- @Monad.mapR _ [Widget.t'] [thd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) => @Widget.configure w)
fl ws;
cfg <- old.tname2.Config;
return (wcfg, keys, cfg)
end,
Auxiliary = fn k2 row =>
keys <- List.mapQuery (SELECT rel.{colR1}, rel.{{map fst3 others}}
FROM rel
WHERE rel.{colR2} = {[k2]}
ORDER BY rel.{colR1})
(fn r => (r.Rel.colR1, r.Rel -- colR1));
aux <- old.tname2.Auxiliary k2 row;
return (keys, aux),
Render = fn entry (k1s, aux) r =>
<xml>
{old.tname2.Render entry aux r}
<tr>
<th style="width: 25%">{[lab2]}</th>
<td>{List.mapX (fn (k1, others) => <xml>{entry (make [tname1] k1) (show k1)}
{@mapX3 [fn _ => string] [Widget.t'] [fst3] [body]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (label : string) (w : Widget.t' p) (v : p.1) =>
<xml>- {[label]}: {[@Widget.asValue w v]}</xml>) fl labels ws others}
<br/></xml>) k1s}</td>
</tr>
</xml>,
FreshWidgets = fn (cfg0, _, cfg) =>
s <- source "";
ws0 <- @Monad.mapR2 _ [Widget.t'] [thd3] [snd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (cfg : p.3) => @Widget.create w cfg)
fl ws cfg0;
sl <- source [];
changed <- source False;
ws <- old.tname2.FreshWidgets cfg;
return (s, ws0, sl, changed, ws),
WidgetsFrom = fn (cfg0, _, cfg) r (keys, aux) =>
s <- source "";
ws0 <- @Monad.mapR2 _ [Widget.t'] [thd3] [snd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (cfg : p.3) => @Widget.create w cfg)
fl ws cfg0;
keys <- List.mapM (fn (k, vs) => vs <- source vs; notEditing <- source None; return (k, vs, notEditing)) keys;
sl <- source keys;
changed <- source False;
ws <- old.tname2.WidgetsFrom cfg r aux;
return (s, ws0, sl, changed, ws),
RenderWidgets = fn k (cfgs, cfg1, cfg2) (s, ws0, sl, changed, wso) =>
<xml>
{old.tname2.RenderWidgets k cfg2 wso}
<div class="form-group">
<label class="control-label">{[lab2]}</label>
<div class="input-group">
{@mapX3 [fn _ => string] [Widget.t'] [snd3] [body]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (label : string) (w : Widget.t' p) (s : p.2) =>
<xml>{[label]}: {@Widget.asWidget w s None}</xml>)
fl labels ws ws0}
</div>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-secondary"
onclick={fn _ =>
sv <- get s;
if sv = "" then
return ()
else
set changed False;
sv <- return (readError sv);
slv <- get sl;
if List.exists (fn (sv', _, _) => sv' = sv) slv then
return ()
else
vs <- @Monad.mapR2 _ [Widget.t'] [snd3] [fst3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (s : p.2) =>
current (@Widget.value w s))
fl ws ws0;
vs <- source vs;
notEditing <- source None;
set sl (List.sort (fn x y => x.1 > y.1) ((sv, vs, notEditing) :: slv))}>Select:</button>
</span>
<cselect class="form-select" source={s} onchange={set changed True}>
<coption/>
{List.mapX (fn s => <xml><coption>{[s]}</coption></xml>) cfg1}
</cselect>
</div>
<table>
<thead><tr><td/>
{@mapX [fn _ => string] [tr]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (label : string) =>
<xml><th>{[label]}</th></xml>)
fl labels}
<td/></tr></thead>
<tbody>
<dyn signal={slv <- signal sl;
return (List.mapX (fn (k2, vs, ws0) => <xml>
<dyn signal={vals <- signal vs;
wids <- signal ws0;
case wids of
None => return <xml>
<tr>
<td>{[k2]}</td>
{@mapX2 [Widget.t'] [fst3] [tr]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (w : Widget.t' p) (v : p.1) =>
<xml><td>{[@Widget.asValue w v]}</td></xml>)
fl ws vals}
{if @Row.isEmpty fl then
<xml></xml>
else <xml>
<td><button class="btn btn-secondary"
onclick={fn _ =>
wids <- @Monad.mapR3 _ [Widget.t'] [thd3] [fst3] [snd3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (cfg : p.3) (v : p.1) =>
@Widget.initialize w cfg v)
fl ws cfgs vals;
set ws0 (Some wids)}>
<span class="glyphicon glyphicon-pencil-alt"/>
</button></td>
<td><button class="btn btn-secondary"
onclick={fn _ => set sl (List.filter (fn (k2', _, _) => k2' <> k2) slv)}>
<span class="glyphicon glyphicon-trash"/>
</button></td>
</xml>}
</tr>
</xml>
| Some wids => return <xml>
<tr>
<td>{[k2]}</td>
{@mapX2 [Widget.t'] [snd3] [tr]
(fn [nm ::_] [p ::_] [r ::_] [[nm] ~ r] (w : Widget.t' p) (s : p.2) =>
<xml><td>{@Widget.asWidget w s None}</td></xml>)
fl ws wids}
<td><button class="btn btn-secondary"
onclick={fn _ =>
vsv <- @Monad.mapR2 _ [Widget.t'] [snd3] [fst3]
(fn [nm ::_] [p ::_] (w : Widget.t' p) (s : p.2) =>
current (@Widget.value w s))
fl ws wids;
set vs vsv;
set ws0 None}>
<span class="glyphicon glyphicon-check"/>
</button></td>
<td><button class="btn btn-secondary"
onclick={fn _ => set ws0 None}>
<span class="glyphicon glyphicon-trash"/>
</button></td>
</tr>
</xml>}/>
</xml>) slv)}/>
</tbody>
</table>
</div>
</xml>,
ReadWidgets = fn (s, _, sl, changed, ws) =>
slv <- signal sl;
slv <- List.mapM (fn (k2, vs, _) => vs <- signal vs; return (k2, vs)) slv;
chd <- signal changed;
(wsv, aux, err) <- old.tname2.ReadWidgets ws;
return (wsv, (slv, aux),
if chd then
let
val msg = "The dropdown for \"" ^ lab1 ^ "\" has changed, but the new value hasn't been selected by pushing the adjacent button."
in
case err of
None => Some msg
| Some err => Some (err ^ "\n" ^ msg)
end
else
err)}}
functor ManyToManyWithFile(M : sig
con full :: {Type}
con tname1 :: Name
con key1 :: Type
con col1 :: Name
con colR1 :: Name
con cols1 :: {Type}
con colsDone1 :: {Type}
con cstrs1 :: {{Unit}}
con impl11 :: Type
con impl12 :: Type
con impl13 :: Type
con tname2 :: Name
con key2 :: Type
con col2 :: Name
con colR2 :: Name
con cols2 :: {Type}
con colsDone2 :: {Type}
con cstrs2 :: {{Unit}}
con impl21 :: Type
con impl22 :: Type
con impl23 :: Type
con cstrs :: {{Unit}}
con old :: {(Type * {Type} * {Type} * {{Unit}} * Type * Type * Type)}
con others :: {(Type * Type * Type)}
constraint [tname1] ~ [tname2]
constraint [tname1, tname2] ~ old
constraint [tname1, tname2] ~ full
constraint [col1] ~ cols1
constraint [col2] ~ cols2
constraint [col1] ~ [col2]
constraint [colR1] ~ [colR2]
constraint others ~ [colR1, colR2]
constraint [FileName, FileType, FileData] ~ [colR1, colR2]
constraint [FileName, FileType, FileData] ~ others
val rel : sql_table ([colR1 = key1, colR2 = key2, FileName = string, FileType = string, FileData = blob] ++ map fst3 others) cstrs
val lab1 : string
val lab2 : string
val eq_key1 : eq key1
val ord_key1 : ord key1
val show_key1 : show key1
val read_key1 : read key1
val inj_key1 : sql_injectable key1
val eq_key2 : eq key2
val ord_key2 : ord key2
val show_key2 : show key2
val read_key2 : read key2
val inj_key2 : sql_injectable key2
val fl : folder others
val ws : $(map Widget.t' others)
val injs : $(map sql_injectable (map fst3 others))
val labels : $(map (fn _ => string) others)
val authorize : key1 -> key2 -> transaction bool
end) = struct
open M
type manyToManyWithFile11 = $(map thd3 others) * list key2 * impl11
type manyToManyWithFile12 = source string * $(map snd3 others) * source (option AjaxUpload.handle) * source (list (key2 * source ($(map fst3 others) * option AjaxUpload.handle) * source (option ($(map snd3 others) * source (option AjaxUpload.handle))))) * source bool * impl12
type manyToManyWithFile13 = list (key2 * $(map fst3 others) * option AjaxUpload.handle) * impl13
type manyToManyWithFile21 = $(map thd3 others) * list key1 * impl21
type manyToManyWithFile22 = source string * $(map snd3 others) * source (option AjaxUpload.handle) * source (list (key1 * source ($(map fst3 others) * option AjaxUpload.handle) * source (option ($(map snd3 others) * source (option AjaxUpload.handle))))) * source bool * impl22
type manyToManyWithFile23 = list (key1 * $(map fst3 others) * option AjaxUpload.handle) * impl23
fun download k1 k2 =
ok <- authorize k1 k2;
if not ok then
error <xml>Access denied</xml>
else
r <- oneRow1 (SELECT rel.FileName, rel.FileType, rel.FileData
FROM rel
WHERE rel.{colR1} = {[k1]}
AND rel.{colR2} = {[k2]});
setHeader (blessResponseHeader "Content-Disposition")
("attachment; filename=" ^ r.FileName);
returnBlob r.FileData (blessMime r.FileType)
val make (old : t ([tname1 = key1, tname2 = key2] ++ full)
([tname1 = (key1, [col1 = key1] ++ cols1, colsDone1, cstrs1, impl11, impl12, impl13),
tname2 = (key2, [col2 = key2] ++ cols2, colsDone2, cstrs2, impl21, impl22, impl23)] ++ old)) =
old -- tname1 -- tname2