|
| 1 | +/*! |
| 2 | + * kernelci dashboard. |
| 3 | + * |
| 4 | + * Copyright (C) 2020 Collabora Limited |
| 5 | + * Author: Guillaume Tucker <[email protected]> |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify it under |
| 8 | + * the terms of the GNU Lesser General Public License as published by the Free |
| 9 | + * Software Foundation; either version 2.1 of the License, or (at your option) |
| 10 | + * any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 14 | + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 15 | + * details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Lesser General Public License |
| 18 | + * along with this library; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | + */ |
| 21 | + |
| 22 | +require([ |
| 23 | + 'jquery', |
| 24 | + 'charts/passpie', |
| 25 | + 'tables/test', |
| 26 | + 'utils/error', |
| 27 | + 'utils/init', |
| 28 | + 'utils/html', |
| 29 | + 'utils/request', |
| 30 | + 'utils/table', |
| 31 | + 'utils/urls', |
| 32 | + 'URI', |
| 33 | +], function($, pieChart, ttable, error, init, html, request, table, |
| 34 | + urls, URI) { |
| 35 | + 'use strict'; |
| 36 | + |
| 37 | + var gPlan; |
| 38 | + var gKernel; |
| 39 | + var gBranch; |
| 40 | + var gJob; |
| 41 | + var gFileServer; |
| 42 | + var gTestsTable; |
| 43 | + |
| 44 | + setTimeout(function() { |
| 45 | + document.getElementById('li-test').setAttribute('class', 'active'); |
| 46 | + }, 15); |
| 47 | + |
| 48 | + function detailsFailed() { |
| 49 | + html.replaceByClassTxt('loading-content', '?'); |
| 50 | + } |
| 51 | + |
| 52 | + function updateDetails(results) { |
| 53 | + var job; |
| 54 | + var branch; |
| 55 | + var kernel; |
| 56 | + var commit; |
| 57 | + var treeNode; |
| 58 | + var describeNode; |
| 59 | + var branchNode; |
| 60 | + var planNode; |
| 61 | + var gitNode; |
| 62 | + var createdOn; |
| 63 | + var dateNode; |
| 64 | + var url; |
| 65 | + var plan; |
| 66 | + |
| 67 | + job = results.revision.tree; |
| 68 | + branch = results.revision.branch; |
| 69 | + kernel = results.revision.describe; |
| 70 | + commit = results.revision.commit; |
| 71 | + url = results.revision.url.replace('.git', '/commit/'+commit); |
| 72 | + plan = results.group; |
| 73 | + |
| 74 | + treeNode = html.tooltip(); |
| 75 | + treeNode.title = "All results for tree «" + job + "»"; |
| 76 | + treeNode.appendChild(document.createTextNode(job)); |
| 77 | + |
| 78 | + planNode = html.tooltip(); |
| 79 | + planNode.title = "All results for test plan «" + plan + "»"; |
| 80 | + planNode.appendChild(document.createTextNode(plan)); |
| 81 | + |
| 82 | + branchNode = html.tooltip(); |
| 83 | + branchNode.title = "All results for branch «" + branch + "»"; |
| 84 | + branchNode.appendChild(document.createTextNode(branch)); |
| 85 | + |
| 86 | + describeNode = html.tooltip(); |
| 87 | + describeNode.title = "Build results for «" + kernel + "» - "; |
| 88 | + describeNode.appendChild(document.createTextNode(kernel)); |
| 89 | + |
| 90 | + gitNode = document.createElement('a'); |
| 91 | + gitNode.appendChild(document.createTextNode(url)); |
| 92 | + gitNode.href = url; |
| 93 | + gitNode.title = "Git URL"; |
| 94 | + |
| 95 | + createdOn = new Date(results.created); |
| 96 | + dateNode = document.createElement('time'); |
| 97 | + dateNode.setAttribute('datetime', createdOn.toISOString()); |
| 98 | + dateNode.appendChild( |
| 99 | + document.createTextNode(createdOn.toCustomISODate())); |
| 100 | + |
| 101 | + html.replaceContent( |
| 102 | + document.getElementById('tree'), treeNode); |
| 103 | + html.replaceContent( |
| 104 | + document.getElementById('plan'), planNode); |
| 105 | + html.replaceContent( |
| 106 | + document.getElementById('git-branch'), branchNode); |
| 107 | + html.replaceContent( |
| 108 | + document.getElementById('git-describe'), describeNode); |
| 109 | + html.replaceContent( |
| 110 | + document.getElementById('git-url'), gitNode); |
| 111 | + html.replaceContent( |
| 112 | + document.getElementById('job-date'), dateNode); |
| 113 | + html.replaceContent( |
| 114 | + document.getElementById('plan-title'), |
| 115 | + document.createTextNode(results.group)); |
| 116 | + html.replaceContent( |
| 117 | + document.getElementById('kernel-title'), |
| 118 | + document.createTextNode(results.revision.describe)); |
| 119 | + html.replaceContent( |
| 120 | + document.getElementById('tree-title'), |
| 121 | + document.createTextNode(job)); |
| 122 | + html.replaceContent( |
| 123 | + document.getElementById('branch-title'), |
| 124 | + document.createTextNode(branch)); |
| 125 | + } |
| 126 | + |
| 127 | + function updateChart(testCount) { |
| 128 | + function countTests(tc) { |
| 129 | + return [ |
| 130 | + tc['total'], |
| 131 | + [tc['pass'], tc['failures'], tc['regressions'], tc['unknown']] |
| 132 | + ]; |
| 133 | + } |
| 134 | + |
| 135 | + pieChart.testpie({ |
| 136 | + element: 'test-chart', |
| 137 | + countFunc: countTests, |
| 138 | + response: testCount, |
| 139 | + legend: true, |
| 140 | + legendIds: { |
| 141 | + 'pass': '#show-pass', |
| 142 | + 'warning': '#show-warning', |
| 143 | + 'fail': '#show-fail', |
| 144 | + 'unknown': '#show-unknown', |
| 145 | + }, |
| 146 | + legendTitles: { |
| 147 | + 'pass': 'Successful', |
| 148 | + 'warning': 'Failures', |
| 149 | + 'fail': 'Regressions', |
| 150 | + 'unknown': 'Unknown', |
| 151 | + }, |
| 152 | + size: { |
| 153 | + height: 200, |
| 154 | + width: 200, |
| 155 | + }, |
| 156 | + radius: {inner: -30, outer: -42}, |
| 157 | + }); |
| 158 | + } |
| 159 | + |
| 160 | + function listenForTableEvents(testCount) { |
| 161 | + var btnList = ['total', 'pass', 'regressions', 'failures', 'unknown']; |
| 162 | + |
| 163 | + function _tableFilter(event) { |
| 164 | + var activeId = event.target.id; |
| 165 | + var status = activeId.substring('btn-'.length); |
| 166 | + |
| 167 | + if (status == 'total') { |
| 168 | + status = ''; |
| 169 | + } else if (status == 'regressions') { |
| 170 | + status = 'fail'; |
| 171 | + } else if (status == 'failures') { |
| 172 | + status = 'warning'; |
| 173 | + } |
| 174 | + |
| 175 | + gTestsTable.table.column(2).search(status).draw(); |
| 176 | + |
| 177 | + btnList.forEach(function(id) { |
| 178 | + var btnId = 'btn-' + id; |
| 179 | + var ele = document.getElementById(btnId); |
| 180 | + |
| 181 | + if (btnId == activeId) { |
| 182 | + html.addClass(ele, 'active'); |
| 183 | + } else { |
| 184 | + html.removeClass(ele, 'active'); |
| 185 | + } |
| 186 | + }); |
| 187 | + } |
| 188 | + |
| 189 | + btnList.forEach(function(id) { |
| 190 | + var ele = document.getElementById('btn-' + id); |
| 191 | + ele.addEventListener('click', _tableFilter, true); |
| 192 | + if (testCount[id]) |
| 193 | + ele.removeAttribute('disabled'); |
| 194 | + if (id == 'total') |
| 195 | + html.addClass(ele, 'active'); |
| 196 | + }); |
| 197 | + } |
| 198 | + |
| 199 | + function updateTestsTable(results) { |
| 200 | + var columns; |
| 201 | + var data; |
| 202 | + function _renderStatus(data, type) { |
| 203 | + if (type == "display") { |
| 204 | + var node = document.createElement('div'); |
| 205 | + node.appendChild(ttable.statusNode(data)); |
| 206 | + return node.outerHTML; |
| 207 | + } else { |
| 208 | + return data; |
| 209 | + } |
| 210 | + } |
| 211 | + |
| 212 | + data = []; |
| 213 | + results.forEach(function(item) { |
| 214 | + var status; |
| 215 | + |
| 216 | + if (item.result == 'pass') |
| 217 | + status = 'PASS'; |
| 218 | + else if (item.result == 'fail') |
| 219 | + status = 'WARNING'; |
| 220 | + else if (item.result === null) |
| 221 | + return |
| 222 | + else |
| 223 | + status = 'UNKNOWN'; |
| 224 | + |
| 225 | + data.push({ |
| 226 | + '_id': item._id, |
| 227 | + 'test_case_path': item.path.join('.'), |
| 228 | + 'measurements': '-', |
| 229 | + 'status': status, |
| 230 | + }); |
| 231 | + }); |
| 232 | + |
| 233 | + columns = [ |
| 234 | + { |
| 235 | + title: 'Test case path', |
| 236 | + data: 'test_case_path', |
| 237 | + type: 'string', |
| 238 | + className: 'test-group-column', |
| 239 | + }, |
| 240 | + { |
| 241 | + title: 'Measurements', |
| 242 | + data: 'measurements', |
| 243 | + type: 'string', |
| 244 | + className: 'test-group-column', |
| 245 | + searchable: false, |
| 246 | + orderable: false, |
| 247 | + }, |
| 248 | + { |
| 249 | + title: 'Status', |
| 250 | + data: 'status', |
| 251 | + type: 'string', |
| 252 | + className: 'pull-center', |
| 253 | + searchable: true, |
| 254 | + orderable: false, |
| 255 | + render: _renderStatus, |
| 256 | + }, |
| 257 | + ]; |
| 258 | + |
| 259 | + gTestsTable |
| 260 | + .data(data) |
| 261 | + .columns(columns) |
| 262 | + .order([0, 'asc']) |
| 263 | + .paging(true) |
| 264 | + .info(false) |
| 265 | + .draw(); |
| 266 | + } |
| 267 | + |
| 268 | + function getTestsFailed() { |
| 269 | + html.removeElement(document.getElementById('table-loading')); |
| 270 | + html.replaceContent( |
| 271 | + document.getElementById('table-div'), |
| 272 | + html.errorDiv('No test data available.') |
| 273 | + ); |
| 274 | + } |
| 275 | + |
| 276 | + function getTestsDone(response) { |
| 277 | + if (response.length === 0) { |
| 278 | + getTestsFailed(); |
| 279 | + return; |
| 280 | + } |
| 281 | + |
| 282 | + updateTestsTable(response.items); |
| 283 | + } |
| 284 | + |
| 285 | + function testCountDone(response) { |
| 286 | + var testCount; |
| 287 | + var total = 0; |
| 288 | + var pass = 0; |
| 289 | + var fail = 0; |
| 290 | + var regressions = 0; |
| 291 | + var unknown = 0; |
| 292 | + |
| 293 | + response.forEach(function(item){ |
| 294 | + if (item.path.length > 2 & item.result !== null) { |
| 295 | + switch(item.result) { |
| 296 | + case 'fail': |
| 297 | + fail += 1; |
| 298 | + break; |
| 299 | + case 'pass': |
| 300 | + pass += 1; |
| 301 | + break; |
| 302 | + case 'unknown': |
| 303 | + unknown += 1; |
| 304 | + break; |
| 305 | + } |
| 306 | + } |
| 307 | + }); |
| 308 | + |
| 309 | + total = fail+pass+regressions+unknown; |
| 310 | + |
| 311 | + testCount = { |
| 312 | + 'total': total, |
| 313 | + 'pass': pass, |
| 314 | + 'regressions': regressions, |
| 315 | + 'failures': fail, |
| 316 | + 'unknown': unknown, |
| 317 | + }; |
| 318 | + updateChart(testCount); |
| 319 | + listenForTableEvents(testCount); |
| 320 | + } |
| 321 | + |
| 322 | + function getPlanFailed() { |
| 323 | + detailsFailed(); |
| 324 | + } |
| 325 | + |
| 326 | + function getPlanDone(response) { |
| 327 | + updateDetails(response.items[0]); |
| 328 | + getTestsDone(response); |
| 329 | + testCountDone(response.items); |
| 330 | + } |
| 331 | + |
| 332 | + function getPlan() { |
| 333 | + var data; |
| 334 | + if (!gPlan) { |
| 335 | + getPlanFailed(); |
| 336 | + return; |
| 337 | + } |
| 338 | + |
| 339 | + data = { |
| 340 | + 'revision.tree': gJob, |
| 341 | + 'revision.branch': gBranch, |
| 342 | + 'revision.describe': gKernel, |
| 343 | + group: gPlan, |
| 344 | + limit: 100000, |
| 345 | + offset: 0, |
| 346 | + }; |
| 347 | + |
| 348 | + $.when(request.get('/_ajax/nodes', data)) |
| 349 | + .fail(error.error, getPlanFailed) |
| 350 | + .done(getPlanDone); |
| 351 | + } |
| 352 | + if (document.getElementById('job-name') !== null) { |
| 353 | + gJob = document.getElementById('job-name').value; |
| 354 | + } |
| 355 | + if (document.getElementById('branch-name') !== null) { |
| 356 | + gBranch = URI.decode(document.getElementById('branch-name').value); |
| 357 | + } |
| 358 | + if (document.getElementById('kernel-name') !== null) { |
| 359 | + gKernel = document.getElementById('kernel-name').value; |
| 360 | + } |
| 361 | + if (document.getElementById('plan-name') !== null) { |
| 362 | + gPlan = document.getElementById('plan-name').value; |
| 363 | + } |
| 364 | + |
| 365 | + gTestsTable = table({ |
| 366 | + tableId: 'tests-table', |
| 367 | + tableLoadingDivId: 'table-loading', |
| 368 | + tableDivId: 'table-div', |
| 369 | + }); |
| 370 | + |
| 371 | + setTimeout(getPlan, 10); |
| 372 | + |
| 373 | + setTimeout(init.hotkeys, 50); |
| 374 | + setTimeout(init.tooltip, 50); |
| 375 | +}); |
0 commit comments