|
| 1 | +// Using jQuery is ok because it is needed by and bundled with sphinx |
| 2 | + |
| 3 | +// Quirk to note: the jQuery.getJSON function fails if you open this locally |
| 4 | +// with Chrome, because Chrome thinks local JSON files are unsafe for some |
| 5 | +// reason. Use basically any other modern browser, or it works fine if its |
| 6 | +// actually on the web server even with chrome. |
| 7 | + |
| 8 | +function url_translator(urltext) { |
| 9 | + if (urltext === undefined) { |
| 10 | + return 'None'; |
| 11 | + } else { |
| 12 | + return '<a href="' + urltext + '">' + 'Website' + '</a>'; |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | + |
| 17 | +function repo_translator(urltext) { |
| 18 | + if (urltext === undefined) { |
| 19 | + return 'None'; |
| 20 | + } else { |
| 21 | + return '<a href="' + urltext + '">' + 'Repository' + '</a>'; |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | + |
| 26 | +function pypi_translator(pypiname) { |
| 27 | + if (pypiname === undefined) { |
| 28 | + return 'None'; |
| 29 | + } else { |
| 30 | + var urltext = 'https://pypi.python.org/pypi/' + pypiname; |
| 31 | + return '<a href="' + urltext + '">' + 'PyPI' + '</a>'; |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | + |
| 36 | +function bool_translator(stable) { |
| 37 | + if (stable) { |
| 38 | + return 'Yes'; |
| 39 | + } else { |
| 40 | + return 'No'; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +function ghuser_translator(fullname, ghname) { |
| 46 | + if (fullname === undefined || ghname === undefined) { |
| 47 | + return 'None'; |
| 48 | + } else { |
| 49 | + var urltext = 'https://github.com/' + ghname; |
| 50 | + if (fullname === null) { |
| 51 | + fullname = ghname; |
| 52 | + } |
| 53 | + return '<a href="' + urltext + '">' + fullname + '</a>'; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +var _email_regex_str = '[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'; |
| 59 | +var _email_regex = new RegExp(_email_regex_str, 'i'); |
| 60 | +var _email_with_name_regex = new RegExp('(.+)<(' + _email_regex_str + ')>', 'i'); |
| 61 | + |
| 62 | + |
| 63 | +function maintainer_translator(maint, pkgnm) { |
| 64 | + var url, match; |
| 65 | + if (_email_with_name_regex.test(maint)) { |
| 66 | + match = _email_with_name_regex.exec(maint); |
| 67 | + url = 'mailto:' + match[2] + '?subject=Astropy%20affiliated%20package%20' + pkgnm; |
| 68 | + return '<a href="' + url + '">' + match[1] + '</a>'; |
| 69 | + } else if (_email_regex.test(maint)) { |
| 70 | + url = 'mailto:' + maint + '?subject=Astropy%20affiliated%20package%20' + pkgnm; |
| 71 | + return '<a href="' + url + '">' + maint + '</a>'; |
| 72 | + } else { |
| 73 | + return maint; |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | +function createRolesTable(roles) { |
| 79 | + //roles is an array of objects called "role" |
| 80 | + var rows = ''; |
| 81 | + roles.forEach(function (role) { |
| 82 | + //role is an object containing information about each team role |
| 83 | + //index marks current people |
| 84 | + var index = 0; |
| 85 | + |
| 86 | + // for roles where there are no sub-roles, the people are defined |
| 87 | + // at the top-level of the JSON role dict - for convenience below we create |
| 88 | + // a virtual sub-role with no heading |
| 89 | + if (!('sub-roles' in role)) { |
| 90 | + role['sub-roles'] = [{'role': '', |
| 91 | + 'people': role['people']}]; |
| 92 | + } |
| 93 | + |
| 94 | + //creating each row by iterating over each person in a role |
| 95 | + role["sub-roles"].forEach(function (subrole) { |
| 96 | + //rowRole is displayed once for each role |
| 97 | + rowRole = index == 0 ? '<a href="#' + role["url"] + '">' + role["role"] + '</a>' : ""; |
| 98 | + |
| 99 | + var rowSubRole = subrole['role']; |
| 100 | + |
| 101 | + if (subrole['people'][0] == "Unfilled") { |
| 102 | + rowPeople = '<a href="mailto:coordinators@astropy.org"><span style="font-style: italic;">Unfilled</span></a>'; |
| 103 | + } else { |
| 104 | + rowPeople = subrole['people'].join(', '); |
| 105 | + } |
| 106 | + |
| 107 | + //generating rows |
| 108 | + if (index == 0) { |
| 109 | + rows += '<tr class="border-top">'; |
| 110 | + } else { |
| 111 | + rows += '<tr>'; |
| 112 | + } |
| 113 | + |
| 114 | + rows += '<td>' + rowRole + '</td>' + |
| 115 | + '<td>' + rowSubRole + '</td>' + |
| 116 | + '<td>' + rowPeople + '</td>' + |
| 117 | + '</tr>'; |
| 118 | + index++; |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + $("#roles-table").append(rows); |
| 123 | +} |
| 124 | + |
| 125 | + |
| 126 | +function createRolesDescription(roles) { |
| 127 | + //roles is an array of objects called "role" |
| 128 | + var blocks = ""; |
| 129 | + roles.forEach(function (role) { |
| 130 | + //role is an object containing information about each team role |
| 131 | + var list = ""; |
| 132 | + //checking if role["description"] array isn't empty |
| 133 | + if (role["responsibilities"] != null) { |
| 134 | + |
| 135 | + // If responsibilities is a dict, wrap inside a list so that all entries have a list |
| 136 | + // dicts |
| 137 | + if (role['responsibilities'].constructor == Object) { |
| 138 | + role['responsibilities'] = [role['responsibilities']]; |
| 139 | + } |
| 140 | + |
| 141 | + //console.log(role['responsibilities']); |
| 142 | + |
| 143 | + blocks += '<br/>' + |
| 144 | + '<h3 id="' + role["url"] + '">' + role["role-head"] + '</h3>'; |
| 145 | + |
| 146 | + index = 0; |
| 147 | + |
| 148 | + role['responsibilities'].forEach(function (resp) { |
| 149 | + |
| 150 | + //console.log(resp); |
| 151 | + |
| 152 | + detail_list = ''; |
| 153 | + resp["details"].forEach(function (detail) { |
| 154 | + detail_list += '<li>' + detail + '</li>'; |
| 155 | + }); |
| 156 | + |
| 157 | + if ('subrole-head' in resp) { |
| 158 | + if (index > 0) { |
| 159 | + blocks += '<br>'; |
| 160 | + } |
| 161 | + blocks += '<em>' + resp["subrole-head"] + '</em>'; |
| 162 | + } |
| 163 | + blocks += '<p>' + resp["description"] + '</p>' + |
| 164 | + '<ul>' + detail_list + '</ul>'; |
| 165 | + |
| 166 | + index += 1; |
| 167 | + |
| 168 | + }) |
| 169 | + |
| 170 | + } |
| 171 | + }); |
| 172 | + $("#roles-description").append(blocks); |
| 173 | +} |
| 174 | + |
| 175 | + |
| 176 | +function populateRoles(data, tstat, xhr) { |
| 177 | + //creating roles table from json data |
| 178 | + createRolesTable(data); |
| 179 | + //creating roles lists from json data |
| 180 | + createRolesDescription(data); |
| 181 | +} |
| 182 | + |
| 183 | + |
| 184 | +function populateTables(data, tstat, xhr) { |
| 185 | + populatePackageTable('coordinated', filter_pkg_data(data, "coordinated", true)); |
| 186 | + populatePackageTable('affiliated', filter_pkg_data(data, "coordinated", false)); |
| 187 | +} |
| 188 | + |
| 189 | + |
| 190 | +function filter_pkg_data(data, field, value) { |
| 191 | + if (data === null) { |
| 192 | + return null; |
| 193 | + } |
| 194 | + var pkgs = data.packages; |
| 195 | + var filtered_data = []; |
| 196 | + |
| 197 | + for (i=0; i<pkgs.length; i++) { |
| 198 | + if (pkgs[i][field] == value) { |
| 199 | + filtered_data.push(pkgs[i]); |
| 200 | + } |
| 201 | + } |
| 202 | + return {'packages': filtered_data}; |
| 203 | +} |
| 204 | + |
| 205 | + |
| 206 | +function populatePackageTable(tableid, data) { |
| 207 | + // Now we get the table and prepare it |
| 208 | + var tab = document.getElementById(tableid + "-package-table"); |
| 209 | + var ncols = tab.rows[0].cells.length; |
| 210 | + |
| 211 | + //we have to delete the "Loading..." row |
| 212 | + tab.deleteRow(1); |
| 213 | + |
| 214 | + if (data === null) { |
| 215 | + var row = tab.insertRow(1); |
| 216 | + row.insertCell(0).innerHTML = 'Could not load registry file!'; |
| 217 | + for (i=0;i<(ncols - 1);i++) { row.insertCell(i + 1).innerHTML = ' '; } |
| 218 | + } else { |
| 219 | + var pkgs = data.packages; |
| 220 | + //inserting total number of affiliated packages at top of table |
| 221 | + $("#total-" + tableid + "-pkgs").text(pkgs.length); |
| 222 | + //First figure out the correct order if we sort on the name |
| 223 | + var nmarr = new Array(pkgs.length); |
| 224 | + var sortorder = new Array(pkgs.length); |
| 225 | + for (i=0; i<pkgs.length; i++) { |
| 226 | + pkgi = pkgs[i]; |
| 227 | + nmarr[i] = pkgi.name.toLowerCase(); |
| 228 | + sortorder[i] = i; |
| 229 | + } |
| 230 | + // This "sorts" the indicies using a compare function that actually sorts nmarr |
| 231 | + sortorder.sort(function (a, b) { return nmarr[a] < nmarr[b] ? -1 : nmarr[a] > nmarr[b] ? 1 : 0; }); |
| 232 | + |
| 233 | + var pkgi; |
| 234 | + var namerow, descrow, shieldrow, maintrow; |
| 235 | + var nmcell, pypicell, urlcell, repocell; |
| 236 | + var desccell, maintcell, shieldcell; |
| 237 | + |
| 238 | + for (i=0; i<sortorder.length; i++) { |
| 239 | + pkgi = pkgs[sortorder[i]]; |
| 240 | + namerow = tab.insertRow(i*4 + 1); |
| 241 | + |
| 242 | + nmcell = namerow.insertCell(0); |
| 243 | + urlcell = namerow.insertCell(1); |
| 244 | + repocell = namerow.insertCell(2); |
| 245 | + pypicell = namerow.insertCell(3); |
| 246 | + |
| 247 | + nmcell.innerHTML = pkgi.name; |
| 248 | + nmcell.className = 'first-package-row' |
| 249 | + nmcell.setAttribute('width', 100) |
| 250 | + urlcell.innerHTML = url_translator(pkgi.home_url); |
| 251 | + repocell.innerHTML = repo_translator(pkgi.repo_url); |
| 252 | + pypicell.innerHTML = pypi_translator(pkgi.pypi_name); |
| 253 | + |
| 254 | + |
| 255 | + descrow = tab.insertRow(i*4 + 2); |
| 256 | + descrow.insertCell(0).innerHTML = ""; |
| 257 | + desccell = descrow.insertCell(1); |
| 258 | + desccell.colSpan = "3"; |
| 259 | + desccell.innerHTML = pkgi.description; |
| 260 | + |
| 261 | + maintrow = tab.insertRow(i*4 + 3); |
| 262 | + maintrow.insertCell(0).innerHTML = ""; |
| 263 | + maintcell = maintrow.insertCell(1); |
| 264 | + maintcell.colSpan = "3"; |
| 265 | + maintcell.innerHTML = "Maintainer(s): " + maintainer_translator(pkgi.maintainer, pkgi.name); |
| 266 | + |
| 267 | + shieldrow = tab.insertRow(i*4 + 4); |
| 268 | + shieldrow.insertCell(0).innerHTML = ""; |
| 269 | + shieldcell = shieldrow.insertCell(1); |
| 270 | + shieldcell.colSpan = "3"; |
| 271 | + shieldcell.innerHTML = makeShields(pkgi) |
| 272 | + |
| 273 | + } |
| 274 | + tab.deleteRow(0); |
| 275 | + } |
| 276 | +} |
| 277 | + |
| 278 | +var review_name_map = {"functionality": "Functionality", |
| 279 | + "ecointegration": "Astropy%20integration", |
| 280 | + "documentation": "Docs", |
| 281 | + "testing": "Tests", |
| 282 | + "devstatus": "Development", |
| 283 | + "python3": "Python 3" |
| 284 | +}; |
| 285 | + |
| 286 | +var review_default_color = "brightgreen"; |
| 287 | +var review_color_map = {'Unmaintained': "red", |
| 288 | + "Functional but low activity": "orange", |
| 289 | + "Good": "brightgreen", |
| 290 | + "Partial": "orange", |
| 291 | + "No": "orange", |
| 292 | + "Needs work": "red" |
| 293 | +}; |
| 294 | + |
| 295 | + |
| 296 | +function makeShields(pkg) { |
| 297 | + var shield_string = ""; |
| 298 | + |
| 299 | + var key, shield_name, pkgvalue, color, url; |
| 300 | + |
| 301 | + for (key in review_name_map) { |
| 302 | + //console.log("K"+key); |
| 303 | + if (review_name_map.hasOwnProperty(key)) { |
| 304 | + shield_name = review_name_map[key]; |
| 305 | + if ("review" in pkg && key in pkg.review ) { |
| 306 | + pkgvalue = pkg.review[key]; |
| 307 | + |
| 308 | + color = review_color_map[pkgvalue]; |
| 309 | + if (typeof color == 'undefined') { |
| 310 | + color = review_default_color; |
| 311 | + } |
| 312 | + |
| 313 | + url = "https://img.shields.io/badge/" + shield_name + "-" + pkgvalue + "-" + color + ".svg"; |
| 314 | + shield_string += "<img src=\"" + url + "\">" + " " |
| 315 | + } |
| 316 | + } |
| 317 | + } |
| 318 | + return shield_string |
| 319 | +} |
| 320 | + |
| 321 | + |
| 322 | +function guess_os() { |
| 323 | + var OSName="source"; |
| 324 | + if (navigator.appVersion.indexOf("Win")!=-1) OSName="windows"; |
| 325 | + if (navigator.appVersion.indexOf("Mac")!=-1) OSName="osx"; |
| 326 | + if (navigator.appVersion.indexOf("Linux")!=-1) OSName="linux"; |
| 327 | + return OSName; |
| 328 | +} |
0 commit comments