CurrStatVDP/Diagram-Canvas/index.js

125 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//Global Params
var htmlDateClient = document.getElementById("DateClient");
var htmlDateServer = document.getElementById("DateServer");
var htmlDateSynch = document.getElementById("DateSynch");
var canvas = document.getElementsByTagName("canvas")[0];
var ctx = canvas.getContext("2d");
var diagram = new Diagram(0, 0, canvas.width, canvas.height);
var update_button = document.getElementById("Update_Button");
//Global Params
//Start Show Date Now
function FNL(a, b) { for (var d = "" + a; d.length < b;)d = "0" + d; return d }
function DateToString(date) { return date.getFullYear() + "." + FNL(date.getMonth() + 1, 2) + "." + FNL(date.getDate(), 2) + " " + FNL(date.getHours(), 2) + ":" + FNL(date.getMinutes(), 2) + ":" + FNL(date.getSeconds(), 2); }
var dateClient = null;
var dateServer = null;
function PrintDateNow() {
var tmp = new Date();
htmlDateClient.innerHTML = DateToString(tmp);
if (dateServer !== null)
if (dateClient !== null)
tmp =
htmlDateServer.innerHTML = timeNow;
htmlDateSynch.innerHTML = timeNow;
setTimeout(PrintDateNow, 1000);
}
PrintDateNow();
/*
//End Show Date Now
//Start Resize Canvas
function Resize() {
if (window.innerWidth > window.innerHeight) {
canvas.height = window.innerHeight - 20
- document.getElementById("First_Head").offsetHeight
- document.getElementById("Second_Head").offsetHeight
- document.getElementById("Third_Head").offsetHeight;
canvas.width = document.getElementById("Canvas_Body").offsetWidth;
diagramStove.Rotate = 0;
diagramStove.RectParam(0, 0, canvas.width, canvas.height);
}
else {
canvas.height = diagramStove.ProcessCount() * 25;
canvas.width = document.getElementById("Canvas_Body").offsetWidth;
diagramStove.Rotate = 1;
diagramStove.RectParam(0, 0, canvas.height, canvas.width);
}
ctx = canvas.getContext("2d");
diagramStove.Print(ctx);
}
window.addEventListener("load", Resize, false);
window.addEventListener("resize", Resize, false);
//End Resize Canvas
//Start Update Status
diagramStove.BuildDefault();
function UpdateStatus() {
var xhr = new XMLHttpRequest();
xhr.open('POST', 'getinfo', true);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) return;
if (xhr.status != 200) {
document.getElementById("Error_Message").innerHTML = "Не удается установить соединение";
$("#Error_Border").show();
$("#Update_Button").show();
return;
}
else
$("#Error_Border").hide();
var Pech = JSON.parse(xhr.responseText);
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 1; i <= diagramStove.ProcessCount(); i++) {
diagramStove.ChangeStatBlink(i, Pech[i].Bstatus);
diagramStove.ChangeStatProc(i, Pech[i].Pstatus);
diagramStove.ChangeStartDate(i, ConvDate(Pech[i].Start));
diagramStove.ChangeEndDate(i, ConvDate(Pech[i].EndTeor));
}
var b = ConvDate(Pech[0].DateNow);
dateUpdateHTML.innerHTML =
b.getFullYear() + "." +
FNL(b.getMonth() + 1, 2) + "." +
FNL(b.getDate(), 2) + " " +
FNL(b.getHours(), 2) + ":" +
FNL(b.getMinutes(), 2) + ":" +
FNL(b.getSeconds(), 2);
if (Math.abs(b - new Date()) > 60000) {
document.getElementById("Error_Message").innerHTML = "Разница между системным и серверным временем " + Math.floor(Math.abs(b - new Date()) / 1000) + " сек";
$("#Error_Border").show();
$("#Update_Button").hide();
}
else
$("#Error_Border").hide();
setTimeout(UpdateStatus, 60000);
diagramStove.Print(ctx);
}
}
UpdateStatus();
function PrintCycle() {
diagramStove.Print(ctx);
setTimeout(PrintCycle, 1000);
}
PrintCycle();
function ConvDate(a) {
a = a.split(".")[0].split("T");
var d = a[0].split("-");
var h = a[1].split(":");
var date = new Date(d[0], parseInt(d[1]) - 1, d[2], h[0], h[1], h[2]);
return date;
}
update_button.onclick = function () {
UpdateStatus();
}
//End Update Status
*/