-
Notifications
You must be signed in to change notification settings - Fork 44
/
generator.html
326 lines (269 loc) · 11.7 KB
/
generator.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
<!DOCTYPE html>
<html lang="en">
<!--
Nick Evans / imin
imin.co | @nickevans / @_imin_
For openactive.io
Free for personal and commercial use under the CC-BY v4.0 license (https://creativecommons.org/licenses/by/4.0/)
-->
<head>
<title>Openactive Dataset Site Generator</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webshim/1.15.10/minified/polyfiller.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/pure-min.css">
<!--[if lte IE 8]>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/grids-responsive-old-ie-min.css">
<![endif]-->
<!--[if gt IE 8]><!-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/grids-responsive-min.css">
<!--<![endif]-->
<script src="generator/generator.js"></script>
<script type="text/javascript">
webshims.polyfill('forms es5');
var INPUTS = "#inputdata input, #inputdata select, #inputdata textarea";
/*
* Generate index.html
*/
function generateIntoTextbox(state) {
var template = $( "#template" ).val();
var output = generate(template, state);
$( "#output" ).val(output);
}
/*
* Replace empty metadata on first run
*/
function firstRun() {
if (!location.origin) location.origin = location.protocol + "//" + location.host;
if ($( "#dataset-site-url" ).val() == "") $( "#dataset-site-url" ).val(location.origin + "/");
if ($( "#attribution-url" ).val() == "") $( "#attribution-url" ).val(location.origin + "/");
}
/*
* Save state to metadata.json textarea
*/
function saveState() {
var state = {};
$( INPUTS ).each(function() {
var id = $( this ).attr('id');
var value;
if ($( this ).attr('type') == "checkbox") {
value = $( this ).prop( "checked" );
} else {
value = $( this ).val();
}
state[id] = value;
});
$( "#state" ).val(JSON.stringify(state, null, 2));
return state;
}
/*
* Load state from metadata.json textarea
*/
function loadState() {
var stateSerialised = $( "#state" ).val();
var state = null;
try {
state = JSON.parse(stateSerialised);
}
catch(err) {
alert("The file that was pasted in the 'metadata.json' box is not valid");
}
$.each( state, function( key, value ) {
$('#' + key).each(function () {
if ($( this ).attr('type') == "checkbox") {
$( this ).prop( "checked", value );
} else {
$( this ).val(value);
}
});
});
return state;
}
/*
* Load state from metadata.json textarea
*/
function loadFile(url, cb) {
$.get(url, function(data) {
cb(data);
}, "text").fail(function() {
alert("Error loading file: " + url);
//In the case of error, enable manual mode
setupForm();
showForm();
showTemplateManualEntry()
});
}
/*
* Extract code from mailchimp textbox
*/
function extractMailchimp() {
var textBox = $( "#mailchimp" );
var value = textBox.val();
if (value) {
var rx = /require.*}\) }\)/g;
var arr = rx.exec(value);
if (arr) {
value = arr[0];
textBox.val(value);
} else {
alert ("Invalid Mailchimp code, please ensure you are clicking 'View Code' in the Subscriber Popup feature within the 'Signup Forms' section of a List");
textBox.val("");
}
}
}
/*
* Extract code from mailchimp textbox
*/
function extractOdiCertificateNumber() {
var textBox = $( "#odi-certificate-number" );
var value = textBox.val();
if (value) {
var numrx = /^[0-9]*$/g;
var rx = /datasets\/([0-9]*)\/certificate/g;
var numarr = numrx.exec(value);
var arr = rx.exec(value);
if (numarr) {
//Already a number in the box, do nothing
} else if (arr && arr.length == 2) {
//Extract the number and put it in the box
value = arr[1];
textBox.val(value);
} else {
alert ("Invalid Open Data Certificate code, please ensure you are copying the Badge, Certificate, or URL from the 'Embed' button in your Certificate page");
textBox.val("");
}
}
}
/*
* Ensure dataset pages ends in a "/"
*/
function datasetBaseUrl() {
var textBox = $( "#dataset-site-url" );
var value = textBox.val();
if (value != "" && !value.endsWith("/")) {
textBox.val(value + "/");
}
}
/*
* Set up form and unhide it
*/
function setupForm() {
//Set up events
$( INPUTS ).blur(function () {
datasetBaseUrl();
extractMailchimp();
extractOdiCertificateNumber();
var state = saveState();
generateIntoTextbox(state);
});
$( "#state" ).blur(function () {
var state = loadState();
generateIntoTextbox(state);
});
}
function showForm() {
$( "#content" ).show();
$( "#loading" ).hide();
}
function showTemplateManualEntry() {
$( "#templateManual" ).show();
}
/*
* On Page Load
*/
$(function() {
//Load template first
loadFile("generator/template.html", function(data) {
$( "#template" ).val( data );
//When template has loaded, load state
loadFile("metadata.json", function(data) {
$( "#state" ).val( data );
loadState();
firstRun();
var state = saveState();
generateIntoTextbox(state);
setupForm();
showForm();
});
});
})
</script>
<style>
body { max-width: 700px; margin: 20px; }
label { padding-top: 20px; }
textarea {height: 200px;}
</style>
</head>
<body>
<h1><a href="https://www.openactive.io/"><img src="https://www.openactive.io/assets/openactive-logo-small.png" width="180" alt="" /></a> Dataset Site Generator</h1>
<div id="loading">Loading...</div>
<form id="content" style="display: none;" class="pure-form pure-form-stacked">
<fieldset id="inputdata">
<h2>Dataset Page Fields</h2>
<label for="dataset-site-url"><strong>Dataset Site URL</strong> (the GitHub pages site you are creating)</label>
<input class="pure-input-1" id="dataset-site-url" type="url" placeholder="https://britishcycling-oa.github.io/">
<label for="title"><strong>Title of Dataset</strong> (keep this as concise as possible)</label>
<input class="pure-input-1" id="title" placeholder="British Cycling Sky Ride Sessions">
<label for="description"><strong>Description</strong></label>
<input class="pure-input-1" id="description" placeholder="Session data from the goskyride.com site">
<label for="publisher-name"><strong>Publisher Name</strong> (usually your organisation's name)</label>
<input class="pure-input-1" id="publisher-name" placeholder="British Cycling">
<label for="publisher-url"><strong>Publisher URL</strong> (usually your organisation's website)</label>
<input class="pure-input-1" id="publisher-url" placeholder="https://www.britishcycling.org.uk" />
<label for="keyword-1"><strong>Keywords</strong> (to help people find your data)</label>
<input class="pure-input-1" id="keyword-1" placeholder="Cycling">
<input class="pure-input-1" id="keyword-2" placeholder="Sky Ride">
<label for="data-url"><strong>Openactive RPDE Data Feed URL</strong></label>
<input class="pure-input-1" id="data-url" type="url" placeholder="http://api.ridesociallondon.co.uk/api/EventFeed">
<label for="created"><strong>Date of Publishing</strong> (the date your Openactive RPDE Data Feed URL went live with the correct license, use today's date if you are creating the license today)</label>
<input class="pure-input-1" id="created" type="date" >
<label for="documentation-url"><strong>Documentation URL</strong> (e.g. GitHub repository, see <a href="https://github.com/openactive/dataset-site-generator/wiki/Creating-Dataset-Documentation">this guide</a> for more information)</label>
<input class="pure-input-1" id="documentation-url" type="url" placeholder="https://github.com/britishcycling-oa/opendata">
<label for="rpde-version"><strong>Openactive RPDE Version</strong> (the version of <a href="https://github.com/openactive/realtime-paged-data-exchange">Openactive RPDE</a> used by your developers).</label>
<input class="pure-input-1" id="rpde-version" placeholder="0.2.3">
<label for="license-name"><strong>License Name</strong> - recommended "Creative Commons Attribution Licence (CC-BY v4.0)"</label>
<input class="pure-input-1" id="license-name" placeholder="Creative Commons Attribution Licence (CC-BY v4.0)" value="Creative Commons Attribution Licence (CC-BY v4.0)">
<label for="license-url"><strong>License URL</strong> - recommended "https://creativecommons.org/licenses/by/4.0/"</label>
<input class="pure-input-1" id="license-url" placeholder="https://creativecommons.org/licenses/by/4.0/" value="https://creativecommons.org/licenses/by/4.0/">
<label for="attribution-text"><strong>Attribution Text</strong> (shown on apps and websites that use the data)</label>
<input class="pure-input-1" id="attribution-text" placeholder="British Cycling">
<label for="attribution-url"><strong>Attribution URL</strong> (linked from apps and websites that use the data)</label>
<input class="pure-input-1" id="attribution-url" type="url" placeholder="https://britishcycling-oa.github.io">
<label for="mailchimp"><strong>Mailchimp Code</strong> (see <a href="https://github.com/openactive/dataset-site-generator/wiki/Setting-up-Mailchimp">this guide</a>)</label>
<textarea class="pure-input-1" id="mailchimp"></textarea>
<label for="copyright-notice"><strong>Copyright HTML</strong> (required if your selected background image is not owned by you)</label>
<textarea class="pure-input-1" id="copyright-notice"></textarea>
<label for="odi-certificate-number"><strong>Open Data Certificate</strong> (see <a href="https://github.com/openactive/dataset-site-generator/wiki/Open-Data-Certificates">this guide</a>)</label>
<textarea class="pure-input-1" id="odi-certificate-number"></textarea>
<label for="publish" class="pure-checkbox">
<input id="publish" type="checkbox" value="publish">
<strong>Publish</strong> (to <a href="https://www.openactive.io/use-data.html">openactive.io</a>)
</label>
</fieldset>
<br />
<hr />
<br />
<fieldset>
<h2>Generated Files (to paste into GitHub)</h2>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2">
<label for="output"><strong>index.html</strong> - Generated Webpage Code</label>
<textarea class="pure-u-23-24" id="output"></textarea>
</div>
<div class="pure-u-1 pure-u-md-1-2">
<label for="state"><strong>metadata.json</strong> - Page Generator Metadata</label>
<textarea class="pure-u-23-24" id="state"></textarea>
</div>
</div>
</fieldset>
<fieldset id="templateManual" style="display: none;">
<br />
<hr />
<br />
<h2>Manual Entry</h2>
<div>When editing this form locally, the ajax fetch of the template will fail. Instead simply copy the contents of template.html into the box below, and the contents of metadata.json into the right-hand box above.</div>
<label for="template">Template HTML (paste <strong>template.html</strong> in here)</label>
<textarea class="pure-input-1" id="template"></textarea>
</fieldset>
</form>
</body>
</html>