Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions kiosk/migrations/0009_kioskitem_duration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.13 on 2025-04-03 15:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("kiosk", "0008_kioskitem_website_url_alter_kioskitem_media"),
]

operations = [
migrations.AddField(
model_name="kioskitem",
name="duration",
field=models.IntegerField(blank=True, default=10000, null=True),
),
]
1 change: 1 addition & 0 deletions kiosk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class KioskItem(models.Model):
ordering = models.IntegerField(null=False, default=random_ordering, blank=False)
start_datetime = models.DateTimeField(null=True, blank=True)
end_datetime = models.DateTimeField(null=True, blank=True)
duration = models.IntegerField(null=False, default=10000, blank=False, verbose_name="Duration (ms)")

@property
def has_media(self):
Expand Down
15 changes: 13 additions & 2 deletions kiosk/templates/kiosk.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
var queue = [].slice.call(document.querySelectorAll(".dummy"));
var front = queue.shift();
var this_id = -1;
var currentDuration = 10000;

function swap(tag) {
//Flip in the DOM
Expand All @@ -31,7 +32,7 @@
}

function updateKiosk() {
var t = front
var t = front;
t.addEventListener("transitionend", function loadnext(tag) {
t.removeEventListener("transitionend", loadnext);
var xmlHttp = new XMLHttpRequest();
Expand Down Expand Up @@ -59,25 +60,35 @@
'src="' + obj.url + '" ' +
'style="width:100%;height:100%;border:none;"></iframe>';
}

// Use the duration from the server response
currentDuration = obj.duration || 10000; // Default to 10 seconds if not provided
} else if (xmlHttp.readyState == 4) {
// Response received, but no image was sent from server
t.style.backgroundImage = 'url("{% static "kiosk/kioskbg.png" %}")';
this_id = -1;
}
}

//Start by asking random for the first image
if(this_id === -1) {
xmlHttp.open("GET", "/kiosk/random", true);
} else {
xmlHttp.open("GET", "/kiosk/next_real/" + this_id + "/", true);
}
xmlHttp.send(null);

});

swap();

// Set a timeout to update the kiosk again after the dynamic duration
setTimeout(updateKiosk, currentDuration);
}

setInterval("updateKiosk()", 10000);
// Initial call to start the cycle
updateKiosk();

</script>
</body>

Expand Down
2 changes: 2 additions & 0 deletions kiosk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def find_random_media(request):
"url": media_url,
"is_image": is_image,
"has_media": item.has_media,
"duration": item.duration,
}
return HttpResponse(json.dumps(response_data), content_type="application/json")

Expand Down Expand Up @@ -84,5 +85,6 @@ def find_next_media_real(request, item_id):
"url": media_url,
"is_image": is_image,
"has_media": next_item.has_media,
"duration": next_item.duration,
}
return HttpResponse(json.dumps(response_data), content_type="application/json")