feat: Return a valid json if playlist/library query result is empty, implement #175.
This commit is contained in:
parent
56399c499f
commit
8472604fdc
13
interface.py
13
interface.py
@ -232,7 +232,12 @@ def index():
|
|||||||
@requires_auth
|
@requires_auth
|
||||||
def playlist():
|
def playlist():
|
||||||
if len(var.playlist) == 0:
|
if len(var.playlist) == 0:
|
||||||
return ('', 204)
|
return jsonify({
|
||||||
|
'items': [],
|
||||||
|
'current_index': -1,
|
||||||
|
'length': 0,
|
||||||
|
'start_from': 0
|
||||||
|
})
|
||||||
|
|
||||||
DEFAULT_DISPLAY_COUNT = 11
|
DEFAULT_DISPLAY_COUNT = 11
|
||||||
_from = 0
|
_from = 0
|
||||||
@ -581,7 +586,11 @@ def library():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if not total_count:
|
if not total_count:
|
||||||
return '', 204
|
return jsonify({
|
||||||
|
'items': [],
|
||||||
|
'total_pages': 0,
|
||||||
|
'active_page': 0
|
||||||
|
})
|
||||||
|
|
||||||
if request.form['action'] == 'add':
|
if request.form['action'] == 'add':
|
||||||
items = dicts_to_items(var.music_db.query_music(condition))
|
items = dicts_to_items(var.music_db.query_music(condition))
|
||||||
|
@ -164,11 +164,16 @@ function displayPlaylist(data) {
|
|||||||
playlist_loading.hide();
|
playlist_loading.hide();
|
||||||
$('.playlist-item').remove();
|
$('.playlist-item').remove();
|
||||||
const items = data.items;
|
const items = data.items;
|
||||||
|
const length = data.length;
|
||||||
|
if (items.length === 0){
|
||||||
|
playlist_empty.removeClass('d-none');
|
||||||
|
playlist_table.animate({ opacity: 1 }, 200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
playlist_items = {};
|
playlist_items = {};
|
||||||
for (const i in items) {
|
for (const i in items) {
|
||||||
playlist_items[items[i].index] = items[i];
|
playlist_items[items[i].index] = items[i];
|
||||||
}
|
}
|
||||||
const length = data.length;
|
|
||||||
const start_from = data.start_from;
|
const start_from = data.start_from;
|
||||||
playlist_range_from = start_from;
|
playlist_range_from = start_from;
|
||||||
playlist_range_to = start_from + items.length - 1;
|
playlist_range_to = start_from + items.length - 1;
|
||||||
@ -200,9 +205,7 @@ function displayPlaylist(data) {
|
|||||||
displayActiveItem(data.current_index);
|
displayActiveItem(data.current_index);
|
||||||
updatePlayerInfo(playlist_items[data.current_index]);
|
updatePlayerInfo(playlist_items[data.current_index]);
|
||||||
bindPlaylistEvent();
|
bindPlaylistEvent();
|
||||||
playlist_table.animate({
|
playlist_table.animate({ opacity: 1 }, 200);
|
||||||
opacity: 1,
|
|
||||||
}, 200);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,11 +254,6 @@ function updatePlaylist() {
|
|||||||
data: data,
|
data: data,
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: displayPlaylist,
|
200: displayPlaylist,
|
||||||
204: function () {
|
|
||||||
playlist_loading.hide();
|
|
||||||
playlist_empty.removeClass('d-none');
|
|
||||||
$('.playlist-item').remove();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
playlist_table.animate({
|
playlist_table.animate({
|
||||||
@ -642,11 +640,6 @@ function updateResults(dest_page = 1) {
|
|||||||
data: data,
|
data: data,
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: processResults,
|
200: processResults,
|
||||||
204: function () {
|
|
||||||
lib_loading.hide();
|
|
||||||
lib_empty.show();
|
|
||||||
page_ul.empty();
|
|
||||||
},
|
|
||||||
403: function () {
|
403: function () {
|
||||||
location.reload(true);
|
location.reload(true);
|
||||||
},
|
},
|
||||||
@ -738,6 +731,13 @@ function processResults(data) {
|
|||||||
const total_pages = data.total_pages;
|
const total_pages = data.total_pages;
|
||||||
const active_page = data.active_page;
|
const active_page = data.active_page;
|
||||||
const items = data.items;
|
const items = data.items;
|
||||||
|
if (items.length === 0) {
|
||||||
|
lib_loading.hide();
|
||||||
|
lib_empty.show();
|
||||||
|
page_ul.empty();
|
||||||
|
lib_group.animate({ opacity: 1 }, 200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
items.forEach(
|
items.forEach(
|
||||||
function (item) {
|
function (item) {
|
||||||
addResultItem(item);
|
addResultItem(item);
|
||||||
@ -797,10 +797,7 @@ function processResults(data) {
|
|||||||
page_no_copy.appendTo(page_li_copy);
|
page_no_copy.appendTo(page_li_copy);
|
||||||
page_li_copy.appendTo(page_ul);
|
page_li_copy.appendTo(page_ul);
|
||||||
}
|
}
|
||||||
|
lib_group.animate({ opacity: 1 }, 200);
|
||||||
lib_group.animate({
|
|
||||||
opacity: 1,
|
|
||||||
}, 200);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1166,6 +1163,7 @@ function playerSetIdle() {
|
|||||||
function updatePlayerInfo(item) {
|
function updatePlayerInfo(item) {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
playerSetIdle();
|
playerSetIdle();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
playerArtwork.style.display = 'block';
|
playerArtwork.style.display = 'block';
|
||||||
playerArtworkIdle.style.display = 'none';
|
playerArtworkIdle.style.display = 'none';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user