META-INF.resources.webjars.timefold.js.timefold-webui.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of timefold-solver-webui
Show all versions of timefold-solver-webui
Timefold solves planning problems.
This lightweight, embeddable planning engine implements powerful and scalable algorithms
to optimize business resource scheduling and planning.
This module contains the web UI.
function replaceTimefoldAutoHeaderFooter() {
const timefoldHeader = $("header#timefold-auto-header");
if (timefoldHeader != null) {
timefoldHeader.addClass("bg-black")
timefoldHeader.append(
$(`
`));
}
const timefoldFooter = $("footer#timefold-auto-footer");
if (timefoldFooter != null) {
timefoldFooter.append(
$(``));
applicationInfo();
}
}
function showSimpleError(title) {
const notification = $(``)
.append($(`
Error
`))
.append($(``)
.append($(``).text(title))
);
$("#notificationPanel").append(notification);
notification.toast({delay: 30000});
notification.toast('show');
}
function showError(title, xhr) {
var serverErrorMessage = !xhr.responseJSON ? `${xhr.status}: ${xhr.statusText}` : xhr.responseJSON.message;
var serverErrorCode = !xhr.responseJSON ? `unknown` : xhr.responseJSON.code;
var serverErrorId = !xhr.responseJSON ? `----` : xhr.responseJSON.id;
var serverErrorDetails = !xhr.responseJSON ? `no details provided` : xhr.responseJSON.details;
if (xhr.responseJSON && !serverErrorMessage) {
serverErrorMessage = JSON.stringify(xhr.responseJSON);
serverErrorCode = xhr.statusText + '(' + xhr.status + ')';
serverErrorId = `----`;
}
console.error(title + "\n" + serverErrorMessage + " : " + serverErrorDetails);
const notification = $(``)
.append($(`
Error
`))
.append($(``)
.append($(``).text(title))
.append($(``)
.append($(`
`).text(serverErrorMessage + "\n\nCode: " + serverErrorCode + "\nError id: " + serverErrorId))
)
);
$("#notificationPanel").append(notification);
notification.toast({delay: 30000});
notification.toast('show');
}
// ****************************************************************************
// Application info
// ****************************************************************************
function applicationInfo() {
$.getJSON("info", function (info) {
$("#applicationInfo").append("" + info.application + " (version: " + info.version + ", built at: " + info.built + ")");
}).fail(function (xhr, ajaxOptions, thrownError) {
console.warn("Unable to collect application information");
});
}
// ****************************************************************************
// TangoColorFactory
// ****************************************************************************
const SEQUENCE_1 = [0x8AE234, 0xFCE94F, 0x729FCF, 0xE9B96E, 0xAD7FA8];
const SEQUENCE_2 = [0x73D216, 0xEDD400, 0x3465A4, 0xC17D11, 0x75507B];
var colorMap = new Map;
var nextColorCount = 0;
function pickColor(object) {
let color = colorMap[object];
if (color !== undefined) {
return color;
}
color = nextColor();
colorMap[object] = color;
return color;
}
function nextColor() {
let color;
let colorIndex = nextColorCount % SEQUENCE_1.length;
let shadeIndex = Math.floor(nextColorCount / SEQUENCE_1.length);
if (shadeIndex === 0) {
color = SEQUENCE_1[colorIndex];
} else if (shadeIndex === 1) {
color = SEQUENCE_2[colorIndex];
} else {
shadeIndex -= 3;
let floorColor = SEQUENCE_2[colorIndex];
let ceilColor = SEQUENCE_1[colorIndex];
let base = Math.floor((shadeIndex / 2) + 1);
let divisor = 2;
while (base >= divisor) {
divisor *= 2;
}
base = (base * 2) - divisor + 1;
let shadePercentage = base / divisor;
color = buildPercentageColor(floorColor, ceilColor, shadePercentage);
}
nextColorCount++;
return "#" + color.toString(16);
}
function buildPercentageColor(floorColor, ceilColor, shadePercentage) {
let red = (floorColor & 0xFF0000) + Math.floor(shadePercentage * ((ceilColor & 0xFF0000) - (floorColor & 0xFF0000))) & 0xFF0000;
let green = (floorColor & 0x00FF00) + Math.floor(shadePercentage * ((ceilColor & 0x00FF00) - (floorColor & 0x00FF00))) & 0x00FF00;
let blue = (floorColor & 0x0000FF) + Math.floor(shadePercentage * ((ceilColor & 0x0000FF) - (floorColor & 0x0000FF))) & 0x0000FF;
return red | green | blue;
}