Checkbox für Playliste hinzugefügt

This commit is contained in:
Erik Thiele
2026-05-10 13:49:05 +02:00
parent 296e59e709
commit a1b48e35d6
8 changed files with 152 additions and 61 deletions

View File

@@ -0,0 +1,33 @@
# CANCOM Simple Signage — Agent Guide
## Start
```bash
pip install -r requirements.txt
python app.py
docker compose up -d
```
`python app.py` serves on `http://localhost:5005`. `app.py` runs Flask with `debug=True`, `host="0.0.0.0"`, and `port=5005`.
## Source Of Truth
- Single Flask app in `app.py`; there is no database.
- Persistent state is `config.json` plus files under `media/<screen>/`.
- `README.md` is stale on the port number; trust `app.py`.
- Existing repo instructions in this file are the main local guidance; there is no `opencode.json` or workflow config in this repo.
## Behavior To Preserve
- `GET /player/<screen>` renders the playlist and auto-reloads from `/playlist/<screen>/hash`.
- `GET /admin` requires login; `config.json.admin` holds the credentials.
- URL playlist items are stored as dicts like `{"url": "https://...", "zoom": 0.8}` and the zoom value must survive save/reorder flows.
- `.html` items in `media/` are rendered inline as content, not in an iframe.
- `config.priority.enabled` makes the priority playlist show on every screen.
- `POST /api/customer` generates `welcome.html` and inserts it at the front of the lobby playlist.
## Repo Quirks
- `media/` and media file extensions are gitignored.
- The app has no configured tests, lint, typecheck, formatter, or CI.
- Hardcoded secrets exist in tracked files; do not commit new secrets or reshuffle them casually.

View File

@@ -91,7 +91,7 @@ python app.py
Server läuft auf: Server läuft auf:
``` ```
http://localhost:5000 http://localhost:5005
``` ```
--- ---

93
app.py
View File

