Sync alternativer
This commit is contained in:
@@ -463,6 +463,7 @@ class PlaylistPanel(QWidget):
|
||||
"file_missing": file_missing,
|
||||
"dances": dance_names,
|
||||
"active_dance": active_dance,
|
||||
"alt_dance": row["alt_dance_override"] if "alt_dance_override" in row.keys() else "",
|
||||
"is_workshop": bool(row["is_workshop"]),
|
||||
})
|
||||
statuses.append(row["status"] or "pending")
|
||||
@@ -779,6 +780,84 @@ class PlaylistPanel(QWidget):
|
||||
self._refresh()
|
||||
self._sync_dance_to_db(idx, song)
|
||||
|
||||
def _change_alt_dance(self, idx: int, song: dict):
|
||||
"""Lad brugeren vælge alternativ dans til denne sang i playlisten."""
|
||||
from ui.alt_dance_picker_dialog import AltDancePickerDialog
|
||||
dlg = AltDancePickerDialog(song, parent=self.window())
|
||||
if dlg.exec():
|
||||
if dlg.was_cleared():
|
||||
chosen = ""
|
||||
else:
|
||||
chosen = dlg.get_dance()
|
||||
rating = dlg.get_rating()
|
||||
song["alt_dance"] = chosen
|
||||
self._refresh()
|
||||
# Gem alt_dance_override på playlist_songs
|
||||
self._sync_alt_dance_to_db(idx, song, chosen)
|
||||
# Gem rating hvis givet
|
||||
if chosen and rating is not None:
|
||||
self._save_alt_dance_rating(song, chosen, rating)
|
||||
|
||||
def _sync_alt_dance_to_db(self, idx: int, song: dict, alt_dance: str):
|
||||
"""Gem alt_dance_override til playlist_songs — både aktiv og navngiven liste."""
|
||||
pl_ids = []
|
||||
if self._active_playlist_id:
|
||||
pl_ids.append(self._active_playlist_id)
|
||||
if self._named_playlist_id and self._named_playlist_id not in pl_ids:
|
||||
pl_ids.append(self._named_playlist_id)
|
||||
if not pl_ids:
|
||||
return
|
||||
try:
|
||||
import logging
|
||||
from local.local_db import get_db
|
||||
with get_db() as conn:
|
||||
for pl_id in pl_ids:
|
||||
conn.execute(
|
||||
"UPDATE playlist_songs SET alt_dance_override=? "
|
||||
"WHERE playlist_id=? AND position=?",
|
||||
(alt_dance, pl_id, idx + 1)
|
||||
)
|
||||
logging.getLogger(__name__).info(
|
||||
f"alt_dance_override='{alt_dance}' gemt på pos {idx+1} i {pl_id}"
|
||||
)
|
||||
except Exception as e:
|
||||
import logging
|
||||
logging.getLogger(__name__).warning(f"alt_dance_to_db fejl: {e}", exc_info=True)
|
||||
|
||||
def _save_alt_dance_rating(self, song: dict, dance_name: str, rating: int):
|
||||
"""Gem brugerens rating på en alternativ-dans."""
|
||||
import uuid
|
||||
song_id = song.get("id", "")
|
||||
try:
|
||||
from local.local_db import get_db
|
||||
with get_db() as conn:
|
||||
# Find dance_id
|
||||
dance_row = conn.execute(
|
||||
"SELECT id FROM dances WHERE name=? COLLATE NOCASE LIMIT 1",
|
||||
(dance_name,)
|
||||
).fetchone()
|
||||
if not dance_row:
|
||||
return
|
||||
dance_id = dance_row["id"]
|
||||
# Opdater eller indsæt rating
|
||||
existing = conn.execute(
|
||||
"SELECT id FROM song_alt_dances WHERE song_id=? AND dance_id=?",
|
||||
(song_id, dance_id)
|
||||
).fetchone()
|
||||
if existing:
|
||||
conn.execute(
|
||||
"UPDATE song_alt_dances SET user_rating=? WHERE song_id=? AND dance_id=?",
|
||||
(rating, song_id, dance_id)
|
||||
)
|
||||
else:
|
||||
conn.execute(
|
||||
"INSERT INTO song_alt_dances (id, song_id, dance_id, user_rating) VALUES (?,?,?,?)",
|
||||
(str(uuid.uuid4()), song_id, dance_id, rating)
|
||||
)
|
||||
except Exception as e:
|
||||
import logging
|
||||
logging.getLogger(__name__).warning(f"save_alt_dance_rating fejl: {e}")
|
||||
|
||||
def _sync_dance_to_db(self, idx: int, song: dict):
|
||||
"""Gem dance_override til playlist_songs (midlertidigt valg)."""
|
||||
import logging
|
||||
@@ -1169,6 +1248,7 @@ class PlaylistPanel(QWidget):
|
||||
act_played = menu.addAction("✓ Sæt til afspillet")
|
||||
menu.addSeparator()
|
||||
act_dance = menu.addAction("💃 Vælg dans...")
|
||||
act_alt_dance = menu.addAction("💃 Vælg alternativ dans...")
|
||||
is_ws = song.get("is_workshop", False) if song else False
|
||||
act_ws = menu.addAction("🎓 Fjern workshop" if is_ws else "🎓 Markér som workshop")
|
||||
menu.addSeparator()
|
||||
@@ -1199,6 +1279,8 @@ class PlaylistPanel(QWidget):
|
||||
self._refresh(); self._trigger_autosave(); self._trigger_event_state_save()
|
||||
elif action == act_dance and song:
|
||||
self._change_dance(idx, song)
|
||||
elif action == act_alt_dance and song:
|
||||
self._change_alt_dance(idx, song)
|
||||
elif action == act_ws and song:
|
||||
song["is_workshop"] = not song.get("is_workshop", False)
|
||||
self._sync_ws_to_db(idx, song)
|
||||
@@ -1357,6 +1439,7 @@ class PlaylistPanel(QWidget):
|
||||
if not active:
|
||||
dances = song.get("dances", [])
|
||||
active = dances[0] if dances else "— ingen dans —"
|
||||
alt = song.get("alt_dance", "")
|
||||
ws_tag = " 🎓" if song.get("is_workshop") else ""
|
||||
|
||||
# Tilgængeligheds-dot til højre — kun hvis tjekket (ikke yellow)
|
||||
@@ -1364,7 +1447,11 @@ class PlaylistPanel(QWidget):
|
||||
avail_color = {"green": "#27ae60", "red": "#e74c3c"}.get(avail, None)
|
||||
avail_tip = {"green": "Tilgængelig lokalt", "red": "Ikke fundet lokalt"}.get(avail, "")
|
||||
|
||||
text = (f"{i+1:>2}. {active}{ws_tag}\n"
|
||||
dance_line = f"{active}{ws_tag}"
|
||||
if alt:
|
||||
dance_line += f" / {alt}"
|
||||
|
||||
text = (f"{i+1:>2}. {dance_line}\n"
|
||||
f" {song.get('title','—')} · {song.get('artist','')}")
|
||||
item = QListWidgetItem(f"{icon} {text}")
|
||||
item.setData(Qt.ItemDataRole.UserRole, i)
|
||||
|
||||
Reference in New Issue
Block a user