-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathmanager.js
More file actions
2422 lines (2232 loc) · 79.8 KB
/
manager.js
File metadata and controls
2422 lines (2232 loc) · 79.8 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 */
/* -*- coding: utf-8-dos -*-
Outline Mode Manager
*/
import * as paneRegistry from 'pane-registry'
import * as $rdf from 'rdflib'
import * as UI from 'solid-ui'
import { authn, authSession, store } from 'solid-logic'
import { propertyViews } from './propertyViews'
import { outlineIcons } from './outlineIcons.js' // @@ chec
import { UserInput } from './userInput.js'
import * as queryByExample from './queryByExample.js'
/* global alert XPathResult sourceWidget */
// XPathResult?
// const iconHeight = '24px'
export default function (context) {
const dom = context.dom
this.document = context.dom
this.outlineIcons = outlineIcons
this.labeller = this.labeller || {}
this.labeller.LanguagePreference = '' // for now
const outline = this // Kenny: do we need this?
const thisOutline = this
let selection = []
this.selection = selection
this.ancestor = UI.utils.ancestor // make available as outline.ancestor in callbacks
this.sparql = $rdf.UpdateManager
this.kb = store
const kb = store
const sf = store.fetcher
dom.outline = this
this.qs = new queryByExample.QuerySource() // Track queries in queryByExample
// var selection = [] // Array of statements which have been selected
// this.focusTd // the <td> that is being observed
this.UserInput = new UserInput(this)
this.clipboardAddress = 'tabulator:clipboard' // Weird
this.UserInput.clipboardInit(this.clipboardAddress)
const outlineElement = this.outlineElement
this.init = function () {
const table = getOutlineContainer()
table.outline = this
}
/** benchmark a function **/
benchmark.lastkbsize = 0
function benchmark (f) {
const args = []
for (let i = arguments.length - 1; i > 0; i--) args[i - 1] = arguments[i]
// UI.log.debug('BENCHMARK: args=' + args.join());
const begin = new Date().getTime()
const returnValue = f.apply(f, args)
const end = new Date().getTime()
UI.log.info(
'BENCHMARK: kb delta: ' +
(kb.statements.length - benchmark.lastkbsize) +
', time elapsed for ' +
f +
' was ' +
(end - begin) +
'ms'
)
benchmark.lastkbsize = kb.statements.length
return returnValue
} // benchmark
// / ////////////////////// Representing data
// Represent an object in summary form as a table cell
function appendRemoveIcon (node, subject, removeNode) {
const image = UI.utils.AJARImage(
outlineIcons.src.icon_remove_node,
'remove',
undefined,
dom
)
image.addEventListener('click', removeNodeIconMouseDownListener)
// image.setAttribute('align', 'right') Causes icon to be moved down
image.node = removeNode
image.setAttribute('about', subject.toNT())
image.style.marginLeft = '5px'
image.style.marginRight = '10px'
// image.style.border='solid #777 1px';
node.appendChild(image)
return image
}
this.appendAccessIcons = function (kb, node, obj) {
if (obj.termType !== 'NamedNode') return
const uris = kb.uris(obj)
uris.sort()
let last = null
for (let i = 0; i < uris.length; i++) {
if (uris[i] === last) continue
last = uris[i]
thisOutline.appendAccessIcon(node, last)
}
}
this.appendAccessIcon = function (node, uri) {
if (!uri) return ''
const docuri = $rdf.uri.docpart(uri)
if (docuri.slice(0, 5) !== 'http:') return ''
const state = sf.getState(docuri)
let icon, alt, listener
switch (state) {
case 'unrequested':
icon = outlineIcons.src.icon_unrequested
alt = 'fetch'
listener = unrequestedIconMouseDownListener
break
case 'requested':
icon = outlineIcons.src.icon_requested
alt = 'fetching'
listener = failedIconMouseDownListener // new: can retry yello blob
break
case 'fetched':
icon = outlineIcons.src.icon_fetched
listener = fetchedIconMouseDownListener
alt = 'loaded'
break
case 'failed':
icon = outlineIcons.src.icon_failed
alt = 'failed'
listener = failedIconMouseDownListener
break
case 'unpermitted':
icon = outlineIcons.src.icon_failed
listener = failedIconMouseDownListener
alt = 'no perm'
break
case 'unfetchable':
icon = outlineIcons.src.icon_failed
listener = failedIconMouseDownListener
alt = 'cannot fetch'
break
default:
UI.log.error('?? state = ' + state)
break
} // switch
const img = UI.utils.AJARImage(
icon,
alt,
outlineIcons.tooltips[icon].replace(/[Tt]his resource/, docuri),
dom
)
img.setAttribute('uri', uri)
img.addEventListener('click', listener) // @@ seemed to be missing 2017-08
addButtonCallbacks(img, docuri)
node.appendChild(img)
return img
} // appendAccessIcon
/** make the td for an object (grammatical object)
* @param obj - an RDF term
* @param view - a VIEW function (rather than a bool asImage)
**/
this.outlineObjectTD = function outlineObjectTD (
obj,
view,
deleteNode,
statement
) {
const td = dom.createElement('td')
td.setAttribute(
'style',
'margin: 0.2em; border: none; padding: 0; vertical-align: top;'
)
td.setAttribute('notSelectable', 'false')
const theClass = 'obj'
// set about and put 'expand' icon
if (
obj.termType === 'NamedNode' ||
obj.termType === 'BlankNode' ||
(obj.termType === 'Literal' &&
obj.value.slice &&
(obj.value.slice(0, 6) === 'ftp://' ||
obj.value.slice(0, 8) === 'https://' ||
obj.value.slice(0, 7) === 'http://'))
) {
td.setAttribute('about', obj.toNT())
td.appendChild(
UI.utils.AJARImage(
UI.icons.originalIconBase + 'tbl-expand-trans.png',
'expand',
undefined,
dom
)
).addEventListener('click', expandMouseDownListener)
}
td.setAttribute('class', theClass) // this is how you find an object
// @@ TAKE CSS OUT OF STYLE SHEET
if (kb.whether(obj, UI.ns.rdf('type'), UI.ns.link('Request'))) {
td.className = 'undetermined'
} // @@? why-timbl
if (!view) {
// view should be a function pointer
view = viewAsBoringDefault
}
td.appendChild(view(obj))
if (deleteNode) {
appendRemoveIcon(td, obj, deleteNode)
}
// set DOM methods
td.tabulatorSelect = function () {
setSelected(this, true)
}
td.tabulatorDeselect = function () {
setSelected(this, false)
}
td.addEventListener('click', selectableTDClickListener)
return td
} // outlineObjectTD
this.outlinePredicateTD = function outlinePredicateTD (
predicate,
newTr,
inverse,
internal
) {
const predicateTD = dom.createElement('TD')
predicateTD.setAttribute('about', predicate.toNT())
predicateTD.setAttribute('class', internal ? 'pred internal' : 'pred')
let lab
switch (predicate.termType) {
case 'BlankNode': // TBD
predicateTD.className = 'undetermined'
break
case 'NamedNode':
lab = UI.utils.predicateLabelForXML(predicate, inverse)
break
case 'Collection': // some choices of predicate
lab = UI.utils.predicateLabelForXML(predicate.elements[0], inverse)
}
lab = lab ? lab.slice(0, 1).toUpperCase() + lab.slice(1) : '...'
// if (kb.statementsMatching(predicate,rdf('type'), UI.ns.link('Request')).length) predicateTD.className='undetermined';
const labelTD = dom.createElement('TD')
labelTD.setAttribute(
'style',
'margin: 0.2em; border: none; padding: 0; vertical-align: top;'
)
labelTD.setAttribute('notSelectable', 'true')
labelTD.appendChild(dom.createTextNode(lab))
predicateTD.appendChild(labelTD)
labelTD.style.width = '100%'
predicateTD.appendChild(termWidget.construct(dom)) // termWidget is global???
for (const w in outlineIcons.termWidgets) {
if (!newTr || !newTr.AJAR_statement) break // case for TBD as predicate
// alert(Icon.termWidgets[w]+' '+Icon.termWidgets[w].filter)
if (
outlineIcons.termWidgets[w].filter &&
outlineIcons.termWidgets[w].filter(
newTr.AJAR_statement,
'pred',
inverse
)
) {
termWidget.addIcon(predicateTD, outlineIcons.termWidgets[w])
}
}
// set DOM methods
predicateTD.tabulatorSelect = function () {
setSelected(this, true)
}
predicateTD.tabulatorDeselect = function () {
setSelected(this, false)
}
predicateTD.addEventListener('click', selectableTDClickListener)
return predicateTD
} // outlinePredicateTD
/**
* Render Tabbed set of home app panes
*
* @param {Object} [options] A set of options you can provide
* @param {string} [options.selectedTab] To open a specific dashboard pane
* @param {Function} [options.onClose] If given, will present an X for the dashboard, and call this method when clicked
* @returns Promise<{Element}> - the div that holds the dashboard
*/
async function globalAppTabs (options = {}) {
console.log('globalAppTabs @@')
const div = dom.createElement('div')
const me = authn.currentUser()
if (!me) {
alert('Must be logged in for this')
throw new Error('Not logged in')
}
const items = await getDashboardItems()
function renderTab (div, item) {
div.dataset.globalPaneName = item.tabName || item.paneName
div.textContent = item.label
}
function renderMain (containerDiv, item) {
// Items are pane names
const pane = paneRegistry.byName(item.paneName) // 20190701
containerDiv.innerHTML = ''
const table = containerDiv.appendChild(dom.createElement('table'))
const me = authn.currentUser()
thisOutline.GotoSubject(
item.subject || me,
true,
pane,
false,
undefined,
table
)
}
div.appendChild(
UI.tabs.tabWidget({
dom,
subject: me,
items,
renderMain,
renderTab,
ordered: true,
orientation: 0,
backgroundColor: '#eeeeee', // black?
selectedTab: options.selectedTab,
onClose: options.onClose
})
)
return div
}
this.getDashboard = globalAppTabs
async function getDashboardItems () {
const me = authn.currentUser()
if (!me) return []
const div = dom.createElement('div')
const [books, pods] = await Promise.all([getAddressBooks(), getPods()])
return [
{
paneName: 'home',
label: 'Your stuff',
icon: UI.icons.iconBase + 'noun_547570.svg'
},
{
paneName: 'basicPreferences',
label: 'Preferences',
icon: UI.icons.iconBase + 'noun_Sliders_341315_00000.svg'
},
{
paneName: 'profile',
label: 'Your Profile',
icon: UI.icons.iconBase + 'noun_15059.svg'
},
{
paneName: 'editProfile',
label: 'Edit your Profile',
icon: UI.icons.iconBase + 'noun_492246.svg'
}
]
.concat(books)
.concat(pods)
async function getPods () {
async function addPodStorage (pod) { // namedNode
await loadContainerRepresentation(pod)
if (kb.holds(pod, ns.rdf('type'), ns.space('Storage'), pod.doc())) {
pods.push(pod)
return true
}
return false
}
async function addPodStorageFromUrl (url) {
const podStorage = new URL(url)
// check for predicate pim:Storage in containers up the path tree
let pathStorage = podStorage.pathname
while (pathStorage.length) {
pathStorage = pathStorage.substring(0, pathStorage.lastIndexOf('/'))
if (await addPodStorage(kb.sym(`${podStorage.origin}${pathStorage}/`))) return
}
// TODO should url.origin be added to pods list when there are no pim:Storage ???
}
try {
// need to make sure that profile is loaded
await kb.fetcher.load(me.doc())
} catch (err) {
console.error('Unable to load profile', err)
return []
}
// load pod's storages from profile
let pods = kb.each(me, ns.space('storage'), null, me.doc())
pods.map(async (pod) => {
// TODO use addPodStorageFromUrl(pod.uri) to check for pim:Storage ???
await loadContainerRepresentation(pod)
})
try {
// if uri then SolidOS is a browse.html web app
const uri = (new URL(window.location.href)).searchParams.get('uri')
const podUrl = uri || window.location.href
await addPodStorageFromUrl(podUrl)
} catch (err) {
console.error('cannot load container', err)
}
// remove namedNodes duplicates
function uniques (nodes) {
const uniqueNodes = []
nodes.forEach(node => {
if (!uniqueNodes.find(uniqueNode => uniqueNode.equals(node))) uniqueNodes.push(node)
})
return uniqueNodes
}
pods = uniques(pods)
if (!pods.length) return []
return pods.map((pod, index) => {
function split (item) { return item.uri.split('//')[1].slice(0, -1) }
const label = split(me).startsWith(split(pod)) ? 'Your storage' : split(pod)
return {
paneName: 'folder',
tabName: `folder-${index}`,
label,
subject: pod,
icon: UI.icons.iconBase + 'noun_Cabinet_251723.svg'
}
})
}
async function getAddressBooks () {
try {
const context = await UI.login.findAppInstances(
{ me, div, dom },
ns.vcard('AddressBook')
)
return (context.instances || []).map((book, index) => ({
paneName: 'contact',
tabName: `contact-${index}`,
label: 'Contacts',
subject: book,
icon: UI.icons.iconBase + 'noun_15695.svg'
}))
} catch (err) {
console.error('oops in globalAppTabs AddressBook')
}
return []
}
}
this.getDashboardItems = getDashboardItems
/**
* Call this method to show the global dashboard.
*
* @param {Object} [options] A set of options that can be passed
* @param {string} [options.pane] To open a specific dashboard pane
* @returns {Promise<void>}
*/
async function showDashboard (options = {}) {
const dashboardContainer = getDashboardContainer()
const outlineContainer = getOutlineContainer()
// reuse dashboard if already children already is inserted
if (dashboardContainer.childNodes.length > 0 && options.pane) {
outlineContainer.style.display = 'none'
dashboardContainer.style.display = 'inherit'
const tab = dashboardContainer.querySelector(
`[data-global-pane-name="${options.pane}"]`
)
if (tab) {
tab.click()
return
}
console.warn(
'Did not find the referred tab in global dashboard, will open first one'
)
}
// create a new dashboard if not already present
const dashboard = await globalAppTabs({
selectedTab: options.pane,
onClose: closeDashboard
})
// close the dashboard if user log out
authSession.events.on('logout', closeDashboard)
// finally - switch to showing dashboard
outlineContainer.style.display = 'none'
dashboardContainer.appendChild(dashboard)
const tab = dashboardContainer.querySelector(
`[data-global-pane-name="${options.pane}"]`
)
if (tab) {
tab.click()
}
function closeDashboard () {
dashboardContainer.style.display = 'none'
outlineContainer.style.display = 'inherit'
}
}
this.showDashboard = showDashboard
function getDashboardContainer () {
return getOrCreateContainer('GlobalDashboard')
}
function getOutlineContainer () {
return getOrCreateContainer('outline')
}
/**
* Get element with id or create a new on the fly with that id
*
* @param {string} id The ID of the element you want to get or create
* @returns {HTMLElement}
*/
function getOrCreateContainer (id) {
return (
document.getElementById(id) ||
(() => {
const dashboardContainer = document.createElement('div')
dashboardContainer.id = id
const mainContainer =
document.querySelector('[role="main"]') || document.body
return mainContainer.appendChild(dashboardContainer)
})()
)
}
async function loadContainerRepresentation (subject) {
// force reload for index.html with RDFa
if (!kb.any(subject, ns.ldp('contains'), undefined, subject.doc())) {
const response = await kb.fetcher.webOperation('GET', subject.uri, kb.fetcher.initFetchOptions(subject.uri, { headers: { accept: 'text/turtle' } }))
const containerTurtle = response.responseText
$rdf.parse(containerTurtle, kb, subject.uri, 'text/turtle')
}
}
async function getRelevantPanes (subject, context) {
// make sure container representation is loaded (when server returns index.html)
if (subject.uri.endsWith('/')) { await loadContainerRepresentation(subject) }
const panes = context.session.paneRegistry
const relevantPanes = panes.list.filter(
pane => pane.label(subject, context) && !pane.global
)
if (relevantPanes.length === 0) {
// there are no relevant panes, simply return default pane (which ironically is internalPane)
return [panes.byName('internal')]
}
const filteredPanes = await UI.login.filterAvailablePanes(relevantPanes)
if (filteredPanes.length === 0) {
// if no relevant panes are available panes because of user role, we still allow for the most relevant pane to be viewed
return [relevantPanes[0]]
}
const firstRelevantPaneIndex = panes.list.indexOf(relevantPanes[0])
const firstFilteredPaneIndex = panes.list.indexOf(filteredPanes[0])
// if the first relevant pane is loaded before the panes available wrt role, we still want to offer the most relevant pane
return firstRelevantPaneIndex < firstFilteredPaneIndex
? [relevantPanes[0]].concat(filteredPanes)
: filteredPanes
}
function getPane (relevantPanes, subject) {
return (
relevantPanes.find(
pane => pane.shouldGetFocus && pane.shouldGetFocus(subject)
) || relevantPanes[0]
)
}
async function expandedHeaderTR (subject, requiredPane, options) {
async function renderPaneIconTray (td, options = {}) {
const paneShownStyle =
'width: 24px; border-radius: 0.5em; border-top: solid #222 1px; border-left: solid #222 0.1em; border-bottom: solid #eee 0.1em; border-right: solid #eee 0.1em; margin-left: 1em; padding: 3px; background-color: #ffd;'
const paneHiddenStyle =
'width: 24px; border-radius: 0.5em; margin-left: 1em; padding: 3px'
const paneIconTray = td.appendChild(dom.createElement('nav'))
paneIconTray.style =
'display:flex; justify-content: flex-start; align-items: center;'
const relevantPanes = options.hideList
? []
: await getRelevantPanes(subject, context)
tr.firstPane = requiredPane || getPane(relevantPanes, subject)
const paneNumber = relevantPanes.indexOf(tr.firstPane)
if (relevantPanes.length !== 1) {
// if only one, simplify interface
relevantPanes.forEach((pane, index) => {
const label = pane.label(subject, context)
const iconSrc = typeof pane.icon === 'function' ? pane.icon(subject, context) : pane.icon
const ico = UI.utils.AJARImage(iconSrc, label, label, dom)
// Handle async icon functions
if (iconSrc instanceof Promise) {
iconSrc.then(resolvedIconSrc => {
ico.setAttribute('src', resolvedIconSrc)
}).catch(err => {
console.error('Error resolving async icon:', err)
})
}
ico.style = pane === tr.firstPane ? paneShownStyle : paneHiddenStyle // init to something at least
// ico.setAttribute('align','right'); @@ Should be better, but ffox bug pushes them down
// ico.style.width = iconHeight
// ico.style.height = iconHeight
const listen = function (ico, pane) {
// Freeze scope for event time
ico.addEventListener(
'click',
function (event) {
let containingTable
// Find the containing table for this subject
for (containingTable = td; containingTable.parentNode; containingTable = containingTable.parentNode) {
if (containingTable.nodeName === 'TABLE') break
}
if (containingTable.nodeName !== 'TABLE') {
throw new Error('outline: internal error.')
}
const removePanes = function (specific) {
for (let d = containingTable.firstChild; d; d = d.nextSibling) {
if (typeof d.pane !== 'undefined') {
if (!specific || d.pane === specific) {
if (d.paneButton) {
d.paneButton.setAttribute('class', 'paneHidden')
d.paneButton.style = paneHiddenStyle
}
removeAndRefresh(d)
// If we just delete the node d, ffox doesn't refresh the display properly.
// state = 'paneHidden';
if (
d.pane.requireQueryButton &&
containingTable.parentNode.className /* outer table */ &&
numberOfPanesRequiringQueryButton === 1 &&
dom.getElementById('queryButton')
) {
dom
.getElementById('queryButton')
.setAttribute('style', 'display:none;')
}
}
}
}
}
const renderPane = function (pane) {
let paneDiv
UI.log.info('outline: Rendering pane (2): ' + pane.name)
try {
paneDiv = pane.render(subject, context, options)
} catch (e) {
// Easier debugging for pane developers
paneDiv = dom.createElement('div')
paneDiv.setAttribute('class', 'exceptionPane')
const pre = dom.createElement('pre')
paneDiv.appendChild(pre)
pre.appendChild(
dom.createTextNode(UI.utils.stackString(e))
)
}
if (
pane.requireQueryButton &&
dom.getElementById('queryButton')
) {
dom.getElementById('queryButton').removeAttribute('style')
}
const second = containingTable.firstChild.nextSibling
const row = dom.createElement('tr')
const cell = row.appendChild(dom.createElement('td'))
cell.appendChild(paneDiv)
if (second) containingTable.insertBefore(row, second)
else containingTable.appendChild(row)
row.pane = pane
row.paneButton = ico
}
const state = ico.getAttribute('class')
if (state === 'paneHidden') {
if (!event.shiftKey) {
// shift means multiple select
removePanes()
}
renderPane(pane)
ico.setAttribute('class', 'paneShown')
ico.style = paneShownStyle
} else {
removePanes(pane)
ico.setAttribute('class', 'paneHidden')
ico.style = paneHiddenStyle
}
let numberOfPanesRequiringQueryButton = 0
for (let d = containingTable.firstChild; d; d = d.nextSibling) {
if (d.pane && d.pane.requireQueryButton) {
numberOfPanesRequiringQueryButton++
}
}
},
false
)
} // listen
listen(ico, pane)
ico.setAttribute(
'class',
index !== paneNumber ? 'paneHidden' : 'paneShown'
)
if (index === paneNumber) tr.paneButton = ico
paneIconTray.appendChild(ico)
})
}
return paneIconTray
} // renderPaneIconTray
// Body of expandedHeaderTR
const tr = dom.createElement('tr')
if (options.hover) {
// By default no hide till hover as community deems it confusing
tr.setAttribute('class', 'hoverControl')
}
const td = tr.appendChild(dom.createElement('td'))
td.setAttribute(
'style',
'margin: 0.2em; border: none; padding: 0; vertical-align: top;' +
'display:flex; justify-content: space-between; flex-direction: row;'
)
td.setAttribute('notSelectable', 'true')
td.setAttribute('about', subject.toNT())
td.setAttribute('colspan', '2')
// Stuff at the right about the subject
const header = td.appendChild(dom.createElement('div'))
header.style =
'display:flex; justify-content: flex-start; align-items: center; flex-wrap: wrap;'
const showHeader = !!requiredPane
if (!options.solo && !showHeader) {
const icon = header.appendChild(
UI.utils.AJARImage(
UI.icons.originalIconBase + 'tbl-collapse.png',
'collapse',
undefined,
dom
)
)
icon.addEventListener('click', collapseMouseDownListener)
const strong = header.appendChild(dom.createElement('h1'))
strong.appendChild(dom.createTextNode(UI.utils.label(subject)))
strong.style =
'font-size: 150%; margin: 0 0.6em 0 0; padding: 0.1em 0.4em;'
UI.widgets.makeDraggable(strong, subject)
}
header.appendChild(
await renderPaneIconTray(td, {
hideList: showHeader
})
)
// set DOM methods
tr.firstChild.tabulatorSelect = function () {
setSelected(this, true)
}
tr.firstChild.tabulatorDeselect = function () {
setSelected(this, false)
}
return tr
} // expandedHeaderTR
// / //////////////////////////////////////////////////////////////////////////
/* PANES
**
** Panes are regions of the outline view in which a particular subject is
** displayed in a particular way. They are like views but views are for query results.
** subject panes are currently stacked vertically.
*/
// / //////////////////// Specific panes are in panes/*.js
//
// The defaultPane is the first one registered for which the label method exists
// Those registered first take priority as a default pane.
// That is, those earlier in this file
/**
* Pane registration
*/
// the second argument indicates whether the query button is required
// / ///////////////////////////////////////////////////////////////////////////
// Remove a node from the DOM so that Firefox refreshes the screen OK
// Just deleting it cause whitespace to accumulate.
function removeAndRefresh (d) {
const table = d.parentNode
const par = table.parentNode
const placeholder = dom.createElement('table')
placeholder.setAttribute('style', 'width: 100%;')
par.replaceChild(placeholder, table)
table.removeChild(d)
par.replaceChild(table, placeholder) // Attempt to
}
const propertyTable = (this.propertyTable = function propertyTable (
subject,
table,
pane,
options
) {
UI.log.debug('Property table for: ' + subject)
subject = kb.canon(subject)
// if (!pane) pane = panes.defaultPane;
if (!table) {
// Create a new property table
table = dom.createElement('table')
table.setAttribute('style', 'width: 100%;')
expandedHeaderTR(subject, pane, options).then(tr1 => {
table.appendChild(tr1)
if (tr1.firstPane) {
let paneDiv
try {
UI.log.info('outline: Rendering pane (1): ' + tr1.firstPane.name)
paneDiv = tr1.firstPane.render(subject, context, options)
} catch (e) {
// Easier debugging for pane developers
paneDiv = dom.createElement('div')
paneDiv.setAttribute('class', 'exceptionPane')
const pre = dom.createElement('pre')
paneDiv.appendChild(pre)
pre.appendChild(dom.createTextNode(UI.utils.stackString(e)))
}
const row = dom.createElement('tr')
const cell = row.appendChild(dom.createElement('td'))
cell.appendChild(paneDiv)
if (
tr1.firstPane.requireQueryButton &&
dom.getElementById('queryButton')
) {
dom.getElementById('queryButton').removeAttribute('style')
}
table.appendChild(row)
row.pane = tr1.firstPane
row.paneButton = tr1.paneButton
}
})
return table
} else {
// New display of existing table, keeping expanded bits
UI.log.info('Re-expand: ' + table)
// do some other stuff here
return table
}
}) /* propertyTable */
function propertyTR (doc, st, inverse) {
const tr = doc.createElement('TR')
tr.AJAR_statement = st
tr.AJAR_inverse = inverse
// tr.AJAR_variable = null; // @@ ?? was just 'tr.AJAR_variable'
tr.setAttribute('predTR', 'true')
const predicateTD = thisOutline.outlinePredicateTD(st.predicate, tr, inverse)
tr.appendChild(predicateTD) // @@ add 'internal' to predicateTD's class for style? mno
return tr
}
this.propertyTR = propertyTR
// / ////////// Property list
function appendPropertyTRs (parent, plist, inverse, predicateFilter) {
// UI.log.info('@appendPropertyTRs, 'this' is %s, dom is %s, '+ // Gives 'can't access dead object'
// 'thisOutline.document is %s', this, dom.location, thisOutline.document.location);
// UI.log.info('@appendPropertyTRs, dom is now ' + this.document.location);
// UI.log.info('@appendPropertyTRs, dom is now ' + thisOutline.document.location);
UI.log.debug('Property list length = ' + plist.length)
if (plist.length === 0) return ''
let sel, j, k
if (inverse) {
sel = function (x) {
return x.subject
}
plist = plist.sort(UI.utils.RDFComparePredicateSubject)
} else {
sel = function (x) {
return x.object
}
plist = plist.sort(UI.utils.RDFComparePredicateObject)
}
const max = plist.length
for (j = 0; j < max; j++) {
// squishing together equivalent properties I think
let s = plist[j]
// if (s.object == parentSubject) continue; // that we knew
// Avoid predicates from other panes
if (predicateFilter && !predicateFilter(s.predicate, inverse)) continue
const tr = propertyTR(dom, s, inverse)
parent.appendChild(tr)
const predicateTD = tr.firstChild // we need to kludge the rowspan later
let defaultpropview = views.defaults[s.predicate.uri]
// LANGUAGE PREFERENCES WAS AVAILABLE WITH FF EXTENSION - get from elsewhere?
let dups = 0 // How many rows have the same predicate, -1?
let langTagged = 0 // how many objects have language tags?
let myLang = 0 // Is there one I like?
for (
k = 0;
k + j < max && plist[j + k].predicate.sameTerm(s.predicate);
k++
) {
if (k > 0 && sel(plist[j + k]).sameTerm(sel(plist[j + k - 1]))) dups++
if (sel(plist[j + k]).lang && outline.labeller.LanguagePreference) {
langTagged += 1
if (
sel(plist[j + k]).lang.indexOf(
outline.labeller.LanguagePreference
) >= 0
) {
myLang++
}
}
}
/* Display only the one in the preferred language
ONLY in the case (currently) when all the values are tagged.
Then we treat them as alternatives. */
if (myLang > 0 && langTagged === dups + 1) {
for (let k = j; k <= j + dups; k++) {
if (
outline.labeller.LanguagePreference &&
sel(plist[k]).lang.indexOf(outline.labeller.LanguagePreference) >= 0
) {
tr.appendChild(
thisOutline.outlineObjectTD(
sel(plist[k]),
defaultpropview,
undefined,
s
)
)
break
}
}
j += dups // extra push
continue
}
tr.appendChild(
thisOutline.outlineObjectTD(sel(s), defaultpropview, undefined, s)
)
/* Note: showNobj shows between n to 2n objects.
* This is to prevent the case where you have a long list of objects
* shown, and dangling at the end is '1 more' (which is easily ignored)
* Therefore more objects are shown than hidden.
*/
tr.showNobj = function (n) {
const predDups = k - dups
const show = 2 * n < predDups ? n : predDups
const showLaterArray = []
if (predDups !== 1) {
predicateTD.setAttribute(
'rowspan',
show === predDups ? predDups : n + 1
)
let l
if (show < predDups && show === 1) {
// what case is this...
predicateTD.setAttribute('rowspan', 2)
}
let displayed = 0 // The number of cells generated-1,
// all duplicate thing removed
for (l = 1; l < k; l++) {
// This detects the same things
if (
!kb
.canon(sel(plist[j + l]))
.sameTerm(kb.canon(sel(plist[j + l - 1])))