-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebuild translation coverage with ajax
- Loading branch information
Showing
6 changed files
with
174 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
integreat_cms/static/src/js/dashboard/translation-coverage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { getCsrfToken } from "../utils/csrf-token"; | ||
|
||
type Content = { | ||
number_of_missing_or_outdated_translations: number; | ||
}; | ||
|
||
const getContent = async (url: string): Promise<Content> => { | ||
const response = await fetch(url, { | ||
method: "POST", | ||
headers: { | ||
"X-CSRFToken": getCsrfToken(), | ||
}, | ||
}); | ||
return response.json(); | ||
}; | ||
|
||
const showAllTotalNumbers = () => { | ||
const elements = document.querySelectorAll<HTMLElement>(".total-results"); | ||
|
||
elements.forEach((element) => { | ||
if (!element.closest("#translation-coverage")) { | ||
const el = element; | ||
el.classList.remove("hidden"); | ||
} | ||
}); | ||
}; | ||
|
||
window.addEventListener("load", async () => { | ||
showAllTotalNumbers(); | ||
|
||
const translationCoverageElement = document.getElementById("translation-coverage"); | ||
|
||
if (!translationCoverageElement) { | ||
return; | ||
} | ||
|
||
const url = translationCoverageElement.dataset.url; | ||
const hideWaitingMessage = () => { | ||
translationCoverageElement.querySelector(".waiting-message").classList.add("hidden"); | ||
}; | ||
|
||
const showSuccessMessage = () => { | ||
translationCoverageElement.querySelector(".success-message").classList.remove("hidden"); | ||
}; | ||
|
||
const showSuccessIcon = () => { | ||
translationCoverageElement.querySelector(".success-icon").classList.remove("hidden"); | ||
}; | ||
|
||
const showDescription = (affectedPageTitle: string) => { | ||
translationCoverageElement.querySelector(".todo-message").classList.remove("hidden"); | ||
(translationCoverageElement.querySelector(".todo-message b") as HTMLElement).innerText = affectedPageTitle; | ||
}; | ||
|
||
const showNumberOfPagesElement = () => { | ||
translationCoverageElement.querySelector(".total-results").classList.remove("hidden"); | ||
}; | ||
|
||
const updateNumberOfPages = (numberOfPages: number) => { | ||
(translationCoverageElement.querySelector(".total-results span") as HTMLElement).innerText = | ||
numberOfPages.toString(); | ||
}; | ||
|
||
const showButton = () => { | ||
translationCoverageElement.querySelector(".todo-button").classList.remove("hidden"); | ||
}; | ||
|
||
if (url) { | ||
console.log(url); | ||
const json = await getContent(url); | ||
console.log(json); | ||
hideWaitingMessage(); | ||
showNumberOfPagesElement(); | ||
if (json.number_of_missing_or_outdated_translations > 0) { | ||
showDescription(String(json.number_of_missing_or_outdated_translations)); | ||
updateNumberOfPages(json.number_of_missing_or_outdated_translations); | ||
showButton(); | ||
} else { | ||
showSuccessMessage(); | ||
showSuccessIcon(); | ||
updateNumberOfPages(0); | ||
} | ||
} | ||
}); |