oi-metrology/Static/js/wafer-counter.js
2024-06-14 16:51:30 -07:00

106 lines
2.8 KiB
JavaScript

var _count = -1;
var _apiUrl = null;
function getUrlParameter(param) {
var pageURL = window.location.search.substring(1),
urlVariables = pageURL.split('&'),
parameterName,
i;
for (i = 0; i < urlVariables.length; i++) {
parameterName = urlVariables[i].split('=');
if (parameterName[0] === param) {
return parameterName[1] === undefined ? true : decodeURIComponent(parameterName[1]);
}
}
return false;
}
function setSlots(slotMap) {
var slots = slotMap.split("");
if (slots.length !== 25)
throw Error;
$('.slot').each(function (index) {
if (slots[index] === '0')
$(this).addClass('waferSlotEmpty').removeClass('waferSlotPresent');
else if (slots[index] === '1')
$(this).addClass('waferSlotPresent').removeClass('waferSlotEmpty');
else
throw Error;
});
}
function setValues(data) {
if (!data)
clearMap();
else {
$('#waferCount').val(data.total);
setSlots(data.slotMap);
$('#lastDateTime').text(new Date().toLocaleString());
}
}
function clearText() {
$("#lot").val('');
$("#lot").show();
$("#lot").focus();
}
function clearMap() {
setSlots('0000000000000000000000000');
}
function poll() {
if (_count >= _stop) {
_count = -1;
$("#Connect").show();
$('#lastDateTime').hide();
}
else if (_count > -1) {
_count++;
$.get(_apiUrl + $("#toolId").val() + '/last-quantity-and-slot-map/?area=' + $("#operation").val(), function (data) {
setValues(data);
}).fail(function () {
ShowErrorMessage("Error");
});
}
}
function save() {
$.get(_apiUrl + $("#toolId").val() + '/last-quantity-and-slot-map-with-text/?area=' + $("#operation").val() + '&text=' + $("#lot").val(), function (data) {
setValues(data);
}).fail(function () {
ShowErrorMessage("Error");
});
}
function initWaferCounter(apiUrl) {
_apiUrl = apiUrl;
$("#Save").click(function () {
save();
});
$("#Clear").click(function () {
clearText();
clearMap();
});
$("#Connect").click(function () {
$("#Connect").hide();
$('#lastDateTime').show();
_count = 0;
clearMap();
});
// http://localhost:5051/wafer-counter.html?interval=1000&stop=3&toolId=8INCH&operation=EPP-East&a=1
$('#waferCount').val('0');
$('#lastDateTime').hide();
var stop = getUrlParameter('stop');
_stop = !stop ? 10 : parseInt(stop);
var interval = getUrlParameter('interval');
$("#toolId").val(getUrlParameter('toolId'));
$("#operation").val(getUrlParameter('operation'));
setInterval(function () {
poll();
}, !interval ? 10000 : parseInt(interval));
clearText();
clearMap();
}