-
Notifications
You must be signed in to change notification settings - Fork 1
/
observationForm.js
741 lines (716 loc) · 31.5 KB
/
observationForm.js
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
var utils = require('./utils');
var TBA = require('./TBA');
/********************
* Types of inputs *
- null (no input)
- dropdown [requires data]
- short_text
- long_text
- multiple_choice [requires data]
- checkbox [requires data]
- number
- increment_number
- slider [requires data]
********************/
var tableStructure = {
team: {
name: "<span class='no-mobile'>Team </span>#",
data: "team"
},
more: {
name: "More Info",
data: {
user: {
name: "User",
data: "user"
},
match: {
name: "Match Number",
data: "match"
},
auto_community: {
name: "[Auto] Community",
data: "auto_community"
},
auto_scored_objects: {
name: "[Auto] Objects Scored",
data: "auto_scored_objects"
},
auto_dropped_objects: {
name: "[Auto] Objects Dropped",
data: "auto_dropped_objects"
},
auto_charging: {
name: "[Auto] Charging",
data: "auto_charging"
},
auto_balanced: {
name: "[Auto] Balanced",
data: "auto_balanced"
},
auto_collisions: {
name: "[Auto] Collisions",
data: "auto_collisions"
},
teleop_scored_objects: {
name: "[Teleop] Scored Objects",
data: "teleop_scored_objects"
},
teleop_dropped_objects: {
name: "[Teleop] Dropped Objects",
data: "teleop_dropped_objects"
},
teleop_element_types: {
name: "[Teleop] Element Types",
data: "teleop_element_types"
},
teleop_robot_died: {
name: "[Teleop] Robot Died",
data: "teleop_robot_died"
},
teleop_time_robot_died: {
name: "[Teleop] Time robot Died",
data: "teleop_time_robot_died"
},
endgame_final_state: {
name: "[Endgame] Final State",
data: "endgame_final_state"
},
endgame_charge_time: {
name: "[Endgame] Charge Time",
data: "endgame_charge_time"
},
endgame_balancing: {
name: "[Endgame] Balancing",
data: "endgame_balancing"
},
time_on_defense: {
name: "[Defense] Percent of time on defense",
data: "time_on_defense"
},
speed: {
name: "[Bot] Speed compared to our robot",
data: "speed"
},
auto_comments: {
name: "Auto comments",
data: "auto_comments"
},
teleop_comments: {
name: "Teleop comments",
data: "teleop_comments"
},
endgame_comments: {
name: "Endgame comments",
data: "endgame_comments"
},
driver_comments: {
name: "Driver comments",
data: "driver_comments"
},
driver_skill: {
name: "Driver Skill",
data: "driver_skill"
},
final_comments: {
name: "Final comments",
data: "final_comments"
}
}
}
}
var observationFormSchema = {
user: {
type: String,
input: null
},
competition: {
type: String,
input: "dropdown",
placeholder: "Select a competition",
title: "Current competition",
subtitle: "If you're at a practice match, select \"Practice Match\""
},
match: {
type: String,
input: "number",
placeholder: "Match number only",
title: "Match Number",
subtitle: "This is the number of the match that you are observing"
},
team: {
type: String,
input: "short_text",
placeholder: "Team number only",
title: "Team Number",
subtitle: "This is the team number that you are observing"
},
auto_community: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No"
},
placeholder: "Yes or No",
title: "[Auto] Community",
subtitle: "Did they exit the community?"
},
auto_scored_objects: {
type: String,
input: "increment_number",
placeholder: "Number only",
title: "[Auto] Objects scored",
subtitle: "How many objects were successfully scored during auto?"
},
auto_dropped_objects: {
type: String,
input: "increment_number",
placeholder: "Number only",
title: "[Auto] Objects dropped",
subtitle: "How many objects were dropped during auto?"
},
auto_charging: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No",
"fell": "Fell/Rolled Off"
},
placeholder: "Yes or No",
title: "[Auto] Charging",
subtitle: "Did they successfully charge on the charging station?"
},
auto_balanced: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No",
},
placeholder: "Yes or No",
title: "[Auto] Charging",
subtitle: "Did they successfully balance on the charging station?"
},
auto_collisions: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No",
},
placeholder: "Yes or No",
title: "[Auto] Collisions",
subtitle: "Did they collide?"
},
teleop_scored_objects: {
type: String,
input: "increment_number",
placeholder: "Number only",
title: "[Teleop] Objects scored",
subtitle: "How many objects were successfully scored during teleop?"
},
teleop_dropped_objects: {
type: String,
input: "increment_number",
placeholder: "Number only",
title: "[Teleop] Objects dropped",
subtitle: "How many objects were dropped during teleop?"
},
teleop_element_types: {
type: String,
input: "checkbox",
placeholder: "Select all that apply",
data: {
"cone": "Cone",
"cube": "Cube",
},
title: "[Teleop] Elements",
subtitle: "What types of objects did they pick up?"
},
teleop_robot_died: {
type: String,
input: "multiple_choice",
data: {
"yes": "Yes",
"no": "No"
},
title: "[Teleop] Did the robot die?",
subtitle: "If they did, note the time of death for the next question"
},
teleop_time_robot_died: {
type: String,
input: "number",
placeholder: "Format: number of seconds only",
title: "[Game] Amount of time that robot was dead",
subtitle: "Max: 150. If the robot didn't die, leave this blank"
},
endgame_final_state: {
type: String,
input: "dropdown",
placeholder: "Select applicable",
data: {
"on_docked": "On Charge Station and docked",
"on_not_docked": "On Charge Station and not docked",
"failed_attempt": "Failed to get on charge station",
"no_attempt": "Did not attempt"
},
title: "[Endgame] Final State",
subtitle: "Carefully select all that apply"
},
endgame_charge_time: {
type: String,
input: "slider",
data: {
"min": 0,
"max": 60
},
title: "[Endgame] Time to charge",
subtitle: "Estimate the amount of time it took for robot to charge"
},
endgame_balancing: {
type: String,
input: "dropdown",
placeholder: "Select applicable",
data: {
"balanced": "Perfectly balanced",
"collided": "Ran into ally",
"fell": "Fell off and made everything tip",
"counter_counter_balancing": "Prevented others from balancing by trying to balance, but incorrectly"
},
title: "[Endgame] Charge station",
subtitle: "Carefully select all that apply"
},
time_on_defense: {
type: String,
input: "slider",
data: {
"min": 0,
"max": 100
},
title: "[Defense] Percent of time on defense",
subtitle: "Approximate percent of time on defense"
},
speed: {
type: String,
input: "dropdown",
data: {
"slow": "Slow (lower than 8 ft/second)",
"medium": "Medium (8 ft/second to 15 ft/second)",
"fast": "Fast (greater than 15 ft/second)",
},
placeholder: "Select one",
title: "[Bot] Speed compared to our robot (18 ft/second)",
subtitle: "Approximate this if you can"
},
auto_comments: {
type: String,
input: "long_text",
title: "[Auto] Extra comments",
subtitle: "Anything noteworthy that occurred during the autonomous period"
},
teleop_comments: {
type: String,
input: "long_text",
title: "[Teleop] Extra comments",
subtitle: "Write anything that might be noteworthy about teleop here."
},
endgame_comments: {
type: String,
input: "long_text",
title: "[Endgame] Any extra comments about the end of the game?",
subtitle: "Put anything that would be noteworthy about the end of the game here."
},
driver_comments: {
type: String,
input: "long_text",
title: "Any comments about the driver's skill?",
subtitle: "Put anything that would be noteworthy about the end of the game here."
},
driver_skill: {
type: String,
input: "slider",
data: {
"min": 1,
"max": 5
},
title: "Driver Skill",
subtitle: "On a scale from 1 (very bad) - 5 (very good), please rate how good the driving was"
},
final_comments: {
type: String,
input: "long_text",
title: "Any extra comments about the game overall? (very important!)",
subtitle: "Describe the driver skill, notable robot mechanisms/skills/flaws/behaviors, and anything else we should know as we try to imagine a robot."
},
}
function getObservationFormStructure() {
var form = {};
for (var key in observationFormSchema) {
if ("data" in observationFormSchema[key]) {
form[key] = {
input: observationFormSchema[key].input,
placeholder: observationFormSchema[key].placeholder,
data: observationFormSchema[key].data,
title: observationFormSchema[key].title,
subtitle: observationFormSchema[key].subtitle
}
} else if (observationFormSchema[key].input != null) {
form[key] = {
input: observationFormSchema[key].input,
placeholder: observationFormSchema[key].placeholder,
title: observationFormSchema[key].title,
subtitle: observationFormSchema[key].subtitle
}
}
}
return form;
}
function getObservationFormSchema() {
var schema = {};
for (var key in observationFormSchema) {
schema[key] = {
type: observationFormSchema[key].type
};
}
return schema;
}
function getObservationFormHandlebarsHelper(structure, options) {
var id = 0;
var finalString = '<form method="post" action="/scout/new">\n<div class="container">\n<div class="row">';
for (var category in structure) {
if (category == "events") continue;
finalString += '<p>';
finalString += '<b>' + structure[category].title + '</b>\n<br>\n' + structure[category].subtitle + '\n';
finalString += '</p>';
if (category == "competition") {
finalString += '<select name="competition">\n';
finalString += '<option value="" disabled ' + (utils.getCurrentEvent() == null ? 'selected' : '') + '>Choose event from list</option>\n';
for (var event in structure.events) {
finalString += '<option value="' + structure.events[event]["key"] + '"' + (structure.events[event]["current"] ? ' selected' : '') + '>' + structure.events[event]["name"] + '</option>\n';
}
finalString += '</select>\n';
} else {
if (structure[category].input == "dropdown") {
finalString += '<select name="' + category + '">\n';
finalString += '<option value="" disabled selected>' + structure[category].placeholder + '</option>\n';
for (var option in structure[category].data) {
finalString += '<option value="' + option + '">' + (structure[category].data)[option] + '</option>\n';
}
finalString += '</select>\n';
} else if (structure[category].input == "multiple_choice") {
for (var option in structure[category].data) {
finalString += '<p>\n';
finalString += '<input class="with-gap" name="' + category + '" value="' + option + '" type="radio" id="' + option + '_' + id + '" />\n';
finalString += '<label for="' + option + '_' + (id ++) + '">' + (structure[category].data)[option] + '</label>\n';
finalString += '</p>\n';
}
} else if (structure[category].input == "long_text") {
finalString += '<div class="input-field">\n';
finalString += '<textarea name="' + category + '" class="materialize-textarea"></textarea>\n';
finalString += '<label for="' + category + '">Message</label>\n';
finalString += '</div>\n';
} else if (structure[category].input == "short_text") {
finalString += '<div class="input-field">\n';
finalString += '<input placeholder="' + structure[category].placeholder + '" name="' + category + '" type="text">\n';
finalString += '</div>\n';
} else if (structure[category].input == "checkbox") {
finalString += '<select name="' + category + '" multiple>\n';
finalString += '<option value="" disabled selected>' + structure[category].placeholder + '</option>\n';
for (var option in structure[category].data) {
finalString += '<option value="' + option + '">' + (structure[category].data)[option] + '</option>\n';
}
finalString += '</select>\n';
} else if (structure[category].input == "number") {
finalString += '<div class="input-field">\n';
finalString += '<input class="validate" placeholder="' + structure[category].placeholder + '" name="' + category + '" type="number">\n';
finalString += '</div>\n';
} else if (structure[category].input == "increment_number") {
finalString += '<div class="box">\n';
if (structure[category].title.includes("Low")) {
// minus button
finalString += '<div class="s6">';
finalString += '<svg width="100%" height="100%" viewBox="0 0 2000 1000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">';
finalString += '<a class="btn increment_number_minus_button lower" data-for="' + category + '">';
finalString += '<g transform="matrix(1,0,0,1,-500,-500)"> <path d="M500,550C500,536.739 505.268,524.021 514.645,514.645C524.021,505.268 536.739,500 550,500C827.197,500 2172.8,500 2450,500C2463.26,500 2475.98,505.268 2485.36,514.645C2494.73,524.021 2500,536.739 2500,550C2500,720.701 2500,1279.3 2500,1450C2500,1463.26 2494.73,1475.98 2485.36,1485.36C2475.98,1494.73 2463.26,1500 2450,1500C2212.71,1500 1204.33,1500 1026.76,1500C1010.04,1500 994.43,1491.64 985.157,1477.74C909.333,1364 566.554,849.832 508.397,762.596C502.922,754.383 500,744.732 500,734.861C500,699.013 500,607.632 500,550Z" style="fill: rgb(38, 166, 154)" /> </g> <rect x="1000" y="475" width="357.411" height="50" />';
finalString += '</a>';
finalString += '</svg>';
finalString += '</div>';
// spacing
finalString += '<div class="col s1"></div>';
// input
finalString += '<input class="validate increment_number col s6" placeholder="' + structure[category].placeholder + '" name="' + category + '" type="number" value="0">\n';
// spacing
finalString += '<div class="col s1"></div>\n';
// plus button
finalString += '<div class="s6">';
finalString += '<svg width="100%" height="100%" viewBox="0 0 2000 1000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">';
finalString += '<a class="btn increment_number_plus_button lower" data-for="' + category + '">';
finalString += '<g transform="matrix(-1,0,0,1,2500,-500)"> <path d="M500,550C500,536.739 505.268,524.021 514.645,514.645C524.021,505.268 536.739,500 550,500C827.197,500 2172.8,500 2450,500C2463.26,500 2475.98,505.268 2485.36,514.645C2494.73,524.021 2500,536.739 2500,550C2500,720.701 2500,1279.3 2500,1450C2500,1463.26 2494.73,1475.98 2485.36,1485.36C2475.98,1494.73 2463.26,1500 2450,1500C2212.71,1500 1204.33,1500 1026.76,1500C1010.04,1500 994.43,1491.64 985.157,1477.74C909.333,1364 566.554,849.832 508.397,762.596C502.922,754.383 500,744.732 500,734.861C500,699.013 500,607.632 500,550Z" style="fill: rgb(38, 166, 154)" /> </g> <rect x="796.3" y="321.289" width="50" height="357.422" /> <g transform="matrix(6.12323e-17,1,-1,6.12323e-17,1321.3,-321.3)" > <rect x="796.3" y="321.289" width="50" height="357.422" /> </g>';
finalString += '</a>';
finalString += '</svg>';
finalString += '</div>';
} else {
// minus button
finalString += '<div class="s6">';
finalString += '<svg width="100%" height="100%" viewBox="0 0 2000 2250" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style=" fill-rule: evenodd; clip-rule: evenodd; stroke-linejoin: round; stroke-miterlimit: 2; " >';
finalString += '<a class="btn increment_number_minus_button upper" data-for="' + category + '">';
finalString += '<g transform="matrix(1,0,0,1,-500,-500)"> <path d="M500,550C500,536.739 505.268,524.021 514.645,514.645C524.021,505.268 536.739,500 550,500L2450,500C2463.26,500 2475.98,505.268 2485.36,514.645C2494.73,524.021 2500,536.739 2500,550L2500,2700C2500,2713.26 2494.73,2725.98 2485.36,2735.36C2475.98,2744.73 2463.26,2750 2450,2750L1332.12,2750C1312.55,2750 1294.78,2738.59 1286.65,2720.79C1187.16,2503.16 563.811,1139.59 504.526,1009.9C501.544,1003.38 500,996.287 500,989.113L500,550Z" style="fill: rgb(38, 166, 154)" /> </g> <rect x="1000" y="1100" width="357.417" height="50" />';
finalString += '</a>';
finalString += '</svg>';
finalString += '</div>';
// spacing
finalString += '<div class="col s1"></div>';
// input
finalString += '<input class="validate increment_number col s6" placeholder="' + structure[category].placeholder + '" name="' + category + '" type="number" value="0">\n';
// spacing
finalString += '<div class="col s1"></div>\n';
// plus button
finalString += '<div class="s6">';
finalString += '<svg width="100%" height="100%" viewBox="0 0 2000 2250" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style=" fill-rule: evenodd; clip-rule: evenodd; stroke-linejoin: round; stroke-miterlimit: 2; " >';
finalString += '<a class="btn increment_number_plus_button upper" data-for="' + category + '">';
finalString += '<g transform="matrix(-1,0,0,1,2500,-500)"> <path d="M500,550C500,536.739 505.268,524.021 514.645,514.645C524.021,505.268 536.739,500 550,500L2450,500C2463.26,500 2475.98,505.268 2485.36,514.645C2494.73,524.021 2500,536.739 2500,550L2500,2700C2500,2713.26 2494.73,2725.98 2485.36,2735.36C2475.98,2744.73 2463.26,2750 2450,2750L1332.12,2750C1312.55,2750 1294.78,2738.59 1286.65,2720.79C1187.16,2503.16 563.811,1139.59 504.526,1009.9C501.544,1003.38 500,996.287 500,989.113L500,550Z" style="fill: rgb(38, 166, 154)" /> </g> <rect x="796.293" y="946.286" width="50" height="357.422" /> <g transform="matrix(6.12323e-17,1,-1,6.12323e-17,1946.29,303.704)" > <rect x="796.293" y="946.286" width="50" height="357.422" /> </g>';
finalString += '</a>';
finalString += '</svg>';
finalString += '</div>';
}
finalString += '</div>\n';
// input field
// These rows provide spacing and make sure that the text box isn't on the same line as the buttons.
// finalString += '<div class="row s1"></div>';
// finalString += '<input class="validate increment_number col s6" placeholder="' + structure[category].placeholder + '" name="' + category + '" type="number" value="0">\n';
// finalString += '<div class="row s1"></div>\n';
} else if (structure[category].input == "slider") {
finalString += '<p class="range-field">';
finalString += '<input type="range" name="' + category + '" min="' + (structure[category].data)["min"] + '" max="' + (structure[category].data)["max"] + '" />';
finalString += '</p>';
}
}
finalString += '<br>';
}
finalString += '</div>\n</div>\n<div class="center">\n<button class="btn waves-effect waves-light green" type="submit" name="action">Submit</button>\n</div>\n</form>';
return finalString;
}
function getEditObservationHandlebarsHelper(observation, structure, observationID, options) {
var id = 0;
var finalString = '<form method="post" action="/scout/saveobservation/' + observationID + '">\n<div class="container">\n<div class="row">';
for (var category in structure) {
if (category == "events") continue;
finalString += '<p>';
finalString += '<b>' + structure[category].title + '</b>\n<br>\n' + structure[category].subtitle + '\n';
finalString += '</p>';
if (category == "competition") {
finalString += '<select name="competition">\n';
finalString += '<option value="" disabled ' + (utils.getCurrentEvent() == null ? 'selected' : '') + '>Choose event from list</option>\n';
for (var event in structure.events) {
finalString += '<option value="' + structure.events[event]["key"] + '"' + (structure.events[event]["key"] == observation[category] ? ' selected' : '') + '>' + structure.events[event]["name"] + '</option>\n';
}
finalString += '</select>\n';
} else {
if (structure[category].input == "dropdown") {
finalString += '<select name="' + category + '">\n';
finalString += '<option value="" disabled selected>' + structure[category].placeholder + '</option>\n';
for (var option in structure[category].data) {
finalString += '<option value="' + option + '"' + (option == observation[category] ? ' selected' : '') + '>' + (structure[category].data)[option] + '</option>\n';
}
finalString += '</select>\n';
} else if (structure[category].input == "multiple_choice") {
for (var option in structure[category].data) {
finalString += '<p>\n';
finalString += '<input class="with-gap" name="' + category + '" value="' + option + '" type="radio" id="' + option + '_' + id + '"' + (option == observation[category] ? ' checked' : '') + ' />\n';
finalString += '<label for="' + option + '_' + (id ++) + '">' + (structure[category].data)[option] + '</label>\n';
finalString += '</p>\n';
}
} else if (structure[category].input == "long_text") {
finalString += '<div class="input-field">\n';
finalString += '<textarea name="' + category + '" class="materialize-textarea">' + observation[category] + '</textarea>\n';
finalString += '<label for="' + category + '">Message</label>\n';
finalString += '</div>\n';
} else if (structure[category].input == "short_text") {
finalString += '<div class="input-field">\n';
finalString += '<input placeholder="' + structure[category].placeholder + '" name="' + category + '" type="text" value="' + observation[category] + '">\n';
finalString += '</div>\n';
} else if (structure[category].input == "checkbox") {
finalString += '<select name="' + category + '" multiple>\n';
finalString += '<option value="" disabled selected>' + structure[category].placeholder + '</option>\n';
for (var option in structure[category].data) {
finalString += '<option value="' + option + '"' + (observation[category] !== undefined && observation[category].split(",").includes(option) ? ' selected' : '') + '>' + (structure[category].data)[option] + '</option>\n';
}
finalString += '</select>\n';
} else if (structure[category].input == "number") {
finalString += '<div class="input-field">\n';
finalString += '<input class="validate" placeholder="' + structure[category].placeholder + '" name="' + category + '" type="number" value="' + observation[category] + '">\n';
finalString += '</div>\n';
} else if (structure[category].input == "increment_number") {
finalString += '<div class="input-field row">\n';
finalString += '<a class="waves-effect light-blue darken-3 waves-light btn increment_number_minus_button col s2" data-for="' + category + '">-</a>';
finalString += '<div class="col s1"></div>';
finalString += '<input class="validate increment_number col s6" placeholder="' + structure[category].placeholder + '" name="' + category + '" type="number" value="' + observation[category] + '">\n';
finalString += '<div class="col s1"></div>';
finalString += '<a class="waves-effect light-blue darken-3 waves-light btn increment_number_plus_button col s2" data-for="' + category + '">+</a>';
finalString += '</div>\n';
} else if (structure[category].input == "slider") {
finalString += '<p class="range-field">';
finalString += '<input type="range" name="' + category + '" min="' + (structure[category].data)["min"] + '" max="' + (structure[category].data)["max"] + '" value="' + observation[category] + '" />';
finalString += '</p>';
}
}
finalString += '<br>';
}
finalString += '</div>\n</div>\n<div class="center">\n<button class="btn waves-effect waves-light green" type="submit" name="action">Submit</button>\n</div>\n</form>';
return finalString;
}
function getTeamSummaryHandlebarsHelper(teamAverage, teamCapabilities, img, options){
var finalString = "";
finalString+="<h2 class= 'med-text blue-text text-darken-4'> Observed Robot Capabilities: </h2>";
finalString += "<table>\n<thead>"
finalString += "<th class='no-padding'>Category</th>\n"
finalString += "<th class='no-padding'>Maximum</th>\n"
finalString += "</thead>\n"
for(var category in teamCapabilities){
finalString+="<tr class='no-padding alternate-colors'><td class='no-padding'>";
if(category=='teleop_robot_died'){
finalString+="<b>Games Robot Has Died</b></td><td class='no-padding'>";
finalString+='Matches (' + teamCapabilities[category]+")</td></tr>"
continue;
}
if(category=='time_on_defense'){
finalString+="<b>[Defense] Defense Games Played</b></td><td class='no-padding'>";
finalString+='Matches (' + teamCapabilities[category]+")</td></tr>"
continue;
}
if(tableStructure["more"]["data"][category] == undefined) continue;
finalString+="<b>"+tableStructure["more"]["data"][category]["name"] + "</b></td><td class='no-padding'>";
if(typeof teamCapabilities[category] === 'object'){
var arr = [];
for(var obs in teamCapabilities[category]){
arr.push(observationFormSchema[category]["data"][teamCapabilities[category][obs]]);
}
var arrStr = arr.join(', ');
finalString += arrStr;
continue;
}
if(typeof teamCapabilities[category] === 'string'){
finalString += observationFormSchema[category]["data"][teamCapabilities[category]];
continue;
}
finalString+=teamCapabilities[category]+"</td></tr>";
}
finalString += "</table></br>";
finalString += "<div><div id='col-small-table'><h2 class= 'med-text blue-text text-darken-4'> Average Points Generated: </h2>";
finalString += "<table class='small-table'>\n<thead>"
finalString += "<th class='no-padding'>Category</th>\n"
finalString += "<th class='no-padding'>Points</th>\n"
finalString += "</thead>\n"
for(var category in teamAverage){
finalString+="<tr class='no-padding alternate-colors'><td class='no-padding'>";
var points = Math.floor(teamAverage[category]*100)/100;
if(category=='points_generated'){
finalString+="<b>Average Points Per Game</b></td><td class='no-padding'>";
finalString+=points+"</td></tr>"
continue;
}
if(tableStructure["more"]["data"][category] == undefined) continue;
finalString+="<b>"+tableStructure["more"]["data"][category]["name"] + "</b></td><td class='no-padding'>";
finalString+=points+"</td></tr>";
}
finalString+="</table></div>";
if(img != undefined){
finalString+="<div id='col-robot-picture' class='no-mobile'><h2 class='med-text blue-text text-darken-4'> Picture: </h2>";
finalString+="<a href='" + img + "' target='_blank'><img src='" + img + "' style='height: 200px'></img></a></div></div>"
}
return finalString;
}
function getTableHandlebarsHelper(structure, res, options) {
var finalString = "";
finalString+="<table class='bordered'>\n<thead>\n";
for (var category in tableStructure) finalString += "<th>" + tableStructure[category]["name"] + "</th>\n";
finalString += "<th class='no-mobile'>Edit</th>\n";
finalString += "<th class='no-mobile'>Delete</th>\n";
finalString += "</thead>\n";
for (var observation in structure) {
finalString += "<tr>";
if(structure[observation]['team'] == undefined) continue;
for (var category in tableStructure) {
var data = tableStructure[category]["data"];
if (typeof data == 'object') {
finalString += "<td>";
for (var subcategory in data) {
var data_subcategory = tableStructure[category]["data"][subcategory]["data"];
var display = structure[observation][data_subcategory];
if (display == null || display == "" || display == "undefined" || display == "NaN") continue;
if (observationFormSchema[subcategory]["input"] == "checkbox") {
var selectedChecks = display.split(",");
var checkboxFinalString = "";
for (var item in selectedChecks) {
checkboxFinalString += observationFormSchema[subcategory]["data"][selectedChecks[item]] + ", ";
}
checkboxFinalString = checkboxFinalString.substring(0, checkboxFinalString.length - 2);
display = checkboxFinalString;
} else if ("data" in observationFormSchema[subcategory] && observationFormSchema[subcategory]["input"] !== "slider") {
display = observationFormSchema[subcategory]["data"][display];
}
finalString += "<b>" + tableStructure[category]["data"][subcategory]["name"] + ": </b>" + display + "</b><br>";
}
finalString += "</td>";
} else if (category == "team") {
finalString += "<td><a href='/scout/list/" + structure[observation][data] + "'><b class='med-text'>" + structure[observation][data] + "</b></a><br>";
finalString +="<a class='mobile-only " + (res.locals.user.admin || res.locals.user.email == structure[observation]["user"] ? "" : " disabled") + "' href='/scout/editobservation/" + structure[observation]["_id"] + "'>Edit <br></a>"
finalString += "<a class='mobile-only modal-trigger open-modal" + (res.locals.user.admin || res.locals.user.email == structure[observation]["user"] ? "" : " disabled") + "' href='#confirm-delete-modal' data-id='" + structure[observation]["_id"] + "'>Delete</a></td>";
} else {
finalString += "<td>" + structure[observation][data] + "</td>";
}
}
finalString += "<td class='no-mobile'><a class='waves-effect waves-light btn-large light-blue" + (res.locals.user.admin || res.locals.user.email == structure[observation]["user"] ? "" : " disabled") + "' href='/scout/editobservation/" + structure[observation]["_id"] + "'><i class='material-icons'>create</i></a></td>";
finalString += "<td class='no-mobile'><a class='waves-effect waves-light btn-large red modal-trigger open-modal" + (res.locals.user.admin || res.locals.user.email == structure[observation]["user"] ? "" : " disabled") + "' href='#confirm-delete-modal' data-id='" + structure[observation]["_id"] + "'><i class='material-icons'>delete</i></a></td>";
finalString += "</tr>";
}
finalString += "</table>";
return finalString;
}
function getRankingHandlebarsHelper(structure, filter, options) {
var finalString = "<table class='bordered'>\n<thead>\n";
finalString += "<th class='stickyy'>Place</th>\n";
rankingStructure = ['place'];
if(structure.length == 0) return;
for (var category in structure[0]) {
if (category==filter || category=='team')
finalString += "<th class='stickyy'>" + category[0].toUpperCase() + category.slice(1) + "</th>\n";
else{
finalString += "<th class='no-mobile stickyy'>" + category[0].toUpperCase() + category.slice(1) + "</th>\n";
}
rankingStructure.push(category);
}
finalString += "</thead>\n";
for (var observation in structure) {
finalString += "<tr class='alternate-colors'>";
for (var category in rankingStructure) {
var data = rankingStructure[category];
if (data == "place") {
finalString += "<td><b>" + (parseInt(observation) + 1) + "</b></td>";
} else if (data == "team") {
finalString += "<td><b><a href='/scout/list/" + structure[observation][data] + "'>" + structure[observation][data] + "</a></b></td>";
continue;
} else {
if (filter == data)
finalString += "<td>" + structure[observation][data] + "</td>";
else{
finalString += "<td class='no-mobile'>" + structure[observation][data] + "</td>";
}
}
}
finalString += "</tr>";
}
finalString += "</table>";
return finalString;
}
module.exports = {
getTeamSummaryHandlebarsHelper: getTeamSummaryHandlebarsHelper,
getObservationFormSchema: getObservationFormSchema,
getObservationFormStructure: getObservationFormStructure,
getObservationFormHandlebarsHelper: getObservationFormHandlebarsHelper,
getEditObservationHandlebarsHelper: getEditObservationHandlebarsHelper,
getTableHandlebarsHelper: getTableHandlebarsHelper,
getRankingHandlebarsHelper: getRankingHandlebarsHelper
};