-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathfunctions.js
More file actions
329 lines (263 loc) · 10.2 KB
/
functions.js
File metadata and controls
329 lines (263 loc) · 10.2 KB
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
// Using jQuery is ok because it is needed by and bundled with sphinx
// Quirk to note: the jQuery.getJSON function fails if you open this locally
// with Chrome, because Chrome thinks local JSON files are unsafe for some
// reason. Use basically any other modern browser, or it works fine if its
// actually on the web server even with chrome.
function url_translator(urltext) {
if (urltext === undefined) {
return 'None';
} else {
return '<a href="' + urltext + '">' + 'Website' + '</a>';
}
}
function repo_translator(urltext) {
if (urltext === undefined) {
return 'None';
} else {
return '<a href="' + urltext + '">' + 'Repository' + '</a>';
}
}
function pypi_translator(pypiname) {
if (pypiname === undefined) {
return 'None';
} else {
var urltext = 'https://pypi.python.org/pypi/' + pypiname;
return '<a href="' + urltext + '">' + 'PyPI' + '</a>';
}
}
function bool_translator(stable) {
if (stable) {
return 'Yes';
} else {
return 'No';
}
}
function ghuser_translator(fullname, ghname) {
if (fullname === undefined || ghname === undefined) {
return 'None';
} else {
var urltext = 'https://github.com/' + ghname;
if (fullname === null) {
fullname = ghname;
}
return '<a href="' + urltext + '">' + fullname + '</a>';
}
}
var _email_regex_str = '[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}';
var _email_regex = new RegExp(_email_regex_str, 'i');
var _email_with_name_regex = new RegExp('(.+)<(' + _email_regex_str + ')>', 'i');
function maintainer_translator(maint, pkgnm) {
var url, match;
if (_email_with_name_regex.test(maint)) {
match = _email_with_name_regex.exec(maint);
url = 'mailto:' + match[2] + '?subject=Astropy%20affiliated%20package%20' + pkgnm;
return '<a href="' + url + '">' + match[1] + '</a>';
} else if (_email_regex.test(maint)) {
url = 'mailto:' + maint + '?subject=Astropy%20affiliated%20package%20' + pkgnm;
return '<a href="' + url + '">' + maint + '</a>';
} else {
return maint;
}
}
function createRolesTable(roles) {
var tab = document.getElementById("roles-table");
tab.deleteRow(1);
//roles is an array of objects called "role"
var rows = '';
roles.forEach(function (role) {
//role is an object containing information about each team role
//index marks current people
var index = 0;
// for roles where there are no sub-roles, the people are defined
// at the top-level of the JSON role dict - for convenience below we create
// a virtual sub-role with no heading
if (!('sub-roles' in role)) {
role['sub-roles'] = [{'role': '',
'people': role['people']}];
}
//creating each row by iterating over each person in a role
role["sub-roles"].forEach(function (subrole) {
//rowRole is displayed once for each role
rowRole = index == 0 ? '<a href="#' + role["url"] + '">' + role["role"] + '</a>' : "";
var rowSubRole = subrole['role'];
if (subrole['people'][0] == "Unfilled") {
rowPeople = '<a href="mailto:coordinators@astropy.org"><span style="font-style: italic;">Unfilled</span></a>';
} else {
rowPeople = subrole['people'].join(', ');
}
//generating rows
if (index == 0) {
rows += '<tr class="border-top">';
} else {
rows += '<tr>';
}
rows += '<td>' + rowRole + '</td>' +
'<td>' + rowSubRole + '</td>' +
'<td>' + rowPeople + '</td>' +
'</tr>';
index++;
});
});
$("#roles-table").append(rows);
}
function createRolesDescription(roles) {
//roles is an array of objects called "role"
var blocks = "";
roles.forEach(function (role) {
//role is an object containing information about each team role
var list = "";
//checking if role["description"] array isn't empty
if (role["responsibilities"] != null) {
// If responsibilities is a dict, wrap inside a list so that all entries have a list
// dicts
if (role['responsibilities'].constructor == Object) {
role['responsibilities'] = [role['responsibilities']];
}
//console.log(role['responsibilities']);
blocks += '<h4 id="' + role["url"] + '">' + role["role-head"] + '</h4>';
index = 0;
role['responsibilities'].forEach(function (resp) {
//console.log(resp);
detail_list = '';
resp["details"].forEach(function (detail) {
detail_list += '<li>' + detail + '</li>';
});
if ('subrole-head' in resp) {
if (index > 0) {
blocks += '<br>';
}
blocks += '<em>' + resp["subrole-head"] + '</em>';
}
blocks += '<p>' + resp["description"] + '</p>' +
'<ul>' + detail_list + '</ul>';
index += 1;
})
}
});
$("#roles-description").append(blocks);
}
function populateRoles(data, tstat, xhr) {
//creating roles table from json data
createRolesTable(data);
//creating roles lists from json data
createRolesDescription(data);
}
function populateTables(data, tstat, xhr) {
populatePackageTable('coordinated', filter_pkg_data(data, "coordinated", true));
populatePackageTable('affiliated', filter_pkg_data(data, "coordinated", false));
}
function filter_pkg_data(data, field, value) {
if (data === null) {
return null;
}
var pkgs = data.packages;
var filtered_data = [];
for (i=0; i<pkgs.length; i++) {
if (pkgs[i][field] == value) {
filtered_data.push(pkgs[i]);
}
}
return {'packages': filtered_data};
}
function populatePackageTable(tableid, data) {
// Now we get the table and prepare it
var tab = document.getElementById(tableid + "-package-table");
var ncols = tab.rows[0].cells.length;
//we have to delete the "Loading..." row
tab.deleteRow(1);
if (data === null) {
var row = tab.insertRow(1);
row.insertCell(0).innerHTML = 'Could not load registry file!';
for (i=0;i<(ncols - 1);i++) { row.insertCell(i + 1).innerHTML = ' '; }
} else {
var pkgs = data.packages;
//inserting total number of affiliated packages at top of table
$("#total-" + tableid + "-pkgs").text(pkgs.length);
//First figure out the correct order if we sort on the name
var nmarr = new Array(pkgs.length);
var sortorder = new Array(pkgs.length);
for (i=0; i<pkgs.length; i++) {
pkgi = pkgs[i];
nmarr[i] = pkgi.name.toLowerCase();
sortorder[i] = i;
}
// This "sorts" the indicies using a compare function that actually sorts nmarr
sortorder.sort(function (a, b) { return nmarr[a] < nmarr[b] ? -1 : nmarr[a] > nmarr[b] ? 1 : 0; });
var pkgi;
var namerow, descrow, shieldrow, maintrow;
var nmcell, pypicell, urlcell, repocell;
var desccell, maintcell, shieldcell;
for (i=0; i<sortorder.length; i++) {
pkgi = pkgs[sortorder[i]];
namerow = tab.insertRow(i*4 + 1);
nmcell = namerow.insertCell(0);
urlcell = namerow.insertCell(1);
repocell = namerow.insertCell(2);
pypicell = namerow.insertCell(3);
nmcell.innerHTML = pkgi.name;
nmcell.className = 'first-package-row'
nmcell.setAttribute('width', 100)
urlcell.innerHTML = url_translator(pkgi.home_url);
repocell.innerHTML = repo_translator(pkgi.repo_url);
pypicell.innerHTML = pypi_translator(pkgi.pypi_name);
descrow = tab.insertRow(i*4 + 2);
descrow.insertCell(0).innerHTML = "";
desccell = descrow.insertCell(1);
desccell.colSpan = "3";
desccell.innerHTML = pkgi.description;
maintrow = tab.insertRow(i*4 + 3);
maintrow.insertCell(0).innerHTML = "";
maintcell = maintrow.insertCell(1);
maintcell.colSpan = "3";
maintcell.innerHTML = "Maintainer(s): " + maintainer_translator(pkgi.maintainer, pkgi.name);
shieldrow = tab.insertRow(i*4 + 4);
shieldrow.insertCell(0).innerHTML = "";
shieldcell = shieldrow.insertCell(1);
shieldcell.colSpan = "3";
shieldcell.innerHTML = makeShields(pkgi)
}
tab.deleteRow(0);
}
}
var review_name_map = {"functionality": "Functionality",
"ecointegration": "Astropy%20integration",
"documentation": "Docs",
"testing": "Tests",
"devstatus": "Development",
"python3": "Python 3"
};
var review_default_color = "brightgreen";
var review_color_map = {'Unmaintained': "red",
"Functional but low activity": "orange",
"Good": "brightgreen",
"Partial": "orange",
"No": "orange",
"Needs work": "red"
};
function makeShields(pkg) {
var shield_string = "";
var key, shield_name, pkgvalue, color, url;
for (key in review_name_map) {
//console.log("K"+key);
if (review_name_map.hasOwnProperty(key)) {
shield_name = review_name_map[key];
if ("review" in pkg && key in pkg.review ) {
pkgvalue = pkg.review[key];
color = review_color_map[pkgvalue];
if (typeof color == 'undefined') {
color = review_default_color;
}
url = "https://img.shields.io/badge/" + shield_name + "-" + pkgvalue + "-" + color + ".svg";
shield_string += "<img src=\"" + url + "\">" + " "
}
}
}
return shield_string
}
function guess_os() {
var OSName="source";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="osx";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="linux";
return OSName;
}