forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserInput.js
More file actions
2373 lines (2235 loc) · 83.9 KB
/
userInput.js
File metadata and controls
2373 lines (2235 loc) · 83.9 KB
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
/* istanbul ignore file */
// Original author: kennyluck
//
// Kenny's Notes:
/* places to generate SPARQL update: clearInputAndSave() pasteFromClipboard()->insertTermTo();
undetermined statement generated formUndetStat()
->fillInRequest()
ontological issues
temporarily using the tabont namespace
clipboard: 'predicates' 'objects' 'all'(internal)
request: 'from' 'to' 'message' 'Request'
*/
import * as UI from 'solid-ui'
import { store } from 'solid-logic'
import * as panes from 'pane-registry'
const $rdf = UI.rdf
let UserInputFormula // Formula to store references of user's work
let TempFormula // Formula to store incomplete triples (Requests),
// temporarily disjoint with kb to avoid bugs
export function UserInput (outline) {
const myDocument = outline.document // is this ok?
// UI.log.warn("myDocument when it's set is "+myDocument.location);
this.menuId = 'predicateMenu1'
/* //namespace information, as a subgraph of the knowledge base, is built in showMenu
this.namespaces={};
for (var name in UI.ns) {
this.namespaces[name] = UI.ns[name]('').uri;
}
var NameSpaces=this.namespaces;
*/
// hq, print and trim functions
const qp = function qp (str) {
console.log(str + '\n')
}
// var tabont = UI.ns.tabont;
// var foaf = UI.ns.foaf
const rdf = UI.ns.rdf
// var RDFS = UI.ns.rdfs
// var OWL = UI.ns.owl
// var dc = UI.ns.dc
// var rss = UI.ns.rss
// var contact = UI.ns.contact
// var mo = UI.ns.mo
const bibo = UI.rdf.Namespace('http://purl.org/ontology/bibo/') // hql for pubsPane
// var dcterms = UI.rdf.Namespace('http://purl.org/dc/terms/')
const dcelems = UI.rdf.Namespace('http://purl.org/dc/elements/1.1/')
let movedArrow = false // hq
// var updateService=new updateCenter(kb);
if (!UserInputFormula) {
UserInputFormula = new UI.rdf.Formula()
UserInputFormula.superFormula = store
// UserInputFormula.registerFormula("Your Work");
}
if (!TempFormula) TempFormula = new UI.rdf.IndexedFormula()
// Use RDFIndexedFormula so add returns the statement
TempFormula.name = 'TempFormula'
if (!store.updater) store.updater = new UI.rdf.UpdateManager(store)
return {
// updateService: updateService,
sparqler: store.updater,
lastModified: null, // the last <input> being modified, .isNew indicates whether it's a new input
lastModifiedStat: null, // the last statement being modified
statIsInverse: false, // whether the statement is an inverse
/**
* Triggering Events: event entry points, should be called only from outline.js but not anywhere else
* in userinput.js, should be as short as possible, function names to be discussed
*/
// Called when the blue cross under the default pane is clicked.
// Add a new row to a property list ( P and O)
addNewPredicateObject: function addNewPredicateObject (e) {
if (UI.utils.getTarget(e).className !== 'bottom-border-active') return
const This = outline.UserInput
const target = UI.utils.getTarget(e)
// UI.log.warn(ancestor(target,'TABLE').textContent);
const insertTr = myDocument.createElement('tr')
UI.utils
.ancestor(target, 'DIV')
.insertBefore(insertTr, UI.utils.ancestor(target, 'TR'))
const tempTr = myDocument.createElement('tr')
const reqTerm1 = This.generateRequest('(TBD)', tempTr, true)
insertTr.appendChild(tempTr.firstChild)
const reqTerm2 = This.generateRequest(
'(Enter text or drag an object onto this field)',
tempTr,
false
)
insertTr.appendChild(tempTr.firstChild)
// there should be an elegant way of doing this
// Take the why of the last TR and write to it.
if (
UI.utils.ancestor(target, 'TR').previousSibling && // there is a previous predicate/object line
UI.utils.ancestor(target, 'TR').previousSibling.AJAR_statement
) {
const preStat = UI.utils.ancestor(target, 'TR').previousSibling
.AJAR_statement
// This should always(?) input a non-inverse statement
This.formUndetStat(
insertTr,
preStat.subject,
reqTerm1,
reqTerm2,
preStat.why,
false
)
} else {
// no previous row: write to the document defining the subject
const subject = UI.utils.getAbout(
store,
UI.utils.ancestor(target.parentNode.parentNode, 'TD')
)
const doc = store.sym(UI.rdf.Util.uri.docpart(subject.uri))
This.formUndetStat(insertTr, subject, reqTerm1, reqTerm2, doc, false)
}
outline.walk('moveTo', insertTr.firstChild)
UI.log.info(
'addNewPredicateObject: selection = ' +
outline
.getSelection()
.map(function (item) {
return item.textContent
})
.join(', ')
)
this.startFillInText(outline.getSelection()[0])
},
// Called when a blue cross on a predicate is clicked
// tr.AJAR_inverse stores whether the clicked predicate is an inverse one
// tr.AJAR_statement (an incomplete statement in TempFormula) stores the destination(why), now
// determined by the preceding one (is this good?)
addNewObject: function addNewObject (e) {
const predicateTd = UI.utils.getTarget(e).parentNode.parentNode
// var predicateTerm = UI.utils.getAbout(kb, predicateTd)
const isInverse = predicateTd.parentNode.AJAR_inverse
// var titleTerm=UI.utils.getAbout(kb,UI.utils.ancestor(predicateTd.parentNode,'TD'));
// set pseudo lastModifiedStat here
this.lastModifiedStat = predicateTd.parentNode.AJAR_statement
const insertTr = this.appendToPredicate(predicateTd)
const reqTerm = this.generateRequest(' (Error) ', insertTr, false)
const preStat = insertTr.previousSibling.AJAR_statement
if (!isInverse) {
this.formUndetStat(
insertTr,
preStat.subject,
preStat.predicate,
reqTerm,
preStat.why,
false
)
} else {
this.formUndetStat(
insertTr,
reqTerm,
preStat.predicate,
preStat.object,
preStat.why,
true
)
}
outline.walk('moveTo', insertTr.lastChild)
this.startFillInText(insertTr.lastChild)
// this.statIsInverse=false;
},
// Called when delete is pressed
Delete: function Delete (selectedTd) {
this.deleteTriple(selectedTd, false)
},
// Called when enter is pressed
Enter: function Enter (selectedTd) {
this.literalModification(selectedTd)
},
// Called when a selected cell is clicked again
Click: function Click (e) {
const target = UI.utils.getTarget(e)
if (UI.utils.getTerm(target).termType !== 'Literal') return
this.literalModification(target)
// this prevents the generated inputbox to be clicked again
e.preventDefault()
e.stopPropagation()
},
// Called when paste is called (Ctrl+v)
pasteFromClipboard: function pasteFromClipboard (address, selectedTd) {
function termFrom (fromCode) {
const term = outline.clipboard[fromCode].shift()
if (term === null) {
UI.log.warn('no more element in clipboard!')
return
}
switch (fromCode) {
case 'predicates':
case 'objects': {
const allArray = outline.clipboard.all
for (let i = 0; true; i++) {
if (term.sameTerm(allArray[i])) {
allArray.splice(i, 1)
break
}
}
break
}
case 'all':
throw new Error(
'hostorical code not understood - what is theCollection?'
)
/*
var isObject = term.sameTerm(theCollection('objects').elements[0])
isObject ? outline.clipboard.objecs.shift() : outline.clipboard.predicates.shift() // drop the corresponding term
return [term, isObject]
break
*/
}
return term
}
let term
switch (selectedTd.className) {
case 'undetermined selected':
term = selectedTd.nextSibling
? termFrom('predicates')
: termFrom('objects')
if (!term) return
break
case 'pred selected': // paste objects into this predicate
term = termFrom('objects')
if (!term) return
break
case 'selected': { // header <TD>, undetermined generated
const returnArray = termFrom('all')
if (!returnArray) return
term = returnArray[0]
this.insertTermTo(selectedTd, term, returnArray[1])
return
}
}
this.insertTermTo(selectedTd, term)
},
/**
* Intermediate Processing:
*/
// a general entry point for any event except Click&Enter(goes to literalModification)
// do a little inference to pick the right input box
startFillInText: function startFillInText (selectedTd) {
switch (this.whatSortOfEditCell(selectedTd)) {
case 'DatatypeProperty-like':
// this.clearMenu();
// selectedTd.className='';
UI.utils.emptyNode(selectedTd)
this.lastModified = this.createInputBoxIn(
selectedTd,
' (Please Input) '
)
this.lastModified.isNew = false
this.lastModified.select()
break
case 'predicate':
// the goal is to bring back all the menus (with autocomplete functionality
// this.performAutoCompleteEdit(selectedTd,['PredicateAutoComplete',
// this.choiceQuery('SuggestPredicateByDomain')]);
this.performAutoCompleteEdit(selectedTd, 'PredicateAutoComplete')
break
case 'ObjectProperty-like':
case 'no-idea':
// menu should be either function that
this.performAutoCompleteEdit(selectedTd, 'GeneralAutoComplete')
/*
//<code time="original">
emptyNode(selectedTd);
this.lastModified=this.createInputBoxIn(selectedTd,"");
this.lastModified.select();
this.lastModified.addEventListener('keypress',this.AutoComplete,false);
//this pops up the autocomplete menu
this.AutoComplete(1);
//</code>
*/
}
},
literalModification: function literalModification (selectedTd) {
UI.log.debug(
'entering literal Modification with ' +
selectedTd +
selectedTd.textContent
)
// var This=outline.UserInput;
if (selectedTd.className.indexOf(' pendingedit') !== -1) {
UI.log.warn(
'The node you attempted to edit has a request still pending.\n' +
'Please wait for the request to finish (the text will turn black)\n' +
'before editing this node again.'
)
return true
}
const target = selectedTd
const about = this.getStatementAbout(target) // timbl - to avoid alert from random clicks
if (!about) return
let obj
let trNode
try {
obj = UI.utils.getTerm(target)
trNode = UI.utils.ancestor(target, 'TR')
} catch (e) {
UI.log.warn('userinput.js: ' + e + UI.utils.getAbout(store, selectedTd))
UI.log.error(target + ' getStatement Error:' + e)
}
let tdNode
try {
tdNode = trNode.lastChild
} catch (e) {
UI.log.error(e + '@' + target)
}
// seems to be a event handling problem of firefox3
/*
if (e.type!='keypress'&&(selectedTd.className=='undetermined selected'||selectedTd.className=='undetermined')){
this.Refill(e,selectedTd);
return;
}
*/
// ignore clicking trNode.firstChild (be careful for <div> or <span>)
// if (e.type!='keypress'&&target!=tdNode && UI.utils.ancestor(target,'TD')!=tdNode) return;
if (obj.termType === 'Literal') {
tdNode.removeChild(tdNode.firstChild) // remove the text
if (obj.value.match('\n')) {
// match a line feed and require <TEXTAREA>
const textBox = myDocument.createElement('textarea')
textBox.appendChild(myDocument.createTextNode(obj.value))
textBox.setAttribute(
'rows',
(obj.value.match(/\n/g).length + 1).toString()
)
// g is for global(??)
textBox.setAttribute('cols', '100') // should be the size of <TD>
textBox.setAttribute('class', 'textinput')
tdNode.appendChild(textBox)
this.lastModified = textBox
} else {
this.lastModified = this.createInputBoxIn(tdNode, obj.value)
}
this.lastModified.isNew = false
// Kenny: What should be expected after you click a editable text element?
// Choice 1
this.lastModified.select()
// Choice 2 - direct the key cursor to where you click (failed attempt)
// --------------------------------------------------------------------------
// duplicate the event so user can edit without clicking twice
// var e2=myDocument.createEvent("MouseEvents");
// e2.initMouseEvent("click",true,true,window,0,0,0,0,0,false,false,false,false,0,null);
// inputBox.dispatchEvent(e2);
// ---------------------------------------------------------------------------
}
return true // this is not a valid modification
},
/**
* UIs: input event handlers, menu generation
*/
performAutoCompleteEdit: function performAutoCompleteEdit (
selectedTd,
menu
) {
UI.utils.emptyNode(selectedTd)
qp('perform AutoCompleteEdit. THIS IS=' + this)
this.lastModified = this.createInputBoxIn(selectedTd, '')
this.lastModified.select()
this.lastModified.addEventListener(
'keypress',
this.getAutoCompleteHandler(menu),
false
)
/* keypress!?
This is what I hate about UI programming.
I shall write something about this but not now.
*/
// this pops up the autocomplete menu
// Pops up the menu even though no keypress has occurred
// 1 is a dummy variable for the "enterEvent"
this.getAutoCompleteHandler(menu)(1)
},
backOut: function backOut () {
this.deleteTriple(this.lastModified.parentNode, true)
this.lastModified = null
},
clearMenu: function clearMenu () {
const menu = myDocument.getElementById(this.menuID)
if (menu) {
menu.parentNode.removeChild(menu)
// emptyNode(menu);
}
},
/* goes here when either this is a literal or escape from menu and then input text */
clearInputAndSave: function clearInputAndSave (e) {
let obj
if (!this.lastModified) return
if (!this.lastModified.isNew) {
try {
obj = this.getStatementAbout(this.lastModified).object
} catch (e) {
return
}
}
let s = this.lastModifiedStat // when 'isNew' this is set at addNewObject()
let defaultpropview
let trNode
let reqTerm
let preStat
if (this.lastModified.value !== this.lastModified.defaultValue) {
let trCache
if (this.lastModified.value === '') {
// ToDo: remove this
this.lastModified.value = this.lastModified.defaultValue
this.clearInputAndSave()
return
} else if (this.lastModified.isNew) {
s = new UI.rdf.Statement(
s.subject,
s.predicate,
store.literal(this.lastModified.value),
s.why
)
// TODO: DEFINE ERROR CALLBACK
defaultpropview = this.views.defaults[s.predicate.uri]
trCache = UI.utils.ancestor(this.lastModified, 'TR')
try {
store.updater.update([], [s], function (
uri,
success,
errorBody
) {
if (!success) {
UI.log.error(
'Error occurs while inserting ' +
s +
'\n\n' +
errorBody +
'\n'
)
// UI.log.warn("Error occurs while inserting "+s+'\n\n'+errorBody);
outline.UserInput.deleteTriple(trCache.lastChild, true)
}
})
} catch (e) {
UI.log.error('Error inserting fact ' + s + ':\n\t' + e + '\n')
return
}
s = store.add(
s.subject,
s.predicate,
store.literal(this.lastModified.value),
s.why
)
} else {
if (this.statIsInverse) {
UI.log.error(
"Invalid Input: a literal can't be a subject in RDF/XML"
)
this.backOut()
return
}
let s1, s2, s3
switch (obj.termType) {
case 'Literal': {
// generate path and nailing from current values
// TODO: DEFINE ERROR CALLBACK
const valueCache = this.lastModified.value
trCache = UI.utils.ancestor(this.lastModified, 'TR')
const oldValue = this.lastModified.defaultValue
s2 = $rdf.st(
s.subject,
s.predicate,
store.literal(this.lastModified.value),
s.why
)
try {
store.updater.update([s], [s2], function (
uri,
success,
errorBody
) {
if (success) {
obj.value = valueCache
} else {
UI.log.warn(
'Error occurs while editing ' + s + '\n\n' + errorBody
)
trCache.lastChild.textContent = oldValue
}
trCache.lastChild.className = trCache.lastChild.className.replace(
/ pendingedit/g,
''
)
})
} catch (e) {
UI.log.warn('Error occurs while editing ' + s + ':\n\t' + e)
return
}
// obj.value=this.lastModified.value;
// UserInputFormula.statements.push(s);
break
}
case 'BlankNode': { // a request refill with text
// var newStat
const textTerm = store.literal(this.lastModified.value, '')
// <Feature about="labelChoice">
if (s.predicate.termType === 'Collection') {
// case: add triple ????????? Weird - tbl
const selectedPredicate = s.predicate.elements[0] // @@ TBL elements is a list on the predicate??
if (store.any(undefined, selectedPredicate, textTerm)) {
if (!e) {
// keyboard
const tdNode = this.lastModified.parentNode
e = {}
e.pageX = UI.utils.findPos(tdNode)[0]
e.pageY = UI.utils.findPos(tdNode)[1] + tdNode.clientHeight
}
this.showMenu(e, 'DidYouMeanDialog', undefined, {
dialogTerm: store.any(undefined, selectedPredicate, textTerm),
bnodeTerm: s.subject
})
} else {
s1 = UI.utils.ancestor(
UI.utils.ancestor(this.lastModified, 'TR').parentNode,
'TR'
).AJAR_statement
s2 = $rdf.st(s.subject, selectedPredicate, textTerm, s.why)
const type = store.the(s.subject, rdf('type'))
s3 = store.anyStatementMatching(
s.subject,
rdf('type'),
type,
s.why
)
// TODO: DEFINE ERROR CALLBACK
// because the table is repainted, so...
trCache = UI.utils.ancestor(
UI.utils.ancestor(this.lastModified, 'TR'),
'TD'
).parentNode
try {
store.updater.update([], [s1, s2, s3], function (
uri,
success,
errorBody
) {
if (!success) {
console.log(
'Error occurs while editing ' +
s1 +
'\n\n' +
errorBody
)
outline.UserInput.deleteTriple(trCache.lastChild, true) // @@@@ This
}
})
} catch (e) {
console.log(
'Error occurs while editing ' + s1 + ':\n\t' + e
)
return
}
store.remove(s)
store.add(s.subject, selectedPredicate, textTerm, s.why) // was: newStat =
// a subtle bug occurs here, if foaf:nick hasn't been dereferneced,
// this add will cause a repainting
}
const enclosingTd = UI.utils.ancestor(
this.lastModified.parentNode.parentNode,
'TD'
)
const defaultPane = panes.byName('default') // @@ check
outline.outlineExpand(enclosingTd, s.subject, {
pane: defaultPane,
already: true
})
outline.walk('right', outline.focusTd)
// </Feature>
} else {
this.fillInRequest(
'object',
this.lastModified.parentNode,
store.literal(this.lastModified.value)
)
return // The new Td is already generated by fillInRequest, so it's done.
}
break
}
}
}
} else if (this.lastModified.isNew) {
// generate 'Request', there is no way you can input ' (Please Input) '
trNode = UI.utils.ancestor(this.lastModified, 'TR')
reqTerm = this.generateRequest(
'(To be determined. Re-type of drag an object onto this field)'
)
preStat = trNode.previousSibling.AJAR_statement // the statement of the same predicate
this.formUndetStat(
trNode,
preStat.subject,
preStat.predicate,
reqTerm,
preStat.why,
false
)
// this why being the same as the previous statement
this.lastModified = null
// UI.log.warn("test .isNew)");
return
} else if (s.predicate.termType === 'Collection') {
store.removeMany(s.subject)
const upperTr = UI.utils.ancestor(
UI.utils.ancestor(this.lastModified, 'TR').parentNode,
'TR'
)
preStat = upperTr.AJAR_statement
reqTerm = this.generateRequest(
'(To be determined. Re-type of drag an object onto this field)'
)
this.formUndetStat(
upperTr,
preStat.subject,
preStat.predicate,
reqTerm,
preStat.why,
false
)
outline.replaceTD(
outline.outlineObjectTD(reqTerm, defaultpropview),
upperTr.lastChild
)
this.lastModified = null
return
} else if (this.statIsInverse) {
/*
if ((s.object.termType === 'BlankNode' && !this.statIsInverse) ||
s.subject.termType === 'BlankNode' && this.statIsInverse) {
this.backOut()
return
*/
if (s.subject.termType === 'BlankNode') {
this.backOut()
return
}
} else {
if (s.object.termType === 'BlankNode') {
this.backOut()
return
}
}
// case modified - literal modification only(for now).
trNode = UI.utils.ancestor(this.lastModified, 'TR')
// var defaultpropview = this.views.defaults[s.predicate.uri]
if (!this.statIsInverse) {
// this is for an old feature
// outline.replaceTD(outline.outlineObjectTD(s.object, defaultpropview),trNode.lastChild);
outline.replaceTD(
outline.outlineObjectTD(
store.literal(this.lastModified.value),
defaultpropview
),
trNode.lastChild
)
} else {
outline.replaceTD(
outline.outlineObjectTD(s.subject, defaultpropview),
trNode.lastChild
)
}
if (this.lastModified.value !== this.lastModified.defaultValue) {
trNode.lastChild.className += ' pendingedit'
}
// trNode.AJAR_statement=s;//you don't have to set AJAR_inverse because it's not changed
// This is going to be painful when predicate-edit allowed
this.lastModified = null
},
/* deletes the triple corresponding to selectedTd, remove that Td. */
deleteTriple: function deleteTriple (selectedTd, isBackOut) {
// ToDo: complete deletion of a node
UI.log.debug('deleteTriple entered')
// allow a pending node to be deleted if it's a backout sent by SPARQL update callback
if (!isBackOut && selectedTd.className.indexOf(' pendingedit') !== -1) {
console.log(
'The node you attempted to edit has a request still pending.\n' +
'Please wait for the request to finish (the text will turn black)\n' +
'before editing this node again.'
)
outline.walk('up')
return
}
let removedTr
// var afterTr
const s = this.getStatementAbout(selectedTd)
if (
!isBackOut &&
!store.whether(s.object, rdf('type'), UI.ns.link('Request')) &&
// Better to check whether provenance is internal?
!store.whether(s.predicate, rdf('type'), UI.ns.link('Request')) &&
!store.whether(s.subject, rdf('type'), UI.ns.link('Request'))
) {
UI.log.debug('about to send SPARQLUpdate')
try {
store.updater.update([s], [], function (uri, success, errorBody) {
if (success) {
removefromview()
} else {
// removedTr.AJAR_statement=kb.add(s.subject,s.predicate,s.object,s.why);
console.log(
'Error occurs while deleting ' + s + '\n\n' + errorBody
)
selectedTd.className = selectedTd.className.replace(
/ pendingedit/g,
''
)
}
})
selectedTd.className += ' pendingedit'
} catch (e) {
UI.log.error(e)
UI.log.warn('Error deleting statement ' + s + ':\n\t' + e)
return
}
UI.log.debug('SPARQLUpdate sent')
} else {
// removal of an undetermined statement associated with pending TRs
// TempFormula.remove(s);
}
UI.log.debug('about to remove ' + s)
UI.log.debug('removed')
outline.walk('up')
removedTr = selectedTd.parentNode
// afterTr = removedTr.nextSibling
function removefromview () {
let trIterator
for (
trIterator = removedTr;
trIterator.childNodes.length === 1;
trIterator = trIterator.previousSibling
);
let predicateTd
if (trIterator === removedTr) {
const theNext = trIterator.nextSibling
if (theNext.nextSibling && theNext.childNodes.length === 1) {
predicateTd = trIterator.firstChild
predicateTd.setAttribute(
'rowspan',
parseInt(predicateTd.getAttribute('rowspan')) - 1
)
theNext.insertBefore(trIterator.firstChild, theNext.firstChild)
}
removedTr.parentNode.removeChild(removedTr)
} else {
// !DisplayOptions["display:block on"].enabled){
predicateTd = trIterator.firstChild
predicateTd.setAttribute(
'rowspan',
parseInt(predicateTd.getAttribute('rowspan')) - 1
)
removedTr.parentNode.removeChild(removedTr)
}
}
if (isBackOut) removefromview()
},
/* clipboard principle: copy wildly, paste carefully
ToDoS:
1. register Subcollection?
2. copy from more than one selectedTd: 1.sequece 2.collection
3. make a clipboard class?
*/
clipboardInit: function clipboardInit () {
outline.clipboard = {}
outline.clipboard.objects = []
outline.clipboard.predicates = []
outline.clipboard.all = []
},
copyToClipboard: function copyToClipboard (address, selectedTd) {
/*
var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
if (!clip) return false;
var clipid = Components.interfaces.nsIClipboard;
var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
if (!trans) return false;
var copytext = "Tabulator!!";
var str = Components.classes["@mozilla.org/supports-string;1"].
createInstance(Components.interfaces.nsISupportsString);
if (!str) return false;
str.data = copytext;
trans.addDataFlavor("text/x-moz-url");
trans.setTransferData("text/x-mox-url", str, copytext.length * 2);
clip.setData(trans, null, clipid.kGlobalClipboard);
*/
const term = UI.utils.getTerm(selectedTd)
switch (selectedTd.className) {
case 'selected': // table header
case 'obj selected':
// var objects = outline.clipboard.objects
outline.clipboard.objects.unshift(term)
break
case 'pred selected':
case 'pred internal selected':
outline.clipboard.predicates.unshift(term)
}
outline.clipboard.all.unshift(term)
},
insertTermTo: function insertTermTo (selectedTd, term, isObject) {
let defaultpropview
let preStat
switch (selectedTd.className) {
case 'undetermined selected':
defaultpropview = this.views.defaults[
selectedTd.parentNode.AJAR_statement.predicate.uri
]
this.fillInRequest(
selectedTd.nextSibling ? 'predicate' : 'object',
selectedTd,
term
)
break
case 'pred selected': { // paste objects into this predicate
const insertTr = this.appendToPredicate(selectedTd)
preStat = selectedTd.parentNode.AJAR_statement
defaultpropview = this.views.defaults[preStat.predicate.uri]
insertTr.appendChild(outline.outlineObjectTD(term, defaultpropview))
// modify store and update here
const isInverse = selectedTd.parentNode.AJAR_inverse
if (!isInverse) {
insertTr.AJAR_statement = store.add(
preStat.subject,
preStat.predicate,
term,
preStat.why
)
} else {
insertTr.AJAR_statemnet = store.add(
term,
preStat.predicate,
preStat.object,
preStat.why
)
}
try {
store.updater.update([], [insertTr.AJAR_statement], function (
uri,
success,
errorBody
) {
if (!success) {
UI.log.error(
'userinput.js (pred selected): Fail trying to insert statement ' +
insertTr.AJAR_statement +
': ' +
errorBody
)
}
})
} catch (e) {
UI.log.error(
'Exception trying to insert statement ' +
insertTr.AJAR_statement +
': ' +
UI.utils.stackString(e)
)
return
}
insertTr.AJAR_inverse = isInverse
UserInputFormula.statements.push(insertTr.AJAR_statement)
break
}
case 'selected': { // header <TD>, undetermined generated
const paneDiv = UI.utils.ancestor(selectedTd, 'TABLE').lastChild
const newTr = paneDiv.insertBefore(
myDocument.createElement('tr'),
paneDiv.lastChild
)
// var titleTerm=UI.utils.getAbout(kb,UI.utils.ancestor(newTr,'TD'));
preStat = newTr.previousSibling.AJAR_statement
if (typeof isObject === 'undefined') isObject = true
if (isObject) {
// object inserted
this.formUndetStat(
newTr,
preStat.subject,
this.generateRequest('(TBD)', newTr, true),
term,
preStat.why,
false
)
// defaultpropview temporaily not dealt with
newTr.appendChild(outline.outlineObjectTD(term))
outline.walk('moveTo', newTr.firstChild)
this.startFillInText(newTr.firstChild)
} else {
// predicate inserted
// existing predicate not expected
const reqTerm = this.generateRequest(
'(To be determined. Re-type of drag an object onto this field)',
newTr
)
this.formUndetStat(
newTr,
preStat.subject,
term,
reqTerm,
preStat.why,
false
)
newTr.insertBefore(
outline.outlinePredicateTD(term, newTr, false, false),
newTr.firstChild
)
outline.walk('moveTo', newTr.lastChild)
this.startFillInText(newTr.lastChild)
}
break
}
}
},
Refill: function Refill (e, selectedTd) {
UI.log.info('Refill' + selectedTd.textContent)
const isPredicate = selectedTd.nextSibling
let predicateQuery
if (isPredicate) {
// predicateTd
let subject
let subjectClass
let sparqlText
if (selectedTd.nextSibling.className === 'undetermined') {
/* Make set of proprties to propose for a predicate.
The naive approach is to take those which have a class
of the subject as their domain. But in fact we must offer anything which
is not explicitly excluded, by having a domain disjointWith a
class of the subject. */
/* SELECT ?pred
WHERE{
?pred a rdf:Property.
?pred rdfs:domain subjectClass.
}
*/
/* SELECT ?pred ?class
WHERE{
?pred a rdf:Property.
subjectClass owl:subClassOf ?class.
?pred rdfs:domain ?class.
}
*/
/* SELECT ?pred
WHERE{
subject a ?subjectClass.
?pred rdfs:domain ?subjectClass.