@@ -70,6 +70,16 @@ def normalize_url(value):
return None return None
def playlist_item_enabled(item):
return not (isinstance(item, dict) and item.get("enabled") is False)
def playlist_item_name(item):
if isinstance(item, dict):
return item.get("url") or item.get("name")
return item
# ------------------------------------------------- # -------------------------------------------------
# Auth / Benutzer # Auth / Benutzer
# ------------------------------------------------- # -------------------------------------------------
@@ -108,7 +118,7 @@ def logout():
# Customer / Willkommensseite # Customer / Willkommensseite
# ------------------------------------------------- # -------------------------------------------------
@app.route("/customer", methods=["GET", "POST"]) @app.route("/customer", methods=["GET", "POST"])
@login_required # @login_required
def add_customer(): def add_customer():
"""Add new customer with logo search and welcome page""" """Add new customer with logo search and welcome page"""
error = None error = None
@@ -147,7 +157,7 @@ def add_customer():
return render_template("customer.html", error=error, success=success, logo_url=logo_url) return render_template("customer.html", error=error, success=success, logo_url=logo_url)
@app.route("/api/customer", methods=["POST"]) @app.route("/api/customer", methods=["POST"])
@login_required # @login_required
def api_add_customer(): def api_add_customer():
"""API endpoint for customer creation""" """API endpoint for customer creation"""
try: try:
@@ -231,25 +241,29 @@ def player(screen):
# 1. Playlist-Reihenfolge # 1. Playlist-Reihenfolge
for item in playlist: for item in playlist:
if not playlist_item_enabled(item):
continue
item_name = playlist_item_name(item)
if is_url(item): if is_url(item):
url_data = normalize_url(item) url_data = normalize_url(item)
if url_data: if url_data:
normal_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0)}) normal_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0), "enabled": True})
continue continue
if os.path.exists(os.path.join(folder, item)) and allowed_file(item): if item_name and os.path.exists(os.path.join(folder, item_name)) and allowed_file(item_name):
normal_files.append({"kind": "file", "name": item}) normal_files.append({"kind": "file", "name": item_name, "enabled": True})
existing_file_names = { existing_file_names = {
item["name"] for item in normal_files if item["kind"] == "file" item["name"] for item in normal_files if item["kind"] == "file"
} }
# 2. Neue Dateien hintendran # 2. Neue Dateien hintendran
for f in sorted(os.listdir(folder)): if not playlist:
if f in existing_file_names or f.startswith("._"): for f in sorted(os.listdir(folder)):
continue if f in existing_file_names or f.startswith("._"):
if allowed_file(f): continue
normal_files.append({"kind": "file", "name": f}) if allowed_file(f):
normal_files.append({"kind": "file", "name": f})
# ------------------------------ # ------------------------------
# Priority-Playlist (global) # Priority-Playlist (global)
@@ -260,23 +274,26 @@ def player(screen):
if priority_cfg.get("enabled", False): if priority_cfg.get("enabled", False):
prio_files = [] prio_files = []
for item in priority_cfg.get("playlist", []): for item in priority_cfg.get("playlist", []):
if not playlist_item_enabled(item):
continue
item_name = playlist_item_name(item)
if is_url(item): if is_url(item):
url_data = normalize_url(item) url_data = normalize_url(item)
if url_data: if url_data:
prio_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0)}) prio_files.append({"kind": "url", "url": url_data["url"], "zoom": url_data.get("zoom", 1.0), "enabled": True})
continue continue
file_path = os.path.join(MEDIA_DIR, "priority", item) file_path = os.path.join(MEDIA_DIR, "priority", item_name)
if os.path.exists(file_path): if os.path.exists(file_path):
prio_files.append({"kind": "file", "name": item}) prio_files.append({"kind": "file", "name": item_name, "enabled": True})
else: else:
prio_files = [] prio_files = []
return render_template( return render_template(
"player.html", "player.html",
screen=screen, screen=screen,
normal_files=normal_files, # ✅ explizit normal_files=[item for item in normal_files if item.get("enabled", True)],
prio_files=prio_files, # ✅ IMMER Liste prio_files=[item for item in prio_files if item.get("enabled", True)],
interval=screen_cfg.get("interval", 10), interval=screen_cfg.get("interval", 10),
newsticker_text=screen_cfg.get("newsticker_text", ""), newsticker_text=screen_cfg.get("newsticker_text", ""),
newsticker_enabled=screen_cfg.get("newsticker_enabled", False) newsticker_enabled=screen_cfg.get("newsticker_enabled", False)
@@ -336,6 +353,8 @@ def admin():
# 1⃣ Playlist-Reihenfolge # 1⃣ Playlist-Reihenfolge
for item in playlist: for item in playlist:
item_name = playlist_item_name(item)
if is_url(item): if is_url(item):
url_data = normalize_url(item) url_data = normalize_url(item)
if url_data: if url_data:
@@ -343,15 +362,16 @@ def admin():
"name": url_data["url"], "name": url_data["url"],
"type": "url", "type": "url",
"size": "URL", "size": "URL",
"zoom": url_data.get("zoom", 1.0) "zoom": url_data.get("zoom", 1.0),
"enabled": playlist_item_enabled(item)
}) })
continue continue
file_path = os.path.join(path, item) file_path = os.path.join(path, item_name)
if not os.path.exists(file_path): if not os.path.exists(file_path):
continue continue
ext = os.path.splitext(item)[1].lower() ext = os.path.splitext(item_name)[1].lower()
if ext == ".mp4": if ext == ".mp4":
ftype = "video" ftype = "video"
if ext in (".jpg", ".jpeg", ".png"): if ext in (".jpg", ".jpeg", ".png"):
@@ -362,14 +382,16 @@ def admin():
size = os.path.getsize(file_path) // 1024 size = os.path.getsize(file_path) // 1024
files.append({ files.append({
"name": item, "name": item_name,
"type": ftype, "type": ftype,
"size": size "size": size,
"enabled": playlist_item_enabled(item)
}) })
# 2⃣ Neue Dateien anhängen (nicht in Playlist) # 2⃣ Neue Dateien anhängen (nicht in Playlist)
playlist_names = {playlist_item_name(item) for item in playlist}
for f in sorted(os.listdir(path)): for f in sorted(os.listdir(path)):
if f in playlist or f.startswith("._"): if f in playlist_names or f.startswith("._"):
continue continue
file_path = os.path.join(path, f) file_path = os.path.join(path, f)
@@ -397,6 +419,7 @@ def admin():
# 1⃣ Playlist-Reihenfolge # 1⃣ Playlist-Reihenfolge
for item in prio_playlist: for item in prio_playlist:
item_name = playlist_item_name(item)
if is_url(item): if is_url(item):
url_data = normalize_url(item) url_data = normalize_url(item)
if url_data: if url_data:
@@ -404,22 +427,24 @@ def admin():
"name": url_data["url"], "name": url_data["url"],
"type": "url", "type": "url",
"size": "URL", "size": "URL",
"zoom": url_data.get("zoom", 1.0) "zoom": url_data.get("zoom", 1.0),
}) "enabled": playlist_item_enabled(item)
})
continue continue
file_path = os.path.join(prio_dir, item) file_path = os.path.join(prio_dir, item_name)
if not os.path.exists(file_path): if not os.path.exists(file_path):
continue continue
ext = os.path.splitext(item)[1].lower() ext = os.path.splitext(item_name)[1].lower()
ftype = "video" if ext == ".mp4" else "image" ftype = "video" if ext == ".mp4" else "image"
size = os.path.getsize(file_path) // 1024 size = os.path.getsize(file_path) // 1024
priority_files.append({ priority_files.append({
"name": item, "name": item_name,
"type": ftype, "type": ftype,
"size": size "size": size,
"enabled": playlist_item_enabled(item)
}) })
# 2⃣ Neue Dateien anhängen (nicht in Playlist) # 2⃣ Neue Dateien anhängen (nicht in Playlist)
@@ -576,6 +601,7 @@ def save_playlist(screen):
cfg = load_config() cfg = load_config()
data = request.get_json() data = request.get_json()
new_order = data["playlist"] # List of filenames/URLs as strings new_order = data["playlist"] # List of filenames/URLs as strings
enabled_map = data.get("enabled", {})
# Get the current playlist with all data (including zoom factors) # Get the current playlist with all data (including zoom factors)
if screen == "priority": if screen == "priority":
@@ -586,20 +612,17 @@ def save_playlist(screen):
# Create a mapping: filename/url -> full item (preserves zoom factor) # Create a mapping: filename/url -> full item (preserves zoom factor)
item_map = {} item_map = {}
for item in old_playlist: for item in old_playlist:
if isinstance(item, dict) and "url" in item: item_map[playlist_item_name(item)] = item
key = item["url"] # URL as key
else:
key = item # Filename as key
item_map[key] = item
# Build new playlist: use the mapping to preserve zoom factors # Build new playlist: use the mapping to preserve zoom factors
new_playlist = [] new_playlist = []
for key in new_order: for key in new_order:
if key in item_map: if key in item_map:
new_playlist.append(item_map[key]) item = dict(item_map[key]) if isinstance(item_map[key], dict) else {"name": item_map[key]}
item["enabled"] = enabled_map.get(key, True if not isinstance(item_map[key], dict) else item_map[key].get("enabled", True))
new_playlist.append(item)
else: else:
# Item not found in mapping - add as is new_playlist.append({"url": key, "zoom": 1.0, "enabled": enabled_map.get(key, True)} if is_url(key) else {"name": key, "enabled": enabled_map.get(key, True)})
new_playlist.append(key)
if screen == "priority": if screen == "priority":
cfg.setdefault("priority", {})["playlist"] = new_playlist cfg.setdefault("priority", {})["playlist"] = new_playlist

