CurrStatVDP/Diagram-Canvas/index.js

168 lines
4.9 KiB
JavaScript
Raw Normal View History

2021-05-18 01:02:10 +05:00
//Global Params
var htmlDateClient = document.getElementById("DateClient");
var htmlDateServer = document.getElementById("DateServer");
var htmlDateSynch = document.getElementById("DateSynch");
2021-05-18 09:14:14 +05:00
var htmlErrMSG = document.getElementById("Error_Message");
2021-05-18 01:02:10 +05:00
var canvas = document.getElementsByTagName("canvas")[0];
var ctx = canvas.getContext("2d");
var diagram = new Diagram(0, 0, canvas.width, canvas.height);
2021-05-18 09:14:14 +05:00
diagram.BuildDefault();
diagram.Cycle(true);
2021-05-18 01:02:10 +05:00
var update_button = document.getElementById("Update_Button");
//Global Params
2021-05-18 09:14:14 +05:00
//Show Date Now \/ \/ \/
2021-05-18 01:02:10 +05:00
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;
2021-05-18 09:14:14 +05:00
var dateSynch = null;
2021-05-18 01:02:10 +05:00
function PrintDateNow() {
2021-05-18 09:14:14 +05:00
var dn = new Date();
if (dateServer !== null && dateClient !== null)
dateServer.setMilliseconds(dateServer.getMilliseconds() + (dn - dateClient));
2021-05-18 01:02:10 +05:00
2021-05-18 09:14:14 +05:00
dateClient = dn;
htmlDateClient.innerHTML = DateToString(dateClient);
if (dateServer != null)
htmlDateServer.innerHTML = DateToString(dateServer);
if (dateSynch !== null)
htmlDateSynch.innerHTML = DateToString(dateSynch);
2021-05-18 01:02:10 +05:00
setTimeout(PrintDateNow, 1000);
}
2021-05-18 09:14:14 +05:00
function updateDateServer(date) {
if (typeof date.getMonth === 'function') {
dateClient = null;
dateServer = date;
} else
dateServer = null;
}
function updateDateSynch(date) {
if (typeof date.getMonth === 'function') {
dateSynch = date;
} else
dateSynch = null;
}
2021-05-18 01:02:10 +05:00
PrintDateNow();
2021-05-18 09:14:14 +05:00
//Show Date Now /\ /\ /\
2021-05-18 01:02:10 +05:00
2021-05-18 09:14:14 +05:00
//Resize Canvas \/ \/ \/
2021-05-18 01:02:10 +05:00
function Resize() {
2021-05-18 09:14:14 +05:00
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;
diagram.Rotate(false);
diagram.RectParam(0.5, 0.5, canvas.width - 1, canvas.height - 1);
}
else {
canvas.height = diagram.ProcCount() * 25;
canvas.width = document.getElementById("Canvas_Body").offsetWidth;
diagram.Rotate(true);
diagram.RectParam(0.5, 0.5, canvas.width - 1, canvas.height - 1);
}
ctx = canvas.getContext("2d");
diagram.Print(ctx);
2021-05-18 01:02:10 +05:00
}
window.addEventListener("load", Resize, false);
window.addEventListener("resize", Resize, false);
2021-05-18 09:14:14 +05:00
//Resize Canvas /\ /\ /\
//Autoprint diagram \/ \/ \/
function PrintCycle() {
diagram.Print(ctx);
setTimeout(PrintCycle, 1000);
}
PrintCycle();
//Autoprint diagram /\ /\ /\
2021-05-18 01:02:10 +05:00
2021-05-18 09:14:14 +05:00
//Update Status \/ \/ \/
2021-05-18 01:02:10 +05:00
function UpdateStatus() {
2021-05-18 09:14:14 +05:00
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://test1.mbucb.ru/api/currcycles', true);
xhr.send();
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) return;
if (xhr.status != 200) {
htmlErrMSG.innerHTML = "Не удается установить соединение";
$("#Error_Border").show();
$("#Update_Button").show();
return;
2021-05-18 01:02:10 +05:00
}
2021-05-18 09:14:14 +05:00
else
$("#Error_Border").hide();
var data = JSON.parse(xhr.responseText);
if (data.currTime === undefined) {
htmlErrMSG.innerHTML = "Ошибка в полученных данных";
$("#Error_Border").show();
$("#Update_Button").show();
return;
}
updateDateSynch(new Date());
updateDateServer(new Date(data.currTime));
2021-05-18 01:02:10 +05:00
2021-05-18 09:14:14 +05:00
/*
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();
*/
diagram.Print();
setTimeout(UpdateStatus, 60 * 1000);
}
2021-05-18 01:02:10 +05:00
}
2021-05-18 09:14:14 +05:00
UpdateStatus();
2021-05-18 01:02:10 +05:00
function ConvDate(a) {
2021-05-18 09:14:14 +05:00
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;
2021-05-18 01:02:10 +05:00
}
update_button.onclick = function () {
2021-05-18 09:14:14 +05:00
UpdateStatus();
2021-05-18 01:02:10 +05:00
}
2021-05-18 09:14:14 +05:00
//Update Status /\ /\ /\
2021-05-18 01:02:10 +05:00
//End Update Status
2021-05-18 09:14:14 +05:00
/*
//End Show Date Now
2021-05-18 01:02:10 +05:00
*/