2024-04-18 00:14:07 +02:00
|
|
|
//Make sure canvasses are in the correct positionG
|
|
|
|
var maincanvas= document.querySelector("MainCanvas");
|
|
|
|
|
|
|
|
var MainCanvas = document.getElementById("MainCanvas");
|
|
|
|
var MainCanvas_ctx = MainCanvas.getContext("2d");
|
|
|
|
var maincanvasBackground="lightgrey";
|
|
|
|
var mouseIsDown=false;
|
|
|
|
var mouseDownLocation;
|
|
|
|
var mouseDidMovement=false;
|
|
|
|
var imageSize=40;
|
2024-04-30 18:14:23 +02:00
|
|
|
var small_button_size = 25;
|
2024-04-22 20:09:44 +02:00
|
|
|
var uiDeviceInfoLevel = 1; //What do we display when we look at the network
|
2024-04-24 23:52:27 +02:00
|
|
|
var uiActions = [];//a list of things on the screen we can click on or process.
|
2024-04-25 21:47:54 +02:00
|
|
|
var ui_highlightRect = null;
|
2024-05-17 18:33:33 +02:00
|
|
|
var ui_selectRect = null;
|
2024-04-27 20:39:36 +02:00
|
|
|
var ui_HadHighlight = false;
|
2024-04-30 18:14:23 +02:00
|
|
|
var ui_status_height = 25;
|
2024-05-10 19:00:42 +02:00
|
|
|
var ui_StatusText = "";
|
|
|
|
var ui_HighlightArray = [];
|
2024-05-18 00:06:03 +02:00
|
|
|
var translator = new Language("en");
|
2024-04-18 00:14:07 +02:00
|
|
|
|
|
|
|
//The user interface mode. 0=network, 1=network information, 2=puzzle-selection menu
|
|
|
|
var uiMode=1;
|
|
|
|
|
|
|
|
|
|
|
|
const imageCollection = loadImages(
|
2024-04-19 20:33:37 +02:00
|
|
|
["ArrowUp", "ArrowDown", "animations",
|
|
|
|
"burnmark", "cellphone", "circle",
|
|
|
|
"copier", "firewall", "fluorescent",
|
|
|
|
"hub", "ip_phone", "laptop",
|
|
|
|
"link", "microwave", "pc", "printer",
|
|
|
|
"router", "select", "server",
|
|
|
|
"shapes", "square", "switch",
|
|
|
|
"tablet", "tree", "vidimage",
|
|
|
|
"wap", "wbridge", "wrepeater",
|
2024-04-22 22:37:28 +02:00
|
|
|
"wrouter", "x", "info", "menu",
|
2024-04-30 17:58:44 +02:00
|
|
|
"eye", "queryuser", "thumb",
|
2024-04-22 22:37:28 +02:00
|
|
|
],
|
2024-04-19 20:33:37 +02:00
|
|
|
["img/ArrowUp.png", "img/ArrowDown.png", "img/Animations.png",
|
|
|
|
"img/BurnMark.png", "img/cellphone.png", "img/Circle.png",
|
|
|
|
"img/Copier.png", "img/firewall.png", "img/fluorescent.png",
|
|
|
|
"img/Hub.png", "img/ip_phone.png", "img/Laptop.png",
|
|
|
|
"img/link.png", "img/microwave.png", "img/PC.png",
|
|
|
|
"img/Printer.png", "img/Router.png", "img/select.png",
|
|
|
|
"img/Server.png", "img/Shapes.png", "img/Square.png",
|
|
|
|
"img/Switch.png", "img/tablet.png", "img/tree.png",
|
|
|
|
"img/VidImage.png", "img/WAP.png", "img/WBridge.png",
|
|
|
|
"img/WRepeater.png", "img/WRouter.png", "img/X.png",
|
2024-04-22 22:37:28 +02:00
|
|
|
"img/info.png", "img/menu.png", "img/eye.png",
|
2024-05-16 01:06:48 +02:00
|
|
|
"img/queryuser.png", "img/thumb.png",
|
2024-04-22 22:37:28 +02:00
|
|
|
],
|
2024-04-30 17:58:44 +02:00
|
|
|
InitializeGameMenu // this is called when all images have loaded.
|
2024-04-18 00:14:07 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
var menuItemSize=50;
|
|
|
|
|
|
|
|
|
|
|
|
function loadImages(names, files, onAllLoaded) {
|
2024-04-30 17:58:44 +02:00
|
|
|
var i = 0, numLoading = names.length;
|
|
|
|
const onload = () => --numLoading === 0 && onAllLoaded();
|
|
|
|
const images = {};
|
|
|
|
while (i < names.length) {
|
|
|
|
const img = images[names[i]] = new Image;
|
|
|
|
img.src = files[i++];
|
|
|
|
img.onload = onload;
|
|
|
|
}
|
|
|
|
return images;
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function imageFromName(name)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
return imageCollection[name];
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function InitializeGameMenu()
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
console.log("Initializing");
|
|
|
|
MainCanvas.addEventListener("touchstart", handleTouchStart);
|
|
|
|
MainCanvas.addEventListener("touchend", handleTouchEnd);
|
|
|
|
MainCanvas.addEventListener("touchcancel", handleTouchCancel);
|
|
|
|
MainCanvas.addEventListener("touchmove", handleTouchMove);
|
|
|
|
MainCanvas.addEventListener('mousedown',handleMouseDown);
|
|
|
|
MainCanvas.addEventListener('mouseup',handleMouseUp);
|
|
|
|
MainCanvas.addEventListener('mousemove',handleMouseMove);
|
|
|
|
|
|
|
|
//MainCanvas_ctx.drawImage(imageCollection['router'],100,100,50,50);
|
|
|
|
//MainCanvas_ctx.drawImage(imageCollection['firewall'],150,150,50,50);
|
2024-04-18 00:14:07 +02:00
|
|
|
|
2024-04-19 20:33:37 +02:00
|
|
|
InitializeSelectMenu();
|
2024-04-30 17:58:44 +02:00
|
|
|
//It should be printed
|
|
|
|
PrintScreen();
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Print the screen. Figure out what needs to be printed based on the mode
|
|
|
|
function PrintScreen(WhatPassedIn=-1)
|
|
|
|
{
|
|
|
|
//allow us to override what is printed
|
2024-04-30 17:58:44 +02:00
|
|
|
var what=uiMode;
|
|
|
|
if(WhatPassedIn >=0) what=WhatPassedIn;
|
2024-04-18 00:14:07 +02:00
|
|
|
|
2024-04-24 23:52:27 +02:00
|
|
|
//Clear out any old ActionStructs. They will get filled in as we print the screen.
|
|
|
|
clearActionStructs();
|
|
|
|
|
2024-05-16 01:06:48 +02:00
|
|
|
//console.log("PrintingScreen for mode: " + what);
|
2024-04-24 23:52:27 +02:00
|
|
|
var rect;
|
2024-04-19 18:02:46 +02:00
|
|
|
|
2024-04-30 17:58:44 +02:00
|
|
|
if(what == 0)
|
|
|
|
{
|
2024-04-24 23:52:27 +02:00
|
|
|
//The network drawing mode. Print the network
|
|
|
|
//Clear the old screen
|
|
|
|
MainCanvas_ctx.fillStyle = maincanvasBackground;
|
|
|
|
MainCanvas_ctx.fillRect(0, 0, MainCanvas.width, MainCanvas.height);
|
|
|
|
|
2024-05-16 01:06:48 +02:00
|
|
|
//Check for device highlights
|
|
|
|
checkDevicesForIssues();
|
2024-05-10 19:00:42 +02:00
|
|
|
|
|
|
|
//print highlights. If we have mouseover highlights, note that.
|
|
|
|
if (printHighlights("mouseover") > 0) ui_HadHighlight = true;
|
2024-04-27 20:39:36 +02:00
|
|
|
else ui_HadHighlight = false;
|
2024-04-25 21:47:54 +02:00
|
|
|
|
2024-04-24 23:52:27 +02:00
|
|
|
//Draw the puzzle-select button
|
2024-04-19 18:02:46 +02:00
|
|
|
//Put the X there so we can click on it
|
2024-04-24 23:52:27 +02:00
|
|
|
rect = makeRectangle(MainCanvas.width - small_button_size, 0, small_button_size, small_button_size);
|
|
|
|
MainCanvas_ctx.drawImage(imageFromName("menu"),rect.sx,rect.sy,rect.deltax,rect.deltay);
|
2024-04-25 21:47:54 +02:00
|
|
|
registerActionStruct("square", rect, null, ui_PuzzleChoiceMenuLeftClick, null, generic_mouseoverHighlight);
|
2024-04-19 18:02:46 +02:00
|
|
|
|
2024-04-24 23:52:27 +02:00
|
|
|
//Draw the info button
|
2024-04-25 21:47:54 +02:00
|
|
|
rect = makeRectangle(MainCanvas.width - small_button_size, small_button_size, small_button_size, small_button_size);
|
|
|
|
MainCanvas_ctx.drawImage(imageFromName("info"), rect.sx, rect.sy, rect.deltax, rect.deltay);
|
|
|
|
registerActionStruct("square", rect, null, ui_InfoLeftClick, null, generic_mouseoverHighlight);
|
2024-04-22 22:37:28 +02:00
|
|
|
|
2024-04-25 21:47:54 +02:00
|
|
|
//Draw the eye button
|
|
|
|
rect = makeRectangle(MainCanvas.width - small_button_size, small_button_size * 2, small_button_size, small_button_size);
|
|
|
|
MainCanvas_ctx.drawImage(imageFromName("eye"), rect.sx, rect.sy, rect.deltax, rect.deltay);
|
|
|
|
registerActionStruct("square", rect, null, ui_eyeLeftClick, null, generic_mouseoverHighlight);
|
2024-04-22 22:37:28 +02:00
|
|
|
|
2024-05-16 01:06:48 +02:00
|
|
|
//Draw the help-level select button
|
|
|
|
rect = makeRectangle(MainCanvas.width - small_button_size, small_button_size * 3, small_button_size, small_button_size);
|
|
|
|
|
|
|
|
//Put any coloring behind the query-user image
|
|
|
|
var tmp_queryhighlight = null;
|
|
|
|
if (ui_helplevel == 0) tmp_queryhighlight = returnHighlightShape("square", rect, "red", "none", 0.3);
|
|
|
|
if (ui_helplevel == 1) tmp_queryhighlight = returnHighlightShape("square", rect, "orange", "none", 0.3);
|
|
|
|
if (ui_helplevel == 2) tmp_queryhighlight = returnHighlightShape("square", rect, "yellow", "none", 0.3);
|
|
|
|
if (ui_helplevel == 3) tmp_queryhighlight = returnHighlightShape("square", rect, "green", "none", 0.3);
|
|
|
|
if (tmp_queryhighlight == null) { }
|
2024-06-06 22:59:59 +02:00
|
|
|
else drawhighlight(tmp_queryhighlight);
|
2024-05-16 01:06:48 +02:00
|
|
|
|
|
|
|
MainCanvas_ctx.drawImage(imageFromName("queryuser"), rect.sx, rect.sy, rect.deltax, rect.deltay);
|
|
|
|
|
|
|
|
registerActionStruct("square", rect, null, ui_queryuserLeftClick, null, generic_mouseoverHighlight);
|
|
|
|
|
|
|
|
|
2024-04-30 18:14:23 +02:00
|
|
|
//Draw simple lines to show boundaries
|
|
|
|
//Select menu separation
|
|
|
|
MainCanvas_ctx.lineWidth = 2;
|
|
|
|
MainCanvas_ctx.strokeStyle = "white";
|
|
|
|
MainCanvas_ctx.beginPath();
|
|
|
|
MainCanvas_ctx.moveTo(menuItemSize, 0); //top side
|
|
|
|
MainCanvas_ctx.lineTo(menuItemSize, MainCanvas.height); //Bottom
|
|
|
|
MainCanvas_ctx.stroke();
|
|
|
|
|
|
|
|
//Right-side menu separator
|
|
|
|
MainCanvas_ctx.beginPath();
|
|
|
|
MainCanvas_ctx.moveTo(MainCanvas.width - small_button_size, 0); //top side
|
|
|
|
MainCanvas_ctx.lineTo(MainCanvas.width - small_button_size, MainCanvas.height - ui_status_height); //Bottom
|
|
|
|
MainCanvas_ctx.stroke();
|
|
|
|
|
|
|
|
//Status Bar separator
|
|
|
|
MainCanvas_ctx.beginPath();
|
|
|
|
MainCanvas_ctx.moveTo(menuItemSize, MainCanvas.height - ui_status_height); //top side
|
|
|
|
MainCanvas_ctx.lineTo(MainCanvas.width, MainCanvas.height - ui_status_height); //Bottom
|
|
|
|
MainCanvas_ctx.stroke();
|
|
|
|
|
2024-05-01 00:38:31 +02:00
|
|
|
var statustext = puzzle.name + ": " + ui_StatusText;
|
|
|
|
printLeftJustifiedText(MainCanvas_ctx, statustext, menuItemSize + 5, (MainCanvas.height - ui_status_height) + 7);
|
2024-04-30 18:14:23 +02:00
|
|
|
|
|
|
|
MainCanvas_ctx.strokeStyle = "black";
|
|
|
|
|
2024-05-17 18:33:33 +02:00
|
|
|
if (ui_selectRect == null) { }
|
|
|
|
else {
|
|
|
|
//console.log("We have something selected.");
|
|
|
|
var tmp_select = returnHighlightShape("selectbox", ui_selectRect, "green", "none", 0.8);
|
2024-06-06 22:59:59 +02:00
|
|
|
drawhighlight(tmp_select);
|
2024-06-01 02:12:00 +02:00
|
|
|
}
|
2024-05-17 18:33:33 +02:00
|
|
|
|
2024-04-24 23:52:27 +02:00
|
|
|
drawSelectMenu();
|
|
|
|
PrintAllNetworkLinks();
|
|
|
|
PrintAllNetworkDevices();
|
|
|
|
}
|
|
|
|
else if(what == 1) //PuzzleDescription/Info
|
|
|
|
{
|
2024-04-18 00:14:07 +02:00
|
|
|
//Display the text about the puzzle
|
2024-05-18 00:06:03 +02:00
|
|
|
console.log("Using language: " + ui_language);
|
|
|
|
textMenuPrint(eval('puzzle.' + ui_language + '_message'));
|
2024-04-24 23:52:27 +02:00
|
|
|
}
|
|
|
|
else if(what == 2) //PuzzleSelect
|
|
|
|
{
|
2024-04-19 18:02:46 +02:00
|
|
|
//TextMenuSelection
|
|
|
|
PrintPuzzleSelectMenu(0);
|
2024-04-24 23:52:27 +02:00
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleTouchStart(evt)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
handleMouseDown(copyLocation(evt));
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
function handleTouchEnd(evt)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
handleMouseUp(copyLocation(evt));
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
function handleTouchCancel(evt)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
evt.preventDefault();
|
|
|
|
console.log("canceling touch");
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
function handleTouchMove(evt)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
//evt.preventDefault();
|
|
|
|
if(evt.touches.length > 0)
|
|
|
|
{
|
|
|
|
handleMouseMove(copyLocation(evt.touches[0]));
|
|
|
|
} else{
|
|
|
|
//console.log("not enough touches");
|
|
|
|
}
|
|
|
|
//console.log("moving touch");
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
function handleMouseDown(evt)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
mouseDownLocation = copyLocation(evt);
|
|
|
|
mouseIsDown=true;
|
|
|
|
//console.log("mousedown");
|
2024-04-18 00:14:07 +02:00
|
|
|
if(uiMode==0) SelectMenu_handleMouseDown(mouseDownLocation);
|
|
|
|
}
|
|
|
|
|
2024-04-24 23:52:27 +02:00
|
|
|
function CheckForActions(actionPoint, action) {
|
|
|
|
if (uiActions.length >= 0) {
|
|
|
|
var checkit = false;
|
|
|
|
var inside = false;
|
2024-04-25 21:47:54 +02:00
|
|
|
for (var index = 0; index < uiActions.length; index++) {
|
2024-05-16 20:13:41 +02:00
|
|
|
checkit = true;
|
|
|
|
if (action == "leftclick" && uiActions[index].funcLeftClick == null) checkit = false;
|
|
|
|
if (action == "rightclick" && uiActions[index].funcRightClick == null) checkit = false;
|
|
|
|
if (action == "mouseover" && uiActions[index].funcMouseover == null) checkit = false;
|
2024-04-24 23:52:27 +02:00
|
|
|
checklocation = uiActions[index];
|
2024-04-27 20:39:36 +02:00
|
|
|
var point = newPointFromPair(actionPoint.pageX - checklocation.shapePoints.offsetx, actionPoint.pageY - checklocation.shapePoints.offsety);
|
2024-04-24 23:52:27 +02:00
|
|
|
if (checkit) {
|
|
|
|
//See if the click is inside the shape
|
|
|
|
if (checklocation.shapeText == "square") {
|
2024-04-27 20:39:36 +02:00
|
|
|
if (pointInRect(point, checklocation.shapePoints))
|
|
|
|
inside = true;
|
|
|
|
}
|
|
|
|
if (checklocation.shapeText == "line") {
|
|
|
|
if (pointInRect(point, checklocation.shapePoints)) {
|
|
|
|
//console.log("inside line square");
|
|
|
|
//We are inside the box. Now determine if we are on the line...
|
|
|
|
var d1 = distance(checklocation.shapePoints.sx, checklocation.shapePoints.sy, actionPoint.pageX, actionPoint.pageY);
|
|
|
|
d1 += distance(checklocation.shapePoints.dx, checklocation.shapePoints.dy, actionPoint.pageX, actionPoint.pageY);
|
|
|
|
var d2 = distance(checklocation.shapePoints.sx, checklocation.shapePoints.sy, checklocation.shapePoints.dx, checklocation.shapePoints.dy);
|
|
|
|
if (Math.abs(d1 - d2) < 3) {
|
|
|
|
inside = true;
|
|
|
|
//console.log("on a line!");
|
2024-04-24 23:52:27 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-25 21:47:54 +02:00
|
|
|
}
|
2024-04-27 20:39:36 +02:00
|
|
|
|
2024-04-25 21:47:54 +02:00
|
|
|
}
|
|
|
|
if (inside) {
|
|
|
|
//console.log("Is inside");
|
|
|
|
switch (action) {
|
|
|
|
case "leftclick":
|
2024-05-16 20:13:41 +02:00
|
|
|
if (checklocation.funcLeftClick == null) { }
|
|
|
|
else {
|
2024-04-25 21:47:54 +02:00
|
|
|
checklocation.funcLeftClick(actionPoint, checklocation);
|
2024-05-16 20:13:41 +02:00
|
|
|
//console.log("Successfully did a left-click UI action");
|
2024-04-25 21:47:54 +02:00
|
|
|
return true;
|
|
|
|
}
|
2024-04-27 20:39:36 +02:00
|
|
|
break;
|
2024-04-25 21:47:54 +02:00
|
|
|
case "mouseover":
|
2024-05-16 20:13:41 +02:00
|
|
|
if (checklocation.funcMouseover == null) { }
|
|
|
|
else {
|
2024-04-25 21:47:54 +02:00
|
|
|
checklocation.funcMouseover(actionPoint, checklocation);
|
|
|
|
//console.log("Successfully did a UI action");
|
|
|
|
return true;
|
|
|
|
}
|
2024-04-27 20:39:36 +02:00
|
|
|
break;
|
2024-04-25 21:47:54 +02:00
|
|
|
}
|
2024-04-24 23:52:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-27 20:39:36 +02:00
|
|
|
function pointInRect(point, rectangle) {
|
|
|
|
if (point.x >= Math.min(rectangle.sx,rectangle.dx)) {
|
|
|
|
if (point.x <= Math.max(rectangle.sx, rectangle.dx)) {
|
|
|
|
if (point.y >= Math.min(rectangle.sy, rectangle.dy)) {
|
|
|
|
if (point.y <= Math.max(rectangle.sy, rectangle.dy)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//return the distance between two points
|
|
|
|
function distance(x1, y1, x2, y2) {
|
|
|
|
return Math.hypot(x2 - x1, y2 - y1);
|
|
|
|
}
|
|
|
|
|
2024-04-18 00:14:07 +02:00
|
|
|
function handleMouseUp(evt)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
//evt.preventDefault();
|
2024-05-17 18:33:33 +02:00
|
|
|
mouseIsDown = false;
|
2024-04-30 17:58:44 +02:00
|
|
|
//See if we have a mouse click
|
|
|
|
let deltaX = Math.abs(evt.pageX - mouseDownLocation.pageX);
|
|
|
|
let deltaY = Math.abs(evt.pageY - mouseDownLocation.pageY);
|
|
|
|
//console.log("delta " + deltaX + "," + deltaY);
|
|
|
|
if(deltaY < 3 && deltaX <3)
|
|
|
|
{
|
2024-04-18 00:14:07 +02:00
|
|
|
//We did not move much. Assume click
|
|
|
|
if(evt.pageX <= menuItemSize && !mouseDidMovement)
|
|
|
|
{
|
|
|
|
if(uiMode==0) SelectMenu_handleMouseUp(evt);
|
|
|
|
|
|
|
|
//We are in the item select menu.
|
|
|
|
}
|
2024-04-19 18:02:46 +02:00
|
|
|
if(!mouseDidMovement)
|
|
|
|
{ //If we are not dragging, it is a click
|
2024-04-24 23:52:27 +02:00
|
|
|
var myevt = copyLocation(evt);
|
2024-05-17 18:33:33 +02:00
|
|
|
var needsrefresh = true;;
|
|
|
|
if (ui_selectRect == null) needsrefresh = false;
|
|
|
|
ui_selectRect = null; //remove any previous selected marker
|
2024-04-25 21:47:54 +02:00
|
|
|
//console.log("evt:" + JSON.stringify(myevt));
|
2024-04-24 23:52:27 +02:00
|
|
|
if (CheckForActions(myevt, "leftclick")) return; //If we did this, do not do anything else.
|
2024-04-19 18:02:46 +02:00
|
|
|
if(uiMode==1) TextWindow_handleMouseUp(evt);
|
2024-05-17 18:33:33 +02:00
|
|
|
else if (uiMode == 2) TextWindow_handleMouseUp(evt);
|
|
|
|
if (needsrefresh) {
|
|
|
|
if (ui_selectRect == null) setStatus(""); //we clicked on nothing
|
|
|
|
PrintScreen();
|
|
|
|
}
|
2024-04-19 18:02:46 +02:00
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
|
2024-04-30 17:58:44 +02:00
|
|
|
}
|
|
|
|
mouseDidMovement=false; //reset it after we raise the button
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
2024-04-25 21:47:54 +02:00
|
|
|
function ui_PuzzleChoiceMenuLeftClick(evt) {
|
|
|
|
//We clicked on the puzzle-select menu
|
|
|
|
console.log("PuzzleSelect pressed in action");
|
|
|
|
uiMode = 2;
|
|
|
|
PrintScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ui_eyeLeftClick(evt) {
|
|
|
|
console.log("Selected 'eye' button in action");
|
|
|
|
//It is the eye button
|
|
|
|
uiDeviceInfoLevel++;
|
|
|
|
if (uiDeviceInfoLevel > 3) uiDeviceInfoLevel = 0;
|
|
|
|
PrintScreen();
|
|
|
|
}
|
|
|
|
|
2024-05-16 01:06:48 +02:00
|
|
|
function ui_queryuserLeftClick(evt) {
|
|
|
|
console.log("Selected 'queryuser' button in action");
|
|
|
|
//It is the eye button
|
|
|
|
ui_helplevel++;
|
|
|
|
if (ui_helplevel > 3) ui_helplevel = 0;
|
|
|
|
if (ui_helplevel == 0) setStatus("There is a disturbance in the force. Guessing...");
|
|
|
|
if (ui_helplevel == 1) setStatus("Service check detected a problem.");
|
|
|
|
if (ui_helplevel == 2) setStatus("Someone submitted a trouble ticket.");
|
|
|
|
if (ui_helplevel == 3) setStatus("Interviewed users for detailed info.");
|
|
|
|
PrintScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-25 21:47:54 +02:00
|
|
|
function ui_InfoLeftClick(evt) {
|
|
|
|
console.log("Selected info button in action");
|
|
|
|
//It is the info button
|
|
|
|
uiMode = 1;
|
|
|
|
PrintScreen();
|
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
|
|
|
|
function handleMouseMove(evt)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
//evt.preventDefault();
|
|
|
|
if(mouseIsDown)
|
|
|
|
{
|
2024-04-27 20:39:36 +02:00
|
|
|
let deltaX = evt.pageX - mouseDownLocation.pageX;
|
|
|
|
let deltaY = evt.pageY - mouseDownLocation.pageY;
|
|
|
|
if(isNaN(deltaY)) deltaY=0;
|
|
|
|
if(isNaN(deltaX)) deltaX=0;
|
|
|
|
//we are dragging
|
|
|
|
//console.log('mousemove ' + evt.pageX + " " + evt.pageY + " delta " + deltaY );
|
|
|
|
if(uiMode == 0)
|
|
|
|
{
|
|
|
|
SelectMenu_handleMouseMove(evt);
|
|
|
|
}
|
2024-04-19 19:11:46 +02:00
|
|
|
|
2024-04-27 20:39:36 +02:00
|
|
|
mouseDidMovement=true;
|
|
|
|
}
|
2024-04-19 19:11:46 +02:00
|
|
|
else //Mouse is not down. Not dragging
|
|
|
|
{
|
2024-04-25 21:47:54 +02:00
|
|
|
var needrefresh = false;
|
2024-05-10 19:00:42 +02:00
|
|
|
var oldRect = structuredClone(findHighlightsNamed("mouseover"));
|
|
|
|
removeHighlightsNamed("mouseover");
|
2024-04-25 21:47:54 +02:00
|
|
|
if (!CheckForActions(evt, "mouseover")) {
|
|
|
|
//We did not find anything
|
2024-05-10 19:23:10 +02:00
|
|
|
if (oldRect == null) {
|
2024-04-27 20:39:36 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2024-05-10 19:23:10 +02:00
|
|
|
//We used to have a highlight, but it was removed
|
2024-04-25 21:47:54 +02:00
|
|
|
needrefresh = true;
|
2024-04-27 20:39:36 +02:00
|
|
|
}
|
|
|
|
if (ui_HadHighlight) { needrefresh = true; }
|
|
|
|
if (needrefresh) {
|
|
|
|
PrintScreen();
|
|
|
|
}
|
2024-04-30 17:58:44 +02:00
|
|
|
}
|
2024-04-19 19:11:46 +02:00
|
|
|
if(uiMode==2)
|
|
|
|
{
|
|
|
|
textMenu_HandleMouseMove(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2024-04-27 20:39:36 +02:00
|
|
|
return;
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function copyLocation({ pageX, pageY }) {
|
|
|
|
return { pageX, pageY };
|
|
|
|
}
|
|
|
|
|
|
|
|
function PrintNetworkLink(linkToPrint)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
//We should have passed in a working link, make sure it exists
|
|
|
|
if(linkToPrint !== null)
|
|
|
|
{
|
2024-04-27 20:39:36 +02:00
|
|
|
if(linkToPrint.SrcNic !== null && linkToPrint.DestNic !== null)
|
|
|
|
{
|
|
|
|
//console.log("printing link from " + linkToPrint.SrcNic.hostname);
|
|
|
|
sdevice = deviceFromID(linkToPrint.SrcNic.hostid);
|
|
|
|
ddevice = deviceFromID(linkToPrint.DstNic.hostid);
|
|
|
|
if(sdevice !== null && ddevice !== null)
|
|
|
|
{
|
|
|
|
//We have an existing link with two devices. Find the device locations and print
|
|
|
|
var spoint = convertXYPointToActual(newPointFromString(sdevice.location));
|
|
|
|
var dpoint = convertXYPointToActual(newPointFromString(ddevice.location));
|
|
|
|
|
|
|
|
//Make an actionstruct
|
|
|
|
var actionLine = makeLine(spoint.x, spoint.y, dpoint.x, dpoint.y);
|
|
|
|
registerActionStruct("line", actionLine, linkToPrint, null, null, generic_mouseoverHighlight);
|
|
|
|
|
|
|
|
var old
|
|
|
|
//Now we draw a line between them
|
|
|
|
MainCanvas_ctx.beginPath();
|
|
|
|
MainCanvas_ctx.moveTo(spoint.x,spoint.y);
|
|
|
|
MainCanvas_ctx.lineTo(dpoint.x,dpoint.y);
|
|
|
|
MainCanvas_ctx.stroke();
|
|
|
|
}
|
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
2024-04-27 20:39:36 +02:00
|
|
|
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function PrintAllNetworkLinks()
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
if (puzzle == null) return; //If the puzzle has not been set, exit
|
2024-04-18 00:14:07 +02:00
|
|
|
|
2024-04-30 17:58:44 +02:00
|
|
|
let index=0;
|
2024-04-19 20:33:37 +02:00
|
|
|
if(puzzle.link !== null && typeof(puzzle.link) === "object")
|
2024-04-19 19:11:46 +02:00
|
|
|
{
|
|
|
|
while (index < puzzle.link.length) {
|
|
|
|
PrintNetworkLink(puzzle.link[index]);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function PrintNetworkDevice(ToPrint)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
//We should have passed in a working device, make sure it exists
|
|
|
|
if(ToPrint !== null)
|
|
|
|
{
|
2024-04-22 20:09:44 +02:00
|
|
|
var rect = deviceRectangle(ToPrint);
|
2024-04-25 21:47:54 +02:00
|
|
|
var actionrect = makeRectangle(rect.spoint.x, rect.spoint.y, rect.width, rect.height);
|
|
|
|
|
2024-04-22 20:09:44 +02:00
|
|
|
var dname = ToPrint.mytype;
|
|
|
|
if(dname=="net_switch") dname="switch";
|
|
|
|
if(dname=="net_hub") dname="hub";
|
|
|
|
//console.log("printing device " + dname);
|
2024-04-25 21:47:54 +02:00
|
|
|
|
2024-05-10 23:03:52 +02:00
|
|
|
if (deviceHasProblem(ToPrint)) {
|
2024-05-16 01:06:48 +02:00
|
|
|
var thshape = returnHighlightShape("square", actionrect, "red", "problem", 0.2);
|
2024-06-06 22:59:59 +02:00
|
|
|
drawhighlight(thshape);
|
2024-05-16 01:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MainCanvas_ctx.drawImage(imageFromName(dname), rect.spoint.x, rect.spoint.y, rect.width, rect.height);
|
|
|
|
registerActionStruct("square", actionrect, ToPrint, device_clickOn, null, generic_mouseoverHighlight);
|
2024-05-10 23:03:52 +02:00
|
|
|
|
2024-04-22 20:09:44 +02:00
|
|
|
//Now, we see if we need to print the name, or a list of IPs..
|
|
|
|
var xpoint = rect.center.x;
|
|
|
|
var ystart = rect.epoint.y; //the bottom-most Y point
|
|
|
|
var gap = 3;
|
2024-04-22 22:32:10 +02:00
|
|
|
var delta;
|
|
|
|
var ipaddresses = ipsFromDevice(ToPrint);
|
2024-04-24 23:52:27 +02:00
|
|
|
//console.log("addresses: " + JSON.stringify(ipaddresses));
|
2024-04-22 20:09:44 +02:00
|
|
|
switch (uiDeviceInfoLevel) {
|
|
|
|
case 0:
|
|
|
|
//Do not print anything
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
//Print the name
|
|
|
|
printCenteredText(MainCanvas_ctx, ToPrint.hostname, xpoint, ystart);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2024-04-25 21:47:54 +02:00
|
|
|
//console.log("printing device " + ToPrint.hostname);
|
2024-04-22 22:32:10 +02:00
|
|
|
//Print both the name and the IP addresses
|
|
|
|
if (uiDeviceInfoLevel == 2) {
|
|
|
|
delta = printCenteredText(MainCanvas_ctx, ToPrint.hostname, xpoint, ystart) + gap;
|
|
|
|
ystart += delta / 2;
|
|
|
|
}
|
|
|
|
//print the ip addresses
|
|
|
|
for (var x = 0; x < ipaddresses.length; x++) {
|
|
|
|
//Print the IP address if the type is correct.
|
2024-04-25 21:47:54 +02:00
|
|
|
//console.log(JSON.stringify(ipaddresses[x]));
|
2024-04-22 22:32:10 +02:00
|
|
|
switch (ipaddresses[x].nictype) {
|
|
|
|
case "eth":
|
|
|
|
case "management_interface":
|
2024-04-25 21:47:54 +02:00
|
|
|
//console.log("Found a " + ipaddresses[x].nictype)
|
2024-04-22 22:32:10 +02:00
|
|
|
let mystring = ipaddresses[x].cidrip;
|
|
|
|
delta = printCenteredText(MainCanvas_ctx, mystring, xpoint, ystart);
|
|
|
|
ystart += (delta / 2);
|
|
|
|
break;
|
2024-04-30 17:58:44 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-22 20:09:44 +02:00
|
|
|
break;
|
2024-04-30 17:58:44 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
2024-05-16 01:06:48 +02:00
|
|
|
function checkDevicesForIssues()
|
2024-04-18 00:14:07 +02:00
|
|
|
{
|
2024-05-16 01:06:48 +02:00
|
|
|
return; //Doing it a different way
|
2024-04-30 17:58:44 +02:00
|
|
|
if (puzzle == null) return; //If the puzzle has not been set, exit
|
2024-04-18 00:14:07 +02:00
|
|
|
|
2024-05-10 23:03:52 +02:00
|
|
|
removeHighlightsNamed("problem");
|
2024-05-16 01:06:48 +02:00
|
|
|
//console.log("Looking for problems in devices." + puzzle.device.length);
|
|
|
|
|
|
|
|
let index = 0;
|
|
|
|
while (index < puzzle.device.length) {
|
|
|
|
if (deviceHasProblem(puzzle.device[index])) {
|
|
|
|
console.log("Found a problem. Registering it...");
|
|
|
|
var actionrect = deviceRectangle(puzzle.device[index]);
|
|
|
|
//If the help level is bigger than 0 (guessing), show which devices have problems
|
|
|
|
if (ui_helplevel > 0) {
|
|
|
|
var answer = registerHighlightShape("square", actionrect, "red", "problem", 0.2);
|
|
|
|
console.log("registered it." + JSON.stringify(answer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function PrintAllNetworkDevices()
|
|
|
|
{
|
|
|
|
if (puzzle == null) return; //If the puzzle has not been set, exit
|
2024-05-10 23:03:52 +02:00
|
|
|
|
|
|
|
let index = 0;
|
2024-04-30 17:58:44 +02:00
|
|
|
while (index < puzzle.device.length) {
|
2024-04-18 00:14:07 +02:00
|
|
|
PrintNetworkDevice(puzzle.device[index]);
|
2024-04-30 17:58:44 +02:00
|
|
|
index++;
|
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
2024-04-22 20:09:44 +02:00
|
|
|
//print centered text. We use y as the top-most y position. But we center around the x position
|
|
|
|
function printCenteredText(canvas_context, text, centerx, top_y, font = "15px serif", textcolor="black") {
|
|
|
|
var metrics = canvas_context.measureText(text);
|
|
|
|
var yHeight = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent + tmTextYGap;
|
|
|
|
var xWidth = metrics.width;
|
|
|
|
|
|
|
|
var oldfill = canvas_context.fillStyle;
|
|
|
|
var oldstroke = canvas_context.strokeStyle;
|
|
|
|
|
|
|
|
canvas_context.font = font;
|
|
|
|
canvas_context.fillStyle = textcolor;
|
|
|
|
canvas_context.strokeStyle = textcolor;
|
|
|
|
|
|
|
|
canvas_context.fillText(text, centerx - (xWidth / 2), top_y + (yHeight / 3));
|
|
|
|
|
|
|
|
//reset stuff when done
|
|
|
|
canvas_context.fillStyle = oldfill;
|
|
|
|
canvas_context.strokeStyle = oldstroke;
|
|
|
|
|
|
|
|
return yHeight; //report back how much space we used. Just in case they want it.
|
|
|
|
}
|
|
|
|
|
2024-05-01 00:38:31 +02:00
|
|
|
//print text. We use y as the top-most y position.
|
|
|
|
function printLeftJustifiedText(canvas_context, text, LeftX, top_y, font = "15px serif", textcolor = "black") {
|
|
|
|
var metrics = canvas_context.measureText(text);
|
|
|
|
var yHeight = metrics.fontBoundingBoxAscent + metrics.fontBoundingBoxDescent + tmTextYGap;
|
|
|
|
var xWidth = metrics.width;
|
|
|
|
|
|
|
|
var oldfill = canvas_context.fillStyle;
|
|
|
|
var oldstroke = canvas_context.strokeStyle;
|
|
|
|
|
|
|
|
canvas_context.font = font;
|
|
|
|
canvas_context.fillStyle = textcolor;
|
|
|
|
canvas_context.strokeStyle = textcolor;
|
|
|
|
|
|
|
|
canvas_context.fillText(text, LeftX, top_y + (yHeight / 3));
|
|
|
|
|
|
|
|
//reset stuff when done
|
|
|
|
canvas_context.fillStyle = oldfill;
|
|
|
|
canvas_context.strokeStyle = oldstroke;
|
|
|
|
|
|
|
|
return yHeight; //report back how much space we used. Just in case they want it.
|
|
|
|
}
|
|
|
|
|
2024-04-18 00:14:07 +02:00
|
|
|
function convertXYPointToActual(point)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
//We have an x and y coordinate which needs to be converted to the canvas size
|
|
|
|
var deltax = (MainCanvas.width - menuItemSize) / puzzle.width;
|
|
|
|
var deltay = MainCanvas.height / puzzle.height;
|
|
|
|
|
2024-04-18 00:14:07 +02:00
|
|
|
return newPointFromPair((point.x * deltax) + menuItemSize, point.y * deltay);
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertXYpairToActual(x,y)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
return convertXYPointToActual(newPointFromPair(x,y));
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function newPointFromPair(x,y)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
var point = {
|
2024-04-18 00:14:07 +02:00
|
|
|
'x' : Math.floor(x),
|
|
|
|
'y' : Math.floor(y)
|
|
|
|
}
|
2024-04-30 17:58:44 +02:00
|
|
|
return point;
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function newPointFromString(pointasstring)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
if(typeof(pointasstring) == "string")
|
|
|
|
{
|
2024-04-18 00:14:07 +02:00
|
|
|
var tarray=pointasstring.split(",");
|
|
|
|
return newPointFromPair(Number(tarray[0]),Number(tarray[1]));
|
2024-04-30 17:58:44 +02:00
|
|
|
}
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//return a rectangle for the device
|
|
|
|
function deviceRectangle(theDevice)
|
|
|
|
{
|
2024-04-30 17:58:44 +02:00
|
|
|
var centerpoint = convertXYPointToActual(newPointFromString(theDevice.location));
|
|
|
|
var delta = imageSize / 2;
|
2024-04-18 00:14:07 +02:00
|
|
|
|
2024-04-30 17:58:44 +02:00
|
|
|
var rect = {
|
2024-04-22 20:09:44 +02:00
|
|
|
spoint : newPointFromPair(centerpoint.x-delta, centerpoint.y-delta),
|
|
|
|
height : imageSize,
|
|
|
|
width : imageSize,
|
|
|
|
epoint : newPointFromPair(centerpoint.x + delta, centerpoint.y + delta),
|
|
|
|
center: centerpoint,
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
2024-04-30 17:58:44 +02:00
|
|
|
return rect;
|
2024-04-18 00:14:07 +02:00
|
|
|
}
|
2024-04-24 23:52:27 +02:00
|
|
|
|
|
|
|
function makeRectangle(x1, y1, deltax, deltay, offsetx = 0, offsety = 0) {
|
|
|
|
//The offset is for when we are drawing on a cached surface. It adds x or y to the point we are looking at
|
|
|
|
var struct = {
|
|
|
|
sx: x1,
|
|
|
|
sy: y1,
|
|
|
|
dx: x1 + deltax,
|
|
|
|
dy: y1 + deltay,
|
|
|
|
deltay: deltay,
|
|
|
|
deltax: deltax,
|
|
|
|
offsetx: offsetx,
|
|
|
|
offsety: offsety,
|
|
|
|
}
|
|
|
|
return struct;
|
|
|
|
}
|
|
|
|
|
2024-04-27 20:39:36 +02:00
|
|
|
function makeLine(x1, y1, x2, y2, offsetx = 0, offsety = 0) {
|
|
|
|
var linestruct = makeRectangle(x1, y1, x2 - x1, y2 - y1, offsetx, offsety);
|
|
|
|
//console.log("Creating a line: " + JSON.stringify(linestruct));
|
|
|
|
return linestruct;
|
|
|
|
}
|
|
|
|
|
2024-04-24 23:52:27 +02:00
|
|
|
//Make a structure to hold all our data
|
2024-06-01 02:12:00 +02:00
|
|
|
class actionStruct {
|
|
|
|
constructor(shapeText, shapePoints, theObject=null, funcLeftClick=null, funcRightClick=null, funcMouseover=null) {
|
|
|
|
|
|
|
|
this.shapeText= shapeText
|
|
|
|
this.shapePoints= structuredClone(shapePoints)
|
|
|
|
this.shapePoints.shapeText = shapeText;
|
|
|
|
this.theObject= theObject
|
|
|
|
this.funcLeftClick= funcLeftClick
|
|
|
|
this.funcRightClick= funcRightClick
|
|
|
|
this.funcMouseover= funcMouseover
|
2024-04-24 23:52:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function registerActionStruct(shapeText, shapePoints, theObject=null, funcLeftClick=null, funcRightClick=null, funcMouseover=null) {
|
|
|
|
//Make an object with all the data
|
2024-06-01 02:12:00 +02:00
|
|
|
var what = new actionStruct(shapeText, shapePoints, theObject, funcLeftClick, funcRightClick, funcMouseover);
|
2024-04-25 21:47:54 +02:00
|
|
|
//console.log("Pushing an action: " + shapeText);
|
2024-04-24 23:52:27 +02:00
|
|
|
//Push it onto the uiActions list
|
2024-04-27 20:39:36 +02:00
|
|
|
uiActions.unshift(what); //Put it at the beginning of the list
|
2024-04-25 21:47:54 +02:00
|
|
|
//console.log("ActionList: " + JSON.stringify(uiActions));
|
2024-04-24 23:52:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function clearActionStructs() {
|
|
|
|
uiActions = [];
|
|
|
|
}
|
|
|
|
|
2024-05-01 00:38:31 +02:00
|
|
|
function setStatus(text) {
|
|
|
|
ui_StatusText = text; //set the text.
|
|
|
|
}
|
|
|
|
|
2024-05-10 19:00:42 +02:00
|
|
|
|
|
|
|
//go through all highlights and print all of them
|
|
|
|
function printHighlights(countof="mouseover") {
|
|
|
|
var count = 0;
|
2024-05-16 01:06:48 +02:00
|
|
|
//console.log("Printing highlights. " + ui_HighlightArray.length)
|
2024-05-10 19:00:42 +02:00
|
|
|
for (var index = 0; index < ui_HighlightArray.length; index++) {
|
|
|
|
var highlight = ui_HighlightArray[index];
|
|
|
|
//console.log("trying to highlight something: " + JSON.stringify(highlight));
|
|
|
|
if (highlight.shapeName == countof) count++;
|
2024-06-06 22:59:59 +02:00
|
|
|
drawhighlight(highlight);
|
2024-05-10 19:00:42 +02:00
|
|
|
}
|
|
|
|
return countof; //the count of the item we were supposed to count
|
|
|
|
}
|
|
|
|
|
2024-06-06 23:16:01 +02:00
|
|
|
function drawhighlight(highlight, canvas = null) {
|
|
|
|
if (canvas == null)
|
|
|
|
canvas = MainCanvas_ctx;
|
|
|
|
canvas.fillStyle = highlight.shapeColor;
|
|
|
|
canvas.globalAlpha = highlight.opaciticy; //mostly transparent
|
2024-05-17 18:33:33 +02:00
|
|
|
var oldWidth;
|
2024-05-16 01:06:48 +02:00
|
|
|
if (highlight.shapeText == "square")
|
2024-06-06 23:16:01 +02:00
|
|
|
canvas.fillRect(highlight.shapePoints.sx, highlight.shapePoints.sy, highlight.shapePoints.deltax, highlight.shapePoints.deltay);
|
2024-05-16 01:06:48 +02:00
|
|
|
else if (highlight.shapeText == "line") {
|
2024-06-06 23:16:01 +02:00
|
|
|
oldWidth = canvas.lineWidth;
|
|
|
|
canvas.lineWidth += 6;
|
|
|
|
canvas.strokeStyle = highlight.shapeColor;
|
|
|
|
canvas.beginPath();
|
|
|
|
canvas.moveTo(highlight.shapePoints.sx, highlight.shapePoints.sy);
|
|
|
|
canvas.lineTo(highlight.shapePoints.dx, highlight.shapePoints.dy);
|
|
|
|
canvas.stroke();
|
|
|
|
canvas.lineWidth = oldWidth;
|
|
|
|
canvas.strokeStyle = "black";
|
2024-05-16 01:06:48 +02:00
|
|
|
}
|
2024-05-17 18:33:33 +02:00
|
|
|
else if (highlight.shapeText == "selectbox") {
|
|
|
|
//console.log("Printing a selectbox");
|
2024-06-06 23:16:01 +02:00
|
|
|
canvas.fillStyle = "green";
|
|
|
|
oldWidth = canvas.lineWidth;
|
|
|
|
canvas.lineWidth += 2;
|
|
|
|
canvas.strokeStyle = "green";
|
|
|
|
canvas.beginPath();
|
|
|
|
canvas.moveTo(highlight.shapePoints.sx, highlight.shapePoints.sy);
|
|
|
|
canvas.lineTo(highlight.shapePoints.dx, highlight.shapePoints.sy);
|
|
|
|
canvas.lineTo(highlight.shapePoints.dx, highlight.shapePoints.dy);
|
|
|
|
canvas.lineTo(highlight.shapePoints.sx, highlight.shapePoints.dy);
|
|
|
|
canvas.lineTo(highlight.shapePoints.sx, highlight.shapePoints.sy);
|
|
|
|
canvas.stroke();
|
|
|
|
canvas.lineWidth = oldWidth;
|
|
|
|
canvas.strokeStyle = "black";
|
2024-05-17 18:33:33 +02:00
|
|
|
}
|
2024-06-06 23:16:01 +02:00
|
|
|
canvas.globalAlpha = 1.0; //reset
|
|
|
|
canvas.fillStyle = "black"; //reset
|
2024-05-16 01:06:48 +02:00
|
|
|
}
|
|
|
|
|
2024-06-06 23:16:01 +02:00
|
|
|
//We use drawhighlight to draw one-off shapes
|
|
|
|
function drawshape( shape, rect, color, opaciticy = 0.4, canvas = null) {
|
|
|
|
if (canvas == null)
|
|
|
|
canvas = MainCanvas_ctx;
|
|
|
|
var tmp_queryhighlight = returnHighlightShape(shape, rect, color, "none", opaciticy);
|
|
|
|
drawhighlight(tmp_queryhighlight, canvas);
|
|
|
|
}
|
2024-05-16 01:06:48 +02:00
|
|
|
|
2024-05-10 19:00:42 +02:00
|
|
|
function countHighlightsNamed(countof = "mouseover") {
|
|
|
|
var count = 0;
|
|
|
|
for (var index = 0; index < ui_HighlightArray.length; index++) {
|
|
|
|
if (ui_HighlightArray[index].shapeName == countof)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return countof; //the count of the item we were supposed to count
|
|
|
|
}
|
|
|
|
|
2024-05-16 01:06:48 +02:00
|
|
|
function returnHighlightShape(shapeText, shapePoints, shapeColor, shapeName, opaciticy = 0.4) {
|
2024-05-10 19:00:42 +02:00
|
|
|
//Create a highlight record with the needed info
|
|
|
|
var newhighlight = {
|
|
|
|
shapeText: shapeText,
|
|
|
|
shapePoints: structuredClone(shapePoints),
|
|
|
|
shapeColor: shapeColor,
|
|
|
|
shapeName: shapeName, //Used when we remove them later
|
|
|
|
opaciticy, opaciticy,
|
|
|
|
}
|
2024-05-16 01:06:48 +02:00
|
|
|
return newhighlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//There may be multiple things
|
|
|
|
function registerHighlightShape(shapeText, shapePoints, shapeColor, shapeName, opaciticy=0.4) {
|
|
|
|
//Create a highlight record with the needed info
|
|
|
|
var newhighlight = returnHighlightShape(shapeText, structuredClone(shapePoints), shapeColor, shapeName, opaciticy)
|
2024-05-10 19:00:42 +02:00
|
|
|
//console.log("registering a highlight: " + JSON.stringify(newhighlight));
|
|
|
|
//Add it to the list of highlights.
|
|
|
|
ui_HighlightArray.unshift(newhighlight);
|
|
|
|
return newhighlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeHighlightsNamed(shapeName) {
|
|
|
|
//console.log("Trying to remove " + shapeName + " in array of " + ui_HighlightArray.length);
|
2024-05-10 19:23:10 +02:00
|
|
|
for (var index = ui_HighlightArray.length; index >= 0; index--) {
|
2024-05-10 19:00:42 +02:00
|
|
|
if (ui_HighlightArray[index] == null) { }
|
|
|
|
else {
|
|
|
|
//console.log("Comparing " + shapeName + " in " + JSON.stringify(ui_HighlightArray[index]));
|
|
|
|
if (ui_HighlightArray[index].shapeName == shapeName) {
|
|
|
|
//console.log("removing " + shapeName + " at index:" + index + " " + ui_HighlightArray.length);
|
|
|
|
ui_HighlightArray.splice(index, 1); //remove it if found
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function findHighlightsNamed(shapeName) {
|
2024-05-10 19:23:10 +02:00
|
|
|
for (var index = ui_HighlightArray.length; index >= 0; index--) {
|
|
|
|
if (ui_HighlightArray[index] == null) { }
|
|
|
|
else {
|
|
|
|
if (ui_HighlightArray[index].shapeName == shapeName)
|
|
|
|
return ui_HighlightArray[index];
|
|
|
|
}
|
2024-05-10 19:00:42 +02:00
|
|
|
}
|
|
|
|
return null; //null if not there
|
|
|
|
}
|
|
|
|
|
2024-04-25 21:47:54 +02:00
|
|
|
//This takes generic information for us to highlight the background
|
|
|
|
function generic_mouseoverHighlight(point, actionrec) {
|
|
|
|
//console.log("Found highlight " + JSON.stringify(actionrec));
|
|
|
|
//The point is the place where the mouse is, but the actionrec.shapePoints is the rectangle (or shape) we want to highlight
|
2024-05-10 19:00:42 +02:00
|
|
|
//var oldrec = structuredClone(ui_highlightRect);
|
|
|
|
var oldrec = findHighlightsNamed("mouseover");
|
|
|
|
var newrec = null;
|
|
|
|
//console.log("setting highlights to:" + JSON.stringify(actionrec));
|
|
|
|
removeHighlightsNamed("mouseover");
|
2024-04-25 21:47:54 +02:00
|
|
|
if (actionrec.shapeText == "square") {
|
2024-05-10 19:00:42 +02:00
|
|
|
//ui_highlightRect = structuredClone(actionrec.shapePoints);
|
|
|
|
//ui_highlightRect.shapeText = "square";
|
|
|
|
newrec = registerHighlightShape("square", actionrec.shapePoints, "white", "mouseover"); //opacity is default
|
2024-04-25 21:47:54 +02:00
|
|
|
//console.log("setting highlights to:" + JSON.stringify(ui_highlightRect));
|
|
|
|
}
|
2024-04-27 20:39:36 +02:00
|
|
|
if (actionrec.shapeText == "line") {
|
2024-05-10 19:00:42 +02:00
|
|
|
//ui_highlightRect = structuredClone(actionrec.shapePoints);
|
|
|
|
//ui_highlightRect.shapeText = "line";
|
|
|
|
newrec = registerHighlightShape("line", actionrec.shapePoints, "white", "mouseover"); //opacity is default
|
2024-04-27 20:39:36 +02:00
|
|
|
//console.log("setting highlights to:" + JSON.stringify(ui_highlightRect));
|
|
|
|
}
|
2024-05-10 19:00:42 +02:00
|
|
|
if (JSON.stringify(newrec) === JSON.stringify(oldrec)) {
|
2024-04-27 20:39:36 +02:00
|
|
|
//they are the same. Nothing to do
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PrintScreen(); //two different areas. Need to print the screen
|
2024-05-01 00:38:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function device_clickOn(point, actionrec) {
|
|
|
|
if (actionrec.theObject !== null && actionrec.theObject.name !== null) {
|
2024-05-17 18:33:33 +02:00
|
|
|
ui_selectRect = structuredClone(actionrec.shapePoints);
|
|
|
|
//console.log("Setting select rect:" + JSON.stringify(ui_selectRect));
|
2024-05-17 23:37:31 +02:00
|
|
|
var ipaddresses = ipsFromDevice(actionrec.theObject);
|
|
|
|
var additional = "";
|
|
|
|
for (var x = 0; x < ipaddresses.length; x++) {
|
|
|
|
//Print the IP address if the type is correct.
|
|
|
|
//console.log(JSON.stringify(ipaddresses[x]));
|
|
|
|
switch (ipaddresses[x].nictype) {
|
|
|
|
case "eth":
|
|
|
|
case "management_interface":
|
|
|
|
//console.log("Found a " + ipaddresses[x].nictype)
|
|
|
|
additional += " " + ipaddresses[x].cidrip;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deviceHasProblem(actionrec.theObject)) {
|
|
|
|
//If we know nothing, we change nothing
|
|
|
|
if (ui_helplevel > 0) {
|
|
|
|
if (ui_helplevel == 1) additional = " " + translator.getStr("NT_TstDscriptProblem");
|
|
|
|
else {
|
|
|
|
//here we get all the problem statements and combine them
|
|
|
|
errors = returnProblemStrings(actionrec.theObject);
|
|
|
|
additional = " " + errors.join(' - ');
|
2024-06-01 02:12:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-17 23:37:31 +02:00
|
|
|
|
|
|
|
setStatus(actionrec.theObject.hostname + additional);
|
2024-05-01 00:38:31 +02:00
|
|
|
//We probably do not want to do printecreen here, but we are doing it here now...
|
|
|
|
PrintScreen();
|
|
|
|
}
|
2024-05-17 18:06:07 +02:00
|
|
|
}
|
|
|
|
|
2024-05-18 00:06:03 +02:00
|
|
|
function Language(lang = null) {
|
2024-05-17 18:06:07 +02:00
|
|
|
var __construct = function () {
|
2024-05-18 00:06:03 +02:00
|
|
|
if (lang == null) {
|
2024-05-17 18:06:07 +02:00
|
|
|
lang = "en";
|
|
|
|
}
|
2024-05-18 00:06:03 +02:00
|
|
|
//console.log("Defining language:" + lang);
|
|
|
|
ui_language = lang;
|
2024-05-17 18:06:07 +02:00
|
|
|
return;
|
|
|
|
}()
|
|
|
|
|
|
|
|
this.getStr = function (str, defaultStr) {
|
2024-05-18 00:06:03 +02:00
|
|
|
var toget = 'language.' + ui_language + "." + str + ".value";
|
2024-05-17 23:37:31 +02:00
|
|
|
//console.log("Translating: " + toget);
|
|
|
|
var retStr = eval(toget);
|
2024-05-17 18:06:07 +02:00
|
|
|
if (typeof retStr != 'undefined') {
|
|
|
|
return retStr;
|
|
|
|
} else {
|
|
|
|
if (typeof defaultStr != 'undefined') {
|
|
|
|
return defaultStr;
|
|
|
|
} else {
|
2024-05-17 23:37:31 +02:00
|
|
|
toget = "language.en." + str;
|
|
|
|
//console.log("First translation failed, falling back to en: " + toget);
|
|
|
|
return eval(toget);
|
2024-05-17 18:06:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-24 23:52:27 +02:00
|
|
|
}
|