Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
fix update issue
Browse files Browse the repository at this point in the history
Signed-off-by: Musilah <nataleigh.nk@gmail.com>
  • Loading branch information
Musilah committed Mar 20, 2024
1 parent cb0b8fa commit f723bb1
Showing 1 changed file with 57 additions and 33 deletions.
90 changes: 57 additions & 33 deletions ui/web/static/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,20 @@ class GaugeChart extends Echart {
};
gaugeChart.setOption(option)
getData(gaugeChart);
var chartData = {
channel: "${this.chartData.channel}",
publisher: "${this.chartData.thing}",
name: "${this.chartData.valueName}",
};
async function getData(gaugeChart) {
getData(gaugeChart, chartData);
async function getData(gaugeChart, chartData) {
try {
const response = await fetch(
"${pathPrefix}/data?channel=${this.chartData.channel}"+
"&publisher=${this.chartData.thing}"+
"&name=${this.chartData.valueName}"+
"${pathPrefix}/data?channel=" + chartData.channel +
"&publisher=" + chartData.publisher +
"&name=" + chartData.name +
"&limit=1",
);
if (response.ok) {
Expand All @@ -692,15 +698,15 @@ class GaugeChart extends Echart {
],
});
} else {
console.error("HTTP request failed with status: ", response.status);
// Handle response errors
console.error("HTTP request failed with status: ", response.status);
}
setTimeout(function () {
getData(gaugeChart);
}, 20000);
} catch (error) {
// Handle fetch or other errors
console.error("Failed to fetch gauge data: ", error);
// Retry after a couple of seconds
setTimeout(function () {
getData(gaugeChart);
getData(gaugeChart, chartData);
}, 20000);
}
};`;
Expand Down Expand Up @@ -1094,6 +1100,7 @@ class MultiBarChart extends Echart {
class MultiGaugeChart extends Echart {
constructor(chartData, widgetID) {
super(widgetID, chartData);
this.multiGaugeChart = null;
this.Script = this.#generateScript();
}

Expand Down Expand Up @@ -1186,7 +1193,8 @@ class MultiGaugeChart extends Echart {
gaugeLabel: gaugeLabel,
name: '${this.chartData.valueName}',
colours: ${colours},
}
};
getData(multiGaugeChart, chartData);
async function getData(multiGaugeChart, chartData) {
Expand All @@ -1198,6 +1206,8 @@ class MultiGaugeChart extends Echart {
const response = await fetch(url);
if (response.ok) {
const data = await response.json();
console.log("response: ", response.url);
console.log("data: ", data.messages);
if (data.messages && data.messages.length > 0) {
gaugeData[i].value = data.messages[0].value;
} else {
Expand Down Expand Up @@ -1236,7 +1246,7 @@ class MultiGaugeChart extends Echart {
}catch (error) {
console.error("Failed to fetch gauge data: ", error);
setTimeout(function () {
getData(multiGaugeChart);
getData(multiGaugeChart, chartData);
}, 20000);
}
};`;
Expand Down Expand Up @@ -1536,15 +1546,22 @@ class SpeedGaugeChart extends Echart {
};
speedGaugeChart.setOption(option)
getData(speedGaugeChart);
var chartData = {
channel: "${this.chartData.channel}",
publisher: "${this.chartData.thing}",
name: "${this.chartData.valueName}",
unit: "${this.chartData.valueUnit}",
};
getData(speedGaugeChart, chartData);
async function getData(speedGaugeChart) {
async function getData(speedGaugeChart, chartData) {
try {
const response = await fetch(
"${pathPrefix}/data?channel=${this.chartData.channel}"+
"&publisher=${this.chartData.thing}"+
"&name=${this.chartData.valueName}"+
"&unit=${this.chartData.valueUnit}"+
"${pathPrefix}/data?channel=" + chartData.channel +
"&publisher=" + chartData.publisher +
"&name=" + chartData.name +
"&unit=" + chartData.unit +
"&limit=1",
);
if (response.ok) {
Expand All @@ -1563,15 +1580,15 @@ class SpeedGaugeChart extends Echart {
],
});
} else {
// Handle response errors
console.error("HTTP request failed with status: ", response.status);
}
setTimeout(function () {
getData(speedGaugeChart);
}, 20000);
} catch (error) {
// Handle fetch or other errors
console.error("Failed to fetch gauge data: ", error);
// Retry after a couple of seconds
setTimeout(function () {
getData(speedGaugeChart);
getData(speedGaugeChart, chartData);
}, 20000);
}
};`;
Expand Down Expand Up @@ -1863,16 +1880,23 @@ class TempGaugeChart extends Echart {
]
};
tempGaugeChart.setOption(option)
getData(tempGaugeChart);
tempGaugeChart.setOption(option);
var chartData = {
channel: "${this.chartData.channel}",
publisher: "${this.chartData.thing}",
name: "${this.chartData.valueName}",
unit: "${this.chartData.valueUnit}",
};
getData(tempGaugeChart, chartData);
async function getData(tempGaugeChart) {
async function getData(tempGaugeChart, chartData) {
try {
const response = await fetch(
"${pathPrefix}/data?channel=${this.chartData.channel}"+
"&publisher=${this.chartData.thing}"+
"&name=${this.chartData.valueName}"+
"&unit=${this.chartData.valueUnit}"+
"${pathPrefix}/data?channel=" + chartData.channel +
"&publisher=" + chartData.publisher +
"&name=" + chartData.name +
"&unit=" + chartData.unit +
"&limit=1",
);
if (response.ok) {
Expand All @@ -1899,15 +1923,15 @@ class TempGaugeChart extends Echart {
],
});
} else {
// Handle response errors
console.error("HTTP request failed with status: ", response.status);
}
setTimeout(function () {
getData(tempGaugeChart);
}, 20000);
} catch (error) {
// Handle fetch or other errors
console.error("Failed to fetch gauge data: ", error);
// Retry after a couple of seconds
setTimeout(function () {
getData(tempGaugeChart);
getData(tempGaugeChart, chartData);
}, 20000);
}
};`;
Expand Down

0 comments on commit f723bb1

Please sign in to comment.