View File

@@ -4,7 +4,8 @@
"playlist": [ "playlist": [
{ {
"url": "https://wbxroompresence.cancom.io/standort?find=Stuttgart", "url": "https://wbxroompresence.cancom.io/standort?find=Stuttgart",
"zoom": 0.8 "zoom": 0.8,
"enabled": true
} }
] ]
}, },
@@ -16,10 +17,18 @@
"playlist": [ "playlist": [
"welcome.html", "welcome.html",
{ {
"url": "https://www.meteoblue.com/en/meteotv/d7b0fd", "name": "welcome.html",
"zoom": 1.0 "enabled": true
}, },
"Cancom_Leitsatz.JPG" {
"url": "https://www.meteoblue.com/en/meteotv/d7b0fd",
"zoom": 1.0,
"enabled": true
},
{
"name": "Cancom_Leitsatz.JPG",
"enabled": true
}
], ],
"newsticker_text": "Herzlich Willkommen bei der CANCOM - wir begr\u00fc\u00dfen unsere G\u00e4ste und w\u00fcnschen Ihnen einen angenehmen Tag! !", "newsticker_text": "Herzlich Willkommen bei der CANCOM - wir begr\u00fc\u00dfen unsere G\u00e4ste und w\u00fcnschen Ihnen einen angenehmen Tag! !",
"newsticker_enabled": true "newsticker_enabled": true
@@ -29,12 +38,15 @@
"show_images": true, "show_images": true,
"show_videos": true, "show_videos": true,
"playlist": [ "playlist": [
"https://wbxroompresence.cancom.io/standort?find=Stuttgart",
{ {
"url": "https://www.meteoblue.com/en/meteotv/d7b0fd", "url": "https://www.meteoblue.com/en/meteotv/d7b0fd",
"zoom": 1.0 "zoom": 1.0,
"enabled": true
}, },
"Video_CANCOM_LIVE_2025_Stuttgart.MP4" {
"name": "Video_CANCOM_LIVE_2025_Stuttgart.MP4",
"enabled": true
}
], ],
"newsticker_text": "Herzlich willkommen bei der CANCOM - wir w\u00fcnschen ihnen einen sch\u00f6nen Tag", "newsticker_text": "Herzlich willkommen bei der CANCOM - wir w\u00fcnschen ihnen einen sch\u00f6nen Tag",
"newsticker_enabled": true "newsticker_enabled": true

