Skip to content

Commit

Permalink
Make top users asyn in organisations
Browse files Browse the repository at this point in the history
  • Loading branch information
suecarmol committed Jun 5, 2024
1 parent bf907bb commit 2740785
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ <h3>Latest link events</h3>
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) {
Expand Down Expand Up @@ -334,4 +335,43 @@ <h3>Latest link events</h3>
});
}

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 = '<span class="sr-only">Loading...</span>';
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)
}
});
}
</script>

0 comments on commit 2740785

Please sign in to comment.