generated from kit-data-manager/template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
619 lines (532 loc) · 24.3 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>FAIR-DOscope</title>
<script src="./js/handle.net_loader.js"></script>
<script src="./js/tpm_loader.js"></script>
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.2.7/dist/js/tabulator.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
<script src="./js/semantic-ui/semantic.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.7.1/ace.min.js"
integrity="sha512-7Jmn5XgQKvX7kd2yARvOywZYQfC6eB7WLLdpWfGifPHe+93PwGf2BpkrX/vPRgPxllivNDnD8TSMHpYb60opMg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.7.1/mode-json.min.js"
integrity="sha512-YXUz04sMmhEPQR5FLg4/6MFWcrTzZRobwv6cEVWsX9bfos1lm/Z5hfVz4WB3Z3XyhcVjWWUOvudJ+CCxecDI7Q=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.7.1/ext-beautify.min.js"
integrity="sha512-uXfi0GwpQZcHIhGOMMHeNYtBSjt7qDXjXHmjShWSp+RWMSmjdy69N7M/pufinvQLv6rSYlpbSXqSnLRzWE952w=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/d3@7.6.1/dist/d3.min.js"></script>
<script type='module' src='https://unpkg.com/@kit-data-manager/pid-component'></script>
<script src="./js/mappings.js"></script>
<script src="./js/ArcGraph.js"></script>
<!--script src="./js/semantic-ui/transition.js"></script>
<script src="./js/semantic-ui/dropdown.js"></script-->
<script src="./js/semantic-ui/transition.min.js"></script>
<script src="./js/semantic-ui/dropdown.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
<link href="https://unpkg.com/tabulator-tables@5.2.7/dist/css/tabulator_materialize.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./css/semantic.min.css">
<link href="./css/fontawesome/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="./css/style.css">
</head>
<body class="ui">
<h1 class="ui block header">
<img src="./images/logo.png" class="ui circular image">
<div class="content">
FAIR-DOscope
<div class="sub header">Explore the facets of FAIR Digital Objects</div>
</div>
</h1>
<div class="ui container">
<div class="ui grid container">
<div class="sixteen wide column">
<div class="ui fluid icon input">
<input id="pid_input" type="text" value="21.T11981/6ab464ed-978b-4996-876f-f68ea913a308"
placeholder="FAIR Digital Object PID">
<i class="search icon"></i>
<div id="show-fdo-button" class="ui vertical animated button" onClick="loadPid()" tabindex="0">
<div class="hidden content">Reload</div>
<div class="visible content">
<i class="fa-solid fa-arrows-rotate"></i>
</div>
</div>
</div>
</div>
</div>
<div class="ui grid container">
<div class="sixteen wide column">
<div class="ui buttons">
<button class="ui button" id="plainTypes" onClick="setRenderType(0)">Plain Record</button>
<div class="or"></div>
<button class="ui positive button active" id="humanReadableTypes" onClick="setRenderType(1)">
Interactive Record
</button>
<div class="ui vertical animated button" tabindex="0" style="width: 128px">
<div class="hidden content" onclick="clearHistory()">Clear History</div>
<div class="visible content">
<i class="trash alternate icon"></i>
</div>
</div>
</div>
</div>
</div>
<div class="ui stackable grid container" style="margin-top: 20px">
<div class="ten wide column">
<h4 class="ui header">
<i class="table icon"></i>
<div class="content">
PID Information Record
</div>
</h4>
<div class="ui segment">
<div id="fairdoscope"></div>
</div>
</div>
<div class="five wide column">
<h4 class="ui header">
<i class="tag icon"></i>
<div class="content">
FDO Badge
</div>
</h4>
<div class="ui segment" >
<div style="margin-left:-4px" id="badges">
</div>
<div class="ui floating dropdown labeled icon button">
<i class="copy icon"></i>
<span class="text">Copy as</span>
<div class="menu">
<div class="item">HTML</div>
<div class="item">Markdown</div>
</div>
</div>
</div>
<h4 class="ui header">
<i class="sitemap icon"></i>
<div class="content">
FAIR DO Graph
</div>
</h4>
<div class="ui segment">
<svg id="tree"/>
</div>
<h4 class="ui header">
<i class="html5 icon"></i>
<div class="content">
PID Component
</div>
</h4>
<div class="ui segment">
<pid-component id="pidcom" value="None"></pid-component><br/>
<div id="copycode" class="ui labeled button">
<div class="ui button">
<i class="code icon"></i> Copy Code
</div>
</div>
</div>
</div>
<div class="sixteen wide column">
<h4 class="ui header">
<i class="info circle icon"></i>
<div class="content">
Messages
</div>
</h4>
<div class="four column ui stackable grid">
<div class="column">
<button class="ui primary basic fluid button" onclick="removeMessages(0)">Remove All</button>
</div>
<div class="column">
<button class="ui positive basic fluid button" onclick="removeMessages(1)">Remove Information</button>
</div>
<div class="column">
<button class="ui negative basic fluid button" onclick="removeMessages(2)">Remove Error</button>
</div>
</div>
<div id="messages" class="ui segment">
<!--messages will go here-->
</div>
</div>
</div>
</div>
<!-- JS -->
<script th:inline="javascript">
const logo_encoded = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAa8SURBVHjadJZbbJ51Hcc//8PzPO/zHtu+Xdtt7boDa8e2sg2FjZodhCwzAhJEVMAQY6JeeaE3Jl5Iol6giVfGG2NCJkQMRjklILCpsKEIbIOx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HPuqVy7/nQtar3H/9G/BwC9WEVtGbxAMwAAAABJRU5ErkJggg==";
let currentUrl = window.location.href;
let url = new URL(currentUrl);
let userProvidedPid = url.searchParams.get("pid");
/**List of all processed FDOs currently in the FDO graph*/
let fdoList = [];
/**List of all historical FDOs*/
let fdoHistory = [];
/**Fill options with model definitions for metadata record. */
let options = {
dataModel: null,
items: null
};
/**PID Record table*/
let table = null;
/**Table columns for interactive mode*/
let interactiveTableColumns = [
{
"title": "Type",
"field": "type",
"formatter": renderCell,
"tooltip": createTooltip,
"width": 300
},
{
"title": "Value",
"field": "data.value",
"formatter": renderCell
}
];
/**Table columns for plain mode*/
let plainTableColumns = [
{
"title": "Type",
"field": "type",
"formatter": renderValuePlain,
"tooltip": createTooltip,
"width": 300
},
{
"title": "Value",
"field": "data.value",
"formatter": renderValuePlain
}
];
/**Ace editor instance*/
let editor = null;
/**D3 tree containing FDO graph*/
let tree = null;
/**Svg element for rendering 'tree' into*/
let svg = null;
/**D3 size information*/
let margin = {top: 20, right: 0, bottom: 20, left: 0},
width = 512 - margin.right - margin.left,
height = 500 - margin.top - margin.bottom;
/**D3 function*/
let diagonal = null;
/**Current root PID (the one entered at the input field)*/
let pid = null;
let resolver = null;
let data = {"nodes": [], "links": []};
function getBadgeElement(pid, type) {
let badgeUrl = "https://img.shields.io/badge/FAIR%20DO-" + encodeURIComponent(pid).replaceAll("-", "--") + "-green?logo=data:image/png;base64," + logo_encoded;
let result = undefined;
let url = new URL(window.location.href);
url.searchParams["pid"] = pid;
let targetUrl = url.toString();
if (type == "html") {
result = "<a href='" + targetUrl + "'><img src='" + badgeUrl + "' style='width: 100%'></img></a>";
} else if (type == "markdown") {
result = "[![FAIRDO](" + badgeUrl + ")](" + targetUrl + ")";
}
return result;
}
function createDummyBadge() {
let badgeUrl = "https://img.shields.io/badge/FAIR%20DO-nothing%20selected-orange?logo=data:image/png;base64," + logo_encoded;
let html = "<a href='" + pid + "'><img src='" + badgeUrl + "'></img></a>";
$("#badges").empty();
$("#badges").append(html);
}
function createBadge(pid) {
$("#badges").empty();
$("#badges").append(getBadgeElement(pid, "html"));
}
$('.ui.dropdown').dropdown({
action: 'hide',
onChange: function (value, text, selectedItem) {
navigator.clipboard.writeText(getBadgeElement(pid, value)).then(function () {
addMessage(0, "Badge copied to clipboard.");
}, function (err) {
addMessage(1, "Failed to copy badge to clipboard.");
});
}
});
$('#copycode').click(() => {
let code = "<html>\n";
code += "<head>\n";
code += "\<script type='module' src='https://unpkg.com/@kit-data-manager/pid-component'\>\</script\>\n";
code += "</head>\n";
code += "<body>\n";
code += "<pid-component value=\"" + $("#pidcom").attr("value") + "\"></pid-component>\n";
code += "</body>\n";
code += "</html>";
navigator.clipboard.writeText(code).then(function () {
addMessage(0, "Code copied to clipboard.");
}, function (err) {
addMessage(1, "Failed to copy code clipboard.");
});
});
/**Renderer function for PID record table cells. This function is used on the one hand for the type column to
* determine the type name obtained from 'js/mappings.js' in interactive mode, on the other hand to render the
* value cell for a selection of supported formats, e.g., URL, data type, FDO, and JSON.
* @param {string} selection The selected object obtained from the table.
*/
function renderCell(selection) {
let value = selection._cell.value;
if (selection._cell.column.field == resolver.keyFieldName) {
if (dataTypes.has(value)) {
let obj = dataTypes.get(value);
return "<a href='https://hdl.handle.net/" + value + "?locatt=view:ui' target='_blank'><i class='" + obj.class + "'> </i>" + obj.name + "</a>";
}
} else if (selection._cell.column.field == resolver.valueFieldName) {
let type = selection._cell.row.cells[0].value;
if (dataTypes.has(type)) {
let obj = dataTypes.get(type);
return obj.renderer(type, value);
}
}
return value;
}
/**Add a child FDO. This function is called if the rendering function detects an FDO in one the the value fields of
* the PID record. In that case, a new FDO is added to the FDO graph and the graph gets updated.
* @param {string} fdoPid The PID of the newly detected FDO.
* @param {string} parentPid The PID of the parent FDO.
*/
function addChildFdo(type, fdoPid, profile, parentPid) {
addMessage(0, "Adding child FDO with pid " + fdoPid + " to parent " + parentPid);
let existing = data.nodes.find((entry) => entry.id == fdoPid);
let modified = false;
if (!existing) {
let node = {"id": fdoPid, "profile": profile};
data.nodes.push(node);
let typeName = (dataTypes.get(type)) ? dataTypes.get(type).name : type;
let link = {"source": parentPid, "target": fdoPid, "type": typeName, "value": 1};
data.links.push(link);
modified = true;
} else {
let existingConnection = data.links.find((entry) => (entry.source == parentPid && entry.target == fdoPid));
if (!existingConnection) {
let typeName = (dataTypes.get(type)) ? dataTypes.get(type).name : type;
let link = {"source": parentPid, "target": fdoPid, "type": typeName, "value": 1};
data.links.push(link);
modified = true;
}/*else{
let nextTypeName = (dataTypes.get(type))?dataTypes.get(type).name:type;
if(existingConnection.type.indexOf(nextTypeName) == -1) {
existingConnection.type = existingConnection.type + " | " + nextTypeName;
modified = true;
}
}*/
}
if (!fdoHistory.includes(fdoPid)) {
fdoHistory.push(fdoPid);
localStorage.setItem("fdoHistory", JSON.stringify(fdoHistory));
}
if (modified) {
renderTree();
}
}
/**Callback for the input field triggered if the search is triggered. This function resets the current FDO graph
* and triggers the resolution of the FDO.
*/
function loadPid() {
pid = document.getElementById("pid_input").value;
$("#pidcom").attr("value", pid);
if (pid.startsWith("sandboxed")) {
resolver = new TPMLoader();
} else {
resolver = new HandleLoader();
}
plainTableColumns[0].field = resolver.keyFieldName;
plainTableColumns[1].field = resolver.valueFieldName;
interactiveTableColumns[0].field = resolver.keyFieldName;
interactiveTableColumns[1].field = resolver.valueFieldName;
let response = resolver.checkForFDO(pid);
let isFairDO = response.isFairDO;
let profilePid = response.profilePid;
if (!isFairDO) {
addMessage(1, "Provided PID " + pid + " is no FDO.");
//continue and try to deal with it somehow
// return;
}
addMessage(0, "Loading FDO from user-provided PID " + pid);
// let existing = data.nodes.find((entry) => entry.id == pid);
// if(!existing){
//reset data
data = {"nodes": [], "links": []};
let node = {"id": pid, "profile": profilePid};
data.nodes.push(node);
// }
//set renderers to trigger start rendering
setRenderType(1);
if (!fdoHistory.includes(pid)) {
fdoHistory.push(pid);
localStorage.setItem("fdoHistory", JSON.stringify(fdoHistory));
}
resolveFDO(pid);
}
/**Resolve a single FDO. This function sets the current PID to the provided value and triggers a replacement of the
* PID record table data.
*
* @param {string} fdo The PID of the FDO to resolve.
*/
function resolveFDO(fdo) {
addMessage(0, "Resolving new FDO with PID " + fdo);
pid = fdo;
resolver.configureTableForReload(table, fdo).then(function () {
renderTree();
createBadge(pid);
}).catch(function (error) {
addMessage(1, "Failed to load FDO record from http://localhost:8090/api/v1/pit/pid/" + fdo);
});
}
/**Plain render function basically returning the selection's value.
*
* @param {object} selection The selection obtained from the table.
*/
function renderValuePlain(selection) {
return selection._cell.value;
}
/**Tooltip function basically returning the selection's value.
*
* @param {object} event The tooltip event.
* @param {object} selection The selection obtained from the table.
*/
function createTooltip(event, selection) {
return selection._cell.value;
}
/**Switch between the table rendering modes, i.e., plain (0) and interactive (1).
*
* @param {number} type The new rendering mode, i.e., plain (0) and interactive (1).
*/
function setRenderType(type) {
if (type === 1) {
addMessage(0, "Setting rendering to <b>interactive</b> mode.");
$("#plainTypes").removeClass("positive");
$("#humanReadableTypes").addClass("positive");
table.setColumns(interactiveTableColumns);
} else {
addMessage(0, "Setting rendering to <b>plain</b> mode.");
$("#plainTypes").addClass("positive");
$("#humanReadableTypes").removeClass("positive");
table.setColumns(plainTableColumns);
}
}
function createFdoNodeName(d) {
let profileName = profiles.get(d.profile) ? profiles.get(d.profile).name : d.profile
return `PID: ${d.id}\nProfile: ${profileName}`;
}
/**Render the current FDO graph.*/
function renderTree() {
d3.select("svg").selectAll('*').remove();
//ForceGraph
ArcGraph(data, {
nodeId: d => d.id,
nodeGroup: d => d.profile,
nodeTitle: d => createFdoNodeName(d),
linkStrokeWidth: l => Math.sqrt(l.value),
width,
height: 600,
undefined
});
}
mainMethod(options);
/**Main method initially creating the table and the FDO graph.
*
* @param {object} options Options object for initializing the table.
*/
function mainMethod(options) {
if (localStorage.getItem("fdoHistory")) {
let historicalData = JSON.parse(localStorage.getItem("fdoHistory"));
for (let i = 0; i < historicalData.length; i++) {
fdoHistory.push(historicalData[i]);
}
addMessage(0, "Loaded " + fdoHistory.length + " PIDs from history.");
}
$("#pid_input").autocomplete({
source: fdoHistory
});
createDummyBadge();
renderTree();
table = new Tabulator("#fairdoscope", {
height: "80%", // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
ajaxResponse: function (url, params, response) {
return response[resolver.valuesFieldName];
},
layout: "fitDataFill", //fit columns to width of table (optional)
columns: interactiveTableColumns,
});
table.on("dataLoadError", function (error) {
addMessage(1, "Failed to load FDO from " + error.url + " (Status: " + error.status + ")");
});
table.on("tableBuilt", function (error) {
if (userProvidedPid) {
addMessage(0, "Loading PID " + userProvidedPid + " from query parameter.");
$("#pid_input").attr("value", userProvidedPid);
loadPid();
}
});
}
/**UUID creation helper for creating unique instances of Ace editor and message elements.*/
function create_UUID() {
let dt = new Date().getTime();
let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
let r = (dt + Math.random() * 16) % 16 | 0;
dt = Math.floor(dt / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}
function addMessage(type, message) {
let element = $("#messages");
let div = document.createElement('div');
let messageType = "positive";
let messageHeader = "Information";
switch (type) {
case 1: {
messageType = "negative";
messageHeader = "Error";
}
}
let uuid = create_UUID();
div.setAttribute("class", "ui " + messageType + " message");
div.setAttribute("id", uuid);
div.innerHTML =
"<i class='close icon' onclick='closeMessage(\"" + uuid + "\")'></i>" +
"<div class='header'>" +
messageHeader +
"</div>" +
"<p>" + message + "</p>";
element.prepend(div);
}
/**Callback for closing a single message.
* @param {string} id UUID of the message to close.
*/
function closeMessage(id) {
$("#" + id).remove();
}
/**Callback for message removal buttons.
* @param {integer} type Message type to remove (0=all, 1=information, 2=error)
*/
function removeMessages(type) {
switch (type) {
case 0:
$("#messages .message").remove();
return;
case 1:
$("#messages .positive").remove();
return;
case 2:
$("#messages .negative").remove();
return;
}
}
function clearHistory() {
localStorage.removeItem("fdoHistory");
addMessage(0, "History cleared.");
}
// Toggle children on click.
function click(d, e) {
resolveFDO(e.id);
}
</script>
</body>
</html>