Edició de llistes (afegir i esborrar llistes)
This commit is contained in:
@@ -24,3 +24,13 @@ def page(request: Request, logged_in: auth.LoggedIn):
|
||||
@router.get("/api/content/llistes")
|
||||
def content(request: Request, logged_in: auth.LoggedIn):
|
||||
return llistes.llistes_pagina(request, logged_in)
|
||||
|
||||
|
||||
@router.post("/api/llistes/editor/")
|
||||
def insert_row(request: Request, _: auth.RequireLogin):
|
||||
return llistes.llistes_editor_insert_row(request)
|
||||
|
||||
|
||||
@router.delete("/api/llistes/{playlist_id}")
|
||||
def delete_playlist(playlist_id: int, _: auth.RequireLogin):
|
||||
return llistes.llistes_editor_delete_row(playlist_id)
|
||||
|
||||
@@ -1147,10 +1147,6 @@ video {
|
||||
transition-duration: 200ms;
|
||||
}
|
||||
|
||||
.hover\:underline:hover {
|
||||
text-decoration-line: underline;
|
||||
}
|
||||
|
||||
.focus\:outline-none:focus {
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 2px;
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
{% include "fragments/menu.html" %}
|
||||
<div class="p-12 text-center">
|
||||
<h3 class="text-3xl text-beige p-4">Llistes de Repertori</h3>
|
||||
|
||||
{% if logged_in %}
|
||||
<button title="Afegeix una llista"
|
||||
class="text-beige m-2"
|
||||
hx-post="/api/llistes/editor/"
|
||||
hx-target="#{{ playlist_list_id }}"
|
||||
hx-swap="afterbegin transition:true">
|
||||
<i class="fa fa-plus" aria-hidden="true"></i>
|
||||
Afegeix una llista
|
||||
</button>
|
||||
{% endif %}
|
||||
<div id="{{ playlist_list_id }}"
|
||||
class="flex flex-col items-center">
|
||||
{% if playlists %}
|
||||
<div class="flex flex-col items-center">
|
||||
{% for playlist in playlists %}
|
||||
{% include "fragments/llistes/playlist_entry.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-center py-8">
|
||||
<p class="text-beige/70">No hi ha llistes disponibles.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<div class="
|
||||
border rounded border-beige
|
||||
p-2 m-2 w-full max-w-xl
|
||||
">
|
||||
relative"
|
||||
id="playlist-entry-{{ playlist.id }}">
|
||||
<div class="flex justify-between items-start">
|
||||
<div class="flex-1">
|
||||
<p class="text-xl text-white">
|
||||
@@ -9,15 +10,22 @@
|
||||
{% if playlist.name %}
|
||||
{{ playlist.name }}
|
||||
{% else %}
|
||||
Llista de temes #{{ playlist.id }}
|
||||
Llista de temes
|
||||
{% endif %}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{% if logged_in %}
|
||||
<div class="ml-2">
|
||||
{% include "fragments/llista/visibility.html" %}
|
||||
<div class="ml-auto">
|
||||
{% include "fragments/llistes/playlist_visibility.html" %}
|
||||
<button title="Esborra la llista"
|
||||
class="text-beige mx-1"
|
||||
hx-delete="/api/llistes/{{ playlist.id }}"
|
||||
hx-target="#playlist-entry-{{ playlist.id }}"
|
||||
hx-swap="outerHTML swap:0.5s">
|
||||
<i class="fa fa-times" aria-hidden="true"></i>
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{% if not playlist.hidden %}
|
||||
<button title="Llista visible (amaga-la)"
|
||||
class="text-beige mx-2"
|
||||
hx-put="/api/llista/{{ playlist.id }}/invisible"
|
||||
hx-swap="outerHTML">
|
||||
<i class="fa fa-eye" aria-hidden="true"></i>
|
||||
</button>
|
||||
{% else %}
|
||||
<button title="Llista invisible (mostra-la)"
|
||||
class="text-beige mx-2"
|
||||
hx-put="/api/llista/{{ playlist.id }}/visible"
|
||||
hx-swap="outerHTML">
|
||||
<i class="fa fa-eye-slash" aria-hidden="true"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
@@ -73,19 +73,26 @@ def get_playlist_name(playlist_id: int, con: Connection | None = None) -> str |
|
||||
|
||||
def get_all_playlists(logged_in: bool = False, con: Connection | None = None) -> Iterator[model.Playlist]:
|
||||
if logged_in:
|
||||
# Show all playlists for logged in users
|
||||
# Show all playlists for logged in users, except session-associated ones
|
||||
query = """
|
||||
SELECT id, name, hidden
|
||||
FROM playlists
|
||||
ORDER BY id ASC
|
||||
WHERE id NOT IN (
|
||||
SELECT DISTINCT playlist_id
|
||||
FROM session_playlists
|
||||
)
|
||||
ORDER BY id DESC
|
||||
"""
|
||||
else:
|
||||
# Show only visible playlists for non-logged in users
|
||||
# Show only visible playlists for non-logged in users, except session-associated ones
|
||||
query = """
|
||||
SELECT id, name, hidden
|
||||
FROM playlists
|
||||
WHERE hidden = 0
|
||||
ORDER BY id ASC
|
||||
WHERE hidden = 0 AND id NOT IN (
|
||||
SELECT DISTINCT playlist_id
|
||||
FROM session_playlists
|
||||
)
|
||||
ORDER BY id DESC
|
||||
"""
|
||||
|
||||
with get_connection(con) as con:
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from fastapi import Request
|
||||
from folkugat_web.model import playlists as playlists_model
|
||||
from folkugat_web.model.pagines import Pages
|
||||
from folkugat_web.services import playlists as playlists_service
|
||||
from folkugat_web.templates import templates
|
||||
|
||||
|
||||
def llistes_pagina(request, logged_in):
|
||||
def llistes_pagina(request: Request, logged_in: bool):
|
||||
playlists = playlists_service.get_all_playlists(logged_in=logged_in)
|
||||
return templates.TemplateResponse(
|
||||
"fragments/llistes/pagina.html",
|
||||
@@ -13,5 +15,28 @@ def llistes_pagina(request, logged_in):
|
||||
"playlists": playlists,
|
||||
"Pages": Pages,
|
||||
"menu_selected_id": Pages.Llistes,
|
||||
"playlist_list_id": "playlist-list",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def llistes_editor_insert_row(request: Request):
|
||||
new_playlist = playlists_service.create_playlist(name=playlists_model.DEFAULT_PLAYLIST_NAME)
|
||||
return llistes_editor_row(request, new_playlist)
|
||||
|
||||
|
||||
def llistes_editor_row(request: Request, playlist: playlists_model.Playlist):
|
||||
return templates.TemplateResponse(
|
||||
"fragments/llistes/playlist_entry.html",
|
||||
{
|
||||
"request": request,
|
||||
"playlist": playlist,
|
||||
"logged_in": True,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def llistes_editor_delete_row(playlist_id: int):
|
||||
playlists_service.delete_playlist(playlist_id)
|
||||
from fastapi.responses import HTMLResponse
|
||||
return HTMLResponse()
|
||||
|
||||
@@ -6,6 +6,8 @@ from typing import Self
|
||||
from folkugat_web.model.temes import Tema
|
||||
from folkugat_web.utils import groupby
|
||||
|
||||
DEFAULT_PLAYLIST_NAME = "Llista de temes"
|
||||
|
||||
|
||||
class PlaylistType(enum.Enum):
|
||||
SESSION_SETLIST = "session_setlist"
|
||||
|
||||
@@ -233,3 +233,12 @@ def set_visibility(playlist_id: int, hidden: bool) -> playlists.Playlist:
|
||||
|
||||
# Return updated playlist
|
||||
return dataclasses.replace(playlist, hidden=hidden)
|
||||
|
||||
|
||||
def create_playlist(name: str | None = None) -> playlists.Playlist:
|
||||
playlist_id = write.create_playlist(name=name)
|
||||
return get_playlist(playlist_id=playlist_id)
|
||||
|
||||
|
||||
def delete_playlist(playlist_id: int):
|
||||
write.delete_playlist(playlist_id=playlist_id)
|
||||
|
||||
Reference in New Issue
Block a user