forked from kit-data-manager/frontend-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdo-creator-ui.html
820 lines (714 loc) · 31.3 KB
/
fdo-creator-ui.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Typed PID Maker UI</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@kit-data-manager/metadata-editor@0.9.3/deps/opt/popper/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@kit-data-manager/metadata-editor/deps/underscore/underscore-umd-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"
integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="js/semantic-ui/semantic.min.js"/>
<script src="js/ajv/ajv.min.js"></script>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@kit-data-manager/metadata-editor@0.9.3/deps/opt/fontawesome/css/all.min.css">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@kit-data-manager/metadata-editor@0.9.3/deps/opt/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="./css/semantic.min.css">
<script src="./js/apply-config.js"></script>
<!--script type='module' src='https://unpkg.com/@kit-data-manager/pid-component@0.0.4'></script-->
<script src="./js/editor/dependencies/jsonform/jsonform.js"></script>
<script src="./js/editor/lib/js/metadataeditor.js"></script>
<script src="./definitions/fdo-maker/hkip.js"></script>
<script src="./js/FDO.js"></script>
<script src="./js/FDOStore.js"></script>
<script src="./definitions/fdo-maker/recordUIDefinitionCreate.js"></script>
<script src="https://cdn.jsdelivr.net/npm/d3@7.6.1/dist/d3.min.js"></script>
<link rel="stylesheet" href="./css/styles.css"/>
<style>
svg {
flex-basis: 100%;
min-width: 200px;
}
.nodes circle {
pointer-events: all;
}
.modal {
height: auto;
}
.marker path {
stroke: #666;
fill: #EEE;
pointer-events: all;
}
.marker text {
stoke: #666;
font-weight: lighter;
}
.highlight {
font-weight: bold;
}
input.firstSelection + label {
color: darkgreen !important;
}
input.secondSelection + label {
color: darkred !important;
}
circle.selected {
stroke: black;
stroke-width: 1px;
}
circle.unselected {
opacity: .2;
}
line.unselected {
opacity: 0;
}
text.unselected {
opacity: 0;
}
#fdo_list {
white-space: nowrap;
}
.link {
font-size: 8px;
}
.link .highlight {
font-weight: bold;
}
#fdo_input {
width: 100%;
height: 256px;
}
.solid {
stroke: solid;
}
.dashed {
stroke-dasharray: 5, 5;
}
</style>
</head>
<body class="ui">
<h1 class="ui block header">
<img id="app-logo" src="./images/typed-pid-maker-logo.svg" class="ui image">
<div id="app-title" class="content">
{app-title}
<div id="app-subtitle" class="sub header">{app-subtitle}</div>
</div>
<div id="login_button" class="ui animated right floated button" tabindex="0">
<div id="login_button_text" class="visible content">Login</div>
<div class="hidden content">
<i id="login_icon" class="sign-in icon"></i>
</div>
</div>
</h1>
<div class="ui container">
<div id="service-url-input" class="sixteen wide column">
<div class="two wide column">
<div class="ui label">
Typed PID Maker URL
</div>
</div>
<div class="fourteen wide column">
<div class="ui fluid icon input">
<input id="endpoint" type="text" placeholder="http://localhost:8090/" value="http://localhost:8090/">
<button class="ui vertical animated button" tabindex="0" onclick="setUrl()">
<div class="hidden content">Reload</div>
<div class="visible content">
<i class="fa-solid fa-arrows-rotate"></i>
</div>
</button>
<script>
function setUrl() {
let url = document.getElementById("endpoint").value;
document.getElementById("known-pids").setAttribute("base-url", url);
}
</script>
</div>
</div>
</div>
<div class="ui top attached tabular menu">
<div class="active item" data-tab="one">Create new FDO</div>
<div class="item" data-tab="two">Add existing FDO(s)</div>
</div>
<div class="ui bottom attached active tab segment" data-tab="one">
<div class="ui segment">
<form id="record-form"></form>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="two">
<div class="ui icon message">
<i class="info icon"></i>
<div class="content">
<p>Adding existing FDOs allows you to use previously created objects to build up relationships between
FDOs. While it is possible to also add externally created FDOs,
only FDOs created by the configured Typed PID Maker instance are fully supported, i.e., can also be
updated by receiving new relational connections, while externally
created FDOs can only be providers of relational connections as they can only be updated by their
respective owner.</p>
<p>To add existing FDOs, provide one or more lines in the textarea below in the following format: <code>$PID[,$CUSTOM_NAME]</code>
</p>
</div>
</div>
<div class="ui grid">
<div class="ten wide column">
<div class="ui icon input" style="width:100%">
<textarea id="fdo_input" placeholder="Add one or more PIDs to load existing FDOs."></textarea>
<i class="asterisk icon"></i>
</div>
</div>
<div class="six wide column">
<div class="mini ui labeled icon button" id="add_fdo_by_pid_button">
<i class="linkify icon"></i>
Add FDOs
</div>
<br/>
</div>
</div>
</div>
<div class="ui grid">
<div class="ten wide column">
<div class="ui segment">
<svg id="tree" style="height:500px;width:100%"/>
</div>
</div>
<div class="six wide column" style="min-height:520px;max-height:520px">
<div class="ui top attached menu">
<a class="item actions">
<i class="sidebar icon"></i>
Show Actions
</a>
</div>
<div class="ui bottom attached segment pushable">
<div class="ui flyout left" tabindex="-1">
<i class="close icon"></i>
<div class="ui header">
<i class="cogs icon"></i>
<div class="content">
Actions
</div>
</div>
<div class="content">
<div class="mini ui labeled icon fluid button disabled" id="create_fdo_relation_button"
data-variation="mini">
<i class="linkify icon"></i>
Link
</div>
<div class="mini ui labeled icon fluid button disabled" id="remove_fdo_relation_button">
<i class="unlink icon"></i>
Unlink
</div>
<div class="mini ui labeled icon fluid button" id="clear_cache_button">
<i class="eraser icon"></i>
Clear Cache
</div>
<div class="mini ui labeled icon fluid button disabled" id="delete_fdo_button">
<i class="eraser icon"></i>
Remove
</div>
</div>
</div>
<div class="pusher">
<div class="ui basic segment">
<div class="ui scrolling segment" style="min-height:450px;max-height:450px">
<div id="fdo_list" class="ui celled list">
</div>
</div>
</div>
</div>
<!--div class="mini ui labeled icon button disabled" id="create_fdo_relation_button" tooltip="TEST" data-variation="mini">
<i class="linkify icon"></i>
Link
</div>
<div class="mini ui labeled icon button disabled" id="remove_fdo_relation_button">
<i class="unlink icon"></i>
Unlink
</div>
<div class="mini ui labeled icon button" id="clear_cache_button">
<i class="eraser icon"></i>
Clear Cache
</div>
<div class="mini ui labeled icon button" id="remove_fdo">
<i class="eraser icon"></i>
Remove
</div>
<div id="fdo_list" class="ui celled list">
</div-->
</div>
</div>
<div class="ui tiny modal" id="link_modal">
<div class="header">Select Relation Type</div>
<div class="content">
<div class="ui label" style="width:100%" id="link_source_label">
<i class="sign out alternate icon"></i>Source:
</div>
<br/>
<select id="relation_type" class="ui dropdown" style="width:100%">
<option value="21.T11148/4fe7cde52629b61e3b82">isMetadataFor</option>
<option value="21.T11148/d0773859091aeb451528">hasMetadata</option>
<option value="21.T11148/c6e4c19f294ee6f41b1e">wasDerivedFrom</option>
<option value="21.T11148/2a1cad55473b20407c78">wasRevisionOf</option>
<option value="21.T11148/a753134738da82809fc1">hadPrimarySource</option>
<option value="21.T11148/beaeecebec408908de35">wasQuotedFrom</option>
<option value="21.T11148/432132bdbd946b2baf2b">alternateOf</option>
<option value="21.T11148/ab53242825e85a0a7f76">specializationOf</option>
<option value="21.T11148/c085f1292d7d4a338d96">wasGeneratedBy</option>
<option value="21.T11148/af11e18f83466642c47d">provenanceGraph</option>
</select>
<br/>
<div class="ui label" style="width:100%" id="link_target_label">
<i class="sign in alternate icon"></i>Target:
</div>
</div>
<div class="actions">
<div class="ui negative button">Cancel</div>
<div class="ui positive button" id="confirm_create_fdo_relation_button">OK</div>
</div>
</div>
<div class="ui tiny modal" id="unlink_modal">
<div class="header">Remove Links</div>
<div class="content">
<p>Do you really want to remove the selected links?</p>
</div>
<div class="actions">
<div class="ui negative button">Cancel</div>
<div class="ui positive button" id="confirm_remove_fdo_relation_button">OK</div>
</div>
</div>
<div class="ui tiny modal" id="clear_cache_modal">
<div class="header">Clear FDO Cache</div>
<div class="content">
<p>Do you really want to remove all FDOs and their links?</p>
</div>
<div class="actions">
<div class="ui negative button">Cancel</div>
<div class="ui positive button" id="confirm_clear_cache_button">OK</div>
</div>
</div>
<div class="ui tiny modal" id="remove_fdo_modal">
<div class="header">Remove FDO(s)</div>
<div class="content">
<p>Do you really want to remove the selected FDO(s)?</p>
</div>
<div class="actions">
<div class="ui negative button">Cancel</div>
<div class="ui positive button" id="confirm_delete_fdo_button">OK</div>
</div>
</div>
</div>
<script>
$('.menu .item').tab();
$('.ui.flyout')
.flyout({
context: $('.bottom.segment')
}).flyout('attach events', '.menu .actions');
</script>
</div>
<script type="module">
import {ajaxBaseUrl, keycloak, tags, showServiceUrl, appDescription} from './js/fdo-maker.settings.js';
import {resolveType, createFdo, readFdo, updateFdo, config} from './js/typed-pid-maker-utils.js'
import {known_types} from './definitions/fdo-maker/known-types.js';
import {chart, render, selectNodes} from './js/fdo-graph.js';
applyConfig(ajaxBaseUrl, keycloak, tags, showServiceUrl, appDescription)
$('#service-url-input').val(ajaxBaseUrl);
config.ajaxBaseUrl = ajaxBaseUrl;
let firstSelection = undefined;
let secondSelection = undefined;
//initialize FDO store and load from local storage
let fdoStore = new FDOStore(resolveType);
//install event handler for all buttons
installEventHandlers();
//initialize JSON form
loadForm();
//initialize graph
chart(fdoStore);
//build initial FDO list
buildFdoList();
//initially render graph
render();
//helper code for obtaining license information
/* new Promise(function (resolve, reject) {
$.ajax({
type: "GET",
url: "https://raw.githubusercontent.com/spdx/license-list-data/main/json/licenses.json",
cache: true,
success: function (result) {
let licenses = JSON.parse(result);
let titleMap = {};
let en = [];
for (let i = 0; i < licenses.licenses.length; i++) {
if (licenses.licenses[i].isOsiApproved || licenses.licenses[i].isFsfLibre) {
let name = licenses.licenses[i].name;
let url = licenses.licenses[i].reference;
titleMap[url] = name;
en.push(url);
}
}
console.log(titleMap);
console.log(en);
resolve(result);
},
error: function (result) {
let message = "Failed read type information. (HTTP " + result.status + ")";
reject(message);
}
});
});*/
/**Install event handler for buttons and fdo list.
*/
function installEventHandlers() {
$("#create_fdo_relation_button").click(() => {
createFDORelation(true);
});
$("#confirm_create_fdo_relation_button").click(() => {
createFDORelation();
});
$("#remove_fdo_relation_button").click(() => {
deleteFDORelation(true);
});
$("#confirm_remove_fdo_relation_button").click(() => {
deleteFDORelation();
});
$("#clear_cache_button").click(() => {
$('#clear_cache_modal').modal('show');
});
$("#confirm_clear_cache_button").click(() => {
fdoStore.reset();
buildFdoList();
render();
});
$("#delete_fdo_button").click(() => {
$('#remove_fdo_modal').modal('show');
});
$("#confirm_delete_fdo_button").click(() => {
deleteFDO();
});
$("#add_fdo_by_pid_button").click(() => {
let separateLines = $("#fdo_input").val().split(/\r?\n|\r|\n/g);
for (let i = 0; i < separateLines.length; i++) {
let pidName = separateLines[i].split(/,/g);
//TODO: check pidName[1] via RegEx?
let fdo = new FDO(pidName[1].trim(), pidName[0].trim());
readFdo(fdo.getPid()).then((success) => {
fdo.fromTypedPidMaker(success);
fdoStore.addFdo(fdo);
buildFdoList();
render();
}).catch((error) => {
console.error(error);
});
}
});
$("#fdo_list").on('mouseover', 'input[inputType=link]', (e) => {
highlightLink(e.target.getAttribute("linksource"), e.target.getAttribute("linktarget"));
});
$("#fdo_list").on('mouseleave', 'input[inputType=link]', (e) => {
unhighlight(e.target.getAttribute("linksource"), e.target.getAttribute("linktarget"));
});
$("#fdo_list").on('mouseover', 'input[inputType=fdo]', (e) => {
highlightFdo(e.target.getAttribute("name"));
});
$("#fdo_list").on('mouseleave', 'input[inputType=fdo]', (e) => {
unhighlight(e.target.getAttribute("name"));
});
$("#fdo_list").on('change', 'input', (e) => {
if (e.target.getAttribute("inputtype") === "fdo") {
valueChangeFDO();
} else if (e.target.getAttribute("inputtype") === "link") {
valueChangeLink();
}
});
}
/**Event handler for creating links between FDOs.
* The function checks if a link between the selected FDOs already exists. If so, an error is shown.
* Otherwise, the modal dialog is opened if dialog is TRUE. Otherwise, the link is created.
* @param dialog If set, the creation dialog is shown, otherwise, the link is created.
*/
function createFDORelation(dialog = false) {
if (dialog) {
//check if FDOs are already connected
let existingLinks = fdoStore.getLinkedFDOs(firstSelection);
let existing = existingLinks.find((element) => element.pid === secondSelection);
if (existing) {
$("#create_fdo_relation_button").attr("data-content", "The selected FDOs are already connected as " + existing.relationType);
$("#create_fdo_relation_button").attr("data-variation", "red");
$('#create_fdo_relation_button').popup({
on: 'mouseover',
variation: 'mini',
boundary: $('body')
}).popup("toggle");
$("#create_fdo_relation_button").removeAttr("data-variation");
return;
}
//FDOs not connected, continue with dialog
let nameSource = fdoStore.getFdo(firstSelection).customName;
let nameTarget = fdoStore.getFdo(secondSelection).customName;
$("#link_source_label").html("<i class=\"sign out alternate icon\"></i> Source: " + nameSource ? nameSource : firstSelection);
$("#link_target_label").html("<i class=\"sign in alternate icon\"></i> Target: " + nameTarget ? nameTarget : secondSelection);
$('#link_modal').modal('show')
} else {
let type = $("#relation_type").val();
let sourceId = $(".firstSelection").attr("name");
let targetId = $(".secondSelection").attr("name");
let sourceFdo = fdoStore.getFdo(sourceId);
sourceFdo.addProperty(type, targetId);
updateFdo(sourceFdo).then((result) => {
fdoStore.addFdo(sourceFdo);
buildFdoList();
valueChangeFDO();
render();
$.toast({
message: 'FDO ' + sourceId + ' successfully updated.'
});
}).catch((error) => {
console.error(error);
$.toast({
message: 'Failed to update FDO (' + error + ")"
});
});
}
}
/**Remove selected FDO links.
* @param confirm If set, a confirmation dialog is shown. Otherwise, the selected links are removed.
*/
function deleteFDORelation(confirm = false) {
if (confirm) {
$('#unlink_modal').modal('show');
} else {
$("#fdo_list").find('input[inputType="link"]:checked').each(function () {
let source = $(this).attr("linksource");
let target = $(this).attr("linktarget");
fdoStore.unlinkFdo(source, target);
let fdo = fdoStore.getFdo(source);
updateFdo(fdo).then((result) => {
buildFdoList();
render();
$.toast({
message: 'Relation between ' + source + ' and ' + target + ' successfully removed.'
});
}).catch((error) => {
$.toast({
message: 'Failed to remove relation (' + error + ')'
});
})
});
}
}
/**Create the list of FDOs.
* The function iterated through all PIDs obtained from the FDOStore and adds entries to the FDO list.
* Furthermore, for each entry it will be checked, if another known FDO is in one of the PID record's attributes values.
* If so, a new link entry is added to the list below its parent FDO.
*/
function buildFdoList() {
let element = $("#fdo_list");
element.empty();
let pids = fdoStore.getPids();
for (let pid of pids) {
let fdo = fdoStore.getFdo(pid);
let name = fdo.getCustomName();
name = name ? name : pid;
let div = document.createElement('div');
div.setAttribute("class", "item");
div.innerHTML = "<div class='ui checkbox'>\n" +
"<input type='checkbox' name=" + pid + " inputType='fdo'>\n" +
"<label name='" + pid + "' labelType='fdo'>" + name + "</label>\n" +
"</div>\n";
//obtain all linked FDOs and add according entries
let linkedFdos = fdoStore.getLinkedFDOs(pid);
if (linkedFdos.length > 0) {
let listDiv = document.createElement('div');
listDiv.setAttribute("class", "list");
for (let i = 0; i < linkedFdos.length; i++) {
let div = document.createElement('div');
div.setAttribute("class", "item");
let name = fdoStore.getFdo(linkedFdos[i].pid).getCustomName();
name = name ? name : linkedFdos[i].pid;
div.innerHTML = "<div class='ui checkbox link'>\n" +
"<input type='checkbox' linkTarget=" + linkedFdos[i].pid + " linkSource='" + pid + "' inputType='link'>\n" +
"<label linkSource=" + pid + " linkTarget=" + linkedFdos[i].pid + " labelType='link'>" + resolveType(linkedFdos[i].relationType) + " \'" + name + "\'</label>\n" +
"</div>\n";
listDiv.append(div);
}
div.append(listDiv);
}
element.append(div);
}
}
/**Event handler for a changed value of an FDO selection.
* This function will handle persistence of selection, style changing, and validation of selection.
*/
function valueChangeFDO() {
//remove all selection markers
$("#fdo_list").find('input[inputType="fdo"]').each(function () {
$(this).removeClass("firstSelection");
$(this).removeClass("secondSelection");
});
//disable link selection for now, enable FDO selection, disable action buttons
$("input[inputType='link']").attr("disabled", true);
$("input[inputType='fdo']").attr("disabled", false);
$("#remove_fdo_relation_button").addClass("disabled");
$("#create_fdo_relation_button").addClass("disabled");
$("#delete_fdo_button").removeClass("disabled");
//get list of selected FDOs
let selectedFdos = $("#fdo_list").find('input[inputType="fdo"]:checked').length;
switch (selectedFdos) {
case 0: {
//do nothing, show no popup, allow select FDO and Link
$("input[inputType='link']").attr("disabled", false);
$("#create_fdo_relation_button").removeAttr("data-content");
$("#create_fdo_relation_button").addClass("disabled");
$("#delete_fdo_button").addClass("disabled");
break;
}
case 1: {
//set first selection, show message asking for second selection
$("#fdo_list").find('input[inputType="fdo"]:checked').each(function () {
$(this).addClass("firstSelection");
firstSelection = $(this).attr("name");
});
$("#create_fdo_relation_button").attr("data-content", "Please select another FDO to link to.");
break;
}
case 2: {
//set second selection, enable link button, remove message
$("#fdo_list").find('input[inputType="fdo"]:checked').each(function () {
if ($(this).attr("name") === firstSelection) {
//mark first selection
$(this).addClass("firstSelection");
} else {
//mark second selection
secondSelection = $(this).attr("name");
$(this).addClass("secondSelection");
}
$("#create_fdo_relation_button").removeClass("disabled");
$("#create_fdo_relation_button").removeAttr("data-content");
});
break;
}
default: {
//set message to allow only two selections
$("#create_fdo_relation_button").attr("data-content", "Only two selected FDOs are allowed.");
}
}
let selectedNodes = [];
$("#fdo_list").find('input[inputType="fdo"]:checked').each(function () {
selectedNodes.push($(this).attr("name"));
});
selectNodes(selectedNodes);
//show popup (only happens in case a message is set)
$('#create_fdo_relation_button').popup({
on: 'mouseover',
variation: 'mini',
boundary: $('body')
}).popup("toggle");
}
/**Event handler for a changed value of a link selection.
* This function will handle enable/disable of buttons and checkboxes depending on the selection.
*/
function valueChangeLink() {
$("input[inputType='link']").attr("disabled", false);
$("#create_fdo_relation_button").addClass("disabled");
if ($("#fdo_list").find('input[inputType="link"]:checked').length > 0) {
//at least one link is selected
$("input[inputType='fdo']").attr("disabled", true);
$("#remove_fdo_relation_button").removeClass("disabled");
} else {
$("input[inputType='fdo']").attr("disabled", false);
$("#remove_fdo_relation_button").addClass("disabled");
}
}
/**Highlight the link between source and target PID as well as the source FDO.
* @param source The PID of the link source.
* @param target The PID of the link target.
*/
function highlightLink(source, target) {
$("label[name=\'" + source + "\'][labelType='fdo']").addClass("highlight");
$("label[name=\'" + target + "\'][labelType='fdo']").addClass("highlight");
$("label[linksource=\'" + source + "\'][linktarget=\'" + target + "\']").addClass("highlight");
let selection = [];
selection.push(source);
selection.push(target);
$("#fdo_list").find('input[inputType="fdo"]:checked').each(function () {
selection.push($(this).attr("name"));
});
selectNodes(selection);
}
function deleteFDO(){
$("#fdo_list").find('input[inputType="fdo"]:checked').each(function () {
fdoStore.removeFdo($(this).attr("name"))
});
buildFdoList();
valueChangeFDO();
render();
$.toast({
message: 'Selected FDOs successfully removed from local cache.'
});
}
/**Highlight the FDO with the given PID in the fdoList.
* @param pid The PID of the FDO to highlight.
*/
function highlightFdo(pid) {
let selection = [];
if (pid) {
$("label[name=\'" + pid + "\']").addClass("highlight");
selection.push(pid);
}
$("#fdo_list").find('input[inputType="fdo"]:checked').each(function () {
selection.push($(this).attr("name"));
});
selectNodes(selection);
}
/**Unhighlight a label with a certain PID, i.e., an FDO or link label.
* @param pid The PID to unhighlight.
*/
function unhighlight(source, target = undefined) {
//unhighlight labels
$("label[name=\'" + source + "\'][labelType='fdo']").removeClass("highlight");
$("label[linksource=\'" + source + "\']").removeClass("highlight");
if (target) {
$("label[name=\'" + target + "\'][labelType='fdo']").removeClass("highlight");
}
//update selection to highlight only selected elements in graph
let selection = [];
$("#fdo_list").find('input[inputType="fdo"]:checked').each(function () {
selection.push($(this).attr("name"));
});
selectNodes(selection);
}
/**Load the PID Record form.
*/
function loadForm() {
//set type names selection
model['properties']['digitalObjectType'].enum = known_types.map(a => a.label);
//create form (mapping service map go here later)
let options = {
operation: "CREATE",
dataModel: model,
uiForm: uiDefinitionCreate,
//resource: rowColumnvalue
};
$('#record-form').empty();
$('#record-form').metadataeditorForm(options, function onSubmitValid(output) {
let f = new FDO().fromJson(output, known_types);
createFdo(f).then((success) => {
let pid = success.pid;
f.setPid(pid);
fdoStore.addFdo(f);
buildFdoList();
render();
$.toast({
message: 'FDO with PID ' + pid + ' successfully created.'
});
}).catch((error) => {
$.toast({
message: 'Failed to create FDO (' + error + ')'
});
});
});
}
</script>
</body>
</html>