Skip to content

Commit

Permalink
Add loading text to info box
Browse files Browse the repository at this point in the history
  • Loading branch information
jmforsythe committed Aug 21, 2023
1 parent c020703 commit b976879
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions static/javascript/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,37 @@ function set_info_content(...child_elements) {
async function get_author_stats(author_email) {
return fetch(`/${DATABASE_NAME}/query/filesChangeMostByAuthor?`
+ new URLSearchParams(author_email)
).then(response => response.json())
)
}

async function get_commit_stats(author_email) {
return fetch(`/${DATABASE_NAME}/query/filesChangeMostByCommit?`
+ new URLSearchParams(author_email)
).then(response => response.json())
)
}

async function get_file_stats(path) {
return fetch(`/${DATABASE_NAME}/query/rankAuthorsByLinesChangedInPath?`
+ new URLSearchParams(path)
).then(response => response.json())
)
}

async function get_file_commits(path) {
return fetch(`/${DATABASE_NAME}/query/rankCommitsByLinesChangedForFile?`
+ new URLSearchParams(path)
).then(response => response.json())
)
}

async function get_all_authors() {
return fetch(`/${DATABASE_NAME}/query/rankAuthorsByLinesChanged`).then(
response => response.json()
)
return fetch(`/${DATABASE_NAME}/query/rankAuthorsByLinesChanged`)
}

async function get_all_commits() {
return fetch(`/${DATABASE_NAME}/query/rankCommitsByLinesChanged`).then(
response => response.json()
)
return fetch(`/${DATABASE_NAME}/query/rankCommitsByLinesChanged`)
}

async function get_all_files() {
return fetch(`/${DATABASE_NAME}/query/rankFilesByLinesChanged`).then(
response => response.json()
)
return fetch(`/${DATABASE_NAME}/query/rankFilesByLinesChanged`)
}

const FIELD_TO_FUNCTION = new Map([
Expand Down Expand Up @@ -137,12 +131,23 @@ function sql_response_to_table(r) {
return table
}

function update_info_box_downloading() {
set_info_content(document.createTextNode("Fetching data..."))
}

function update_info_box_rendering() {
set_info_content(document.createTextNode("Rendering data..."))
}

async function update_info_box_with_author_stats(author_email) {
const h1 = document.createElement("h1")
h1.appendChild(document.createTextNode("Files changed most by author"))
const h2 = document.createElement("h2")
h2.appendChild(document.createTextNode(author_email))
const table = sql_response_to_table(await get_author_stats(author_email))
update_info_box_downloading()
const response = await get_author_stats(hash)
update_info_box_rendering()
const table = sql_response_to_table(await response.json())
set_info_content(h1, h2, table)
}

Expand All @@ -151,7 +156,10 @@ async function update_info_box_with_commit_stats(hash) {
h1.appendChild(document.createTextNode("Files changed in commit"))
const h2 = document.createElement("h2")
h2.appendChild(document.createTextNode(hash))
const table = sql_response_to_table(await get_commit_stats(hash))
update_info_box_downloading()
const response = await get_commit_stats(hash)
update_info_box_rendering()
const table = sql_response_to_table(await response.json())
set_info_content(h1, h2, table)
}

Expand All @@ -160,14 +168,20 @@ async function update_info_box_with_file_stats(path) {
h1.appendChild(document.createTextNode("Author emails with most changes to"))
const h2 = document.createElement("h2")
h2.appendChild(document.createTextNode(path))
const table = sql_response_to_table(await get_file_stats(path))
update_info_box_downloading()
const response = await get_file_stats(path)
update_info_box_rendering()
const table = sql_response_to_table(await response.json())
set_info_content(h1, h2, table)
}

async function update_info_box_all_authors() {
const h1 = document.createElement("h1")
h1.appendChild(document.createTextNode("Author emails sorted by most changes"))
const table = sql_response_to_table(await get_all_authors())
update_info_box_downloading()
const response = await get_all_authors()
update_info_box_rendering()
const table = sql_response_to_table(await response.json())
set_info_content(h1, table)
}

Expand All @@ -179,7 +193,10 @@ async function browse_authors() {
async function update_info_box_all_commits() {
const h1 = document.createElement("h1")
h1.appendChild(document.createTextNode("Commits sorted by most changes"))
const table = sql_response_to_table(await get_all_commits())
update_info_box_downloading()
const response = await get_all_commits()
update_info_box_rendering()
const table = sql_response_to_table(await response.json())
set_info_content(h1, table)
}

Expand All @@ -191,7 +208,10 @@ async function browse_commits() {
async function update_info_box_all_files() {
const h1 = document.createElement("h1")
h1.appendChild(document.createTextNode("Files sorted by most changes"))
const table = sql_response_to_table(await get_all_files())
update_info_box_downloading()
const response = await get_all_files()
update_info_box_rendering()
const table = sql_response_to_table(await response.json())
set_info_content(h1, table)
}

Expand Down

0 comments on commit b976879

Please sign in to comment.