From 23e7bf71bcca6eefbfecd3b909c824a9208e8db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Sat, 9 Oct 2021 19:34:12 +0200 Subject: [PATCH] Add transfer status toggle button --- backend/app/database.py | 25 ++++++++++++++++++++++--- backend/app/main.py | 9 +++++++++ backend/app/templates/main_admin.html | 21 ++++++++++++++++++++- backend/app/templates/songlist.html | 6 ++++++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/backend/app/database.py b/backend/app/database.py index 4cae8a2..8fe2cd2 100644 --- a/backend/app/database.py +++ b/backend/app/database.py @@ -33,7 +33,7 @@ def import_songs(song_csv): def create_entry_table(): conn = open_db() conn.execute('CREATE TABLE IF NOT EXISTS '+entry_table + - ' (ID INTEGER PRIMARY KEY NOT NULL, Song_Id INTEGER NOT NULL, Name VARCHAR(255), Client_Id VARCHAR(36))') + ' (ID INTEGER PRIMARY KEY NOT NULL, Song_Id INTEGER NOT NULL, Name VARCHAR(255), Client_Id VARCHAR(36), Transferred INTEGER DEFAULT 0)') conn.close() @@ -63,7 +63,7 @@ def create_song_table(): def create_list_view(): conn = open_db() conn.execute("""CREATE VIEW IF NOT EXISTS [Liste] AS - SELECT Name, Title, Artist, entries.Id, songs.Id + SELECT Name, Title, Artist, entries.Id, songs.Id, entries.Transferred FROM entries, songs WHERE entries.Song_Id=songs.Id""") conn.close() @@ -139,18 +139,37 @@ def add_sung_song(entry_id): return True +def toggle_transferred(entry_id): + conn = open_db() + cur = conn.cursor() + cur.execute("SELECT Transferred FROM entries WHERE ID =?", (entry_id,)) + marked = cur.fetchall()[0][0] + if(marked == 0): + cur.execute( + "UPDATE entries SET Transferred = 1 WHERE ID =?", (entry_id,)) + else: + cur.execute( + "UPDATE entries SET Transferred = 0 WHERE ID =?", (entry_id,)) + conn.commit() + conn.close() + return True + + def check_entry_quota(client_id): conn = open_db() cur = conn.cursor() - cur.execute("SELECT Count(*) FROM entries WHERE entries.Client_Id = ?", (client_id,)) + cur.execute( + "SELECT Count(*) FROM entries WHERE entries.Client_Id = ?", (client_id,)) return cur.fetchall()[0][0] + def check_queue_length(): conn = open_db() cur = conn.cursor() cur.execute("SELECT Count(*) FROM entries") return cur.fetchall()[0][0] + def clear_played_songs(): conn = open_db() cur = conn.cursor() diff --git a/backend/app/main.py b/backend/app/main.py index 55611b6..a36000c 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -172,6 +172,15 @@ def mark_sung(entry_id): else: return Response('{"status": "FAIL"}', mimetype='text/json') +@app.route("/api/entries/mark_transferred/") +@nocache +@basic_auth.required +def mark_transferred(entry_id): + if database.toggle_transferred(entry_id): + return Response('{"status": "OK"}', mimetype='text/json') + else: + return Response('{"status": "FAIL"}', mimetype='text/json') + @app.route("/api/entries/accept/") @nocache diff --git a/backend/app/templates/main_admin.html b/backend/app/templates/main_admin.html index 42d40f8..5234a88 100644 --- a/backend/app/templates/main_admin.html +++ b/backend/app/templates/main_admin.html @@ -146,6 +146,19 @@ table td:nth-child(2) { $("#entrytable").bootstrapTable('refresh') } + + function markEntryAsTransferred(entry_id) { + $.ajax({ + type: 'GET', + url: '/api/entries/mark_transferred/'+entry_id, + contentType: "application/json", + dataType: 'json', + async: false + }); + $("#entrytable").bootstrapTable('refresh') + + } + function DeleteSelectedEntries(ids) { $.ajax({ type: 'POST', @@ -182,7 +195,13 @@ table td:nth-child(2) { }); } function TableActions (value, row, index) { - return " "; + let outerHTML = "" + if (row.Transferred==1) { + outerHTML = "  "; + } else { + outerHTML = "  "; + } + return outerHTML; } function getIdSelections() { return $.map($("#entrytable").bootstrapTable('getSelections'), function (row) { diff --git a/backend/app/templates/songlist.html b/backend/app/templates/songlist.html index 5294024..eb0221e 100644 --- a/backend/app/templates/songlist.html +++ b/backend/app/templates/songlist.html @@ -111,6 +111,7 @@ } + {% if not auth %} function entriesAccepted() { $.getJSON("/api/entries/accept", (data, out) => { if (data["value"] == 0) { @@ -125,6 +126,11 @@ }) } + {% else %} + function entriesAccepted() { + $(".enqueueButton").prop("disabled", false) + } + {% endif %} {% endblock %} \ No newline at end of file