From 2740785602dedaada5caf5c06685814b747dc51b Mon Sep 17 00:00:00 2001 From: suecarmol Date: Tue, 4 Jun 2024 21:47:52 -0600 Subject: [PATCH] Make top users asyn in organisations --- .../organisation_charts_include.html | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/extlinks/organisations/templates/organisations/organisation_charts_include.html b/extlinks/organisations/templates/organisations/organisation_charts_include.html index bbc3a94a..828aa87b 100644 --- a/extlinks/organisations/templates/organisations/organisation_charts_include.html +++ b/extlinks/organisations/templates/organisations/organisation_charts_include.html @@ -164,6 +164,7 @@

Latest link events

getProjectCount(collection_id, form_data); getTopPages(collection_id, form_data); getTopProjects(collection_id, form_data); + getTopUsers(collection_id, form_data); {% endfor %} function openGraph(evt, collection, graphName) { @@ -334,4 +335,43 @@

Latest link events

}); } + function getTopUsers(collection_id, form_data){ + $.ajax({ + url: "{% url 'organisations:top_users' %}?collection=" + collection_id + "&form_data=" + JSON.stringify(form_data), + beforeSend: function() { + //Show loading spinner + var loadingSpinner = document.createElement("div"); + loadingSpinner.id = "loading-spinner-users"; + loadingSpinner.classList.add("spinner-border"); + loadingSpinner.role = "status"; + loadingSpinner.innerHTML = 'Loading...'; + document.getElementById(collection_id + "-top-users-table").appendChild(loadingSpinner); + }, + // on success + success: function(response) { + document.getElementById("loading-spinner-users").style.display = "none"; + // Building table data + users = JSON.parse(response.top_users) + for (var i = 0; i < users.length; i++) { + var tr = document.createElement("tr"); + var tdUsername = document.createElement("td"); + var a = document.createElement("a"); + a.href = "https://meta.wikimedia.org/wiki/User:" + users[i].username; + a.appendChild(document.createTextNode(users[i].username)); + tdUsername.appendChild(a); + var tdLinks = document.createElement("td"); + tdLinks.innerHTML = users[i].links_diff; + tr.appendChild(tdUsername); + tr.appendChild(tdLinks); + document.getElementById(collection_id + "-top-users-table").appendChild(tr); + } + + }, + // on error + error: function(response) { + // alert the error if any error occured + console.log(response.responseJSON.errors) + } + }); + }