Skip to content
Snippets Groups Projects
Commit 640c0c80 authored by Lucio Zambon's avatar Lucio Zambon
Browse files

Add new file

parent 5c2f83de
No related branches found
No related tags found
No related merge requests found
bl2d.js 0 → 100644
// jshint esversion: 6
const data_color = {};
const data_value = {};
function updateBl(blName) {
fetch('./updater.php?read&filename=elettrabl.1000.'+blName).then((response) => {return response.text();}).then((data) => {
const values = data.split(';');
for (let j=0; j<data_color[blName].length; j++) {
// console.log("$('#"+data_color[blName][j][0]+"').css('fill',values[data_color[blName][j][2]]=='1'? 'red': 'limegreen')", data_color[blName][j][2], values[data_color[blName][j][2]]);
$('#'+data_color[blName][j][0].replace(' ', '_').replace('.', '_')).css('fill', values[data_color[blName][j][2]]=='1'? 'red': 'limegreen');
}
for (let j=0; j<data_value[blName].length; j++) {
const id = data_value[blName][j][0].replace(' ', '_').replace('.', '_')+'value';
if ($('#'+id)[0]) $('#'+id)[0].innerHTML = '';
}
for (let j=0; j<data_value[blName].length; j++) {
const id = data_value[blName][j][0].replace(' ', '_').replace('.', '_')+'value';
console.log("$('#"+id+"')[0].innerHTML", data_value[blName][j][2], values[data_value[blName][j][2][0]]);
for (let i=0; i<data_value[blName][j][2].length; i++) {
if ($('#'+id)[0]) $('#'+id)[0].innerHTML = $('#'+id)[0].innerHTML+' '+values[data_value[blName][j][2][i]];
}
}
// console.log('initBl()', data);
});
}
function initBl(blName) {
fetch('./updater.php?read&filename=elettrabl.1000.'+blName+'.src').then((response) => {return response.text();}).then((data) => {
const names = data.split(',');
for (let i=0; i<names.length; i++) {
for (let j=0; j<data_color[blName].length; j++) {
if (data_color[blName][j][1] == names[i]) data_color[blName][j].push(i);
}
for (let j=0; j<data_value[blName].length; j++) {
if (typeof data_value[blName][j][2]=='undefined') data_value[blName][j][2] = [];
for (let k=0; k<data_value[blName][j][1].length; k++) {
if (data_value[blName][j][1][k] == names[i]) {
data_value[blName][j][2].push(i);
console.log(i, j, names[i], data_value[blName][j][1][k], data_value[blName]);
}
}
}
}
console.log('initBl()', data.split(','), data_color, data_value);
updateBl(blName);
colorReader = setInterval(updateBl, 5000, blName);
});
}
function bl2d(lattice) {
// console.log('bl2d');
for (let facility in lattice) {
if (facility == 'conf') continue;
data_color[facility] = [];
data_value[facility] = [];
const sections = lattice[facility].sections;
for (let section=0; section< sections.length; section++) {
const components = sections[section].components;
// console.log(components, facility, section, sections[section]);
if (components) for (let i=0; i<components.length; i++) {
console.log(i, components[i]);
if (components[i]['data-color']) data_color[facility].push([components[i].name, components[i]['data-color']]);
if (components[i]['data-value']) {
data_value[facility].push([components[i].name, components[i]['data-value']]);
const id = components[i].name.replace(' ', '_')+'value';
console.log("$('#"+id+")[0].style.display'");
if ($('#'+id)[0]) $('#'+id)[0].style.display = 'block';
}
}
}
if (data_color[facility].length > 0) initBl(facility);
}
// console.log('data_color', data_color);
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment