function isLogFile(path) { var ext = path.split(".").pop(); if (["log", "done", "youri"].indexOf(ext) < 0) { return true; } return false; } function isShortFile(path) { var ext = path.split(".").pop(); var file = path.split("/").pop(); if (["done"].indexOf(ext) >= 0 || ["status.log"].indexOf(file) >= 0) { return true; } return false; } /** * Inject elements with appropriate classes into given text * to allow for highlighting specific portions of a text file. * * Here, log files with ok|success|test|warning|info|error|fail|etc. * * @param string text * * @return string */ function highlight_text(text) { return text.replace(/.*(ok|succe|test|warn|info|deprecat|error|fail).*/gi, function (match, p1, p2, offset, string) { console.log([match, p1, offset, string]); var cl = 'none'; switch (p1.toLowerCase()) { case 'succe': case 'ok': cl = 'ok'; break case 'test': case 'info': cl = 'info'; break; case 'warn': case 'deprecat': cl = 'warn'; break; case 'error': case 'fail': cl = 'error'; break; } return '' + match + ''; }); } $(function () { $('.status-link').on("click", function (ev) { if (!ev.metaKey) { ev.preventDefault(); var key = $(this).attr("href"); var elId = 'e' + key.replace(/\/|\./g, '-'); var el = $("#" + elId); if (el.length == 0) { $(this).parent().parent().after($("", { class: "build-files-list", id: elId, html: 'loading' } )); $.get( "/log_files.php", {"k": $(this).attr("href")}, function (data) { $("#" + elId).html('' + data + ''); } ); } else { el.toggle(); } } }); $("table#submitted-packages tbody").on("click", "tr td li a.view-inline", function (ev) { if (isLogFile($(this).attr("href"))) { return true; } if (!ev.metaKey) { ev.preventDefault(); var elId = 'view-' + $(this).attr("href").replace(/\/|\./g, '-'); var cId = elId + '-container'; var c = $("#" + cId); var el = $("#" + elId); if (c.length == 0) { $(this).after($("
", { id: cId }) .addClass(isShortFile($(this).attr("href")) ? "short" : "") .append($("
", { id: elId, class: "file-view", html: "loading..." })) ); $.get( "/" + $(this).attr("href"), {}, function (data) { $("#" + elId).html(highlight_text(data)) .before( $("
", { class: "controls" }) .append($("