(Server) Added moving entries to arbitrary positions

(web) Updated web, implemented drag and drop
This commit is contained in:
Christoph Stahl 2024-10-13 15:38:35 +02:00
parent a134a07bff
commit 3f6113dab1
6 changed files with 652 additions and 600 deletions

View file

@ -181,3 +181,28 @@ class Queue:
tmp = self._queue[uuid_idx] tmp = self._queue[uuid_idx]
self._queue[uuid_idx] = self._queue[uuid_idx - 1] self._queue[uuid_idx] = self._queue[uuid_idx - 1]
self._queue[uuid_idx - 1] = tmp self._queue[uuid_idx - 1] = tmp
async def move_to(self, uuid: str, target: int) -> None:
"""
Move an :py:class:`syng.entry.Entry` with the uuid to a specific position.
:param uuid: The uuid of the entry.
:type uuid: str
:param target: The target position.
:type target: int
:rtype: None
"""
async with self.readlock:
uuid_idx = 0
for idx, item in enumerate(self._queue):
if item.uuid == uuid or str(item.uuid) == uuid:
uuid_idx = idx
if uuid_idx != target:
entry = self._queue[uuid_idx]
self._queue.remove(entry)
if target > uuid_idx:
target = target - 1
self._queue.insert(target, entry)

View file

@ -972,6 +972,32 @@ async def handle_skip_current(sid: str) -> None:
await send_state(state, room) await send_state(state, room)
@sio.on("move-to")
async def handle_move_to(sid: str, data: dict[str, Any]) -> None:
"""
Handle the "move-to" message.
If on an admin connection, moves the entry specified in the data to the
position specified in the data.
:param sid: The session id of the client requesting.
:type sid: str
:param data: A dictionary with at least an "uuid" and a "target" entry
:type data: dict[str, Any]
:rtype: None
"""
async with sio.session(sid) as session:
room = session["room"]
is_admin = session["admin"]
state = clients[room]
if is_admin:
await state.queue.move_to(data["uuid"], data["target"])
await send_state(state, room)
@sio.on("move-up") @sio.on("move-up")
async def handle_move_up(sid: str, data: dict[str, Any]) -> None: async def handle_move_up(sid: str, data: dict[str, Any]) -> None:
""" """

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico"> <link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Syng Rocks!</title> <title>Syng Rocks!</title>
<script type="module" crossorigin src="/assets/index.66bf185e.js"></script> <script type="module" crossorigin src="/assets/index.953ecce8.js"></script>
<link rel="stylesheet" href="/assets/index.66ac6ae8.css"> <link rel="stylesheet" href="/assets/index.ceeebb4f.css">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>