diff --git a/static/script.js b/static/script.js index 8a40ac7..edd12d1 100644 --- a/static/script.js +++ b/static/script.js @@ -1353,7 +1353,17 @@ function renderEvents() { return `
${event.side === "home" ? cardHtml : ""}
-
${escapeHtml(event.minute)}
+
+ ${escapeHtml(event.minute)} + ${ + event.id !== null && event.id !== undefined && event.id !== "" + ? `` + : "" + } +
${event.side === "away" ? cardHtml : ""}
`; @@ -2454,6 +2464,76 @@ function getRowArcOffsets(count, arcStrength = 0, direction = "up") { }); } + +function parseEventTimeInput(value) { + const raw = String(value || "").trim().replace("’", "'"); + + // варианты: 12, 12', 45+2, 45'+2, 90+4 + const match = raw.match(/^(\d{1,3})'?(?:\+(\d{1,2}))?$/); + if (!match) return null; + + const baseMinute = Number(match[1]); + const extraMinute = Number(match[2] || 0); + + if (!Number.isFinite(baseMinute) || baseMinute < 1) return null; + + const totalMinute = baseMinute + extraMinute; + const seconds = Math.max(0, (totalMinute - 1) * 60); + + const label = extraMinute > 0 + ? `${baseMinute}'+${extraMinute}` + : `${baseMinute}'`; + + return { + label, + minute: totalMinute, + seconds + }; +} + +async function editEventTime(eventId) { + const event = matchEvents.find((e) => String(e.id) === String(eventId)); + if (!event) return; + + const value = prompt("Новое время события. Например: 23, 45+2, 90+4", event.minute || ""); + if (value === null) return; + + const parsed = parseEventTimeInput(value); + if (!parsed) { + alert("Неверный формат времени. Пример: 23 или 45+2"); + return; + } + + const updated = { + side: event.side, + type: event.type, + player_name: event.player_name || "", + minute: parsed.minute, + seconds: parsed.seconds, + meta: event.meta || "", + player_id: event.player_id ?? null, + player_out_id: event.player_out_id ?? null, + player_in_id: event.player_in_id ?? null + }; + + const ok = await updateEventOnServer(event.id, updated); + if (!ok) { + alert("Не удалось обновить время события"); + return; + } + + event.minute = parsed.label; + event.seconds = parsed.seconds; + + matchEvents = sortEventsForStorage(matchEvents); + + renderEvents(); + rebuildLineupsFromEvents(); + saveMatchState(); +} + + + function getRowTopLift(profile, count) { const arc = Number(profile?.arc || 0); const yOffset = Number(profile?.yOffset || 0); diff --git a/static/styles.css b/static/styles.css index 83f7349..22a4bc2 100644 --- a/static/styles.css +++ b/static/styles.css @@ -2293,3 +2293,16 @@ body:not(.edit-mode-on) .referee-search { border-radius: 6px; } +.event-time-edit-btn { + margin-left: 4px; + border: none; + background: transparent; + color: inherit; + cursor: pointer; + opacity: 0.55; + font-size: 11px; +} + +.event-time-edit-btn:hover { + opacity: 1; +} \ No newline at end of file