-
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.
Add translation coverage row to dashboard
- Loading branch information
Showing
8 changed files
with
280 additions
and
4 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
38 changes: 38 additions & 0 deletions
38
integreat_cms/cms/templates/dashboard/todo_dashboard_rows/_missing_translations_row.html
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,38 @@ | ||
{% extends "../_todo_dashboard_row.html" %} | ||
{% load i18n %} | ||
{% block todo_dashboard_icon %} | ||
languages | ||
{% endblock todo_dashboard_icon %} | ||
{% block todo_dashboard_title_link %} | ||
{% url 'translation_coverage' region_slug=request.region.slug %} | ||
{% endblock todo_dashboard_title_link %} | ||
{% block todo_dashboard_title %} | ||
{% translate "Outdated and missing translations" %} | ||
{% endblock todo_dashboard_title %} | ||
{% block todo_dashboard_number %} | ||
{% with total=number_of_missing_translations %} | ||
{{ block.super }} | ||
{% endwith %} | ||
{% endblock todo_dashboard_number %} | ||
{% block todo_dashboard_description %} | ||
{% if number_of_missing_translations > 0 %} | ||
{% blocktranslate trimmed %} | ||
Your pages currently have <b>{{ number_of_missing_translations }} pages </b>that have an outdated or no translation. | ||
In order for the users to benefit from your content you should translate them or have them translated. | ||
{% endblocktranslate %} | ||
{% else %} | ||
{% blocktranslate trimmed %} | ||
At the moment all pages have up-to-date translations. Good job! | ||
{% endblocktranslate %} | ||
{% endif %} | ||
{% endblock todo_dashboard_description %} | ||
{% block todo_dashboard_button_link %} | ||
{% if outdated_pages %} | ||
<a class="btn !rounded-full" | ||
href="{% url 'translation_coverage' region_slug=request.region.slug %}"> | ||
{% translate "Go to <br> translation coverage" %} | ||
</a> | ||
{% else %} | ||
<i class="w-8 h-8 text-green-500" icon-name="check-circle-2"></i> | ||
{% endif %} | ||
{% endblock todo_dashboard_button_link %} |
53 changes: 53 additions & 0 deletions
53
...mplates/dashboard/todo_dashboard_rows/number_of_missing_or_outdated_translations_row.html
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,53 @@ | ||
{% extends "../_todo_dashboard_row.html" %} | ||
{% load i18n %} | ||
{% block todo_dashboard_ajax_url %} | ||
{{ translation_coverage_ajax }} | ||
{% endblock todo_dashboard_ajax_url %} | ||
{% block todo_dashboard_id %} | ||
translation-coverage | ||
{% endblock todo_dashboard_id %} | ||
{% block todo_dashboard_icon %} | ||
languages | ||
{% endblock todo_dashboard_icon %} | ||
{% block todo_dashboard_title_link %} | ||
{% url 'translation_coverage' region_slug=request.region.slug %} | ||
{% endblock todo_dashboard_title_link %} | ||
{% block todo_dashboard_title %} | ||
{% translate "Outdated and missing translations" %} | ||
{% endblock todo_dashboard_title %} | ||
{% block todo_dashboard_number %} | ||
{% with total=number_of_missing_or_outdated_translations %} | ||
{{ block.super }} | ||
{% endwith %} | ||
{% endblock todo_dashboard_number %} | ||
{% block todo_dashboard_description %} | ||
<div class="hidden todo-message"> | ||
{# djlint:off #} | ||
{% blocktranslate trimmed %} | ||
Your pages currently have <b></b> <b>pages</b> that have an outdated or no translation. | ||
In order for the users to benefit from your content you should translate them or have them translated. | ||
{% endblocktranslate %} | ||
{# djlint:on #} | ||
</div> | ||
<div class="hidden success-message"> | ||
{% blocktranslate trimmed %} | ||
At the moment all pages have up-to-date translations. Good job! | ||
{% endblocktranslate %} | ||
</div> | ||
<div class="waiting-message"> | ||
{% blocktranslate trimmed %} | ||
We are loading your outdated and missing translations in the background. Please be patient. | ||
{% endblocktranslate %} | ||
</div> | ||
{% endblock todo_dashboard_description %} | ||
{% block todo_dashboard_button_link %} | ||
<div class="hidden todo-button"> | ||
<a class="btn !rounded-full" | ||
href="{% url 'translation_coverage' region_slug=request.region.slug %}"> | ||
{% translate "Go to <br> translation coverage" %} | ||
</a> | ||
</div> | ||
<div class="hidden success-icon"> | ||
<i class="w-8 h-8 text-green-500" icon-name="check-circle-2"></i> | ||
</div> | ||
{% endblock todo_dashboard_button_link %} |
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); | ||
} | ||
} | ||
}); |