(Server) Added moving entries to arbitrary positions
(web) Updated web, implemented drag and drop
This commit is contained in:
parent
a134a07bff
commit
3f6113dab1
6 changed files with 652 additions and 600 deletions
|
@ -181,3 +181,28 @@ class Queue:
|
|||
tmp = self._queue[uuid_idx]
|
||||
self._queue[uuid_idx] = self._queue[uuid_idx - 1]
|
||||
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)
|
||||
|
|
|
@ -972,6 +972,32 @@ async def handle_skip_current(sid: str) -> None:
|
|||
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")
|
||||
async def handle_move_up(sid: str, data: dict[str, Any]) -> None:
|
||||
"""
|
||||
|
|
File diff suppressed because one or more lines are too long
598
syng/static/assets/index.953ecce8.js
Normal file
598
syng/static/assets/index.953ecce8.js
Normal file
File diff suppressed because one or more lines are too long
1
syng/static/assets/index.ceeebb4f.css
Normal file
1
syng/static/assets/index.ceeebb4f.css
Normal file
File diff suppressed because one or more lines are too long
|
@ -5,8 +5,8 @@
|
|||
<link rel="icon" href="/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Syng Rocks!</title>
|
||||
<script type="module" crossorigin src="/assets/index.66bf185e.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index.66ac6ae8.css">
|
||||
<script type="module" crossorigin src="/assets/index.953ecce8.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index.ceeebb4f.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
|
Loading…
Add table
Reference in a new issue