Checkbox für Playliste hinzugefügt
This commit is contained in:
33
AGENTS.md
33
AGENTS.md
@@ -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.
|
||||
|
||||
@@ -91,7 +91,7 @@ python app.py
|
||||
Server läuft auf:
|
||||
|
||||
```
|
||||
http://localhost:5000
|
||||
http://localhost:5005
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
81
app.py
81
app.py
@@ -70,6 +70,16 @@ def normalize_url(value):
|
||||
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
|
||||
# -------------------------------------------------
|
||||
@@ -108,7 +118,7 @@ def logout():
|
||||
# Customer / Willkommensseite
|
||||
# -------------------------------------------------
|
||||
@app.route("/customer", methods=["GET", "POST"])
|
||||
@login_required
|
||||
# @login_required
|
||||
def add_customer():
|
||||
"""Add new customer with logo search and welcome page"""
|
||||
error = None
|
||||
@@ -147,7 +157,7 @@ def add_customer():
|
||||
return render_template("customer.html", error=error, success=success, logo_url=logo_url)
|
||||
|
||||
@app.route("/api/customer", methods=["POST"])
|
||||
@login_required
|
||||
# @login_required
|
||||
def api_add_customer():
|
||||
"""API endpoint for customer creation"""
|
||||
try:
|
||||
@@ -231,20 +241,24 @@ def player(screen):
|
||||
|
||||
# 1. Playlist-Reihenfolge
|
||||
for item in playlist:
|
||||
if not playlist_item_enabled(item):
|
||||
continue
|
||||
item_name = playlist_item_name(item)
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
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
|
||||
|
||||
if os.path.exists(os.path.join(folder, item)) and allowed_file(item):
|
||||
normal_files.append({"kind": "file", "name": 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_name, "enabled": True})
|
||||
|
||||
existing_file_names = {
|
||||
item["name"] for item in normal_files if item["kind"] == "file"
|
||||
}
|
||||
|
||||
# 2. Neue Dateien hintendran
|
||||
if not playlist:
|
||||
for f in sorted(os.listdir(folder)):
|
||||
if f in existing_file_names or f.startswith("._"):
|
||||
continue
|
||||
@@ -260,23 +274,26 @@ def player(screen):
|
||||
if priority_cfg.get("enabled", False):
|
||||
prio_files = []
|
||||
for item in priority_cfg.get("playlist", []):
|
||||
if not playlist_item_enabled(item):
|
||||
continue
|
||||
item_name = playlist_item_name(item)
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
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
|
||||
|
||||
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):
|
||||
prio_files.append({"kind": "file", "name": item})
|
||||
prio_files.append({"kind": "file", "name": item_name, "enabled": True})
|
||||
else:
|
||||
prio_files = []
|
||||
|
||||
return render_template(
|
||||
"player.html",
|
||||
screen=screen,
|
||||
normal_files=normal_files, # ✅ explizit
|
||||
prio_files=prio_files, # ✅ IMMER Liste
|
||||
normal_files=[item for item in normal_files if item.get("enabled", True)],
|
||||
prio_files=[item for item in prio_files if item.get("enabled", True)],
|
||||
interval=screen_cfg.get("interval", 10),
|
||||
newsticker_text=screen_cfg.get("newsticker_text", ""),
|
||||
newsticker_enabled=screen_cfg.get("newsticker_enabled", False)
|
||||
@@ -336,6 +353,8 @@ def admin():
|
||||
|
||||
# 1️⃣ Playlist-Reihenfolge
|
||||
for item in playlist:
|
||||
item_name = playlist_item_name(item)
|
||||
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
if url_data:
|
||||
@@ -343,15 +362,16 @@ def admin():
|
||||
"name": url_data["url"],
|
||||
"type": "url",
|
||||
"size": "URL",
|
||||
"zoom": url_data.get("zoom", 1.0)
|
||||
"zoom": url_data.get("zoom", 1.0),
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
continue
|
||||
|
||||
file_path = os.path.join(path, item)
|
||||
file_path = os.path.join(path, item_name)
|
||||
if not os.path.exists(file_path):
|
||||
continue
|
||||
|
||||
ext = os.path.splitext(item)[1].lower()
|
||||
ext = os.path.splitext(item_name)[1].lower()
|
||||
if ext == ".mp4":
|
||||
ftype = "video"
|
||||
if ext in (".jpg", ".jpeg", ".png"):
|
||||
@@ -362,14 +382,16 @@ def admin():
|
||||
size = os.path.getsize(file_path) // 1024
|
||||
|
||||
files.append({
|
||||
"name": item,
|
||||
"name": item_name,
|
||||
"type": ftype,
|
||||
"size": size
|
||||
"size": size,
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
|
||||
# 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)):
|
||||
if f in playlist or f.startswith("._"):
|
||||
if f in playlist_names or f.startswith("._"):
|
||||
continue
|
||||
|
||||
file_path = os.path.join(path, f)
|
||||
@@ -397,6 +419,7 @@ def admin():
|
||||
|
||||
# 1️⃣ Playlist-Reihenfolge
|
||||
for item in prio_playlist:
|
||||
item_name = playlist_item_name(item)
|
||||
if is_url(item):
|
||||
url_data = normalize_url(item)
|
||||
if url_data:
|
||||
@@ -404,22 +427,24 @@ def admin():
|
||||
"name": url_data["url"],
|
||||
"type": "url",
|
||||
"size": "URL",
|
||||
"zoom": url_data.get("zoom", 1.0)
|
||||
"zoom": url_data.get("zoom", 1.0),
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
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):
|
||||
continue
|
||||
|
||||
ext = os.path.splitext(item)[1].lower()
|
||||
ext = os.path.splitext(item_name)[1].lower()
|
||||
ftype = "video" if ext == ".mp4" else "image"
|
||||
size = os.path.getsize(file_path) // 1024
|
||||
|
||||
priority_files.append({
|
||||
"name": item,
|
||||
"name": item_name,
|
||||
"type": ftype,
|
||||
"size": size
|
||||
"size": size,
|
||||
"enabled": playlist_item_enabled(item)
|
||||
})
|
||||
|
||||
# 2️⃣ Neue Dateien anhängen (nicht in Playlist)
|
||||
@@ -576,6 +601,7 @@ def save_playlist(screen):
|
||||
cfg = load_config()
|
||||
data = request.get_json()
|
||||
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)
|
||||
if screen == "priority":
|
||||
@@ -586,20 +612,17 @@ def save_playlist(screen):
|
||||
# Create a mapping: filename/url -> full item (preserves zoom factor)
|
||||
item_map = {}
|
||||
for item in old_playlist:
|
||||
if isinstance(item, dict) and "url" in item:
|
||||
key = item["url"] # URL as key
|
||||
else:
|
||||
key = item # Filename as key
|
||||
item_map[key] = item
|
||||
item_map[playlist_item_name(item)] = item
|
||||
|
||||
# Build new playlist: use the mapping to preserve zoom factors
|
||||
new_playlist = []
|
||||
for key in new_order:
|
||||
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:
|
||||
# Item not found in mapping - add as is
|
||||
new_playlist.append(key)
|
||||
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)})
|
||||
|
||||
if screen == "priority":
|
||||
cfg.setdefault("priority", {})["playlist"] = new_playlist
|
||||
|
||||
26
config.json
26
config.json
@@ -4,7 +4,8 @@
|
||||
"playlist": [
|
||||
{
|
||||
"url": "https://wbxroompresence.cancom.io/standort?find=Stuttgart",
|
||||
"zoom": 0.8
|
||||
"zoom": 0.8,
|
||||
"enabled": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -16,10 +17,18 @@
|
||||
"playlist": [
|
||||
"welcome.html",
|
||||
{
|
||||
"url": "https://www.meteoblue.com/en/meteotv/d7b0fd",
|
||||
"zoom": 1.0
|
||||
"name": "welcome.html",
|
||||
"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_enabled": true
|
||||
@@ -29,12 +38,15 @@
|
||||
"show_images": true,
|
||||
"show_videos": true,
|
||||
"playlist": [
|
||||
"https://wbxroompresence.cancom.io/standort?find=Stuttgart",
|
||||
{
|
||||
"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_enabled": true
|
||||
|
||||
@@ -12,5 +12,5 @@ services:
|
||||
- "5005:5005"
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- OPENAI_API_KEY="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"
|
||||
- OPENAI_API_KEY="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"
|
||||
- BRANDFETCH_API_KEY="eBwCQW_DcQ_jvdqZRNph0JBtRA36XoMTufaaU4AoirOBnqXX9fMqHDw7uYfiz8kSFYMNKGMZtuHxrmud9hn0WQ"
|
||||
|
||||
@@ -15,7 +15,7 @@ WELCOME_FILENAME = "welcome.html"
|
||||
def get_openai_client():
|
||||
"""Initialize OpenAI client from environment variable"""
|
||||
# api_key = os.getenv("OPENAI_API_KEY")
|
||||
api_key = "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"
|
||||
api_key = "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"
|
||||
if not api_key:
|
||||
raise ValueError("OPENAI_API_KEY environment variable not set")
|
||||
return OpenAI(api_key=api_key)
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
.playlist-row {
|
||||
display: grid;
|
||||
grid-template-columns:
|
||||
28px /* Enabled */
|
||||
1fr /* Name */
|
||||
90px /* Typ */
|
||||
80px /* Größe */
|
||||
@@ -198,6 +199,11 @@
|
||||
<li class="list-group-item playlist-row"
|
||||
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"
|
||||
{% if file.type == "image" %}
|
||||
data-bs-toggle="tooltip"
|
||||
@@ -248,7 +254,7 @@
|
||||
|
||||
<button class="btn btn-primary"
|
||||
onclick="savePlaylist('priority')">
|
||||
Priority-Reihenfolge speichern
|
||||
Priority-Playlist speichern
|
||||
</button>
|
||||
|
||||
</div>
|
||||
@@ -354,6 +360,11 @@
|
||||
<li class="list-group-item playlist-row"
|
||||
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"
|
||||
{% if file.type == "image" %}
|
||||
data-bs-toggle="tooltip"
|
||||
@@ -400,7 +411,7 @@
|
||||
|
||||
<button class="btn btn-primary"
|
||||
onclick="savePlaylist('{{ screen }}')">
|
||||
Reihenfolge speichern
|
||||
Playlist speichern
|
||||
</button>
|
||||
|
||||
</div>
|
||||
@@ -448,12 +459,22 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
const items = document.querySelectorAll(
|
||||
"#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, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
playlist: Array.from(items).map(i => i.dataset.file)
|
||||
playlist: playlist,
|
||||
enabled: enabled
|
||||
})
|
||||
}).then(() => location.reload());
|
||||
}
|
||||
@@ -471,5 +492,3 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
@@ -131,6 +131,9 @@ function normalizeItem(item) {
|
||||
if (item.kind === "url" && !("zoom" in item)) {
|
||||
item.zoom = 1.0;
|
||||
}
|
||||
if (!("enabled" in item)) {
|
||||
item.enabled = true;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
@@ -149,29 +152,31 @@ function isHtml(item) {
|
||||
function getNextItem() {
|
||||
const normalizedNormal = normalFiles.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
|
||||
if (normalizedNormal.length === 0 && normalizedPrio.length > 0) {
|
||||
if (activeNormal.length === 0 && activePrio.length > 0) {
|
||||
return {
|
||||
item: normalizedPrio[prioIndex++ % normalizedPrio.length],
|
||||
item: activePrio[prioIndex++ % activePrio.length],
|
||||
isPrio: true
|
||||
};
|
||||
}
|
||||
|
||||
// ✅ Sonderfall: nur normale Playlist vorhanden
|
||||
if (normalizedPrio.length === 0 && normalizedNormal.length > 0) {
|
||||
if (activePrio.length === 0 && activeNormal.length > 0) {
|
||||
return {
|
||||
item: normalizedNormal[normalIndex++ % normalizedNormal.length],
|
||||
item: activeNormal[normalIndex++ % activeNormal.length],
|
||||
isPrio: false
|
||||
};
|
||||
}
|
||||
|
||||
// ✅ Normal-Phase
|
||||
if (mode === "normal") {
|
||||
const item = normalizedNormal[normalIndex++];
|
||||
if (normalIndex >= normalizedNormal.length) {
|
||||
const item = activeNormal[normalIndex++];
|
||||
if (normalIndex >= activeNormal.length) {
|
||||
normalIndex = 0;
|
||||
if (normalizedPrio.length > 0) {
|
||||
if (activePrio.length > 0) {
|
||||
mode = "prio"; // ➜ nach kompletter Normal-Playlist wechseln
|
||||
}
|
||||
}
|
||||
@@ -180,8 +185,8 @@ function getNextItem() {
|
||||
|
||||
// ✅ Priority-Phase
|
||||
if (mode === "prio") {
|
||||
const item = normalizedPrio[prioIndex++];
|
||||
if (prioIndex >= normalizedPrio.length) {
|
||||
const item = activePrio[prioIndex++];
|
||||
if (prioIndex >= activePrio.length) {
|
||||
prioIndex = 0;
|
||||
mode = "normal"; // ➜ nach kompletter Priority zurück
|
||||
}
|
||||
@@ -280,4 +285,3 @@ setInterval(checkForUpdates, 5000);
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user