-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvolume_ui.ml
371 lines (369 loc) · 14.1 KB
/
volume_ui.ml
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
let create_volume total_free_space =
Tyxml_html.(
section
~a:[ a_id "block-create"; a_class [ "w-full mx-auto" ] ]
[
div
~a:[ a_class [ "my-6" ] ]
[
label
~a:
[
a_class [ "block text-sm font-medium" ];
a_label_for "block name";
]
[ txt "Volume name" ];
input
~a:
[
a_autocomplete `On;
a_input_type `Text;
a_name "block_name";
a_id "block_name";
a_class
[
"ring-primary-100 mt-1.5 transition appearance-none \
block w-full px-3 py-3 rounded-xl shadow-sm border \
hover:border-primary-200\n\
\ \
focus:border-primary-300 bg-primary-50 bg-opacity-0 \
hover:bg-opacity-50 focus:bg-opacity-50 \
ring-primary-200 focus:ring-primary-200\n\
\ \
focus:ring-[1px] focus:outline-none";
];
]
();
];
div
~a:[ a_class [ "my-6" ] ]
[
label
~a:
[
a_class [ "block text-sm font-medium" ];
a_label_for "block size";
]
[ txt "Volume size" ];
small
~a:[ a_class [ "text-sm" ] ]
[
txt
("can assign up to: " ^ string_of_int total_free_space ^ " MB");
];
div
~a:
[
a_class [ "space-x-5 my-4" ];
Unsafe.string_attrib "x-data" "{count : 50}";
]
[
Utils.button_component
~attribs:
[ Unsafe.string_attrib "x-on:click" "count = count + 50" ]
~content:(i ~a:[ a_class [ "fa-solid fa-plus" ] ] [])
~btn_type:`Primary_outlined ();
span
~a:
[
a_id "block_size";
a_contenteditable true;
a_class [ "text-4xl border px-4" ];
a_user_data "x-on:keydown.enter.prevent" "";
Unsafe.string_attrib "x-on:input"
"let value = \
$event.target.innerText.replace(/[^0-9]/g,'');\n\
\ \
$event.target.innerText = value;\n\
\ count = \
parseInt(value) || 1;";
Unsafe.string_attrib "x-text" "count";
Unsafe.string_attrib "x-on:blur"
"$event.target.innerText = count;";
]
[];
span ~a:[ a_class [ "text-4xl" ] ] [ txt "MB" ];
Utils.button_component
~attribs:
[
Unsafe.string_attrib "x-on:click"
"if (count > 1) count = count - 50";
]
~content:(i ~a:[ a_class [ "fa-solid fa-minus" ] ] [])
~btn_type:`Danger_outlined ();
];
];
div
~a:
[
a_class [ "my-6" ];
Unsafe.string_attrib "x-data" "{ showUpload : false}";
]
[
label
~a:
[
a_label_for "dataToggle";
a_class [ "inline-flex cursor-pointer items-center gap-3" ];
]
[
input
~a:
[
a_id "dataToggle";
a_input_type `Checkbox;
a_class [ "peer sr-only" ];
a_role [ "switch" ];
Unsafe.string_attrib "x-on:click"
"showUpload = !showUpload";
]
();
span
~a:
[
a_aria "hidden" [ "true" ];
a_class
[
"relative h-6 w-11 after:h-5 after:w-5 \
peer-checked:after:translate-x-5 rounded-full \
border border-gray-300 bg-gray-50 after:absolute \
after:bottom-0 after:left-[0.0625rem] after:top-0 \
after:my-auto after:rounded-full after:bg-gray-600 \
after:transition-all after:content-[''] \
peer-checked:bg-primary-500 \
peer-checked:after:bg-white peer-focus:outline \
peer-focus:outline-2 peer-focus:outline-offset-2 \
peer-focus:outline-gray-800 \
peer-focus:peer-checked:outline-primary-500 \
peer-active:outline-offset-0 \
peer-disabled:cursor-not-allowed \
peer-disabled:opacity-70 dark:border-gray-700 \
dark:bg-gray-900 dark:after:bg-gray-300 \
dark:peer-checked:bg-primary-500 \
dark:peer-checked:after:bg-white \
dark:peer-focus:outline-gray-300 \
dark:peer-focus:peer-checked:outline-primary-500";
];
]
[];
span
~a:
[
a_class
[
"trancking-wide text-sm font-medium text-gray-600 \
peer-checked:text-gray-900 \
peer-disabled:cursor-not-allowed \n\
\ \
dark:peer-checked:text-white";
];
]
[ txt "Dumb data to this volume" ];
];
div
~a:
[
Unsafe.string_attrib "x-show" "showUpload"; a_class [ "my-4" ];
]
[
div
~a:[ a_class [ "my-4" ] ]
[
label
~a:
[
a_class [ "block text-sm font-medium" ];
a_label_for "data";
]
[ txt "Select a file to dump to the volume" ];
input
~a:
[
a_input_type `File;
a_name "block_data";
a_id "block_data";
a_class
[
"ring-primary-100 mt-1.5 transition \
appearance-none block w-full px-3 py-3 \
rounded-xl shadow-sm border \
hover:border-primary-200\n\
\ \
focus:border-primary-300 bg-primary-50 \
bg-opacity-0 hover:bg-opacity-50 \
focus:bg-opacity-50 ring-primary-200 \
focus:ring-primary-200\n\
\ \
focus:ring-[1px] focus:outline-none";
];
]
();
];
div
~a:[ a_class [ "my-4 flex items-center" ] ]
[
input
~a:
[
a_input_type `Checkbox;
a_name "block_compressed";
a_id "block_compressed";
a_class [ "accent-primary-500 mr-2 w-6 h-6" ];
]
();
label
~a:
[
a_class [ "text-sm font-medium" ]; a_label_for "data";
]
[ txt "Is this file compressed?" ];
];
];
];
div
~a:[ a_class [ "my-6" ] ]
[
Utils.button_component
~attribs:
[ a_id "create-block-button"; a_onclick "createVolume()" ]
~extra_css:"w-full" ~content:(txt "Create Volume")
~btn_type:`Primary_full ();
];
])
let download_volume name =
Tyxml_html.(
section
~a:[ a_id "block-download"; a_class [ "w-full mx-auto" ] ]
[
div
[
label
~a:
[
a_class [ "block my-2 font-medium" ]; a_label_for "block name";
]
[ txt name ];
p ~a:[ a_id "download-alert"; a_class [ "my-2 hidden" ] ] [];
label
~a:
[
a_class [ "block text-sm font-medium" ];
a_label_for "compression_level";
]
[ txt "Set Compression level" ];
div
~a:
[
a_class [ "space-x-5 my-4" ];
Unsafe.string_attrib "x-data" "{level : 1}";
]
[
Utils.button_component
~attribs:
[
Unsafe.string_attrib "x-on:click"
"if (level < 9) level = level + 1";
]
~content:(i ~a:[ a_class [ "fa-solid fa-plus" ] ] [])
~btn_type:`Primary_outlined ();
span
~a:
[
a_id "compression-level";
a_contenteditable true;
a_class [ "text-4xl border px-4" ];
a_user_data "x-on:keydown.enter.prevent" "";
Unsafe.string_attrib "x-on:input"
"let value =\n\
\ \
$event.target.innerText.replace(/[^0-9]/g,'');\n\
\ \
$event.target.innerText = value;\n\
\ \
level = parseInt(value) || 1;";
Unsafe.string_attrib "x-text" "level";
Unsafe.string_attrib "x-on:blur"
"$event.target.innerText = level;";
]
[];
Utils.button_component
~attribs:
[
Unsafe.string_attrib "x-on:click"
"if (level > 1) level = level - 1";
]
~content:(i ~a:[ a_class [ "fa-solid fa-minus" ] ] [])
~btn_type:`Danger_outlined ();
];
Utils.button_component
~attribs:
[
a_id ("download-block-button-" ^ name);
a_onclick ("downloadVolume('" ^ name ^ "')");
]
~extra_css:"my-4"
~content:(txt ("Download " ^ name))
~btn_type:`Primary_full ();
];
])
let upload_to_volume name =
Tyxml_html.(
section
~a:[ a_id "block-upload"; a_class [ "w-full mx-auto" ] ]
[
div
~a:[ a_class [ "my-4" ] ]
[
label
~a:[ a_class [ "block text-sm font-medium" ]; a_label_for "data" ]
[ txt "Select a file to dump to the volume" ];
input
~a:
[
a_input_type `File;
a_name "block_data";
a_id "block_data";
a_class
[
"ring-primary-100 mt-1.5 transition appearance-none \
block w-full px-3 py-3 rounded-xl shadow-sm border \
hover:border-primary-200\n\
\ \
focus:border-primary-300 bg-primary-50 bg-opacity-0 \
hover:bg-opacity-50 focus:bg-opacity-50 \
ring-primary-200 focus:ring-primary-200\n\
\ \
focus:ring-[1px] focus:outline-none";
];
]
();
];
div
~a:[ a_class [ "my-4 flex items-center" ] ]
[
input
~a:
[
a_input_type `Checkbox;
a_name "block_compressed";
a_id "block_compressed";
a_class [ "accent-primary-500 mr-2 w-6 h-6" ];
]
();
label
~a:[ a_class [ "text-sm font-medium" ]; a_label_for "data" ]
[ txt "Is this file compressed?" ];
];
div
~a:[ a_class [ "my-6" ] ]
[
Utils.button_component
~attribs:
[
a_id ("upload-block-button-" ^ name);
a_onclick ("uploadToVolume('" ^ name ^ "')");
]
~extra_css:"w-full" ~content:(txt "Upload data")
~btn_type:`Primary_full ();
];
])