View File

@@ -12,5 +12,5 @@ services:
- "5005:5005" - "5005:5005"
restart: unless-stopped restart: unless-stopped
environment: environment:
- OPENAI_API_KEY="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" - OPENAI_API_KEY="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"
- BRANDFETCH_API_KEY="eBwCQW_DcQ_jvdqZRNph0JBtRA36XoMTufaaU4AoirOBnqXX9fMqHDw7uYfiz8kSFYMNKGMZtuHxrmud9hn0WQ" - BRANDFETCH_API_KEY="eBwCQW_DcQ_jvdqZRNph0JBtRA36XoMTufaaU4AoirOBnqXX9fMqHDw7uYfiz8kSFYMNKGMZtuHxrmud9hn0WQ"

View File

@@ -15,7 +15,7 @@ WELCOME_FILENAME = "welcome.html"
def get_openai_client(): def get_openai_client():
"""Initialize OpenAI client from environment variable""" """Initialize OpenAI client from environment variable"""
# api_key = os.getenv("OPENAI_API_KEY") # api_key = os.getenv("OPENAI_API_KEY")
api_key = "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" api_key = "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"
if not api_key: if not api_key:
raise ValueError("OPENAI_API_KEY environment variable not set") raise ValueError("OPENAI_API_KEY environment variable not set")
return OpenAI(api_key=api_key) return OpenAI(api_key=api_key)

View File

