-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.js
813 lines (737 loc) · 24.6 KB
/
main.js
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
console.log('working');
$(document).ready(function() {
'use strict';
// Don't submit the form when someone hits "enter".
$('form').keypress(function(e) {
// Enter key is 13.
if (e.which == 13) {
return false;
}
});
// Visibility toggle for headers and footers.
$('.headfoot').on('change', function() {
$(this)
.siblings('div:first-of-type')
.slideToggle();
});
// About box slide
$('#showabout').on('click tap', function() {
if ($(this).attr('aria-expanded') === 'false') {
$(this).attr('aria-expanded', 'true');
$(this).text('Righty-o.');
$('#abouttext').attr('aria-hidden', 'false');
$('#abouttext').show();
} else {
$(this).attr('aria-expanded', 'false');
$('#abouttext').attr('aria-hidden', 'true');
$('#abouttext').hide();
$(this).text("Wot's this then?");
}
});
// When the page loads, or when anything changes,
// build the template by which we make the tarball.
constructCourseTemplate();
$('input').on('change', function(e) {
// console.log(e);
console.log(constructCourseTemplate());
});
// Interface niceness for greyed-out options
$('input[name="corecontent"]').on('change', function() {
let whichoption = $('input[name="corecontent"]:checked').val();
$('#numprob').addClass('disabled');
$('#whatcustom').addClass('disabled');
if (whichoption === 'special') {
$('#whatcustom').removeClass('disabled');
} else if (whichoption === 'problem') {
$('#numprob').removeClass('disabled');
}
});
$('#whatcustom').on('focus', function() {
$('#usespec').click();
});
$('#numprob').on('focus', function() {
$('#useprob').click();
});
// Copying terms for s, ss, u across the page
['section', 'subsection', 'unit'].forEach(function(t) {
$('#' + t + 'name').on('input', function() {
$('.' + t + 'text').text(
$(this)
.val()
.toLowerCase()
);
});
});
// Update the output filename when the number, run, or user changes
$('#coursenum,#courserun').on('input', function(e) {
$('#filename').val($('#coursenum').val() + '_' + $('#courserun').val() + '.tar.gz');
});
// Dropdown for choosing use case: hx, blank course, or custom repo
$('#user').on('input', function(e) {
$('#courseorg').val('UniversityX');
$('#coursenum').val('UX101');
$('#sourcerepo').val('');
$('#sourcefile').val('');
if (e.target.value === 'blank') {
$('.custom_repo').hide();
} else if (e.target.value === 'harvardx') {
$('#courseorg').val('HarvardX');
$('#coursenum').val('HX101');
$('#sourcerepo').val('https://harvardx.github.io/edx_course_templater/');
$('#sourcefile').val('harvard_boilerplate_course.txt');
$('.custom_repo').hide();
} else if (e.target.value === 'custom') {
$('.custom_repo').show();
$('#sourcerepo').val('https://raw.githubusercontent.com/((Organization/Repo/master))');
$('#sourcefile').val('course_file.txt');
}
$('#name_and_number input').attr('disabled', false);
$('#filename').attr('disabled', false);
$('#filename').val($('#coursenum').val() + '_' + $('#courserun').val() + '.tar.gz');
});
});
// Makes the pair of files you need for HTML in edX.
// The "filename" here should have .xml at the end.
function makeHTMLFilePair(filename) {
return [{
path: 'html/' + filename,
text: '<html display_name="Text/HTML" filename="' +
filename.slice(0, -4) +
'" editor="raw" />'
},
{
path: 'html/' + filename.slice(0, -3) + 'html',
text: ''
}
];
}
// add content page tags
function makeContentPageTags(name, tag, num_elem) {
let temp = [];
let innards = '';
for (let n = 0; n < num_elem; n++) {
let filename = name + '_' + tag + '_' + (n + 1) + '.xml';
innards += '<' + tag + ' url_name="' + filename.slice(0, -4) + '" />\n';
if (tag === 'html') {
temp.push(...makeHTMLFilePair(filename));
} else {
temp.push({
path: tag + '/' + filename,
text: '<' + tag + ' display_name="' + tag + '">\n</' + tag + '>'
});
}
}
return {
array: temp,
innards: innards
};
}
// Make the core of a subsection
function makeSequentialCore(
s,
ss,
num_pages,
coreTag,
num_core_components,
u_name
) {
let temp = [];
let innards = '';
let prob_on_every_page = $('#poep')[0].checked;
let disc_on_every_page = $('#doep')[0].checked;
let disc_has_intro = $('#dhti')[0].checked;
let vid_has_intro = $('#vhti')[0].checked;
for (let p = 0; p < num_pages; p++) {
let vertical_innards = '';
if (vid_has_intro) {
if (coreTag == 'video') {
let vhti_file =
's_' +
(s + 1) +
'_ss_' +
(ss + 1) +
'_p_' +
(p + 1) +
'_vidintro.xml';
vertical_innards +=
'<html url_name="' + vhti_file.slice(0, -4) + '" />\n';
temp.push(...makeHTMLFilePair(vhti_file));
}
}
// add content page tags
let c_name = 's_' + (s + 1) + '_ss_' + (ss + 1) + '_p_' + (p + 1);
let c_tags = makeContentPageTags(c_name, coreTag, num_core_components);
temp.push(...c_tags.array);
vertical_innards += c_tags.innards;
if (prob_on_every_page) {
let poep_file = c_name + '_problem_x.xml';
vertical_innards +=
'<problem url_name="' + poep_file.slice(0, -4) + '" />\n';
temp.push({
path: 'problem/' + poep_file,
text: '<problem display_name="Problem">\n</problem>'
});
}
if (disc_on_every_page) {
if (disc_has_intro) {
let dhti_file = c_name + '_discintro.xml';
vertical_innards +=
'<html url_name="' + dhti_file.slice(0, -4) + '" />\n';
temp.push(...makeHTMLFilePair(dhti_file));
}
let doep_file = c_name + '_problem_x.xml';
vertical_innards +=
'<discussion url_name="' +
doep_file.slice(0, -4) +
'" xblock-family="xblock.v1" discussion_category="Chapter ' +
(s + 1) +
'" />\n';
// no need to add to template, only declared inline.
}
// add vertical tag to template
let vert_file = c_name + '.xml';
temp.push({
path: 'vertical/' + vert_file,
text: '<vertical display_name="' +
u_name +
' ' +
(p + 1) +
'" >\n' +
vertical_innards +
'</vertical>'
});
innards += ' <vertical url_name="' + vert_file.slice(0, -4) + '" />\n';
}
return {
array: temp,
innards: innards
};
}
// This builds the user-defined part of the course, without the boilerplate.
function constructCourseTemplate() {
// The template is an array of objects that look like this:
// {
// 'path': 'path to final file',
// 'text': 'inner xml for file'
// }
let template = [];
let sections = $('#numsections').val();
let subsections = $('#numsubsections').val();
let pages = $('#numpages').val();
let s_name = $('#sectionname').val();
let ss_name = $('#subsectionname').val();
let u_name = $('#unitname').val();
// Core part of the page - is it a video page, a text page, etc.
let coreTag = $('input[name="corecontent"]:checked').val();
if (coreTag === 'special') {
coreTag = $('#whatcustom').val();
}
let num_core_components = 1;
if (coreTag === 'problem') {
num_core_components = Number($('#numprob').val());
}
let subsHaveHeaders = $('#headerpage')[0].checked;
let subsHaveFooters = $('#footerpage')[0].checked;
let sectsHaveHeaders = $('#headerss')[0].checked;
let sectsHaveFooters = $('#footerss')[0].checked;
let use_hxjs = $('#hxjs')[0].checked;
for (let s = 0; s < sections; s++) {
let chapter_innards = '';
if (sectsHaveHeaders) {
// Not currently making header/footer sections for headers/footers.
let head_pages = $('#numheadpages').val();
let s_head_tag = $('input[name="ssheaders"]:checked').val();
if (s_head_tag === 'special') {
s_head_tag = $('#whatcustom').val();
}
let num_head_components =
s_head_tag === 'problem' ? Number($('#numsshprob').val()) : 1;
let sect_head = makeSequentialCore(
s,
'intro',
head_pages,
s_head_tag,
num_head_components,
u_name
);
let sequential_innards = sect_head.innards;
template.push(...sect_head.array);
// add sequential tag to template
let seq_file = 's_' + (s + 1) + '_ss_head.xml';
template.push({
path: 'sequential/' + seq_file,
text: '<sequential display_name="Intro ' +
ss_name +
'">\n' +
sequential_innards +
'</sequential>'
});
chapter_innards +=
' <sequential url_name="' + seq_file.slice(0, -4) + '" />\n';
}
for (let ss = 0; ss < subsections; ss++) {
let sequential_innards = '';
// add tags for subsection header page
if (subsHaveHeaders) {
let head_tag = $('input[name="unitheaders"]:checked').val();
// console.log(head_tag);
if (head_tag === 'special') {
head_tag = $('#whatcustomhead').val();
}
let num_head_elements =
head_tag === 'problem' ? Number($('#numunithprob').val()) : 1;
let h_name = 's_' + (s + 1) + '_ss_' + (ss + 1) + '_p_head';
let h_tags = makeContentPageTags(h_name, head_tag, num_head_elements);
template.push(...h_tags.array);
template.push({
path: 'vertical/' + h_name + '.xml',
text: '<vertical display_name="' +
u_name +
' ' +
(ss + 1) +
' intro">\n' +
h_tags.innards +
'</vertical>'
});
sequential_innards += ' <vertical url_name="' + h_name + '" />\n';
}
// Build the core pages of the sequence.
let ss_core = makeSequentialCore(
s,
ss,
pages,
coreTag,
num_core_components,
u_name
);
sequential_innards += ss_core.innards;
template.push(...ss_core.array);
// add tags for subsection footer page
if (subsHaveFooters) {
let foot_tag = $('input[name="unitfooters"]:checked').val();
// console.log(foot_tag);
if (foot_tag === 'special') {
foot_tag = $('#whatcustomfoot').val();
}
let num_foot_elements =
foot_tag === 'problem' ? Number($('#numunitfprob').val()) : 1;
let f_name = 's_' + (s + 1) + '_ss_' + (ss + 1) + '_p_foot';
let f_tags = makeContentPageTags(f_name, foot_tag, num_foot_elements);
template.push(...f_tags.array);
template.push({
path: 'vertical/' + f_name + '.xml',
text: '<vertical display_name="' +
u_name +
' ' +
(ss + 1) +
' outro">\n' +
f_tags.innards +
'</vertical>'
});
sequential_innards += ' <vertical url_name="' + f_name + '" />\n';
}
// add sequential tag to template
let seq_file = 's_' + (s + 1) + '_ss_' + (ss + 1) + '.xml';
template.push({
path: 'sequential/' + seq_file,
text: '<sequential display_name="' +
ss_name +
' ' +
(ss + 1) +
'">\n' +
sequential_innards +
'</sequential>'
});
chapter_innards +=
' <sequential url_name="' + seq_file.slice(0, -4) + '" />\n';
}
if (sectsHaveFooters) {
// Not currently making header/footer sections for headers/footers.
// Not currently making header/footer sections for headers/footers.
let foot_pages = $('#numfootpages').val();
let s_foot_tag = $('input[name="ssfooters"]:checked').val();
if (s_foot_tag === 'special') {
s_foot_tag = $('#whatcustom').val();
}
let num_foot_components =
s_foot_tag === 'problem' ? Number($('#numssfprob').val()) : 1;
let sect_foot = makeSequentialCore(
s,
'outro',
foot_pages,
s_foot_tag,
num_foot_components,
u_name
);
let sequential_innards = sect_foot.innards;
template.push(...sect_foot.array);
// add sequential tag to template
let seq_file = 's_' + (s + 1) + '_ss_foot.xml';
template.push({
path: 'sequential/' + seq_file,
text: '<sequential display_name="Outro ' +
ss_name +
'">\n' +
sequential_innards +
'</sequential>'
});
chapter_innards +=
' <sequential url_name="' + seq_file.slice(0, -4) + '" />\n';
}
// add chapter tag to template
template.push({
path: 'chapter/s_' + (s + 1) + '.xml',
text: '<chapter display_name="' +
s_name +
' ' +
(s + 1) +
'">\n' +
chapter_innards +
'</chapter>'
});
}
// Syllabus and related are currently automatically included.
let policies = {
// 'syllabus': $('#syllabus')[0].checked,
// 'related': $('#related')[0].checked,
calendar: $('#calendar')[0].checked,
FAQ: $('#faq')[0].checked,
course_glossary: $('#glossary')[0].checked,
resources: $('#resources')[0].checked,
course_outline: $('#outline')[0].checked
};
Object.keys(policies).forEach(k => {
if (policies[k]) {
let n = k.split('_').slice(-1)[0]; // If it has course_ in front, take that out.
template.push({
path: 'tabs/' + k,
text: '<h3>' + n.charAt(0).toUpperCase() + n.slice(1) + ' placeholder</h3>'
});
}
});
// Add HX-JS to first HTML component on every page.
if (use_hxjs) {
let hxjscode =
'<script src="/static/hx.js" type="text/javascript"></script>\n' +
'<link rel="stylesheet" type="text/css" href="/static/hx.css">';
// Get the locations of all the first HTML elements
let all_verticals = template.filter(e => e.path.startsWith('vertical'));
let expanded_tags = all_verticals.map(v => v.text.split('\n'));
let first_html = expanded_tags.map(
t => t.filter(r => r.indexOf('html') > -1)[0]
);
let html_urls = first_html.reduce((result, e) => {
if (e) {
result.push($.parseXML(e).children[0].attributes.url_name.value);
}
return result;
}, []);
// console.log(html_urls);
// Add HX-JS to the start of each of them.
template.forEach(function(e) {
html_urls.forEach(function(h) {
if (e.path == 'html/' + h + '.html') {
e.text = hxjscode + e.text;
}
});
});
}
return {
template: template,
policies: policies
};
}
// Reads files from the boilerplate course and returns the raw text.
function readCourseFile(filepath, callback) {
console.log('reading file ' + filepath);
let rawFile = new XMLHttpRequest();
rawFile.overrideMimeType('text/plain');
rawFile.onreadystatechange = function() {
console.log(rawFile.readyState, rawFile.status);
if (rawFile.readyState === 4 && rawFile.status == '200') {
// console.log('file:');
console.log(rawFile.responseText);
callback(rawFile.responseText);
} else if (rawFile.readyState === 4 && rawFile.status != '200') {
// We didn't load the file. Use a blank course instead.
callback(false);
}
};
rawFile.open('GET', filepath, true);
rawFile.send(null);
}
// Returns raw, prettified text for revised policies/(run)/policy.json file.
async function makeNewCoursePolicy(
policies,
path,
run,
new_course_info,
callback
) {
// console.log(policies);
let policy_file = await readCourseFile(
path + 'policies/' + run + '/policy.json',
async function(j) {
if (!j) {
console.log('No policy file found.');
}
j = JSON.parse(j);
let cid = 'course/' + new_course_info.run;
// console.log(j);
// Duplicate the existing run info for the new run.
j[cid] = JSON.parse(JSON.stringify(j['course/' + run]));
// Set course name
j[cid].display_name = $('#coursename').val();
// Set up the tabs
Object.keys(policies).forEach(tab => {
if (policies[tab]) {
let n = tab.split('_').slice(-1)[0]; // Remove course_ from name.
j[cid].tabs.push({
course_staff_only: false,
name: n.charAt(0).toUpperCase() + n.slice(1),
type: 'static_tab',
url_slug: tab
});
}
});
// console.log(j);
callback(JSON.stringify(j, null, 2));
}
);
}
// Returns raw, prettified text for revised course/(run).xml file.
async function makeNewCourseXML(
template,
path,
run,
new_course_info,
callback
) {
// console.log(template);
let new_chapters = template.filter(function(row) {
return row.path.slice(0, 7) === 'chapter';
});
// console.log(new_chapters);
let course_xml = await readCourseFile(
path + 'course/' + run + '.xml',
async function(coursefile) {
if (!coursefile) {
console.log('No course_run.xml file found.');
}
let course = $(coursefile);
course.attr('display_name', new_course_info.name);
// Swap out the old wiki slug for a new one.
let new_slug =
new_course_info.org +
'.' +
new_course_info.number +
'.' +
new_course_info.run;
course.find('wiki').replaceWith('<wiki slug="' + new_slug + '"/>');
for (let i = 0; i < new_chapters.length; i++) {
// Cutting off chapter/ and .xml from paths.
let newtag = $(
'<chapter url_name="' + new_chapters[i].path.slice(8, -4) + '" />'
);
// Insert new chapters after the first chapter in the boilerplate.
let try_to_insert = course
.find('chapter:nth-child(' + (i + 1) + ')')
.after(newtag);
if (try_to_insert.length === 0) {
// Course isn't long enough; maybe it's blank? Insert row anywhere.
course.append(newtag);
}
}
// console.log(course);
callback({
new: vkbeautify.xml(course[0].outerHTML, 2),
old: coursefile
});
}
);
}
// Composits the template and boilerplate into a combined course.
async function makeTarFromFlatFile(
f,
path,
template,
policies,
run,
makeDownloadLink
) {
// Make an array from the flat file and throw out blank lines.
let textlines = f.split('\n').filter(l => l.trim().length > 0);
console.log('Making course tarball from...');
console.log(textlines);
let tar = new tarball.TarWriter();
let filecounter = 0;
let new_course_info = {
name: $('#coursename').val(),
run: $('#courserun').val(),
org: $('#courseorg').val(),
number: $('#coursenum').val()
};
// Are we done adding files?
function incrementAndCheckStatus(num_files) {
num_files += 1;
if (num_files == textlines.length) {
console.log('tar complete');
makeDownloadLink(tar);
} else {
return num_files;
}
}
// Make files for all the items in our template.
template.forEach(temp_row => {
tar.addTextFile(temp_row.path, temp_row.text);
});
// Now add in the boilerplate files.
textlines.forEach(async function(row) {
// console.log(row);
// Taking off the ./ from start of each. Artifact of using "find" command.
if (row.slice(0, 2) == './') {
row = row.slice(2);
}
// Ignore invisible files.
if (row[0] == '.') {
filecounter = incrementAndCheckStatus(filecounter);
} else {
// Add the files as you get them.
let thefile = await fetch(path + row)
.then(res => res.blob())
.then(blob => {
// console.log('blob obtained');
// console.log(blob);
let new_row = row.replace(run, new_course_info.run);
if (row.startsWith('course/')) {
let course = makeNewCourseXML(
template,
path,
run,
new_course_info,
function(course) {
// console.log('new course/(run).xml file')
// console.log(row);
// console.log(xml);
// Old course run keeps old XML.
tar.addTextFile(row, course.old);
tar.addTextFile(new_row, course.new);
filecounter = incrementAndCheckStatus(filecounter);
}
);
} else if (row.startsWith('course.xml')) {
// Write course file that points to new run.
tar.addTextFile(
'course.xml',
'<course url_name="' +
new_course_info.run +
'" org="' +
new_course_info.org +
'" course="' +
new_course_info.number +
'"/>'
);
filecounter = incrementAndCheckStatus(filecounter);
} else if (
row.startsWith('policies/' + run + '/grading_policy.json')
) {
// Copy old grading policy into both runs.
tar.addFile(row, blob);
tar.addFile(new_row, blob);
filecounter = incrementAndCheckStatus(filecounter);
} else if (row.startsWith('policies/' + run + '/policy.json')) {
let newJSON = makeNewCoursePolicy(
policies,
path,
run,
new_course_info,
function(j) {
// console.log('new policies/(run)/json.xml file')
// console.log(row);
// console.log(JSON.parse(j));
// Copy new policy.json into both runs.
tar.addTextFile(row, j);
tar.addTextFile(new_row, j);
filecounter = incrementAndCheckStatus(filecounter);
}
);
} else {
// Sweet functionality note: folders are added automatically
// because the row text has the folder name and a slash.
tar.addFile(row, blob);
filecounter = incrementAndCheckStatus(filecounter);
}
});
}
});
}
// This is our "main" that gets called by the submit button
async function makeDownload() {
// Insert placeholder text while we wait for things to tar up.
let target_location = $('#dlink');
let download_placeholder = $('<p>Creating tar file...</p>');
let filename = $('#filename').val();
target_location.append(download_placeholder);
// Get the parts of the template that aren't boilerplate.
let new_course = constructCourseTemplate();
let template = new_course.template;
let policies = new_course.policies;
// Path to the boilerplate parts of the template.
let boilerplate_structure_repo = $('#sourcerepo').val();
let boilerplate_structure_file =
boilerplate_structure_repo + $('#sourcefile').val();
if ($('#sourcefile').val() === '') {
boilerplate_structure_file =
boilerplate_structure_repo + 'blank_course.wtf';
}
let boilerplate_structure_path =
boilerplate_structure_file.slice(0, -4) + '/';
let course_tarball;
let course_run = await readCourseFile(
boilerplate_structure_path + 'course.xml',
async function(coursefile) {
if (!coursefile) {
console.log('No course.xml file found.');
}
let run = $(coursefile).attr('url_name');
// console.log(run);
// Get the flat file that describes the boilerplate course.
let boilerplate_flat = await readCourseFile(
boilerplate_structure_file,
async function(result) {
if (!result) {
console.log('No flat file found. Using default blank course.');
result =
'./course/2022.xml\n./about/overview.html\n./policies/2022/policy.json\n./policies/2022/grading_policy.json\n./policies/assets.json\n./info/updates.items.json\n./info/handouts.html\n./info/updates.html\n./course.xml\n./assets/assets.xml\n';
}
// console.log('course structure:');
// console.log(result);
// Take the tar and make a download link with it.
function makeDownloadLink(tar) {
let written = tar.write().then(tarblob => {
// console.log('tar written');
// console.log(tarblob);
// Remove the placeholder and put in the download link.
// The tar file is inserted as a Data URI.
let download_link = $('<a>Click to download archive</a>');
download_placeholder.remove();
download_link.attr('href', URL.createObjectURL(tarblob));
download_link.attr('download', filename);
target_location.append(download_link);
target_location[0].scrollIntoView();
});
}
// Construct a tarball from the flat file.
course_tarball = await makeTarFromFlatFile(
result,
boilerplate_structure_path,
template,
policies,
run,
makeDownloadLink
);
}
);
}
);
}