Newer
Older
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
"use strict";
/**
* A MMT..whatever. Somewhere between the first and second "meta-" MMT had to leave common nomenclature behind
* @typedef {{kind : string, uri: string}} MMTReference
*/
/**
* Facts, as they are send by MMT. Not *quite* the same format as Unity uses \*sigh\*, and everything has shortened names to avoid five additional letters \*double sigh\*
* @typedef {Object} MMTFact
* @property {MMTReference} ref the reference MMT uses to identify this fact
* @property {string} label the human readable lable to display this fact.
* @property {?any} df the definition of the Fact. May be null for {@link MMTScroll.requiredFacts}
* @property {?MMTReference} tp the MMT type of this fact
* @property {string} kind since a Fact is a MMTThingy, they also have a {@link MMTReference.kind}
*/
/**
* A Slot is an interface that can stand in for either
* - a {@link Fact}, or
* - the {@link Backend_Object} used to define the {@link Scroll} (in the backend)
*
* depending on what is needed.
*
* If all Slots of a {@link Scroll} are assigned, it can compute its {@link Scroll.acquiredFacts}.
*/
class Slot {
/**
* @param default_label The default label of the Slot. Fallback if no Fact is assigned.
* @param uri The uri of the Slot
* @param type The expected type of the assigned Fact
* @param assignedFact The Fact assigned to this Slot (may not exist yet)
*/
constructor(default_label, uri, type, assignedFact) {
this.default_label = default_label;
this.uri = uri;
this.type = type;
this.assignedFact = assignedFact;
this.assignedFact = assignedFact;
}
/**
* The MathML element to display when this Slot is referenced.
*
* This is either the label of the {@link assignedFact}, or {@link default_label} if the former doesn't exist.
*/
get label() {
if (this.assignedFact) {
return this.assignedFact.label;
}
else {
return this.default_label;
}
}
}
/**
* A Scroll, as it is implemented in the backend.
*
* Can do fancy stuff elsewhere, here we only want display its {@link description} and (possibly) {@link depiction}.
* Both will reference the {@link slots}, and need dynamic adaption to the {@link Fact}s assigned to them.
* The {@link acquiredFacts} referenced do not change, but they are semantically important and deserve special treatment.
*/
class Scroll {
constructor(label, uri, slots, acquiredFacts, description, depiction) {
this.label = label;
this.uri = uri;
this.slots = slots;
this.acquiredFacts = acquiredFacts;
this.description = description;
this.depiction = depiction;
this.type = "Scroll";
}
/** TODO */
static fromString(scrollString) {
throw new Error("Not implemented.");
}
}
let currentScrollRef = ""; // ref of the scroll currently displayed
function RenderScroll() {
const dataSource = document.querySelector("#Unity-Data-Interface");
if (!(dataSource instanceof HTMLElement)
|| dataSource === null
|| dataSource.dataset.scrollDynamic === undefined) {
console.error("No Scroll found in the Unity-Data-Interface");
return;
}
const scroll = Scroll.fromString(dataSource.dataset.scrollDynamic);
//console.log(scroll.requiredFacts);
const scrollContainer = document.querySelector("#scrollContainer");
// replace the description if the scroll changed, otherwise only its content needs update
// if (scroll.ref != currentScrollRef) {
// currentScrollRef = scroll.ref;
// scrollContainer.innerHTML = scroll.description;
// }
// go through the facts in the scroll, show their labels, add dropzones and limit the allowed types
scroll.slots.forEach(slot => {
$(`[data-slot-id='${slot.uri}']`)
.html(slot.label)
.attr("dropzone", "copy");
});
// acquired facts only need updated labels
scroll.acquiredFacts.forEach(fact => {
$(`[data-solution-id='${fact.uri}']`)
.html(fact.label);
});
console.log(scroll.label + 'Scroll rendered');
}
$(function () {
RenderScroll();
});