add watch progress tiles

This commit is contained in:
Simon 2023-08-31 22:28:36 +07:00
parent 5acc1ea718
commit 4650963cc7
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 29 additions and 1 deletions

View File

@ -9,7 +9,8 @@
<div id="primaryBox" class="info-box info-box-4"></div>
</div>
<div>
<h2>Watch Progress</h2>
<div id="watchBox" class="info-box info-box-3"></div>
</div>
<script type="text/javascript" src="{% static 'stats.js' %}"></script>
{% endblock settings_content %}

View File

@ -70,8 +70,35 @@ function buildDownloadTile(responseData) {
return tile;
}
function watchStats() {
let apiEndpoint = '/api/stats/watch/';
let responseData = apiRequest(apiEndpoint, 'GET');
let watchBox = document.getElementById('watchBox');
for (const property in responseData) {
let tile = buildWatchTile(property, responseData[property]);
watchBox.appendChild(tile);
}
}
function buildWatchTile(title, watchDetail) {
let tile = buildTile(`Total ${title}`);
let message = document.createElement('p');
message.innerHTML = `
${watchDetail.items} Videos<br>
${watchDetail.duration} Seconds<br>
${watchDetail.duration_str} Playback
`;
if (watchDetail.progress) {
message.innerHTML += `<br>${Number(watchDetail.progress * 100).toFixed(2)}%`;
}
tile.appendChild(message);
return tile;
}
function buildStats() {
primaryStats();
watchStats();
}
buildStats();