-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
303 lines (250 loc) · 9.11 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>OpenActive Activity List ConceptCollection Editor</title>
<style>
body {
font-family: Helvetica;
}
html,
body {
height: 100%;
margin: 0px;
padding: 0px;
}
label {
font-weight: bold;
}
.explainer {
display: block;
width: 100%;
font-size: 0.8em;
color: gray;
padding: 3px 0px;
}
textarea {
margin: 0px;
width: 100%;
height: 100%;
}
.container {
display: flex;
height: 100%;
max-height: 100%;
margin: 0px;
padding: 0px;
}
.activity-list {
flex: 1;
padding: 1rem;
overflow-y: scroll;
}
.meta {
width: 100%;
}
#collection {
flex: 1;
border-width: 0px;
padding: 0px 1em;
}
.cascade-link {
font-size: 0.6em;
color: #0000AA;
padding-left: 3px;
display: inline-block;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/@openactive/skos/dist/skos.min.js" type="text/javascript"></script>
<script type="text/javascript">
function getIdentifier(id) {
return id.substring(id.indexOf('#') + 1);
}
function renderTree(concepts, level, parent) {
var output = [];
// Recursively .getNarrower() on concepts
concepts.forEach(function(concept) {
var label = concept.prefLabel;
var hidden = "";
// Include altLabels (e.g. Group Cycling) to make them visible to the user
if (concept.altLabel && concept.altLabel.length > 0) {
label = label + ' / ' + concept.altLabel.join(' / ')
}
// Include hiddenLabels (e.g. 5aside) as hidden so they will still match search terms
if (concept.hiddenLabel && concept.hiddenLabel.length > 0) {
hidden = concept.hiddenLabel.join(' / ')
}
var identifier = getIdentifier(concept.id);
// Use jQuery to escape all values when outputting HTML
var li = $("<li/>", {
"class": "dropdown-item " + identifier,
"data-value": concept.id,
"data-hidden": hidden,
"data-level": level,
text: label
});
var checkbox = $("<input/>", {
value: concept.id,
class: 'concept-check ' + identifier,
type: 'checkbox'
});
checkbox.prependTo(li);
checkbox.click(function() {
$('.concept-check.' + identifier).prop("checked", this.checked);
renderCollection();
});
$('#jsonId').change(renderCollection);
$('#prefLabel').change(renderCollection);
$('#definition').change(renderCollection);
var narrower = concept.getNarrower();
if (Array.isArray(narrower) && narrower.length > 0) {
var checkLink = $("<a/>", {
"class": "cascade-link",
"href": "#",
text: "[check]"
});
checkLink.appendTo(li);
checkLink.click(function() {
$('.dropdown-item.' + identifier + ' .concept-check:checkbox:not(:checked)').map(function() {
$(".concept-check." + getIdentifier($(this).val())).prop("checked", true);
})
renderCollection();
})
var uncheckLink = $("<a/>", {
"class": "cascade-link",
"href": "#",
text: "[uncheck]"
});
uncheckLink.appendTo(li);
uncheckLink.click(function() {
$('.dropdown-item.' + identifier + ' .concept-check:checkbox:checked').map(function() {
$(".concept-check." + getIdentifier($(this).val())).prop("checked", false);
})
$(".dropdown-item." + identifier + " .concept-check").prop("checked", false);
renderCollection();
})
var ul = $("<ul/>", {
"class": "dropdown-item"
});
renderTree(narrower, level + 1, ul);
ul.appendTo(li);
}
li.appendTo(parent);
});
}
function renderCollection() {
var collection = {
"@context": "https://openactive.io/",
"@type": "ConceptCollection",
"@id": $('#jsonId').val().trim(),
"prefLabel": $('#prefLabel').val().trim(),
"inScheme": "https://openactive.io/activity-list",
"license": "https://creativecommons.org/licenses/by/4.0/",
"definition": $('#definition').val().trim(),
"member": Array.from(new Set($('.concept-check:checkbox:checked').map(function() {
return $(this).val();
}).get())).sort()
};
$("#collection").val(JSON.stringify(collection, null, 2));
}
$(function() {
// Load the activity list
$.getJSON('https://openactive.io/activity-list/activity-list.jsonld', function(data) {
// Use SKOS.js to read the file (https://www.openactive.io/skos.js/)
var scheme = new skos.ConceptScheme(data);
renderTree(scheme.getTopConcepts(), 1, $('#activity-list-dropdown'));
var url = window.location.hash.substring(window.location.hash.indexOf('=') + 1);
if (url) {
$.getJSON(url, function(data) {
$("#collection").val(JSON.stringify(data, null, 2));
processFile();
}).fail(function() {
alert( "Error loading url: " + url );
});
}
});
$('#download').click(function() {
var id = $('#jsonId').val();
var filename = id.substring(id.lastIndexOf('/') + 1) || "collection.json";
download(filename, $("#collection").val());
});
$('#collection').on('input', function() {
processFile();
});
});
function processFile() {
try {
var collection = JSON.parse($("#collection").val());
$('.concept-check').prop("checked", false);
if (Array.isArray(collection.member)) {
collection.member.forEach(function(id) {
var identifier = id.substring(id.indexOf('#') + 1);
$('.concept-check.' + identifier).prop("checked", true);
});
}
$('#jsonId').val(collection['@id'] || collection['id']);
$('#prefLabel').val(collection['prefLabel']);
$('#definition').val(collection['definition']);
} catch (err) {
alert(err);
}
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:application/json;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function openFile(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function() {
var text = reader.result;
$("#collection").val(text);
processFile();
};
reader.readAsText(input.files[0]);
};
</script>
</head>
<body>
<div class="container">
<div class="activity-list">
<h1>OpenActive Activity List ConceptCollection Editor</h1>
<p>
Edit the ConceptCollection below, or paste in an existing ConceptCollection on the right hand side. Alternatively load a file using the "Choose file" button below.
</p>
<p>
<input type='file' onchange='openFile(event)'>
</p>
<p>When you've finished, make sure you save your changes using the "Download" button.
</p>
<p>
<button type="button" id="download">Download</button>
</p>
<p>
<label for="jsonId">@id</label>
<span class="explainer">The live URL where this ConceptCollection is located, e.g. <code>https://sportengland-jointhemovement.github.io/collections/boxing-fitness.jsonld</code></span>
<input class="meta" id="jsonId">
</p>
<p>
<label for="prefLabel">prefLabel</label>
<span class="explainer">The name of this ConceptCollection, e.g. <code>Boxing Fitness</code></span>
<input class="meta" id="prefLabel">
</p>
<p>
<label for="definition">definition</label>
<span class="explainer">The documented purpose of this ConceptCollection, e.g. <code>Activity types that fit under the 'Boxing Fitness' drop down filter on the Join the Movement virtual timetable.</code></span>
<input class="meta" id="definition">
</p>
<ul id="activity-list-dropdown">
</ul>
</div>
<textarea id="collection"></textarea>
</div>
</body>
</html>