-
Notifications
You must be signed in to change notification settings - Fork 1
/
qrdcreator.html
788 lines (713 loc) · 29 KB
/
qrdcreator.html
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
<!DOCTYPE html>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
<!-- <link rel="stylesheet" href=".css"> -->
<style>
</style>
<script> //getter API
// getElementById
function $id(id) {
console.log(id);
var element=document.getElementById(id);
if (element){
element.tag = function(tag){
return element.getElementsByTagName(tag);
};
} else {
element=[];
element.tag = function(tag){
return undefined;
};
};
return element;
}
chr=String.fromCharCode; cN=chr(13); cT=chr(9); cTT=cT+cT; cTTT=cTT+cT; //define special characters
</script>
<script>
////////////// Restoring data
var textHandle='';
function loadFile(){
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.onload = function() {
var text = reader.result;
textHandle=text;
//console.log(text);
fillForm(text);
};
reader.readAsText(file);
};
function Output(msg) {
var m = $id("messages");
m.innerHTML = msg + m.innerHTML;
};
var jay={};
var jkeys=[];
function fillForm(txt) {
jay=JSON.parse(txt);
jkeys=Object.keys(jay); // remove the offending additParams here
if (jkeys.indexOf('additParams')<0){
additParams=[];
} else {
additParamsKey=jkeys.splice(jkeys.indexOf('additParams'),1);
additParams=jay[additParamsKey];
};
for (i in jkeys){
$id(jkeys[i]).value=jay[jkeys[i]];
};
checkBoxChkUpdate(); //update checked state of checkboxes after loading data
remakeAdditForm();
};
////////////// Saving data
function save() {
checkBoxValUpdate(); // set checkboxes values before saving
collectAdditParamInputs()
var link = $id("downloadLink");
link.href = makeTextFile(JSON.stringify(buildDict()));
link.style.display = 'block';
};
var textFile = null;
function makeTextFile(text) {
var data = new Blob([text], {type: 'text/plain'});
if (textFile !== null) {window.URL.revokeObjectURL(textFile);}; // prevent memory leaks.
textFile = window.URL.createObjectURL(data);
return textFile;
};
//var DEBUGdict={};
//var DEBUGlistOfFormIds=[];
function buildDict(){
// listOfFormIds=[for (x of $id("form").tag("input")) x.id].concat( [for (x of $id("form").tag("select")) x.id] );
var listOfFormIds=[];
for (x of $id("form").tag("input")) {
listOfFormIds.push(x.id);
};
let q=[];
for (x of $id("form").tag("select")) {
q.push(x.id);
};
listOfFormIds.concat(q);
listOfFormIds=listOfFormIds.concat(q);
//[for (x of $id("form").tag("input")) x.id].concat( [for (x of $id("form").tag("select")) x.id] );
var dict = {};
listOfFormIds.forEach(
function(x,i,q){
// console.log('v = ' + v);
v=x[0];
if (v==='m' || v==='r' || v==='V'){
console.log('x = ' + x);
dict[x]=$id(x).value;
};
}
);
dict.additParams=additParams; /// WILL THIS WORK???
// DEBUGdict=dict;
// DEBUGlistOfFormIds=listOfFormIds;
return dict;
};
/////////// make form empty
var text='';
function clearForm(){
// read text from URL location
var request = new XMLHttpRequest();
request.open('GET', 'void.txt', true);
request.send(null);
request.onreadystatechange = function () {
if (request.readyState==4){
text=request.responseText;
// console.log(text);
fillForm(text);
};
};
};
//// update checkbox values
var myboxes;
function checkBoxValUpdate(){
myboxes = document.querySelectorAll('input[type=checkbox]');
myboxes.forEach(function (mybox,b,c){
mybox.value=['off','on'][+(mybox.checked)];
});
};
function checkBoxChkUpdate(){
myboxes = document.querySelectorAll('input[type=checkbox]');
myboxes.forEach(function (mybox,b,c){
mybox.checked=mybox.value=='on';
});
};
</script>
<!--------------------->
</head>
<div>
Use previously saved file:
<input type="file" id="fileselect" name="fileselect[]" multiple="multiple" onchange="loadFile()" />
</div>
<br />
<div id="messages"></div>
Save current edits:
<button id="save" onclick="save()">Save</button>
<a download="form.txt" id="downloadLink" style="display: none">Download</a>
<p>Clear form:
<button id="save" onclick="clearForm()">Restore defaults</button>
</p>
<!-----------------------------><hr />
<div id="form">
URL of your data relative to the q.rd: <input id="m_Data_Source"></input><br />
<i>e.g.: data/fp05-good.csv</i><br /><br />
Describe your table: <input id="m_Service_Description"></input><br />
<i>e.g.: EPN-TAP access to the Test CRISM database.</i>
<div class='MetaData'></div>
<h1 style="color:red">Mandatory parameters:</h1>
<p><i>This may include python expressions. <br />
To map input directly to output choose "MAP" <br />
To use expressions choose "VAR"<br />
For null values choose "NUL"
</i></p>
<div class="MandatoryData"></div>
<p />
<p />
<h1 style="color:red">Optional parameters</h1>
<div class="OptionalData"></div>
<p />
<p />
<!-------------ADDITIONAL PARAMETERS ------------>
<h1 style="color:red">Additional parameters</h1>
<div class="AdditionalDataWrapper">
<div id="AdditionalData"></div>
<button id="btnAddParams" onclick="addAdditionalParameterNew();">Add parameter</button>
</div>
<p>
<button id="btnGenerate">generate q.rd</button>
</p>
<div><PRE id="output"> javascript outputs here </PRE></div>
<!--------------------->
<script>
//////////////////// DATA INIT BEGINS ///////////
var TableMetaRowsData=[];
TableMetaRowsData[0]={};
TableMetaRowsData[0].header = "Metadata for the resource:";
TableMetaRowsData[0].comment = "test comment";
TableMetaRowsData[0].optionsEnabled = false;
TableMetaRowsData[0].waveband = [
["Radio","mWbRadio"],
["Millimeter","mWbMillimeter"],
["Infrared","mWbInfrared"],
["Optical","mWbOptical"], // THIS THING NEEDS FIXING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!!
["UV","mWbUV"],
["EUV","mWbEUV"],
["X-ray","mWbXRay"],
["Gamma-ray","mWbGammaRay"]
];
TableMetaRowsData[0].rows = [
["Schema name:","mSchema"],
["Title:","mTitle",,,,"title"],
["Description:","mDescription",,,,"description"],
["Creation date:","mCreationDate"," (e.g. 2016-03-30T00:00:00)",,,"creationDate"],
["Subject:","mSubject",,,,"subject"],
["Creator name:","mCreatorName",,,,"creator.name"],
["Contact name:","mContactName",,,,"contact.name"],
["Contact email:","mContactEmail",,,,"contact.email"],
["Instrument:","mInstrument",,,,"instrument"],
["Facility:","mFacility",,,,"facility"],
["Source:","mSource",,,,"source"],
["Content level:","mContentLevel",,,,"contentLevel"],
["Waveband (Mark all that apply): ",TableMetaRowsData[0].waveband,,"checkbox"],
["Profile:","mProfile"],
];
var TableRowsData=[];
TableRowsData[0]={};
TableRowsData[0].header = "1 - Granule references";
TableRowsData[0].comment = "NUL values not allowed, all values required"
TableRowsData[0].optionsEnabled = true;
TableRowsData[0].rows = [
["Unique granule ID (granule_uid):","r_granule_uid",,,["MAP","VAR"]],
["Granule group ID (granule_gid):","r_granule_gid",,,["MAP","VAR"]],
["Observation ID (obs_id):","r_obs_id",,,["MAP","VAR"]],
];
TableRowsData[1]={};
TableRowsData[1].header = "2 - Data description";
TableRowsData[1].comment = ""
TableRowsData[1].optionsEnabled = true;
TableRowsData[1].rows = [
["DataProduct Type (dataproduct_type): ","r_dataproduct_type",,,["NUL","MAP","VAR"]],
["Measurement Type (measurement_type): ","r_measurement_type",,,["NUL","MAP","VAR"]],
,
["Processing Level (processing_level):",["r_processing_level",
["Unprocessed Data Record", "1","1 - Unprocessed"],
["Experiment Data Record", "2","2 - Experiment"],
["Reduced Data Record", "3","3 - Reduced"],
["Reformatted Data Record", "4","4 - Reformatted"],
["Derived Data Record", "5","5 - Derived"],
["Ancillary Data Record", "6","6 - Ancillary"],
]," * This field is mandatory.","option",["VAR"]],
];
TableRowsData[2]={};
TableRowsData[2].header = "3 - Target descripion";
TableRowsData[2].comment = ""
TableRowsData[2].optionsEnabled = true;
TableRowsData[2].rows = [
["Target Name (target_name):","r_target_name",,,["NUL","MAP","VAR"]],
["Target Class (target_class):","r_target_class",,,["NUL","MAP","VAR"]]
];
TableRowsData[3]={};
TableRowsData[3].header = "4 - Axes";
TableRowsData[3].comment = ""
TableRowsData[3].optionsEnabled = true;
TableRowsData[3].rows = [
["Time Range minimum (time_min):","r_time_min",,,["NUL","MAP","VAR"]],
["Time Range maximum (time_max):","r_time_max",,,["NUL","MAP","VAR"]],
["Time Sampling Step minimum (time_sampling_step_min):","r_time_sampling_step_min",,,["NUL","MAP","VAR"]],
["Time Sampling Step maximum (time_sampling_step_max):","r_time_sampling_step_max",,,["NUL","MAP","VAR"]],
["Exposure time minimum (time_exp_min):","r_time_exp_min",,,["NUL","MAP","VAR"]],
["Exposure time maximum (time_exp_max):","r_time_exp_max",,,["NUL","MAP","VAR"]],
,
["Spectral Range minimum (spectral_range_min):","r_spectral_range_min",,,["NUL","MAP","VAR"]],
["Spectral Range maximum (spectral_range_max):","r_spectral_range_max",,,["NUL","MAP","VAR"]],
["Spectral Sampling Step (spectral_sampling_step):","r_spectral_sampling_step",,,["NUL","MAP","VAR"]],
["Spectral Resolution (spectral_resolution):","r_spectral_resolution",,,["NUL","MAP","VAR"]],
["Spatial Coordinates:",,,"subtitle"],
["C1 minimum (c1min):","r_c1min",,,["NUL","MAP","VAR"]],
["C1 maximum (c1max):","r_c1max",,,["NUL","MAP","VAR"]],
["C1 Spatial Resolution minimum (c1_resol_min):","r_c1_resol_min",,,["NUL","MAP","VAR"]],
["C1 Spatial Resolution maximum (c1_resol_max):","r_c1_resol_max",,,["NUL","MAP","VAR"]],
,
["C2 minimum (c2min):","r_c2min",,,["NUL","MAP","VAR"]],
["C2 maximum (c2max):","r_c2max",,,["NUL","MAP","VAR"]],
["C2 Spatial Resolution minimum (c2_resol_min):","r_c2_resol_min",,,["NUL","MAP","VAR"]],
["C2 Spatial Resolution maximum (c2_resol_max):","r_c2_resol_max",,,["NUL","MAP","VAR"]],
,
["C3 minimum (c3min):","r_c3min",,,["NUL","MAP","VAR"]],
["C3 maximum (c3max):","r_c3max",,,["NUL","MAP","VAR"]],
["C3 Spatial Resolution minimum (c3_resol_min):","r_c3_resol_min",,,["NUL","MAP","VAR"]],
["C3 Spatial Resolution maximum (c3_resol_max):","r_c3_resol_max",,,["NUL","MAP","VAR"]],
,
["Spatial Frame Type (spatial_frame_type):",["r_spatial_frame_type",
["celestial","celestial","celestial"],
["body","body","body"],
["cartesian","cartesian","cartesian"],
["cylindrical","cylindrical","cylindrical"],
["spherical","spherical","spherical"],
["healpix","healpix","healpix"],
]," * This field is mandatory.","option",["VAR"]],
["Angles:","",,"subtitle"],
["Incidence Angle minimum (incidence_min):","r_incidence_min",,,["NUL","MAP","VAR"]],
["Incidence Angle maximum (incidence_max):","r_incidence_max",,,["NUL","MAP","VAR"]],
,
["Emergence Angle minimum (emergence_min):","r_emergence_min",,,["NUL","MAP","VAR"]],
["Emergence Angle maximum (emergence_max):","r_emergence_max",,,["NUL","MAP","VAR"]],
,
["Phase Angle minimum (phase_min):","r_phase_min",,,["NUL","MAP","VAR"]],
["Phase Angle maximum (phase_max):","r_phase_max",,,["NUL","MAP","VAR"]],
,
["Footprint (s_region):","r_s_region","e.g.: {(10.d,5d),(15.d,5d),...}",,["NUL","MAP","VAR"]],
];
TableRowsData[4]={};
TableRowsData[4].header = "5 - Data origin";
TableRowsData[4].comment = "";
TableRowsData[4].optionsEnabled = true;
TableRowsData[4].rows = [
["Instrument Host Name (instrument_host_name):","r_instrument_host_name",,,["NUL","MAP","VAR"]],
["Instrument Name (instrument_name):","r_instrument_name",,,["NUL","MAP","VAR"]]
];
TableRowsData[5]={};
TableRowsData[5].header = "6 - Granule call-back info";
TableRowsData[5].comment = ""
TableRowsData[5].optionsEnabled = true;
TableRowsData[5].rows = [
["Service title (service_title):","r_service_title",,,["NUL","MAP","VAR"]], // Is this even necessary? shouldn't it be the same as schema??
["Creation date (creation_date):","r_creation_date",,,["NUL","MAP","VAR"]],
["Modification date (modification_date):","r_modification_date",,,["NUL","MAP","VAR"]],
["Release date (release_date):","r_release_date",,,["NUL","MAP","VAR"]]
];
var TableOptionalRowsData=[]; // All the optional parameters and functionality of adding rows should go here
TableOptionalRowsData[0]={};
TableOptionalRowsData[0].header = "7 - Data Access Reference";
TableOptionalRowsData[0].comment = ""
TableOptionalRowsData[0].optionsEnabled = true;
TableOptionalRowsData[0].rows = [
["Data file (access_url):","r_access_url","URL, case sensitive. If present, next 2 paramenters must be present.",,["NUL","MAP","VAR"]],
["File format MIME-type (access_format):","r_access_format",,,["NUL","MAP","VAR"]],
["File size (access_estsize):","r_access_estsize","in kilobytes",,["NUL","MAP","VAR"]],
["Thumbnail (thumbnail_url):","r_thumbnail_url","typically 200x200px",,["NUL","MAP","VAR"]],
["File name (file_name):","r_file_name",,,["NUL","MAP","VAR"]],
["MD5 Hash (access_md5):","r_access_md5",,,["NUL","MAP","VAR"]],
];
TableOptionalRowsData[1]={};
TableOptionalRowsData[1].header = "8 - Supplementary descriptions";
TableOptionalRowsData[1].comment = ""
TableOptionalRowsData[1].optionsEnabled = true;
TableOptionalRowsData[1].rows = [
["Additional location in time and space:",,,"subtitle"],
["Solar longtude minimum (solar_longitude_min):","r_solar_longitude_min",,,["NUL","MAP","VAR"]],
["Solar longtude maximum (solar_longitude_max):","r_solar_longitude_max",,,["NUL","MAP","VAR"]],
["Local time minimum (local_time_min):","r_local_time_min",,,["NUL","MAP","VAR"]],
["Local time maximum (local_time_max):","r_local_time_max",,,["NUL","MAP","VAR"]],
["Target distance minimum (target_distance_min):","r_target_distance_min",,,["NUL","MAP","VAR"]],
["Target distance maximum (target_distance_max):","r_target_distance_max",,,["NUL","MAP","VAR"]],
["Target time minimum (target_time_min):","r_target_time_min",,,["NUL","MAP","VAR"]],
["Target time maximum (target_time_max):","r_target_time_max",,,["NUL","MAP","VAR"]],
["Earth distance minimum (earth_distance_min):","r_earth_distance_min",,,["NUL","MAP","VAR"]],
["Earth distance maximum (earth_distance_max):","r_earth_distance_max",,,["NUL","MAP","VAR"]],
["Sun distance minimum (sun_distance_min):","r_sun_distance_min",,,["NUL","MAP","VAR"]],
["Sun distance maximum (sun_distance_max):","r_sun_distance_max",,,["NUL","MAP","VAR"]],
["Observing geometry:",,,"subtitle"],
["subsolar_longitude:","r_subsolar_longitude",,,["NUL","MAP","VAR"]],
["subsolar_latitude","r_subsolar_latitude",,,["NUL","MAP","VAR"]],
["subobserver_longitude","r_subobserver_longitude",,,["NUL","MAP","VAR"]],
["subobserver_latitude","r_subobserver_latitude",,,["NUL","MAP","VAR"]],
["Celestial coordinates:",,,"subtitle"],
["ra","r_ra",,,["NUL","MAP","VAR"]],
["dec","r_dec",,,["NUL","MAP","VAR"]],
["Vertical scales on planets:",,,"subtitle"],
["radial_distance","r_radial_distance",,,["NUL","MAP","VAR"]],
["altitude_fromshape","r_altitude_fromshape",,,["NUL","MAP","VAR"]],
["Description of coordinate frame:",,,"subtitle"],
["spatial_coordinate_description","r_spatial_coordinate_description",,,["NUL","MAP","VAR"]],
["spatial_origin","r_spatial_origin",,,["NUL","MAP","VAR"]],
["time_origin","r_time_origin",,,["NUL","MAP","VAR"]],
["time_scale","r_time_scale",,,["NUL","MAP","VAR"]],
["Other optional parameters:",,,"subtitle"],
["bib_reference","r_bib_reference",,,["NUL","MAP","VAR"]],
["publisher","r_publisher",,,["NUL","MAP","VAR"]],
["internal_reference","r_internal_reference",,,["NUL","MAP","VAR"]],
["external_link","r_external_link",,,["NUL","MAP","VAR"]],
["species","r_species",,,["NUL","MAP","VAR"]],
["filter","r_filter",,,["NUL","MAP","VAR"]],
["alt_target_name","r_alt_target_name",,,["NUL","MAP","VAR"]],
["feature_name","r_feature_name",,,["NUL","MAP","VAR"]],
["target_region","r_target_region",,,["NUL","MAP","VAR"]],
//["","r_",,,["NUL","MAP","VAR"]],
];
var accessibilityRows=[
//name, ucd, description
['access_url',"meta.ref.url;meta.file",'URL of the data file, \n'+cTTT+'case sensitive. If present, next 2 paramenters must be present.'],
['access_format','meta.code.mime','File format type'],
['access_estsize','phys.size;meta.file','Estimate file size in kbyte (with this spelling)'],
['thumbnail_url','meta.ref.url;meta.preview','URL of a thumbnail image with predefined size (png ~200 pix, for use in a client only)'],
['file_name','meta.id;meta.file','Name of the data file only, case sensitive'],
['access_md5','meta.checksum;meta.file','MD5 Hash for the file when available (real file, not script)']
];
var additionalRowsTest = [
["test_01_name", "test_01_ucd", "test_01_desc"],
["test_02_name", "test_02_ucd", "test_02_desc"],
["test_03_name", "test_03_ucd", "test_03_desc"]
];
///TEMPLATE FOR DATA: // ["","",,,["NUL","MAP","VAR"]],
//////////////////// DATA INIT ENDS ///////////
//////// POPULATE INPUT TABLE BEGINS //////////
function makeInputText(name, comment, type){
comment = comment || "";
if (type === undefined) {
return "<input id="+name+"></input>"+comment;
} else if (type == "checkbox") {
var html="";
for (var i=0; i<name.length; i++){
var checkbox = name[i];
html+="<input type=\"checkbox\" id=\""+checkbox[1]+"\" value=\"off\">"+checkbox[0]+"<br />";
};
return html;
} else if (type === "option") {
var html="<select id=\""+name[0]+"\">";
for (var i=1; i<name.length; i++){
var option=name[i];
html+="<option title=\""+option[0]+"\" value=\"""+option[1]+""\">"+option[2]+"</option>";
};
return html + "</select>" + comment;
};
};
function makeTable(target,TableRowsDataObject){
with (TableRowsDataObject) {
if (comment === undefined) {
comment = "";
} else {
comment="<p><i>"+comment+"</i><p>";
};
var html = "<h1>"+header+"</h1>" + comment;
for (var i=0; i<rows.length; i++){
var fields = rows[i];
if (fields === undefined){
html+="<tr><td><br /></td></tr>"
} else if (fields[3]==="subtitle") {
html+="<tr><td colspan=\"2\"><p><b>"+fields[0]+"</b></p></td></tr>"
} else {
var optionsHTML = "";
if (optionsEnabled){
var options=fields[4];
var selectID=fields[1];
if (typeof selectID === 'object'){
selectID=selectID[0];//selectID="AAAA";
};//selectID[0]};////SOMETHING VERY BAD HAPPENS HERE!
var optionsHTML = "<td><select id=\"VM_"+selectID+"\">"; //this line may cause problems
for (var j=0; j<options.length; j++){
optionsHTML += "<option>"+options[j]+"</option>";
};
optionsHTML +="</td>"
};
html+="<tr>"+optionsHTML+"<td>"+fields[0]+" </td><td>"+makeInputText(fields[1], fields[2], fields[3])+"</td></tr>";
};
};
document.getElementsByClassName(target)[0].innerHTML="<table>"+html+"</table>";
};
};
function makeManyTables(target, TableRowsDataObjectList){
html="";
for (i=0; i < TableRowsDataObjectList.length; i++){
var newname=target+' '+i;
html += "<div class=\""+newname+"\"></div>";
};
document.getElementsByClassName(target)[0].outerHTML=html;
for (i=0; i < TableRowsDataObjectList.length; i++){
var newname=target+' '+i;
makeTable(newname,TableRowsDataObjectList[i]);
};
};
/// MAKE ADDITIONAL ROWS --- CLEAN///
var additParams=[];
function makeAdditFormElement(p){
var additForm = "<table>\
<tr><td></td>\
<td>Name: </td>\
<td>UCD: </td><td> </td></tr>\
<tr><td></td>\
<td><input id=\"" + p.id + "_name\" value=\"" + p.pname + "\"></input></td>\
<td colspan=\"2\"><input id=\"" + p.id + "_ucd\" value=\"" + p.ucd + "\"></input></td></tr>\
<tr><td>Description: </td>\
<td colspan=\"3\"><input style=\"width:97%\" id=\""+p.id+"_desc\" value=\""+p.desc+"\"></input></td></tr>\
<tr><td align=\"right\"><select id=\""+p.id+"_VM\"><option>MAP</option><option>VAR</option></select></td>\
<td colspan=\"2\"><input style=\"width:97%\" id=\""+p.id+"_val\" value=\""+p.pvalue+"\"></input></td>\
<td align=\"right\"><button id=\""+p.id+"_btn\" onclick=\"rmAdditElement("+p.id+")\">Delete Parameter</button></td></tr>\
<tr><td colspan=\"4\"><hr /></td></tr>\
</table>";
return additForm;
};
function remakeAdditForm(){
document.getElementById("AdditionalData").innerHTML="";
for (var i=0; i<additParams.length; i++){
var param=additParams[i];
document.getElementById("AdditionalData").innerHTML+=makeAdditFormElement(param);
};
for (var i=0; i<additParams.length; i++){ // can update selections only after all html is in place for this element div
var param=additParams[i];
document.getElementById(param.id+"_VM").value=param.vvalue;
};
};
function addAdditionalParameterNew(){
collectAdditParamInputs();
additParams.push({id:additParams.length, pname:"name", ucd:"ucd", desc:"desc", pvalue:"value", vvalue:"MAP"});
remakeAdditForm();
};
function rmAdditElement(pid){
collectAdditParamInputs();
var additParamsUpdate=[];
var j=0;
for (var i=0; i<additParams.length; i++){
if(i!=pid){
var param=additParams[i];
param.id=j;
additParamsUpdate.push(param);
j++;
};
};
additParams=additParamsUpdate;
remakeAdditForm();
collectAdditParamInputs();
};
function collectAdditParamInputs(){
for (var i=0; i<additParams.length; i++){
var p=additParams[i];
additParams[i].pname = document.getElementById(i+'_name').value;
additParams[i].ucd = document.getElementById(i+'_ucd').value;
additParams[i].desc = document.getElementById(i+'_desc').value;
additParams[i].pvalue = document.getElementById(i+'_val').value;
additParams[i].vvalue = document.getElementById(i+'_VM').value;
};
};
/// EXECUTE POPULATE TABLE //
window.onload=function() {
makeManyTables("MetaData", TableMetaRowsData);
makeManyTables("MandatoryData", TableRowsData);
makeManyTables("OptionalData", TableOptionalRowsData);
//var sampleAdditDataRestore='[{"id":0,"pname":"name1","ucd":"ucd","desc":"desc","pvalue":"value"},{"id":1,"pname":"name2","ucd":"ucd","desc":"desc","pvalue":"value"}]';
//additParams=JSON.parse(sampleAdditDataRestore);
remakeAdditForm();
};
//////// POPULATE INPUT TABLE ENDS //////////
</script>
<!--Scripting of interactivity-->
<script>
//BIND BUTTON TO EXECUTE
$(document).ready(function(e){
$("#btnGenerate").click( function(){
urResourceName = $('#mSchema').val();
//BEGIN by filling out METADATA
var metaOpen = function (name) {return cT + "<meta name=\"" + name + "\">";}
var metaClose = "</meta>" + cN;
function metaLine(name, value) {
return cT+"<meta name=\"" + name + "\">" + value + "</meta>"+cN;
};
var metaLines = [];
for (i=0; i<TableMetaRowsData[0].rows.length;i++){
fields=TableMetaRowsData[0].rows[i];
if (fields[5]){
metaLines.push([fields[5],fields[1]]);
};
};
myStr = "<resource schema=\"" + $('#mSchema').val() + "\">" + cN
for (i=0;i<metaLines.length;i++){
myStr+=metaLine(metaLines[i][0], $('#'+metaLines[i][1]).val() );
};
myStr+= metaLine("type","Catalog");
// Waveband and Profile are children of Coverage, these should be computed first
// Wavebands:
var wavebands = [];
for (let bandparam of TableMetaRowsData[0].waveband){
wavebands.push([bandparam[0],$('#'+bandparam[1]).is(':checked')]);
};
var myMetaWavebands = ["band1", "band2", "band3"];
myWavebands = [];
for (let band of wavebands) {
if (band[1]) {
myWavebands.push(band[0])
};
};
function myOutWaveband(band) {
return cTT + '<meta name=\"waveband\">' + band + '</meta>' + cN
};
outMyMetaWavebands= "";
for (band of myWavebands) {outMyMetaWavebands += myOutWaveband(band)}
// Profile:
var myMetaProfile = $('#mProfile').val();
var myMetaProfileT = cT + metaOpen("Profile") + myMetaProfile + metaClose + cT;
var outMyMetaProfile = (myMetaProfile != "" ? myMetaProfileT : "");
myStr += metaOpen("coverage") + cN + outMyMetaWavebands + outMyMetaProfile + cT + metaClose + cN;
// END of METADATA
myStr += '<!-- METADATA COMPLETE -->' + cN + cN;
// START make TABLE
//var myTableID = "epn_core";
myStr += cT + '<table id=\""epn_core"\" onDisk=\"true\">' + cN;
// add mixin
var myProcessingLvl = $('#r_processing_level').val();
var mySpatialFrameType = $('#r_spatial_frame_type').val();
myStr += cTT + '<mixin processing_level=\"' + myProcessingLvl
+ '\" spatial_frame_type=\"' + mySpatialFrameType + '\">//epntap2#table</mixin>' + cN;
// make table metadata
myStr += cTT + '<meta name=\"info\" infoName=\"SERVICE_PROTOCOL\" infoValue=\"0.3\">EPN-TAP</meta>' + cN;
var myServiceDescription = $('#m_Service_Description').val();
myStr += cTT + '<meta name=\"description\">' + myServiceDescription + '</meta>' + cN;
// make table STC
myStr += cTT + '<stc>' + cN + cTTT + "Polygon ICRS [s_region]" + cN + cTT + '</stc>' + cN;
// make table optional columns
myStr += '<!-- MAKE OPTIONAL COLUMNS: -->' + cN;
for (let accRow of accessibilityRows){
if ($('#VM_r_' + accRow[0]).val() != "NUL") {
myStr+=cTT+'<column name=\"'+accRow[0]+'\" type=\"text\" ucd=\"'+accRow[1]+'\" verbLevel=\"1\" description=\"'+accRow[2]+'\"/> '+cN;
};
};
// [===>MAKE ADDITIONAL COLUMNS<===]
// {this is where the code will go for adding custom fields}
myStr += '<!-- MAKE ADDITIONAL COLUMNS: -->' + cN;
collectAdditParamInputs(); // update data for additional rows, we only want fresh stuff
for (p of additParams){
//myStr += cTT + 'additional' + cN;
myStr += cTT + '<column name=\"'+p.pname+'\" type=\"text\" '
+ 'ucd=\"'+p.ucd+'\" tablehead=\"value\" verbLevel=\"1\"'
+ ' description=\"'+p.desc+'\" />' + cN;
};
/*myStr += '<!-- MAKE NON-STANDARD COLUMNS, for example: -->' + cN;
myStr += '<!--' + cN + cTT + '<column name=\"counter\" type=\"text\" '
+ 'ucd=\"meta.note;meta.main\" tablehead=\"value\" verbLevel=\"1\"'
+ ' description=\"non standard\" />' + cN + '-->' + cN;
*/
// publish
myStr += cTT + '<publish />' + cN;
// close
myStr += cT + '</table>' + cN;
// END make TABLE
myStr += '<!-- TABLE COMPLETE -->' + cN + cN;
// START data import
myDataSource = $('#m_Data_Source').val();
myStr += cT + '<data id=\"import\">' + cN + cTT + '<sources>' + myDataSource + '</sources>' + cN;
myStr += cTT + '<csvGrammar>' + cN + cTTT + '<rowfilter procDef=\"//products#define\">' + cN
+ cT + cTTT + '<bind name=\"table\">\"schema.epn_core\"</bind>'+ cN
+ cTTT + '</rowfilter>' + cN + cTT + '</csvGrammar>' + cN;
// maketable & rowmaker
myStr += cTT + '<make table=\"epn_core\">' + cN + cTTT + '<rowmaker idmaps=\"*\">' + cN;
//START of MANDATORY PARAMS:
var makeRow = function(myType, myValue, myKey) {
if (myType == "MAP") {
return cTT + cTT + '<var key=\"' + myKey + '\" source=\"' + myValue + '\" />' + cN;
} else if (myType == "VAR") {
return cTT + cTT + '<var key=\"' + myKey + '\">' + myValue + '</var>' + cN;
} else if (myType == "NUL") {
return "";
};
};
function makeRowStd(name) {
return makeRow($('#VM_r_' + name).val(), $('#r_' + name).val(), name);
};
function makeRowStdSet(TRDobject){
rows="";
for (let fields of TRDobject.rows){
if (fields && fields[1]){
if (typeof fields[1] === "object"){
rows+= makeRowStd(fields[1][0].slice(2));
} else {
rows+= makeRowStd(fields[1].slice(2));
};
} else {
rows+=cN;
};
};
return rows;
};
for (TRD of TableRowsData){
myStr += makeRowStdSet(TRD) + cN;
};
for (TRD of TableOptionalRowsData){
myStr += makeRowStdSet(TRD) + cN;
};
for (param of additParams){
// myStr+='additional' + cN;
if (document.getElementById(param.id+'_VM').value==='MAP'){
myStr+=cTT+cTT+'<var key=\"'+param.pname+'\" source=\"'+param.pvalue+'\" />' + cN;
} else {
myStr+=cTT+cTT+'<var key=\"'+param.pname+'\">'+param.pvalue+'</var>' + cN;
};
};
myStr+=cN;
//apply procDef:
myStr += cTT + cTT + '<apply procDef=\"//epntap2#populate\" name=\"fillepn\">' + cN;
function procDefBind(name) {
if ($('#VM_r_' + name).val() != "NUL") {
return cTTT + cTT + '<bind name=\"' + name + '\">@' + name + '</bind>' + cN;
} else {
return "";
};
};
function makeProcDefBindSet(TRDobject){
rows="";
for (let fields of TRDobject.rows){
if (fields && fields[1]){
if (typeof fields[1] === "object"){
rows+= procDefBind(fields[1][0].slice(2));
} else {
rows+= procDefBind(fields[1].slice(2));
};
} else {
rows+=cN;
};
};
return rows;
};
for (TRD of TableRowsData){
myStr += makeProcDefBindSet(TRD) + cN;
};
for (TRD of TableOptionalRowsData){
myStr += makeProcDefBindSet(TRD) + cN;
};
//close
myStr += cTT+cTT+'</apply>'+cN+cTTT+'</rowmaker>'+cN+cTT+'</make>'+cN+cT+'</data>'+cN+'</resource>'+cN;
// WRITEOUT:
document.getElementById("output").innerText = myStr;
});
});
</script>
</body>