diff --git a/app.py b/app.py index ec841ee..e55cf02 100644 --- a/app.py +++ b/app.py @@ -1404,7 +1404,40 @@ def vmix_standings(session_token: str): for row in rows ] +class MatchChannelPayload(BaseModel): + match_external_id: str + channel: str = "" +@app.post("/admin/session/{session_token}/schedule/channel") +def update_schedule_channel(session_token: str, payload: MatchChannelPayload): + session_row = get_match_session_by_token(session_token) + if not session_row: + return JSONResponse({"error": "session_not_found"}, status_code=404) + + allowed = {"", "match", "match_premier", "match_and_premier"} + if payload.channel not in allowed: + return JSONResponse({"error": "invalid_channel"}, status_code=400) + + conn = get_connection() + try: + with conn.cursor() as cur: + cur.execute( + """ + UPDATE matches + SET channel = %s + WHERE external_id = %s + """, + (payload.channel, payload.match_external_id), + ) + + conn.commit() + return {"success": True} + except Exception as e: + conn.rollback() + return JSONResponse({"error": str(e)}, status_code=500) + finally: + conn.close() + @app.get("/vmix/session/{session_token}/schedule") def vmix_schedule(session_token: str): session_row = get_match_session_by_token(session_token) @@ -1431,7 +1464,7 @@ def vmix_schedule(session_token: str): ), "mask_time": "#FFFFFF00" if row[2] is not None and row[3] is not None else "#FFFFFF", "mask_score": "#FFFFFF00" if row[2] is None and row[3] is None else "#FFFFFF", - "channel": row[6] or "", + "channel": row[7] or "", } for row in rows ] diff --git a/services/vmix_json_service.py b/services/vmix_json_service.py index d8fa880..488ddb9 100644 --- a/services/vmix_json_service.py +++ b/services/vmix_json_service.py @@ -210,7 +210,8 @@ def get_vmix_schedule(session_token: str): m.away_score, m.match_date, m.status, - m.id + m.id, + m.chanell FROM matches m LEFT JOIN teams t1 ON m.home_team_id = t1.id LEFT JOIN teams t2 ON m.away_team_id = t2.id diff --git a/static/script.js b/static/script.js index 249d31a..add23ce 100644 --- a/static/script.js +++ b/static/script.js @@ -3723,5 +3723,39 @@ function getTourChannelLogoPath(matchId) { return "D:\\Графика\\ФУТБОЛ\\Женская Суперлига 2026\\Photo\\EMPTY.png"; } + return ""; +} + +async function saveTourChannel(matchExternalId) { + const channel = buildChannelValue(matchExternalId); + + const res = await fetch(`/admin/session/${MATCH_DATA.sessionToken}/schedule/channel`, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + match_external_id: String(matchExternalId), + channel + }) + }); + + if (!res.ok) { + alert("Не удалось сохранить канал"); + } +} + +function buildChannelValue(matchId) { + const checked = Array.from( + document.querySelectorAll(`.tour-channel-checkbox[data-match-id="${matchId}"]:checked`) + ).map(el => el.dataset.channel); + + const hasMatch = checked.includes("match"); + const hasPremier = checked.includes("match_premier"); + + if (hasMatch && hasPremier) return "match_and_premier"; + if (hasPremier) return "match_premier"; + if (hasMatch) return "match"; + return ""; } \ No newline at end of file diff --git a/templates/match_workspace.html b/templates/match_workspace.html index 494b361..555ce72 100644 --- a/templates/match_workspace.html +++ b/templates/match_workspace.html @@ -978,26 +978,34 @@ data-role="{{ p.position or '' }}" -