From 47f8654a15f0643b244c2c680f25f3c740816c7e Mon Sep 17 00:00:00 2001 From: Arnaud Levy <arnaud.levy@noesya.coop> Date: Wed, 13 Nov 2024 12:49:52 +0100 Subject: [PATCH] =?UTF-8?q?Informations=20sur=20les=20nouveaut=C3=A9s=20d'?= =?UTF-8?q?Osuny=20(#2417)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/dashboard/_chronicles.html.erb | 45 +++++++++++++++++++ app/views/admin/dashboard/index.html.erb | 1 + config/locales/en.yml | 3 ++ config/locales/fr.yml | 3 ++ 4 files changed, 52 insertions(+) create mode 100644 app/views/admin/dashboard/_chronicles.html.erb diff --git a/app/views/admin/dashboard/_chronicles.html.erb b/app/views/admin/dashboard/_chronicles.html.erb new file mode 100644 index 000000000..b8b048e4b --- /dev/null +++ b/app/views/admin/dashboard/_chronicles.html.erb @@ -0,0 +1,45 @@ +<%= osuny_panel t('admin.chronicles.title') do %> + <div id="chronicles-feed" class="row g-4 mb-3" style="max-height:60vh; overflow-y: scroll"></div> +<% end %> + +<script nonce="<%= request.content_security_policy_nonce %>"> +const RSS_URL = "https://chroniques.osuny.org/faits/index.xml"; +const element = document.getElementById("chronicles-feed"); +fetch(RSS_URL) + .then(response => response.text()) + .then(str => new window.DOMParser().parseFromString(str, "text/xml")) + .then(data => { + const items = data.querySelectorAll("item"); + let html = ""; + let index = 0; + items.forEach(item => { + let title = item.querySelector("title"); + let link = item.querySelector("link"); + if (title == '' || link == '' || index >= 12) { + return; + } + let pubDate = item.querySelector("pubDate"); + let date = new Date(pubDate.textContent); + let description = item.querySelector("description"); + html += ` + <div class="col-lg-6 col-xl-4 col-xxl-3"> + <div class="card h-100"> + <div class="card-body"> + <h3 class="card-title">${title.textContent}</h3> + <p class="small">${description.textContent}</p> + </div> + <p class="card-footer mb-1 small text-end"> + ${date.getMonth()}/${date.getFullYear()} + — + <a href="${link.textContent}" target="_blank" rel="noopener"> + <%= t('admin.chronicles.read_more') %> + </a> + </p> + </div> + </div> + `; + index += 1; + }); + element.insertAdjacentHTML("beforeend", html); + }); +</script> \ No newline at end of file diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 3a371396e..fbb2bd394 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -9,6 +9,7 @@ <% end %> <%= render 'admin/application/favorites/show' %> +<%= render 'admin/dashboard/chronicles' %> <% if current_university.is_really_a_university? %> <%= render 'admin/dashboard/really_a_university' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index d05c5fa09..d6629056e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -120,6 +120,9 @@ en: admin: advanced_settings: Advanced settings attachment_not_available: Attachment not available + chronicles: + title: Chronicles + read_more: Learn more dashboard: Dashboard directory: Directory duplicate: Duplicate diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1352438d1..f51b55803 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -120,6 +120,9 @@ fr: admin: advanced_settings: Réglages avancés attachment_not_available: Impossible d'accéder à l'élément + chronicles: + title: Chroniques + read_more: En savoir plus dashboard: Tableau de bord directory: Annuaire duplicate: Dupliquer -- GitLab