-
Notifications
You must be signed in to change notification settings - Fork 7
/
data-entry-form.html
2199 lines (1900 loc) · 74.3 KB
/
data-entry-form.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title> Basic Data Entry Form </title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<!-- Authentication and RDF procssing library -->
<script src="./oidc_web/oidc-web.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rdflib.min.js"></script>
</head>
<body>
<div id="snackbar">
<div id="msg1"></div>
<div id="msg2"></div>
</div>
<!-- Button feedback spinner -->
<div id="spinner"></div>
<!-- Start of tabs container -->
<div class="container">
<!-- Create tabs menu -->
<ul class="nav nav-tabs">
<li class="active" id="dbmsTabID"><a data-toggle="tab" href="#dbmsID">DBMS</a></li>
<li id="fsTabID"><a data-toggle="tab" href="#fsID">File System</a></li>
<li id="aboutTabID"><a data-toggle="tab" href="#aboutID">About</a></li>
<!-- Start Dropdown -->
<li class="pull-right" class="dropdown">
<a class="dropdown-toggle" style="max-height: 40px" data-toggle="dropdown" href="#">
<span class="glyphicon glyphicon-cog"></span>
<span class="caret"></span></a>
<ul class="dropdown-menu">
<!-- Faceted Browser Links Checkbox -->
<div class="checkbox">
<label><input id="fctID" type="checkbox" value="">Faceted Browser Links</label>
</div>
<!-- Full URI Query Results -->
<div class="checkbox">
<label><input id="uriID" type="checkbox" value="">Shortened URI Results</label>
</div>
<!-- Reasoning and Inference -->
<div class="checkbox">
<label><input id="riID" type="checkbox" value="">owl:sameAs Reasoning & Inference</label>
</div>
<!-- Inference Rule Name -->
<div class="checkbox">
<label><input id="ruleNameID" type="checkbox" value="">Inference Rule</label>
<input type="text" style="max-width: 250px" value="urn:ifp:inference:rule" id="infRuleNameID">
</div>
<div >
<label style="font-weight: normal" >SPARQL Endpoint</label>
<input type="text" style="width: 20em" value="https://linkeddata.uriburner.com/sparql" id="sparql_endpoint">
</div>
<!-- Console Print Commands Checkbox -->
<div class="checkbox">
<label><input id="cmdID" type="checkbox" value="">Console Log Commands</label>
</div>
<!-- Number of Results per Page -->
<div class="form-group">
<label style="font-weight: normal" for="resultsID">Results per Page:</label>
<input type="text" style="width: 5em" value="5" id="resultsID">
</div>
<h5> Return Data As: </h4>
<!-- Default Download Type -->
<div class="radio">
<label><input id="defaultID" type="radio" name="radiogroup" checked>Default (JSON)</label>
</div>
<!-- CSV Download Checkbox -->
<div class="radio">
<label><input id="csvID" type="radio" name="radiogroup">CSV</label>
</div>
<!-- XML Download Checkbox -->
<div class="radio">
<label><input id="xmlID" type="radio" name="radiogroup">XML</label>
</div>
</ul>
</li>
<!-- End Dropdown -->
<a id="logged-href" href="" title="" style="margin-top: 5px; margin-left: 15px; max-height: 35px"
class="pull-right" class="hidden"><img id="uid-icon" src="./common/uid.png"></a>
<li class="pull-right"> <button id="loginID" style="margin-top: 5px" type="button"
class="hidden btn btn-primary">Login</button> </li>
<li class="pull-right"><button id="logoutID" style="margin-top: 5px" type="button"
class="hidden btn btn-danger">Logout</button></li>
<li class="pull-right"><a id="permalinkID">Permalink</a></li>
</ul>
<!-- End of tabs menu -->
<!-- Add content to the tabs-->
<div class="tab-content">
<!-- Start DBMS Tab -->
<div id="dbmsID" class="tab-pane fade in active">
<div class="container">
<div class="row">
<!-- Form Div (Left Side) -->
<div class="col-xs-6">
<h1 style="text-align:center">Data Entry</h1>
<form id="dbmsFormID" class="form" method="post">
<div class="form-group">
<label for="subjectID">Subject</label>
<span class="glyphicon glyphicon-question-sign" data-toggle="tooltip"
data-original-title="If the subject is not a URI it will be used as the fragment identifier of a Relative URI."></span>
<textarea class="form-control" placeholder="Subject" rows="1"
style="resize:vertical" id="subjectID" ></textarea>
<p class="errorMessage" id="subjectErrorID"></p>
</div>
<div class="form-group">
<label for="predicateID">Predicate</label>
<span class="glyphicon glyphicon-question-sign" data-toggle="tooltip"
data-original-title="The predicate can either be a URI (ex. http://xmlns.com/foaf/0.1/name) or a curie (ex. foaf:name) because these are preloaded in Virtuoso."></span>
<input type="text" class="form-control" placeholder="Predicate" id="predicateID">
<p class="errorMessage" id="predicateErrorID"></p>
</div>
<div class="form-group">
<label for="objectID">Object</label> <span class="glyphicon glyphicon-question-sign"
data-toggle="tooltip"
data-original-title="Whether or not the Object is a literal value or a reference is determined by the range of the predicate. Quoting the Object will override this feature and make it a literal value."></span>
<textarea class="form-control" placeholder="Object" rows="1" style="resize:vertical"
id="objectID"></textarea>
</div>
<div class="form-group">
<label for="docNameID">Document Name</label>
<input type="text" class="form-control" value="urn:records:test" id="docNameID">
<p class="errorMessage" id="docNameErrorID"></p>
</div>
<!-- Start Buttons -->
<div class=button-wrapper>
<span>
<button id="clearBtnID" type="button"
class="btn btn-primary">Clear</button>
<button id="insertBtnID" type="button"
class="btn btn-success">Add</button>
<button id="deleteBtnID" type="button"
class="btn btn-danger">Delete</button>
<button id="queryBtnID" type="button"
class="btn btn-warning">Query</button>
<button id="dataBtnID" type="button"
class="btn btn-info">All Data</button>
</span>
</div>
<!-- End Buttons -->
</form>
<!-- End of Form Div -->
<!--Start Table Div (Right Side) -->
</div>
<div class="col-xs-6">
<h1 style="text-align:center">Data</h1>
<table id="dbmsTableID" class="table table-bordered"
style="table-layout: fixed; max-width:600px;">
<div style="padding-top: 25px">
<!-- Table is empty because it is created by the updateTable, queryGen, or bnQueryGen method -->
</div>
</table>
<div class="button-wrapper">
<button id="firstBtnID" type="button"
style="background-color: #99A3A4; color: #FDFEFE; margin-right: 5px"
class="btn pull-left">First</button>
<button id="prevBtnID" type="button"
style="background-color: #99A3A4; color: #FDFEFE"
class="btn pull-left">Prev</button>
<button id="lastBtnID" type="button"
style="background-color: #99A3A4; color: #FDFEFE; margin-left: 5px"
class="btn pull-right">Last</button>
<button id="nextBtnID" type="button"
style="background-color: #99A3A4; color: #FDFEFE"
class="btn pull-right ">Next</button>
</div>
</div>
<!--Table Div End (Right Side) -->
</div>
</div>
</div>
<!-- End DBMS Tab -->
<!-- Start File System Tab -->
<div id="fsID" class="tab-pane fade">
<div class="container">
<div class="row">
<!-- Form Div (Left Side) -->
<div class="col-xs-6">
<h1 style="text-align:center">Data Entry</h1>
<form id="fsFormID" class="form" method="post">
<div class="form-group">
<label for="subjectID2">Subject</label>
<span class="glyphicon glyphicon-question-sign" data-toggle="tooltip"
data-original-title="If the subject is not a URI it will be used as the fragment identifier of a Relative URI."></span>
<textarea class="form-control" placeholder="Subject" rows="1"
style="resize:vertical" id="subjectID2" ></textarea>
<p class="errorMessage" id="subjectErrorID2"></p>
</div>
<div class="form-group">
<label for="predicateID2">Predicate</label>
<span class="glyphicon glyphicon-question-sign" data-toggle="tooltip"
data-original-title="The predicate can either be a URI (ex. http://xmlns.com/foaf/0.1/name) or a curie (ex. foaf:name) because these are preloaded in Virtuoso."></span>
<input type="text" class="form-control" placeholder="Predicate" id="predicateID2">
<p class="errorMessage" id="predicateErrorID2"></p>
</div>
<div class="form-group">
<label for="objectID2">Object</label> <span
class="glyphicon glyphicon-question-sign" data-toggle="tooltip"
data-original-title="Wether or not the Object is a literal value or a reference is determined by the range of the predicate. Quoting the Object will override this feature and make it a literal value."></span>
<textarea class="form-control" placeholder="Object" rows="1" style="resize:vertical"
id="objectID2" ></textarea>
</div>
<div class="form-group">
<label for="docNameID2">Document Name</label>
<input type="text" class="form-control"
value="https://id.myopenlink.net/public_home/KingsleyUyiIdehen/RWW-QA/test1.ttl"
id="docNameID2" >
<p class="errorMessage" id="docNameErrorID2"></p>
</div>
<!-- Start Buttons -->
<div class=button-wrapper>
<span>
<button id="clearBtnID2" type="button"
class="btn btn-primary">Clear</button>
<button id="insertBtnID2" type="button"
class="btn btn-success">Add</button>
<button id="deleteBtnID2" type="button"
class="btn btn-danger">Delete</button>
<button id="queryBtnID2" type="button"
class="btn btn-warning">Query</button>
<button id="dataBtnID2" type="button"
class="btn btn-info">All Data</button>
</span>
</div>
<!-- End Buttons -->
</form>
<!-- End of Form Div -->
<!--Start Table Div (Right Side) -->
</div>
<div class="col-xs-6">
<h1 style="text-align:center">Data</h1>
<table id="fsTableID" class="table table-bordered"
style="table-layout: fixed; max-width:600px;">
<div style="padding-top: 25px">
<!-- Table is empty because it is created by the updateTable method -->
</div>
</table>
<div class="button-wrapper">
<button id="firstBtnID2" type="button"
style="background-color: #99A3A4; color: #FDFEFE; margin-right: 5px"
class="btn pull-left disabled">First</button>
<button id="prevBtnID2" type="button"
style="background-color: #99A3A4; color: #FDFEFE"
class="btn pull-left disabled">Prev</button>
<button id="lastBtnID2" type="button"
style="background-color: #99A3A4; color: #FDFEFE; margin-left: 5px"
class="btn pull-right disabled">Last</button>
<button id="nextBtnID2" type="button"
style="background-color: #99A3A4; color: #FDFEFE"
class="btn pull-right disabled">Next</button>
</div>
</div>
<!--Table Div End (Right Side) -->
</div>
</div>
</div>
<!-- End File System Tab -->
<!-- Start About Tab -->
<div id="aboutID" class="tab-pane fade">
<div class="container">
<p style="padding-top: 10px"> Generic SPARQL Data Entry Form 1.0.4<br>
Description: Simple Data Entry Form that helps unravel the power of RDF and SPARQL with regards
to Structured Data creation and interaction. <br>
Creator: <a href="https://jordan.solid.openlinksw.com:8444/profile/card#me">Jordan Idehen</a>
(<a href="https://github.com/jidehen#this">Github</a>, <a
href="https://www.linkedin.com/in/jordan-idehen-143934157/#this">LinkedIn</a>) <br>
Supervisor: <a href="https://github.com/OpenLinkSoftware#this">OpenLink Software</a> <br>
License: Public Domain
</p>
</div>
<!-- End About Tab -->
</div>
<!-- End of tabs container -->
</div>
<!-- Error Display CSS -->
<style>
/* sets input field red if invalid */
.error {
border: 2px solid red;
}
/* sets error message color red */
.errorMessage {
color: red;
}
/* wraps text in table */
td {
word-wrap: break-word;
}
</style>
<!-- Spinner CSS -->
<style>
#spinner {
position: fixed;
width: 100%;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(255, 255, 255, 0.7);
z-index: 9999;
display: none;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#spinner::after {
content: '';
display: block;
position: absolute;
left: 48%;
top: 40%;
width: 40px;
height: 40px;
border-style: solid;
border-color: black;
border-top-color: transparent;
border-width: 4px;
border-radius: 50%;
-webkit-animation: spin .8s linear infinite;
animation: spin .8s linear infinite;
}
</style>
<!-- Dropdown menu CSS-->
<style>
.dropdown-menu {
padding-left: 15px;
width: 450px;
}
.glyphicon.glyphicon-cog {
font-size: 20px;
}
</style>
<!-- Snackbar CSS-->
<style>
#snackbar {
visibility: hidden;
min-width: 250px;
margin-left: -125px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
font-size: 17px;
}
#snackbar.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
</style>
<!-- Spinner Javascript -->
<script>
function showSpinner() {
DOC.iSel("spinner").className = "show";
}
function hideSpinner() {
DOC.iSel("spinner").className = DOC.iSel("spinner").className.replace("show", "");
}
const delay = ms => new Promise(res => setTimeout(res, ms));
async function showSnackbar(text1, text2) {
const tm = 5000;
var x = DOC.iSel("snackbar");
DOC.qSel("#snackbar #msg1").innerText = text1;
DOC.qSel("#snackbar #msg2").innerText = text2 ? text2 : '';
//x.innerText = text;
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, tm);
await delay(tm);
}
class State {
constructor() {
this.solid_storage = null;
this.is_solid_id = false;
this.webid = null;
this.initialTab = "";
this.initialSubject = "";
this.initialPredicate = "";
this.initialObject = "";
this.initialDocumentName = "";
this.initialEndpoint = "";
this.lastState = {tab:"dbms", documentName:""};
}
loadPermalink() {
this.resetPermalink();
try {
var lastState = JSON.parse(sessionStorage.getItem('lastState'))
if (lastState)
this.lastState = lastState;
if (!this.lastState.tab && (this.lastState.tab !== "dbms" || this.lastState.tab !== "fs"))
this.lastState.tab = "dbms";
if (this.lastState.endpoint)
DOC.iSel("sparql_endpoint").value = this.lastState.endpoint;
} catch(e) {}
var queryString = window.location.search;
var params = new URLSearchParams(queryString);
var setInputs = params.get("setInputs");
if (setInputs == "true") {
this.initialTab = decodeURIComponent(params.get("tab"));
this.initialSubject = decodeURIComponent(params.get("subject"));
this.initialPredicate = decodeURIComponent(params.get("predicate"));
this.initialObject = decodeURIComponent(params.get("object"));
this.initialDocumentName = decodeURIComponent(params.get("documentName"));
this.initialEndpoint = decodeURIComponent(params.get("endpoint"));
this.handlePermalink();
if (this.initialTab === "dbms")
$('a[href="#dbmsID"]').tab('show');
else if (this.initialTab === "fs")
$('a[href="#fsID"]').tab('show');
}
else {
var documentName;
if (this.getCurTab() === "fs") {
$('a[href="#fsID"]').tab('show');
if (this.lastState.documentName)
document.getElementById('docNameID2').value = this.lastState.documentName;
} else {
$('a[href="#dbmsID"]').tab('show');
if (this.lastState.documentName)
document.getElementById('docNameID').value = this.lastState.documentName;
}
}
this.updateLoginState();
}
resetPermalink() {
var permalink = DOC.iSel("permalinkID");
permalink.href = window.location.href;
}
updatePermalink() {
if (DOC.iSel('dbmsTabID').getAttribute('class') === "active") {
this.lastState.tab = tab = "dbms";
} else if (DOC.iSel('fsTabID').getAttribute('class') === "active") {
this.lastState.tab = tab = "fs";
}
var permalink = DOC.iSel("permalinkID");
var subject = this.checkId("subjectID", "subjectID2");
var predicate = this.checkId("predicateID", "predicateID2");
var object = this.checkId("objectID", "objectID2");
var documentName = this.checkId("docNameID", "docNameID2");
var endpoint = DOC.iSel('sparql_endpoint');
var tab = "";
if (endpoint.value)
this.lastState.endpoint = endpoint.value;
this.lastState.documentName = documentName.value;
sessionStorage.setItem('lastState', JSON.stringify(this.lastState));
var href = window.location.origin + window.location.pathname;
href += "?setInputs=true&";
href += "tab=" + encodeURIComponent(tab) + "&";
href += "subject=" + encodeURIComponent(subject.value) + "&";
href += "predicate=" + encodeURIComponent(predicate.value) + "&";
href += "object=" + encodeURIComponent(object.value) + "&";
href += "documentName=" + encodeURIComponent(documentName.value) + "&";
href += "endpoint=" + encodeURIComponent(endpoint.value);
permalink.href = href;
}
// Handle the permalink parameters
handlePermalink() {
var subject = this.checkPermalinkTab("subjectID", "subjectID2");
var predicate = this.checkPermalinkTab("predicateID", "predicateID2");
var object = this.checkPermalinkTab("objectID", "objectID2");
var documentName = this.checkPermalinkTab("docNameID", "docNameID2");
var endpoint = DOC.iSel("sparql_endpoint");
if (this.initialSubject) {
subject.value = this.initialSubject;
this.initialSubject = "";
}
if (this.initialPredicate) {
predicate.value = this.initialPredicate;
this.initialPredicate = "";
}
if (this.initialObject) {
object.value = this.initialObject;
this.initialObject = "";
}
if (this.initialDocumentName) {
documentName.value = this.initialDocumentName;
//this.initialDocumentName = "";
}
if (this.initialEndpoint) {
endpoint.value = this.initialEndpoint;
this.initialEndpoint = "";
}
}
checkPermalinkTab(id1, id2) {
if (this.initialTab === 'fs')
return DOC.iSel(id2);
else
return DOC.iSel(id1);
}
/* Gets the solid storage from window > application > session storage
so it can be used as the document name for functions
function is called when page is loaded/reloaded */
docNameValue() {
this.solid_storage = sessionStorage.getItem("solid_storage")
var solid_storage_value = this.solid_storage;
if (DOC.iSel("cmdID").checked == true) {
console.log('solid storage: ' + this.solid_storage);
}
if (this.solid_storage && this.solid_storage !== "null") {
DOC.iSel("docNameID").value = solid_storage_value;
DOC.iSel("docNameID2").value = solid_storage_value;
} else {
DOC.iSel("docNameID").value = "urn:records:test";
// DOC.iSel("docNameID2").value = "https://kingsley.idehen.net/public_home/jordan/Public/record-test.ttl";
}
// value from permalink
if (this.initialDocumentName !== "" && this.initialTab !== "") {
var documentName = this.checkPermalinkTab("docNameID", "docNameID2");
documentName.value = initialDocumentName;
}
}
// This function checks which tab the user is in to determine focus of functions
checkValue(id1, id2) {
if (this.getCurTab() === "dbms")
return DOC.iSel(id1).value;
else
return DOC.iSel(id2).value;
}
// This function checks which tab the user is in to determine table to display data (different because of .value)
checkId(id1, id2) {
if (this.getCurTab() === "dbms")
return DOC.iSel(id1);
else
return DOC.iSel(id2);
}
// Clears subject, predicate, object input fields
clearInput() {
if (this.getCurTab() === "dbms") {
var curDocName = DOC.iSel("docNameID").value; // Stores current value of docName
DOC.iSel("dbmsFormID").reset(); // Resets entire form
DOC.iSel("docNameID").value = curDocName; // Added so docname is not reset
} else if (this.getCurTab() === "fs") {
var curDocName = DOC.iSel("docNameID2").value;
DOC.iSel("fsFormID").reset();
DOC.iSel("docNameID2").value = curDocName;
}
}
getCurTab() {
return this.lastState.tab;
}
async updateLoginState() {
const loginButton = DOC.iSel('loginID');
const logoutButton = DOC.iSel('logoutID');
const session = await authClient.currentSession()
const loggedHref = DOC.iSel('logged-href')
const loggedIn = (session && session.hasCredentials());
loginButton.classList.toggle('hidden', loggedIn)
logoutButton.classList.toggle('hidden', !loggedIn)
if (loggedIn) {
var webid = session.idClaims.sub;
if (webid) {
this.webid = webid;
loggedHref.classList.remove('hidden')
loggedHref.href = webid
loggedHref.title = webid
var rc = await loadProfile(webid);
if (rc) {
this.solid_storage = rc.store;
this.is_solid_id = rc.is_solid_id;
} else {
this.solid_storage = null;
this.is_solid_id = false;
}
sessionStorage.setItem('solid_storage', this.solid_storage);
this.docNameValue()
}
} else {
loggedHref.classList.add('hidden')
loggedHref.href = ''
loggedHref.title = ''
this.solid_storage = null;
this.is_solid_id = false;
this.webid = null;
sessionStorage.removeItem('solid_storage');
}
click_updateTable();
}
}
</script>
<!-- These Functions Modify the Onscreen Display -->
<script>
var state = new State();
const { OIDCWebClient } = OIDC;
const authClient = new OIDCWebClient({ solid: true });
//Tooltip activation function
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip({
placement: 'right'
});
DOC.iSel('loginID').onclick = () => { authLogin() }
DOC.iSel('logoutID').onclick = () => { authLogout() }
DOC.iSel('subjectID').onchange = () => { state.updatePermalink() }
DOC.iSel('predicateID').onchange = () => { state.updatePermalink() }
DOC.iSel('objectID').onchange = () => { state.updatePermalink() }
DOC.iSel('docNameID').onchange = () => { state.updatePermalink() }
DOC.iSel('clearBtnID').onclick = () => { state.clearInput() }
DOC.iSel('insertBtnID').onclick = () => { recordGen() }
DOC.iSel('deleteBtnID').onclick = () => { recordDel() }
DOC.iSel('queryBtnID').onclick = () => { click_queryGen() }
DOC.iSel('dataBtnID').onclick = () => { click_updateTable() }
DOC.iSel('firstBtnID').onclick = () => { first() }
DOC.iSel('prevBtnID').onclick = () => { previous() }
DOC.iSel('lastBtnID').onclick = () => { last() }
DOC.iSel('nextBtnID').onclick = () => { next() }
DOC.iSel('subjectID2').onchange = () => { state.updatePermalink() }
DOC.iSel('predicateID2').onchange = () => { state.updatePermalink() }
DOC.iSel('objectID2').onchange = () => { state.updatePermalink() }
DOC.iSel('docNameID2').onchange = () => { state.updatePermalink() }
DOC.iSel('clearBtnID2').onclick = () => { state.clearInput() }
DOC.iSel('insertBtnID2').onclick = () => { turtleGen() }
DOC.iSel('deleteBtnID2').onclick = () => { turtleDel() }
DOC.iSel('queryBtnID2').onclick = () => { click_queryGen() }
DOC.iSel('dataBtnID2').onclick = () => { click_updateTable() }
DOC.iSel('firstBtnID2').onclick = () => { first() }
DOC.iSel('prevBtnID2').onclick = () => { previous() }
DOC.iSel('lastBtnID2').onclick = () => { last() }
DOC.iSel('nextBtnID2').onclick = () => { next() }
DOC.iSel('sparql_endpoint').onchange = () => { state.updatePermalink() }
// update table and permalink on tab switch
$('.nav-tabs a').on('shown.bs.tab', function (event) {
var currTab = $(event.target).text();
var prevTab = $(event.relatedTarget).text();
if (currTab != "About" && prevTab != "About") {
state.updatePermalink();
click_updateTable();
}
});
// check for permalink
state.loadPermalink();
//docNameValue() ; //Checks/Updates document name when page is loaded
});
class DOC {
static qSel(sel) { return document.querySelector(sel) }
static qSelAll(sel) { return document.querySelectorAll(sel) }
static iSel(id) { return document.getElementById(id) }
static qShow(sel) { DOM.qSel(sel).classList.remove('hidden') }
static qHide(sel) { DOM.qSel(sel).classList.add('hidden') }
static elShow(sel) { el.classList.remove('hidden') }
static elHide(sel) { el.classList.add('hidden') }
static qGetValue(sel) { return DOM.qSel(sel).value }
static qSetValue(sel, val) { DOM.qSel(sel).value = val }
static iGetValue(sel) { return DOM.iSel(sel).value }
static iSetValue(sel, val) { DOM.iSel(sel).value = val }
}
</script>
<!-- These Functions are Used to Display Validation Errors -->
<script>
// Function is used to remove input field border color
function setInputColor(id) {
DOC.iSel(id).className = DOC.iSel(id).className + " error"; // this adds the error class
}
// Function is used to remove input field border color
function removeInputColor(id) {
DOC.iSel(id).className = "form-control"; // removes error class
}
// Function is used to display error message
function errorMessage(id, error) {
DOC.iSel(id).innerHTML = error;
}
</script>
<!-- These Functions Handle the Form Validation -->
<script>
// Regular Expression for URIs
const regexp = /(https|http|mailto|tel|dav|ftp|ftps|urn)[:^/s]/i;
// This function validates the uri used for PATCH
DOC.iSel("docNameID2").addEventListener("input", docNameValidation);
function docNameValidation() {
var str = DOC.iSel("docNameID2").value;
try {
if (regexp.test(str)) { //removes error for valid uri
errorMessage("docNameErrorID2", "");
removeInputColor('docNameID2');
} else {
setInputColor("docNameID2");
errorMessage("docNameErrorID2", "Document name must be a full uri for patch method");
throw new Error("Document Name must be a full uri for patch method"); // Throws error because input is not a valid uri
}
} catch (e) {
console.error('Invalid uri', e);
}
}
// Function checks if input is a blank node
function isBlankNode(str) {
str = str.trim();
if (str.charAt(0) == "_" && str.charAt(1) == ":") {
return str;
} else if (str.charAt(0) == "[" && str.charAt(str.length - 1) == "]") {
return str;
} else {
return false;
}
}
// Function checks if input contains a language tag
function langTag(str) {
const langexp = /@[a-zA-Z][a-zA-Z]/; // regexp for languge tag ex. @en
if (langexp.test(str)) {
return true;
} else {
return false;
}
}
// Function formats literal inputs
function formatLiteral(str) {
if (langTag(str)) { // str has lang tag
strArray = str.split('@'); // split string at @ so the langtag is removed from string
str = strArray[0].trim();
langtag = '@' + strArray[1].trim(); // need to add @ because it is removed by split
if (str.charAt(0) != '"' && str.charAt(0) != "'") {
return '"' + str + '"' + langtag
} else {
return str + langtag
}
} else { // str does not have lang tag
if (isBlankNode(str)) {
return str;
} else if (str.charAt(0) == "'" && str.charAt(str.length - 1) == "'") {
return str // If string begins and ends with single quote return it as is
} else if (str.charAt(0) == '"' && str.charAt(str.length - 1) == '"') {
return str;
} else if (str.indexOf(' ') >= 0) {
if (str.charAt(0) != '"' && str.charAt(0) != "'") {
return '"' + str + '"';
} else {
return str;
}
} else {
return '"' + str + '"';
}
}
}
// This function formats the Subject input. Comments are inline
function formatSubject() {
if (state.getCurTab() === "dbms") {
var str = DOC.iSel("subjectID").value;
} else if (state.getCurTab() === "fs") {
var str = DOC.iSel("subjectID2").value;
}
if (str.charAt(0) == '<' && str.charAt(str.length - 1) == '>') {
return str;
} else if (regexp.test(str) && !isBlankNode(str)) {
return '<' + str + '>'; // Case: input is a uri. Solution: quote it
} else if (str.charAt(0) == "#") {
return '<' + str + '>'; // Case: input is an unquoted relative uri. Solution: quote it
} else if (str.charAt(0) == '<' && str.charAt(1) == '#' && str.charAt(str.length - 1) == '>') {
return str; // Case: input is already a relative uri. Solution: return it as is
} else if (str.includes(":") || str.includes("<#")) {
return str; // Case: input is a curie. Solution: return it as is
} else if (str.charAt(0) == "?") {
return str; // checks if input is a variable for deletion
}
else {
if (isBlankNode(str)) {
return isBlankNode(str); // Case: input is a blank node. Solution: return it as is
} else {
return ':' + str; // Case: input is not a uri or a blank node. Solution: make it a relative uri
}
}
}
// If the subject is quoted or contains a space this function throws and error
DOC.iSel("subjectID").addEventListener("input", validateSubject);
DOC.iSel("subjectID2").addEventListener("input", validateSubject);
function validateSubject() {
var str = state.checkValue("subjectID", "subjectID2");
try {
if (state.getCurTab() === "dbms") {
if (isBlankNode(str)) { // removes error message for complete blank node
errorMessage("subjectErrorID", "");
removeInputColor('subjectID');
return formatSubject();
} else if (str.includes('"') || str.includes("'")) {
setInputColor("subjectID");
errorMessage("subjectErrorID", "Subject cannot contain a literal value unless it is a blank node");
throw new Error("Subject cannot be a literal value"); // Throws error because input is a literal value
} else if (str.indexOf(' ') >= 0) {
setInputColor('subjectID');
errorMessage("subjectErrorID", "Subject cannot contain spaces unless it is a blank node");
throw new Error("Subject cannot contain spaces");
}
else {
errorMessage("subjectErrorID", "");
removeInputColor("subjectID");
return formatSubject(); // Returns formatted subject because it is valid
}
} else if (state.getCurTab() === "fs") {
if (isBlankNode(str)) { // removes error message for complete blank node
errorMessage("subjectErrorID2", "");
removeInputColor('subjectID2');
return formatSubject();
} else if (str.includes('"') || str.includes("'")) {
setInputColor("subjectID2");
errorMessage("subjectErrorID2", "Subject cannot contain a literal value unless it is a blank node");
throw new Error("Subject cannot be a literal value"); // Throws error because input is a literal value
} else if (str.indexOf(' ') >= 0) {
setInputColor('subjectID2');
errorMessage("subjectErrorID2", "Subject cannot contain spaces unless it is a blank node");
throw new Error("Subject cannot contain spaces");
}
else {
errorMessage("subjectErrorID2", "");
removeInputColor("subjectID2");
return formatSubject(); // Returns formatted subject because it is valid
}
}
} catch (e) {
console.error('Invalid Subject', e);
}
}
// This function formats the Predicate input. Comments are inline
function formatPredicate() {
var str = state.checkValue("predicateID", "predicateID2");
if (regexp.test(str) && !isBlankNode(str)) {
return '<' + str + '>'; // Case: input is a uri. Solution: quote it
} else if (str.charAt(0) == "#") {
return '<' + str + '>'; // Case: input is an unquoted relative uri. Solution: quote it
} else if (str.charAt(0) == '<' && str.charAt(1) == '#' && str.charAt(str.length - 1) == '>') {
return str; // Case: input is already a relative uri. Solution: return it as is
} else if (str.includes(":") || str.includes("<#")) {
return str; // Case: input is a curie. Solution: return it as is
} else if (str.charAt(0) == "?") {
return str; // checks if input is a variable for deletion
}
else {
if (str.charAt(0) == '<' && str.charAt(str.length - 1) == '>') {
var newStr = str.slice(1, -1); // Case: input is quoted uri. Solution: must be unquotted to be recognize as a uri by regexp
return formatPredicate(newStr);
} else {
return ':' + str; // Case: input is not a uri or a blank node. Solution: make it a relative uri
}
}
}
// If the predicate is quoted, contains, or is a blank node a space this function throws and error
DOC.iSel("predicateID").addEventListener("input", validatePredicate);
DOC.iSel("predicateID2").addEventListener("input", validatePredicate);
function validatePredicate() {
var str = state.checkValue("predicateID", "predicateID2");
try {
if (state.getCurTab() === "dbms") {
if (str.includes('"') || str.includes("'")) {
setInputColor('predicateID');
errorMessage("predicateErrorID", "Predicate cannot be a literal value");
throw new Error("Predicate cannot be a literal value"); // Throws error because input is a literal value
} else if (str.indexOf(' ') >= 0) {
setInputColor('predicateID');
errorMessage("predicateErrorID", "Predicate cannot contain spaces");
throw new Error("Predicate cannot contain spaces"); // Throws error because input subject can't contain spaces
} else {
removeInputColor('predicateID');
errorMessage("predicateErrorID", "");
return formatPredicate(); // Returns formatted subject because it is valid
}
} else if (state.getCurTab() === "fs") {
if (str.includes('"') || str.includes("'")) {
setInputColor('predicateID2');
errorMessage("predicateErrorID2", "Predicate cannot be a literal value");
throw new Error("Predicate cannot be a literal value"); // Throws error because input is a literal value
} else if (str.indexOf(' ') >= 0) {