From 756c1aac7fe5659691e98f3c3ea10ca10528b2a3 Mon Sep 17 00:00:00 2001 From: afabiani Date: Fri, 20 Nov 2020 05:12:14 +0000 Subject: [PATCH] [Performance] Dinamically loading the list of users geo-limits (cherry picked from commit c54cc617337efdfb6319a93abf77beed4d016963) --- geonode/layers/views.py | 2 +- geonode/templates/_permissions_form.html | 151 ++++++++++++++++------- 2 files changed, 106 insertions(+), 47 deletions(-) diff --git a/geonode/layers/views.py b/geonode/layers/views.py index e933fd22a56..871ca27a1c3 100644 --- a/geonode/layers/views.py +++ b/geonode/layers/views.py @@ -764,7 +764,7 @@ def sld_definition(style): if request.user.is_authenticated and (request.user.is_superuser or "change_resourcebase_permissions" in perms_list): context_dict['users'] = [user for user in get_user_model().objects.all().exclude( - id=request.user.id).exclude(is_superuser=True)] + id=request.user.id).exclude(is_superuser=True).order_by('username')] if request.user.is_superuser: context_dict['groups'] = [group for group in GroupProfile.objects.all()] else: diff --git a/geonode/templates/_permissions_form.html b/geonode/templates/_permissions_form.html index 79c7fab8c75..fed37ae42d3 100644 --- a/geonode/templates/_permissions_form.html +++ b/geonode/templates/_permissions_form.html @@ -104,53 +104,15 @@ var userList = new List('gis-limits-users', {valueNames: ['gis-limits-user-name', 'gis-limits-user-title']}); var groupList = new List('gis-limits-groups', {valueNames: ['gis-limits-group-name', 'gis-limits-group-title']}); + var limit = 5; + var offset = 0; + var lastOffset = 0; + $(function() { + load_gis_limits_users(); + $('#gis-limits-users-content').on("scroll", function(event) { + var scrollHeight = $('#gis-limits-users').height(); + var scrollPosition = $('#gis-limits-users-content').scrollTop(); + if (scrollPosition >= 50*(offset-3)){ + if (offset == lastOffset) { + offset += limit; + load_gis_limits_users(); + } + // event.stopPropagation(); + event.preventDefault(); + } + }); + + function load_gis_limits_users() { + $.ajax({ + url: "/api/profiles/", + dataType: 'json', + data: { + limit: limit, + offset: offset, + order_by: 'username' + }, + beforeSend: function() { + $('#loading_icon').show(); + }, + success: function(data) { + $('#loading_icon').hide(); + users = $(data.objects); + if (users.length) { + var html = ""; + users.each(function() { + userid = $(this)[0].id; + username = $(this)[0].username; + avatar = $(this)[0].avatar_100; + organization = $(this)[0].organization; + if (organization == null) { + organization = "{% trans "No Group" %}"; + } + html += ` + +
+
+ +
+

${username}

+

${organization}

+
+
+
+
+ + + + +
+
+
+
+
` + }); + + if (html) { + $('#gis-limits-users-list').append(html); + lastOffset = offset; + // offset += limit; + } + } else { + $('#warning_area').text("That's all folks!"); + } + }, + error: function() { + $('#loading_icon').hide(); + $('#warning_area').text('Unable to load articles, please check your internet connection or try again later.'); + console.log('Ajax Request Has Failed'); + } + }); + } + }); $(".input-file").before( function() { @@ -553,7 +611,7 @@ }); } - $('.serialize-geo-limit').click(function() { + $(document).on('click', '.serialize-geo-limit', function() { serializeGeoLimit($(this).attr('id')); }); @@ -624,7 +682,8 @@ }); } - $('.deserialize-geo-limit').click(function(event) { + $(document).on('click', '.deserialize-geo-limit', function(event) { + console.log($(this).attr('id')); deserializeGeoLimit($(this).attr('id')); }); @@ -675,10 +734,10 @@ }); } - $('.delete-geo-limit').click(function() { + $(document).on('click', '.delete-geo-limit', function() { deleteGeoLimit($(this).attr('id')); }); } }); -{% endif %} \ No newline at end of file +{% endif %}