mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-05-19 11:01:47 +02:00
Add option to disable new entries
This commit is contained in:
parent
655cb73e0c
commit
58695e568f
36
app/main.py
36
app/main.py
@ -8,6 +8,7 @@ from flask_basicauth import BasicAuth
|
||||
app = Flask(__name__, static_url_path='/static')
|
||||
|
||||
basic_auth = BasicAuth(app)
|
||||
accept_entries = False
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
@ -18,13 +19,17 @@ def home():
|
||||
|
||||
@app.route('/api/enqueue', methods=['POST'])
|
||||
def enqueue():
|
||||
if not request.json:
|
||||
print(request.data)
|
||||
abort(400)
|
||||
name = request.json['name']
|
||||
song_id = request.json['id']
|
||||
database.add_entry(name,song_id)
|
||||
return Response('{"status":"OK"}', mimetype='text/json')
|
||||
if accept_entries:
|
||||
if not request.json:
|
||||
print(request.data)
|
||||
abort(400)
|
||||
name = request.json['name']
|
||||
song_id = request.json['id']
|
||||
database.add_entry(name, song_id)
|
||||
return Response('{"status":"OK"}', mimetype='text/json')
|
||||
else:
|
||||
return Response('{"status":"Currently not accepting entries"}', mimetype='text/json',status=423)
|
||||
|
||||
|
||||
@app.route("/list")
|
||||
def songlist():
|
||||
@ -97,6 +102,23 @@ def mark_sung(entry_id):
|
||||
else:
|
||||
return Response('{"status": "FAIL"}', mimetype='text/json')
|
||||
|
||||
@app.route("/api/entries/accept/<value>")
|
||||
@basic_auth.required
|
||||
def set_accept_entries(value):
|
||||
global accept_entries
|
||||
if (value=='0' or value=='1'):
|
||||
accept_entries=bool(int(value))
|
||||
return Response('{"status": "OK"}', mimetype='text/json')
|
||||
else:
|
||||
return Response('{"status": "FAIL"}', mimetype='text/json', status=400)
|
||||
|
||||
|
||||
@app.route("/api/entries/accept")
|
||||
def get_accept_entries():
|
||||
global accept_entries
|
||||
return Response('{"status": "OK", "value": '+str(int(accept_entries))+'}', mimetype='text/json')
|
||||
|
||||
|
||||
@app.route("/api/played/clear")
|
||||
@basic_auth.required
|
||||
def clear_played_songs():
|
||||
|
@ -25,6 +25,9 @@
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
|
||||
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
|
||||
|
||||
<!-- Bootstraptoggle -->
|
||||
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -93,6 +96,7 @@
|
||||
integrity="sha256-4F7e4JsAJyLUdpP7Q8Sah866jCOhv72zU5E8lIRER4w=" crossorigin="anonymous">
|
||||
</script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
|
||||
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
|
||||
{% block extrajs %}{% endblock %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
|
@ -10,6 +10,7 @@
|
||||
<button type="button" class="topbutton btn btn-danger" onclick="confirmUpdateSongDatabase()"><i
|
||||
class="fas fa-file-import mr-2"></i>Song-Datenbank
|
||||
aktualisieren</button>
|
||||
<input id="entryToggle" type="checkbox" class="topbutton" data-toggle="toggle" data-on="Eintragen erlaubt" data-off="Eintragen deaktiviert" data-onstyle="success" data-offstyle="danger">
|
||||
</div>
|
||||
<table class="table"
|
||||
id="entrytable"
|
||||
@ -40,7 +41,12 @@
|
||||
{% block extrajs %}
|
||||
<script>
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
$('#entryToggle').change(function() {
|
||||
$.ajax({url: "/api/entries/accept/"+($('#entryToggle').is(":checked") ? "1" : "0")});
|
||||
refreshEntryToggle()
|
||||
})
|
||||
refreshEntryToggle()
|
||||
})
|
||||
function confirmDeleteEntry(name, entry_id) {
|
||||
bootbox.confirm("Wirklich den Eintrag von "+name+" löschen?", function(result){
|
||||
@ -94,6 +100,18 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
function refreshEntryToggle() {
|
||||
$.getJSON("/api/entries/accept", (data) => {
|
||||
if (data["value"]!=$('#entryToggle').is(":checked")) {
|
||||
if(data["value"]==1) {
|
||||
$('#entryToggle').bootstrapToggle('on')
|
||||
}
|
||||
else {
|
||||
$('#entryToggle').bootstrapToggle('off')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
function deleteEntry(entry_id) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
|
@ -47,7 +47,7 @@
|
||||
$.each(data, function (key, val) {
|
||||
items.push("<tr><td>"+val[0]+`</td>
|
||||
<td><button type='button'
|
||||
class='btn btn-primary justify-content-center align-content-between'
|
||||
class='btn btn-primary justify-content-center align-content-between enqueueButton'
|
||||
data-toggle='modal'
|
||||
data-target='#enqueueModal' onclick='setSelectedId(`+val[1]+`)'><i
|
||||
class="fas fa-plus"></i></button></td>
|
||||
@ -62,6 +62,12 @@
|
||||
}
|
||||
});
|
||||
|
||||
$.getJSON("/api/entries/accept", (data) => {
|
||||
if (data["value"]==0) {
|
||||
$("#filter").prop("disabled",true);
|
||||
}
|
||||
})
|
||||
|
||||
$("#nameForm").submit( function (e) {
|
||||
e.preventDefault();
|
||||
submitModal();
|
||||
@ -69,7 +75,7 @@
|
||||
});
|
||||
|
||||
|
||||
function enqueue(id,name,success_callback) {
|
||||
function enqueue(id,name,success_callback, blocked_callback) {
|
||||
var data = {
|
||||
"name": name,
|
||||
"id": id
|
||||
@ -79,6 +85,9 @@
|
||||
url: '/api/enqueue',
|
||||
data: JSON.stringify(data), // or JSON.stringify ({name: 'jonas'}),
|
||||
success: success_callback,
|
||||
statusCode: {
|
||||
423: blocked_callback
|
||||
},
|
||||
contentType: "application/json",
|
||||
dataType: 'json'
|
||||
});
|
||||
@ -91,9 +100,16 @@
|
||||
function submitModal() {
|
||||
var name = $("#singerNameInput").val();
|
||||
var id = $("#selectedId").attr("value");
|
||||
enqueue(id,name,function(){
|
||||
enqueue(id,name,function () {
|
||||
$("#enqueueModal").modal('hide');
|
||||
window.location.href = '/#end';
|
||||
}, function () {
|
||||
bootbox.alert({
|
||||
message: "Es werden leider keine neuen Anmeldungen mehr angenommen. Tut mir leid :(",
|
||||
});
|
||||
$(".enqueueButton").prop("disabled",true);
|
||||
$("#enqueueModal").modal('hide');
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user