@@ -64,6 +64,7 @@
.playlist-row { .playlist-row {
display: grid; display: grid;
grid-template-columns: grid-template-columns:
28px /* Enabled */
1fr /* Name */ 1fr /* Name */
90px /* Typ */ 90px /* Typ */
80px /* Größe */ 80px /* Größe */
@@ -198,6 +199,11 @@
<li class="list-group-item playlist-row" <li class="list-group-item playlist-row"
data-file="{{ file.name }}"> data-file="{{ file.name }}">
<input class="form-check-input playlist-enabled"
type="checkbox"
{% if file.enabled %}checked{% endif %}
title="Element aktivieren">
<span class="playlist-name" <span class="playlist-name"
{% if file.type == "image" %} {% if file.type == "image" %}
data-bs-toggle="tooltip" data-bs-toggle="tooltip"
@@ -248,7 +254,7 @@
<button class="btn btn-primary" <button class="btn btn-primary"
onclick="savePlaylist('priority')"> onclick="savePlaylist('priority')">
Priority-Reihenfolge speichern Priority-Playlist speichern
</button> </button>
</div> </div>
@@ -354,6 +360,11 @@
<li class="list-group-item playlist-row" <li class="list-group-item playlist-row"
data-file="{{ file.name }}"> data-file="{{ file.name }}">
<input class="form-check-input playlist-enabled"
type="checkbox"
{% if file.enabled %}checked{% endif %}
title="Element aktivieren">
<span class="playlist-name" <span class="playlist-name"
{% if file.type == "image" %} {% if file.type == "image" %}
data-bs-toggle="tooltip" data-bs-toggle="tooltip"
@@ -400,7 +411,7 @@
<button class="btn btn-primary" <button class="btn btn-primary"
onclick="savePlaylist('{{ screen }}')"> onclick="savePlaylist('{{ screen }}')">
Reihenfolge speichern Playlist speichern
</button> </button>
</div> </div>
@@ -448,12 +459,22 @@ document.addEventListener("DOMContentLoaded", function () {
const items = document.querySelectorAll( const items = document.querySelectorAll(
"#playlist-" + screen + " li" "#playlist-" + screen + " li"
); );
const playlist = [];
const enabled = {};
items.forEach((item) => {
const checkbox = item.querySelector(".playlist-enabled");
const fileName = item.dataset.file;
enabled[fileName] = !!(checkbox && checkbox.checked);
playlist.push(fileName);
});
fetch("/admin/playlist/" + screen, { fetch("/admin/playlist/" + screen, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
playlist: Array.from(items).map(i => i.dataset.file) playlist: playlist,
enabled: enabled
}) })
}).then(() => location.reload()); }).then(() => location.reload());
} }
@@ -471,5 +492,3 @@ document.addEventListener("DOMContentLoaded", function () {
</body> </body>
</html> </html>

View File

@@ -131,6 +131,9 @@ function normalizeItem(item) {
if (item.kind === "url" && !("zoom" in item)) { if (item.kind === "url" && !("zoom" in item)) {
item.zoom = 1.0; item.zoom = 1.0;
} }
if (!("enabled" in item)) {
item.enabled = true;
}
return item; return item;
} }
@@ -149,29 +152,31 @@ function isHtml(item) {
function getNextItem() { function getNextItem() {
const normalizedNormal = normalFiles.map(normalizeItem); const normalizedNormal = normalFiles.map(normalizeItem);
const normalizedPrio = prioFiles.map(normalizeItem); const normalizedPrio = prioFiles.map(normalizeItem);
const activeNormal = normalizedNormal.filter(item => item.enabled !== false);
const activePrio = normalizedPrio.filter(item => item.enabled !== false);
// ✅ Sonderfall: nur Priority vorhanden // ✅ Sonderfall: nur Priority vorhanden
if (normalizedNormal.length === 0 && normalizedPrio.length > 0) { if (activeNormal.length === 0 && activePrio.length > 0) {
return { return {
item: normalizedPrio[prioIndex++ % normalizedPrio.length], item: activePrio[prioIndex++ % activePrio.length],
isPrio: true isPrio: true
}; };
} }
// ✅ Sonderfall: nur normale Playlist vorhanden // ✅ Sonderfall: nur normale Playlist vorhanden
if (normalizedPrio.length === 0 && normalizedNormal.length > 0) { if (activePrio.length === 0 && activeNormal.length > 0) {
return { return {
item: normalizedNormal[normalIndex++ % normalizedNormal.length], item: activeNormal[normalIndex++ % activeNormal.length],
isPrio: false isPrio: false
}; };
} }
// ✅ Normal-Phase // ✅ Normal-Phase
if (mode === "normal") { if (mode === "normal") {
const item = normalizedNormal[normalIndex++]; const item = activeNormal[normalIndex++];
if (normalIndex >= normalizedNormal.length) { if (normalIndex >= activeNormal.length) {
normalIndex = 0; normalIndex = 0;
if (normalizedPrio.length > 0) { if (activePrio.length > 0) {
mode = "prio"; // ➜ nach kompletter Normal-Playlist wechseln mode = "prio"; // ➜ nach kompletter Normal-Playlist wechseln
} }
} }
@@ -180,8 +185,8 @@ function getNextItem() {
// ✅ Priority-Phase // ✅ Priority-Phase
if (mode === "prio") { if (mode === "prio") {
const item = normalizedPrio[prioIndex++]; const item = activePrio[prioIndex++];
if (prioIndex >= normalizedPrio.length) { if (prioIndex >= activePrio.length) {
prioIndex = 0; prioIndex = 0;
mode = "normal"; // ➜ nach kompletter Priority zurück mode = "normal"; // ➜ nach kompletter Priority zurück
} }
@@ -280,4 +285,3 @@ setInterval(checkForUpdates, 5000);
</body> </body>
</html> </html>