xref: /dflybsd-src/usr.bin/dsynth/progress.js (revision b81e76a3785f67a811dad5e50f4f3027034c6eff)
18b485838SMatthew Dillon/*
28b485838SMatthew Dillon * Copyright (c) 2015-2017, John R. Marino <draco@marino.st>
38b485838SMatthew Dillon *
48b485838SMatthew Dillon * Permission to use, copy, modify, and/or distribute this software for any
58b485838SMatthew Dillon * purpose with or without fee is hereby granted, provided that the above
68b485838SMatthew Dillon * copyright notice and this permission notice appear in all copies.
78b485838SMatthew Dillon *
88b485838SMatthew Dillon * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
98b485838SMatthew Dillon * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
108b485838SMatthew Dillon * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
118b485838SMatthew Dillon * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
128b485838SMatthew Dillon * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
138b485838SMatthew Dillon * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
148b485838SMatthew Dillon * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
158b485838SMatthew Dillon */
168b485838SMatthew Dillonvar SbInterval = 10;
178b485838SMatthew Dillonvar progwidth = 950;
188b485838SMatthew Dillonvar progheight = 14;
198b485838SMatthew Dillonvar progtop    = 2;
208b485838SMatthew Dillonvar run_active;
218b485838SMatthew Dillonvar kfiles = 0;
228b485838SMatthew Dillonvar last_kfile = 1;
238b485838SMatthew Dillonvar history = [[]];
248b485838SMatthew Dillon
258b485838SMatthew Dillon/* Disabling jQuery caching */
268b485838SMatthew Dillon$.ajaxSetup({
278b485838SMatthew Dillon	cache: false
288b485838SMatthew Dillon});
298b485838SMatthew Dillon
308b485838SMatthew Dillonfunction catwidth (variable, queued) {
318b485838SMatthew Dillon	if (variable == 0)
328b485838SMatthew Dillon		return 0;
338b485838SMatthew Dillon	var width = variable * progwidth / queued;
348b485838SMatthew Dillon	return (width < 1) ? 1 : Math.round (width);
358b485838SMatthew Dillon}
368b485838SMatthew Dillon
378b485838SMatthew Dillonfunction maxcatwidth(A, B, C, D, queued) {
388b485838SMatthew Dillon	var cat = new Array();
398b485838SMatthew Dillon	cat[0] = catwidth (A, queued);
408b485838SMatthew Dillon	cat[1] = catwidth (B, queued);
418b485838SMatthew Dillon	cat[2] = catwidth (C, queued);
428b485838SMatthew Dillon	cat[3] = catwidth (D, queued);
438b485838SMatthew Dillon	cat.sort(function(a,b){return a-b});
448b485838SMatthew Dillon	return (progwidth - cat[0] - cat[1] - cat[2]);
458b485838SMatthew Dillon}
468b485838SMatthew Dillon
478b485838SMatthew Dillonfunction minidraw(x, context, color, queued, variable, mcw) {
488b485838SMatthew Dillon	var width = catwidth (variable, queued);
498b485838SMatthew Dillon	if (width == 0)
508b485838SMatthew Dillon		return (0);
518b485838SMatthew Dillon	if (width > mcw)
528b485838SMatthew Dillon		width = mcw;
538b485838SMatthew Dillon	context.fillStyle = color;
548b485838SMatthew Dillon	context.fillRect(x, progtop + 1, width, progheight + 2);
558b485838SMatthew Dillon	return (width);
568b485838SMatthew Dillon}
578b485838SMatthew Dillon
588b485838SMatthew Dillonfunction update_canvas(stats) {
598b485838SMatthew Dillon	var queued = stats.queued;
608b485838SMatthew Dillon	var built = stats.built;
6151705b28SAntonio Huete Jimenez	var meta = stats.meta;
628b485838SMatthew Dillon	var failed = stats.failed;
638b485838SMatthew Dillon	var skipped = stats.skipped;
648b485838SMatthew Dillon	var ignored = stats.ignored;
658b485838SMatthew Dillon
668b485838SMatthew Dillon	var canvas = document.getElementById('progressbar');
678b485838SMatthew Dillon	if (canvas.getContext === undefined) {
688b485838SMatthew Dillon		/* Not supported */
698b485838SMatthew Dillon		return;
708b485838SMatthew Dillon	}
718b485838SMatthew Dillon
728b485838SMatthew Dillon	var context = canvas.getContext('2d');
738b485838SMatthew Dillon
748b485838SMatthew Dillon	context.fillStyle = '#D8D8D8';
758b485838SMatthew Dillon	context.fillRect(0, progtop + 1, progwidth, progheight + 2);
768b485838SMatthew Dillon	var x = 0;
7751705b28SAntonio Huete Jimenez	var mcw = maxcatwidth (built, meta, failed, ignored, skipped, queued);
788b485838SMatthew Dillon	x += minidraw(x, context, "#339966", queued, built, mcw);
7951705b28SAntonio Huete Jimenez	x += minidraw(x, context, "#A577E1", queued, meta, mcw);
808b485838SMatthew Dillon	x += minidraw(x, context, "#CC0033", queued, failed, mcw);
818b485838SMatthew Dillon	x += minidraw(x, context, "#FFCC33", queued, ignored, mcw);
828b485838SMatthew Dillon	x += minidraw(x, context, "#CC6633", queued, skipped, mcw);
838b485838SMatthew Dillon}
848b485838SMatthew Dillon
858b485838SMatthew Dillonfunction filter (txt) {
868b485838SMatthew Dillon	$('#report input').val (txt).trigger('search');
878b485838SMatthew Dillon}
888b485838SMatthew Dillon
898b485838SMatthew Dillonfunction process_summary(data) {
908b485838SMatthew Dillon	var html;
918b485838SMatthew Dillon	var RB = '<tr>';
928b485838SMatthew Dillon	var RE = '</tr>';
938b485838SMatthew Dillon	var B = '<td>';
948b485838SMatthew Dillon	var E = '</td>';
958b485838SMatthew Dillon
968b485838SMatthew Dillon	kfiles = parseInt (data.kfiles);
978b485838SMatthew Dillon	run_active = parseInt (data.active);
988b485838SMatthew Dillon	$('#profile').html(data.profile);
998b485838SMatthew Dillon	$('#kickoff').html(data.kickoff);
1008b485838SMatthew Dillon	$('#polling').html(run_active ? "Active" : "Complete");
1018b485838SMatthew Dillon	if (data.stats) {
1028b485838SMatthew Dillon		$.each(data.stats, function(status, count) {
1038b485838SMatthew Dillon			html = count;
1048b485838SMatthew Dillon			$('#stats_' + status).html(html);
1058b485838SMatthew Dillon		});
1068b485838SMatthew Dillon		update_canvas (data.stats);
1078b485838SMatthew Dillon	}
1088b485838SMatthew Dillon
1098b485838SMatthew Dillon	$('#builders_body tbody').empty();
1108b485838SMatthew Dillon	for (n = 0; n < data.builders.length; n++) {
1118b485838SMatthew Dillon		var trow = RB + '<td class="b' + data.builders[n].ID +
1128b485838SMatthew Dillon			'" onclick="filter(\'[' + data.builders[n].ID +
1138b485838SMatthew Dillon			']\')" title="Click to filter for work done by builder ' +
1148b485838SMatthew Dillon			data.builders[n].ID + '">'
1158b485838SMatthew Dillon			  + data.builders[n].ID + E +
1168b485838SMatthew Dillon			B + data.builders[n].elapsed + E +
1178b485838SMatthew Dillon			B + data.builders[n].phase + E +
1188b485838SMatthew Dillon			B + data.builders[n].origin + E +
1198b485838SMatthew Dillon			B + data.builders[n].lines + E +
1208b485838SMatthew Dillon			RE;
1218b485838SMatthew Dillon		$('#builders_body tbody').append (trow);
1228b485838SMatthew Dillon	}
1238b485838SMatthew Dillon}
1248b485838SMatthew Dillon
1258b485838SMatthew Dillonfunction digit2(n){
1268b485838SMatthew Dillon	return n > 9 ? "" + n: "0" + n;
1278b485838SMatthew Dillon}
1288b485838SMatthew Dillon
1298b485838SMatthew Dillonfunction logfile (origin) {
1308b485838SMatthew Dillon	var parts = origin.split('/');
1318b485838SMatthew Dillon	return '../' + parts[0] + '___' + parts[1] + '.log';
1328b485838SMatthew Dillon}
1338b485838SMatthew Dillon
1348b485838SMatthew Dillonfunction format_result (result) {
1358b485838SMatthew Dillon	return '<div class="' + result + ' result">' + result + '<div>';
1368b485838SMatthew Dillon}
1378b485838SMatthew Dillon
1388b485838SMatthew Dillonfunction format_entry (entry, origin) {
1398b485838SMatthew Dillon	return '<span class="entry" onclick="filter(\'' + origin+ '\')">' +
1408b485838SMatthew Dillon		entry + '</span>';
1418b485838SMatthew Dillon}
1428b485838SMatthew Dillon
1438b485838SMatthew Dillonfunction information (result, origin, info) {
1448b485838SMatthew Dillon	var parts;
14551705b28SAntonio Huete Jimenez	if (result == "meta") {
14651705b28SAntonio Huete Jimenez		return 'meta-node complete.';
14751705b28SAntonio Huete Jimenez	} else if (result == "built") {
1488b485838SMatthew Dillon		return '<a href="' + logfile (origin) + '">logfile</a>';
1498b485838SMatthew Dillon	} else if (result == "failed") {
1508b485838SMatthew Dillon		parts = info.split(':');
1518b485838SMatthew Dillon		return 'Failed ' + parts[0] + ' phase (<a href="' + logfile (origin) +
1528b485838SMatthew Dillon			'">logfile</a>)';
1538b485838SMatthew Dillon	} else if (result == "skipped") {
1548b485838SMatthew Dillon		return 'Issue with ' + info;
1558b485838SMatthew Dillon	} else if (result == "ignored") {
1568b485838SMatthew Dillon		parts = info.split(':|:');
1578b485838SMatthew Dillon		return parts[0];
1588b485838SMatthew Dillon	} else {
1598b485838SMatthew Dillon		return "??";
1608b485838SMatthew Dillon	}
1618b485838SMatthew Dillon}
1628b485838SMatthew Dillon
1638b485838SMatthew Dillonfunction skip_info (result, info) {
1648b485838SMatthew Dillon	var parts;
1658b485838SMatthew Dillon	if (result == "failed") {
1668b485838SMatthew Dillon		parts = info.split(':');
1678b485838SMatthew Dillon		return parts[1];
1688b485838SMatthew Dillon	} else if (result == "ignored") {
1698b485838SMatthew Dillon		parts = info.split(':|:');
1708b485838SMatthew Dillon		return parts[1];
1718b485838SMatthew Dillon	} else {
1728b485838SMatthew Dillon		return "";
1738b485838SMatthew Dillon	}
1748b485838SMatthew Dillon}
1758b485838SMatthew Dillon
1768b485838SMatthew Dillonfunction portsmon (origin) {
177*b81e76a3SPierre-Alain TORET	var portparts = origin.split('/');
178*b81e76a3SPierre-Alain TORET	var nameparts = portparts[1].split('@');
179*b81e76a3SPierre-Alain TORET	var FPClink = '<a title="portsmon for "' + origin + '" href="https://www.freshports.org/' + portparts[0] + '/' + nameparts[0] + '">' + origin + '</a>';
1808b485838SMatthew Dillon	var NPSlink = '<a title="pkgsrc.se overview" href="http://pkgsrc.se/' + origin + '">' + origin + '</a>';
1818b485838SMatthew Dillon	return FPClink;
1828b485838SMatthew Dillon}
1838b485838SMatthew Dillon
1848b485838SMatthew Dillonfunction process_history_file(data, k) {
1858b485838SMatthew Dillon	history [k] = [];
1868b485838SMatthew Dillon	for (n = 0; n < data.length; n++) {
1878b485838SMatthew Dillon		var trow = [];
1888b485838SMatthew Dillon		trow.push(format_entry (data[n].entry, data[n].origin));
1898b485838SMatthew Dillon		trow.push(data[n].elapsed);
1908b485838SMatthew Dillon		trow.push('[' + data[n].ID + ']');
1918b485838SMatthew Dillon		trow.push(format_result (data[n].result));
1928b485838SMatthew Dillon		trow.push(portsmon (data[n].origin));
1938b485838SMatthew Dillon		trow.push(information (data[n].result, data[n].origin, data[n].info));
1948b485838SMatthew Dillon		trow.push(skip_info (data[n].result, data[n].info));
1958b485838SMatthew Dillon		trow.push(data[n].duration);
1968b485838SMatthew Dillon		history [k].push (trow);
1978b485838SMatthew Dillon	}
1988b485838SMatthew Dillon}
1998b485838SMatthew Dillon
2008b485838SMatthew Dillonfunction cycle () {
2018b485838SMatthew Dillon	if (run_active) {
2028b485838SMatthew Dillon		setTimeout(update_summary_and_builders, SbInterval * 1000);
2038b485838SMatthew Dillon	} else {
2048b485838SMatthew Dillon		$('#builders_zone_2').fadeOut(2500);
2058b485838SMatthew Dillon		$('#main').css('border-top', '1px solid #404066');
2068b485838SMatthew Dillon	}
2078b485838SMatthew Dillon}
2088b485838SMatthew Dillon
2098b485838SMatthew Dillonfunction update_history_success(kfile) {
2108b485838SMatthew Dillon	if (kfile == kfiles) {
2118b485838SMatthew Dillon		var full_history = [];
2128b485838SMatthew Dillon		for (var k = 1; k <= kfiles; k++) {
2138b485838SMatthew Dillon			full_history = full_history.concat (history[k]);
2148b485838SMatthew Dillon		}
2158b485838SMatthew Dillon		$('#report_table').dataTable().fnClearTable();
2168b485838SMatthew Dillon		$('#report_table').dataTable().fnAddData(full_history);
2178b485838SMatthew Dillon		cycle();
2188b485838SMatthew Dillon	} else {
2198b485838SMatthew Dillon		last_kfile = kfile + 1;
2208b485838SMatthew Dillon		update_history();
2218b485838SMatthew Dillon	}
2228b485838SMatthew Dillon}
2238b485838SMatthew Dillon
2248b485838SMatthew Dillonfunction update_history() {
2258b485838SMatthew Dillon	if (kfiles == 0) {
2268b485838SMatthew Dillon		cycle();
2278b485838SMatthew Dillon		return;
2288b485838SMatthew Dillon	}
2298b485838SMatthew Dillon	clearInterval(update_history);
2308b485838SMatthew Dillon	$.ajax({
2318b485838SMatthew Dillon		url: digit2(last_kfile) + '_history.json',
2328b485838SMatthew Dillon		dataType: 'json',
2338b485838SMatthew Dillon		success: function(data) {
2348b485838SMatthew Dillon			process_history_file(data, last_kfile);
2358b485838SMatthew Dillon			update_history_success (last_kfile);
2368b485838SMatthew Dillon		},
2378b485838SMatthew Dillon		error: function(data) {
2388b485838SMatthew Dillon			/* May not be there yet, try again shortly */
2398b485838SMatthew Dillon			setTimeout(update_history, SbInterval * 500);
2408b485838SMatthew Dillon		}
2418b485838SMatthew Dillon	})
2428b485838SMatthew Dillon}
2438b485838SMatthew Dillon
2448b485838SMatthew Dillonfunction update_summary_and_builders() {
2458b485838SMatthew Dillon	$.ajax({
2468b485838SMatthew Dillon		url: 'summary.json',
2478b485838SMatthew Dillon		dataType: 'json',
2488b485838SMatthew Dillon		success: function(data) {
2498b485838SMatthew Dillon			process_summary(data);
2508b485838SMatthew Dillon			clearInterval(update_summary_and_builders);
2518b485838SMatthew Dillon			update_history();
2528b485838SMatthew Dillon		},
2538b485838SMatthew Dillon		error: function(data) {
2548b485838SMatthew Dillon			/* May not be there yet, try again shortly */
2558b485838SMatthew Dillon			setTimeout(update_summary_and_builders, SbInterval * 500);
2568b485838SMatthew Dillon		}
2578b485838SMatthew Dillon	});
2588b485838SMatthew Dillon}
2598b485838SMatthew Dillon
2608b485838SMatthew Dillon$(document).ready(function() {
2618b485838SMatthew Dillon
2628b485838SMatthew Dillon	$('#report_table').dataTable({
2638b485838SMatthew Dillon		"aaSorting": [[ 0, 'desc' ]],
2648b485838SMatthew Dillon		"bProcessing": true, // Show processing icon
2658b485838SMatthew Dillon		"bDeferRender": true, // Defer creating TR/TD until needed
2668b485838SMatthew Dillon		"aoColumnDefs": [
2678b485838SMatthew Dillon			{"bSortable": false, "aTargets": [1,2,3,5]},
2688b485838SMatthew Dillon			{"bSearchable": false, "aTargets": [0,1,6,7]},
2698b485838SMatthew Dillon		],
2708b485838SMatthew Dillon		"bStateSave": true, // Enable cookie for keeping state
2718b485838SMatthew Dillon		"aLengthMenu":[10,20,50, 100, 200],
2728b485838SMatthew Dillon		"iDisplayLength": 20,
2738b485838SMatthew Dillon		});
2748b485838SMatthew Dillon
2758b485838SMatthew Dillon	update_summary_and_builders();
2768b485838SMatthew Dillon})
2778b485838SMatthew Dillon
2788b485838SMatthew Dillon$(document).bind("keydown", function(e) {
2798b485838SMatthew Dillon  /* Disable F5 refreshing since this is AJAX driven. */
2808b485838SMatthew Dillon  if (e.which == 116) {
2818b485838SMatthew Dillon    e.preventDefault();
2828b485838SMatthew Dillon  }
2838b485838SMatthew Dillon});
284