forked from hl7-be/fhir-ig-history-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.js
131 lines (120 loc) · 4.33 KB
/
history.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
function hrow(tableTagsArray, title) {
tableTagsArray.push('<tr style="background-color: #f9f9f9"><td colspan="3"><b>');
tableTagsArray.push(title);
tableTagsArray.push('</b></td></tr>');
}
function nrow(tableTagsArray, content) {
tableTagsArray.push('<tr><td colspan="3">');
tableTagsArray.push(content);
tableTagsArray.push('</td></tr>');
}
function row(tableTagsArray, date, url, ver, desc, cl) {
tableTagsArray.push('<tr>');
tableTagsArray.push('<td><a href="' + url + '">' + date + '</a></td>');
tableTagsArray.push('<td>' + ver + '</td>');
if (cl)
tableTagsArray.push('<td>' + desc + ' - see <a href="'+url+"/"+cl+'">Change Notes</a></td>');
else
tableTagsArray.push('<td>' + desc + '</td>');
tableTagsArray.push('</tr>');
}
function rowNL(tableTagsArray, date, ver, desc) {
tableTagsArray.push('<tr>');
tableTagsArray.push('<td>'+ date + '</td>');
tableTagsArray.push('<td>' + ver + '</td>');
tableTagsArray.push('<td>' + desc + '</td>');
tableTagsArray.push('</tr>');
}
function buildDataTable(dataList, curl, dataContainer, title) {
var tableTagsArray = [
'<table class="history-grid">',
'<thead><tr style="background-color: #efefef">',
'<th width="100px">Date</th>',
'<th width="100px">Version</th>',
'<th>Description</th>',
'</tr></thead><tbody>'
];
hrow(tableTagsArray, "Current Versions");
var ci = null;
var cp = null;
// first pass: any versions labelled current + ci-build
for (var historyNode in dataList) {
if (dataList.hasOwnProperty(historyNode)) {
var element = dataList[historyNode];
if (element.status == 'ci-build') {
ci = element;
} else if (element.current) {
cp = element.path;
desc = element.descCurrent;
if (!desc) {
desc = element.desc
}
row(tableTagsArray, element.date, curl, element.version, desc, null);
}
}
}
if (!cp) {
rowNL(tableTagsArray, 'n/a', '', '(no released version at this time)');
}
if (ci) {
desc = ci.descCurrent;
if (!desc) {
desc = ci.descmd;
if (desc) {
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(desc);
var desc = writer.render(parsed);
}
}
if (!desc)
desc = ci.desc;
row(tableTagsArray, '(current)', ci.path, '(last commit)', desc, null);
}
var seq = "!!";
// second pass: all versions, with sequence tag
for (var historyNode in dataList) {
if (dataList.hasOwnProperty(historyNode)) {
var element = dataList[historyNode];
if (element.status != 'ci-build') {
if (element.sequence != seq) {
seq = element.sequence;
hrow(tableTagsArray, seq+' Sequence');
if (element.sequenceNote)
nrow(tableTagsArray, element.sequenceNote);
}
desc = element.descmd;
if (desc) {
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(desc);
var desc = writer.render(parsed);
} else
desc = element.desc;
row(tableTagsArray, element.date, element.path, element.version, desc, element.changes);
}
}
}
tableTagsArray.push('</tbody></table>');
dataContainer.innerHTML = "<p>The following versions of the "+title+" have been published:</p>"+tableTagsArray.join('');
}
function processIntro(md) {
var reader = new commonmark.Parser();
var writer = new commonmark.HtmlRenderer();
var parsed = reader.parse(md);
var result = writer.render(parsed);
document.getElementById('intro').innerHTML = result;
}
function load(json) {
var historyJson = JSON.parse(json.replace(/\n/g, "\\n").replace(/\r/g, "\\r"));
document.title = historyJson.title;
var h = document.getElementById('ig-title');
h.innerHTML = historyJson.title;
var f = document.getElementById('ig-footer');
f.innerHTML = historyJson.title;
if (historyJson.introduction) {
processIntro(historyJson.introduction);
}
var dataContainer = document.getElementById('history-data');
buildDataTable(historyJson.list, historyJson.canonical, dataContainer, historyJson.title);
}