Update custom.html
parent
556b7838ce
commit
137b9feaaa
|
|
@ -3,47 +3,44 @@
|
||||||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>Data Tesst 2</p>
|
<p>Data Test 2</p>
|
||||||
<script src="../../core/lib/customize.js"></script>
|
<script src="../../core/lib/customize.js"></script>
|
||||||
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||||
<div id="storageInfo"></div>
|
<div id="storageInfo"></div>
|
||||||
<div id="piechart" style="width: 900px; height: 500px;"></div>
|
<div id="piechart" style="width: 900px; height: 500px;"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
let globalApps = [];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Called when we know what device we're using
|
|
||||||
function onInit(device) {
|
function onInit(device) {
|
||||||
Util.showModal("Reading Storage...");
|
Util.showModal("Reading Storage...");
|
||||||
Puck.eval(`require("Storage").list(/\\.info$/).map(appInfoName => {
|
Puck.eval(`require("Storage").list(/\\.info$/).map(appInfoName => {
|
||||||
let appInfo = require("Storage").readJSON(appInfoName,1)||{};
|
let appInfo = require("Storage").readJSON(appInfoName,1)||{};
|
||||||
//print(appInfoName, appInfo);
|
|
||||||
var fileSize = 0, dataSize = 0;
|
var fileSize = 0, dataSize = 0;
|
||||||
appInfo.files.split(",").forEach(f => fileSize += require("Storage").read(f).length);
|
appInfo.files.split(",").forEach(f => fileSize += require("Storage").read(f).length);
|
||||||
var data = (appInfo.data||"").split(";");
|
var data = (appInfo.data||"").split(";");
|
||||||
function wildcardToRegexp(wc) {
|
function wildcardToRegexp(wc) {
|
||||||
return new RegExp("^"+wc.replaceAll(".","\\\\.").replaceAll("?",".*")+"$");
|
return new RegExp("^"+wc.replaceAll(".","\\\\.").replaceAll("?",".*")+"$");
|
||||||
}
|
}
|
||||||
// normal files
|
|
||||||
if (data[0]) data[0].split(",").forEach(wc => {
|
if (data[0]) data[0].split(",").forEach(wc => {
|
||||||
require("Storage").list(wildcardToRegexp(wc), {sf:false}).forEach(f => {
|
require("Storage").list(wildcardToRegexp(wc), {sf:false}).forEach(f => {
|
||||||
dataSize += require("Storage").read(f).length
|
dataSize += require("Storage").read(f).length
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// storage files
|
|
||||||
if (data[1]) data[1].split(",").forEach(wc => {
|
if (data[1]) data[1].split(",").forEach(wc => {
|
||||||
require("Storage").list(wildcardToRegexp(wc), {sf:true}).forEach(f => {
|
require("Storage").list(wildcardToRegexp(wc), {sf:true}).forEach(f => {
|
||||||
dataSize += require("Storage").open(f,"r").getLength();
|
dataSize += require("Storage").open(f,"r").getLength();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return [appInfo.id, fileSize, dataSize];
|
return [appInfo.id, fileSize, dataSize];
|
||||||
})`, function(apps) {
|
})`, function(apps) {
|
||||||
apps.sort((a,b) => (b[1]+b[2]) - (a[1]+a[2]));
|
|
||||||
Util.hideModal();
|
Util.hideModal();
|
||||||
console.log(apps);
|
globalApps = apps.sort((a,b) => (b[1]+b[2]) - (a[1]+a[2]));
|
||||||
|
|
||||||
|
if (apps.length === 0) {
|
||||||
|
document.getElementById("storageInfo").innerHTML = "<p>No apps found</p>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("storageInfo").innerHTML = `
|
document.getElementById("storageInfo").innerHTML = `
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
|
|
@ -65,33 +62,33 @@
|
||||||
</tr>`).join("")}
|
</tr>`).join("")}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>`;
|
</table>`;
|
||||||
if (apps.length === 0) {
|
|
||||||
document.getElementById("storageInfo").innerHTML = "<p>No apps found</p>";
|
drawChart(); // Now safe to call
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
function drawChart() {
|
function drawChart() {
|
||||||
|
if (globalApps.length === 0) return;
|
||||||
|
|
||||||
var data = google.visualization.arrayToDataTable([
|
const chartData = [
|
||||||
${apps.map(app => `
|
['App', 'Total Size']
|
||||||
[${app[0]},${app[1]+app[2]}],
|
].concat(globalApps.map(app => [app[0], app[1] + app[2]]));
|
||||||
).join("")}
|
|
||||||
|
|
||||||
]);
|
const data = google.visualization.arrayToDataTable(chartData);
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
title: 'App Storage'
|
title: 'App Storage Breakdown',
|
||||||
|
is3D: true
|
||||||
};
|
};
|
||||||
|
|
||||||
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
|
const chart = new google.visualization.PieChart(document.getElementById('piechart'));
|
||||||
|
|
||||||
chart.draw(data, options);
|
chart.draw(data, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
google.charts.load('current', {'packages':['corechart']});
|
google.charts.load('current', {'packages':['corechart']});
|
||||||
google.charts.setOnLoadCallback(drawChart);
|
google.charts.setOnLoadCallback(() => {
|
||||||
|
drawChart();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue