Fix manual refreshing the libraries/users list

This commit is contained in:
JonnyWong16 2018-02-16 11:17:30 -08:00
parent dc4e6edc9a
commit b4a4f60b04
3 changed files with 34 additions and 22 deletions

View file

@ -180,18 +180,19 @@
% if _session['user_group'] == 'admin':
$("#refresh-libraries-list").click(function () {
showMsg('Refreshing libraries list...', true, false);
$.ajax({
url: 'refresh_libraries_list',
cache: false,
async: true,
success: function (data) {
showMsg('<i class="fa fa-refresh"></i>&nbspLibraries list refresh started...', false, true, 2000, false);
},
complete: function (data) {
showMsg('<i class="fa fa-check"></i>&nbspLibraries list refreshed.', false, true, 2000, false);
},
error: function (jqXHR, textStatus, errorThrown) {
showMsg('<i class="fa fa-exclamation-circle"></i>&nbspUnable to refresh libraries list.', false, true, 2000, true);
complete: function (xhr, status) {
var result = $.parseJSON(xhr.responseText);
var msg = result.message;
if (result.result == 'success') {
showMsg('<i class="fa fa-check"></i> ' + msg, false, true, 2000, false);
} else {
showMsg('<i class="fa fa-times"></i> ' + msg, false, true, 2000, true);
}
}
});
});

View file

@ -184,18 +184,19 @@
% if _session['user_group'] == 'admin':
$("#refresh-users-list").click(function() {
showMsg('Refreshing users list...', true, false);
$.ajax({
url: 'refresh_users_list',
cache: false,
async: true,
success: function(data) {
showMsg('<i class="fa fa-check"></i>&nbspUsers list refresh started...', false, true, 2000, false);
},
complete: function (data) {
showMsg('<i class="fa fa-check"></i>&nbspUsers list refreshed.', false, true, 2000, false);
},
error: function (jqXHR, textStatus, errorThrown) {
showMsg('<i class="fa fa-exclamation-circle"></i>&nbspUnable to refresh users list.', false, true, 2000, true);
complete: function (xhr, status) {
var result = $.parseJSON(xhr.responseText);
var msg = result.message;
if (result.result == 'success') {
showMsg('<i class="fa fa-check"></i> ' + msg, false, true, 2000, false);
} else {
showMsg('<i class="fa fa-times"></i> ' + msg, false, true, 2000, true);
}
}
});
});

View file

@ -458,12 +458,17 @@ class WebInterface(object):
logger.warn(u"Unable to retrieve data for get_library_sections.")
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
def refresh_libraries_list(self, **kwargs):
""" Refresh the libraries list on it's own thread. """
threading.Thread(target=libraries.refresh_libraries).start()
""" Manually refresh the libraries list. """
logger.info(u"Manual libraries list refresh requested.")
return True
result = libraries.refresh_libraries()
if result:
return {'result': 'success', 'message': 'Libraries list refreshed.'}
else:
return {'result': 'error', 'message': 'Unable to refresh libraries list.'}
@cherrypy.expose
@requireAuth()
@ -1079,12 +1084,17 @@ class WebInterface(object):
return user_list
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
def refresh_users_list(self, **kwargs):
""" Refresh the users list on it's own thread. """
threading.Thread(target=users.refresh_users).start()
""" Manually refresh the users list. """
logger.info(u"Manual users list refresh requested.")
return True
result = users.refresh_users()
if result:
return {'result': 'success', 'message': 'Users list refreshed.'}
else:
return {'result': 'error', 'message': 'Unable to refresh users list.'}
@cherrypy.expose
@requireAuth()