Skip to content

Commit

Permalink
Add async top projects on organisation view
Browse files Browse the repository at this point in the history
  • Loading branch information
suecarmol committed Jun 5, 2024
1 parent b992ccc commit bf907bb
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ <h3>Latest link events</h3>
getEditorCount(collection_id, form_data);
getProjectCount(collection_id, form_data);
getTopPages(collection_id, form_data);
getTopProjects(collection_id, form_data);
{% endfor %}

function openGraph(evt, collection, graphName) {
Expand Down Expand Up @@ -296,4 +297,41 @@ <h3>Latest link events</h3>
});
}

function getTopProjects(collection_id, form_data){
$.ajax({
url: "{% url 'organisations:top_projects' %}?collection=" + collection_id + "&form_data=" + JSON.stringify(form_data),
beforeSend: function() {
// Show loading spinner
var loadingSpinner = document.createElement("div");
loadingSpinner.id = "loading-spinner-projects";
loadingSpinner.classList.add("spinner-border");
loadingSpinner.role = "status";
loadingSpinner.innerHTML = '<span class="sr-only">Loading...</span>';
document.getElementById(collection_id + "-top-projects-table").appendChild(loadingSpinner);
},
// on success
success: function(response) {
document.getElementById("loading-spinner-projects").style.display = "none";
// Building table data
projects = JSON.parse(response.top_projects)
for (var i = 0; i < projects.length; i++) {
var tr = document.createElement("tr");
var tdProjectName = document.createElement("td");
tdProjectName.appendChild(document.createTextNode(projects[i].project_name));
var tdLinks = document.createElement("td");
tdLinks.innerHTML = projects[i].links_diff;
tr.appendChild(tdProjectName);
tr.appendChild(tdLinks);
document.getElementById(collection_id + "-top-projects-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 bf907bb

Please sign in to comment.