// Copyright Epic Games, Inc. All Rights Reserved.
// boilerplate.js -- This script should be loaded for every Robomerge page to provide a consistent UI and dataset for each page,
// as well as provide common, shared functions to our client-side Javascript.
/********************
* COMMON FUNCTIONS *
********************/
// Global user information map
let robomergeUser
window.showNodeLastChanges = false
window.allowNodeReconsiders = false
// Common mutex variable around displaying error messages
let clearer = null
function clearErrorText() {
const $err = $('#error')
$err.addClass('_hidden');
if (!clearer) {
clearer = setTimeout(() => {
if (clearer) {
$err.empty();
}
}, 1000);
}
}
function setErrorText(text) {
if (clearer) {
clearTimeout(clearer);
clearer = null;
}
$('#error').text(text).removeClass('_hidden');
}
function setError(xhr, error) {
setErrorText(createErrorMessage(xhr, error))
}
function createErrorMessage(xhr, error) {
if (xhr.responseText)
return `${xhr.status ? xhr.status + ": " : ""}${xhr.responseText}`
else if (xhr.status == 0) {
document.title = "ROBOMERGE (error)";
return "Connection error";
}
else
return `HTTP ${xhr.status}: ${error}`;
}
function promptFor(map) {
var result = {};
var success = true;
$.each(Object.keys(map), function(_, key) {
if (success) {
var p = map[key];
var dflt = "";
if (typeof(p) === "object") {
dflt = p.default || "";
p = p.prompt || key;
}
var data = prompt(p, dflt);
if (data === null) {
success = false;
}
else {
result[key] = data;
}
}
});
return success ? result : null;
}
// Add way to prompt the user on leave/reload before the perform an action
function addOnBeforeUnload(message) {
$( window ).on("beforeunload", function() {
return message
})
}
function removeOnBeforeUnload() {
$( window ).off("beforeunload")
}
function makeClLink(cl, swarmURL, alias) {
if (typeof(cl) !== "number") {
return `${cl}`
}
if (swarmURL) {
return `${alias || cl}`
}
else {
return `${alias || cl}`
}
}
function makeSwarmFileLink(depotPath, swarmURL, alias) {
if (swarmURL) {
return `${alias ? alias : depotPath}`
}
else {
return `${alias ? alias : depotPath}`
}
}
function debug(message) {
log('DEBUG: ' + message)
}
function error(message) {
log('ERROR!: ' + message + '\n' + (new Error()).stack)
}
function log(message) {
const now = new Date(Date.now())
console.log(
now.toLocaleString(undefined, {dateStyle: 'short', timeStyle: 'medium', hour12: false}) +
"." + String(now.getMilliseconds()).padStart(3, '0') +
": " + message
)
}
// Reload the branchlist div
let updateBranchesPending = false;
function updateBranchList(graphBotName=null) {
if (updateBranchesPending)
return;
updateBranchesPending = true;
let expandedDivIds = []
$('#branchList .elist-row>.collapse.show').each( (_index, div) => {
expandedDivIds.push(div.id)
})
// Keep the height value pre-refresh
const beginningBLHeight = $('#branchList').height()
// Capture the current tab (if any) so we can swap back to it post-refresh if it still exists
const currentBotNavLinkId = $('.nav-item.nav-item-active>a.nav-link.botlink.active.show').attr("id")
// Prevent window resizing and scrolling
$('#branchList').css('min-height', beginningBLHeight + 'px')
getBranchList(function(data) {
if (data && data.started) {
preprocessData(data)
// clear 'error' or 'stopped' from title if present
document.title = 'ROBOMERGE';
$('div#currentlyRunning').empty()
let newBranchList = $('
').append(renderBranchList(data))
expandedDivIds.forEach( (divId) => {
const escapedDivId = divId.replace(/\./g, '\\.')
// Show the div again
const div = newBranchList.find(`#${escapedDivId}`)
if (div.hasClass('collapse') && !div.hasClass('show')) {
div.addClass('show')
}
// Ensure the caret icon in the link is correct
const collapseControlIcon = newBranchList.find(`.nrow .namecell a[data-target="#${escapedDivId}"]>i`)
if (collapseControlIcon.length === 1 && collapseControlIcon.hasClass("fa-caret-right")) {
collapseControlIcon.removeClass("fa-caret-right")
collapseControlIcon.addClass("fa-caret-down")
}
})
// Prevent window resizing and scrolling
newBranchList.css('min-height', beginningBLHeight + 'px')
$('#branchList').replaceWith(newBranchList)
$('body').trigger('branchListUpdated')
}
else {
const bl = $('#branchList').empty()
$('
')
.text('Cannot communicate with Robomerge.')
.appendTo(bl)
$('