From 183163e36c202a9eee657162844bd4f4c82fac1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Fri, 29 Dec 2023 12:06:16 +0100 Subject: [PATCH] server specific js + sync all theme versions btn --- app/assets/javascripts/server.js | 17 ++++++++++ app/assets/javascripts/server/websites.js | 1 + .../server/websites/batch-sync-themes.js | 31 +++++++++++++++++++ app/controllers/server/websites_controller.rb | 8 ++--- app/views/server/layouts/application.html.erb | 2 +- .../server/websites/manage_versions.html.erb | 7 +++-- config/locales/en.yml | 2 +- config/locales/fr.yml | 4 +-- config/routes/server.rb | 2 +- 9 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/server.js create mode 100644 app/assets/javascripts/server/websites.js create mode 100644 app/assets/javascripts/server/websites/batch-sync-themes.js diff --git a/app/assets/javascripts/server.js b/app/assets/javascripts/server.js new file mode 100644 index 000000000..5cebd6b2a --- /dev/null +++ b/app/assets/javascripts/server.js @@ -0,0 +1,17 @@ +//= require activestorage +//= require popper +//= require bootstrap-sprockets +//= require jquery3 +//= require jquery_ujs +//= require notyf/notyf.min +//= require simple_form_bs5_file_input +//= require sortablejs/Sortable +//= require summernote/summernote-bs5 +//= require_self +//= require ./admin/commons/nav +//= require ./admin/commons/sso +//= require_tree ./application/plugins +//= require ./admin/plugins/sortable +//= require_tree ./server + +window.osuny = {}; diff --git a/app/assets/javascripts/server/websites.js b/app/assets/javascripts/server/websites.js new file mode 100644 index 000000000..0ec338730 --- /dev/null +++ b/app/assets/javascripts/server/websites.js @@ -0,0 +1 @@ +window.osuny.websites = {}; \ No newline at end of file diff --git a/app/assets/javascripts/server/websites/batch-sync-themes.js b/app/assets/javascripts/server/websites/batch-sync-themes.js new file mode 100644 index 000000000..8e5393f5e --- /dev/null +++ b/app/assets/javascripts/server/websites/batch-sync-themes.js @@ -0,0 +1,31 @@ +window.osuny.websites.batchSyncThemes = { + init: function () { + 'use strict'; + this.syncAllBtn = document.querySelector('.js-sync-all-theme-versions'); + this.syncBtns = document.querySelectorAll('.js-sync-theme-version'); + this.syncAllBtn.addEventListener('click', this.syncAll.bind(this)); + }, + + syncAll: function (e) { + 'use strict'; + var i; + e.preventDefault(); + for (i = 0; i < this.syncBtns.length; i += 1) { + this.syncBtns[i].click(); + } + }, + + invoke: function () { + 'use strict'; + return { + init: this.init.bind(this) + } + } +}.invoke(); + +window.addEventListener('DOMContentLoaded', function () { + 'use strict'; + if (document.body.classList.contains('websites-manage_versions')) { + window.osuny.websites.batchSyncThemes.init(); + } +}) \ No newline at end of file diff --git a/app/controllers/server/websites_controller.rb b/app/controllers/server/websites_controller.rb index c9e5f860e..b118fd306 100644 --- a/app/controllers/server/websites_controller.rb +++ b/app/controllers/server/websites_controller.rb @@ -1,6 +1,6 @@ class Server::WebsitesController < Server::ApplicationController - before_action :load_websites, only: [:index, :manage_versions, :update_all_themes] - before_action :load_website, except: [:index, :manage_versions, :update_all_themes] + before_action :load_websites, only: [:index, :manage_versions, :clean_and_rebuild_all_websites] + before_action :load_website, except: [:index, :manage_versions, :clean_and_rebuild_all_websites] has_scope :for_theme_version has_scope :for_production @@ -19,11 +19,11 @@ class Server::WebsitesController < Server::ApplicationController add_breadcrumb "Gestion des versions" end - def update_all_themes + def clean_and_rebuild_all_websites @websites.find_each do |website| website.clean_and_rebuild end - redirect_back(fallback_location: manage_versions_server_websites_path, notice: t('server_admin.websites.update_all_themes_notice')) + redirect_back(fallback_location: manage_versions_server_websites_path, notice: t('server_admin.websites.clean_and_rebuild_all_websites_notice')) end def sync_theme_version diff --git a/app/views/server/layouts/application.html.erb b/app/views/server/layouts/application.html.erb index bf62d98d8..9bcbe98a4 100644 --- a/app/views/server/layouts/application.html.erb +++ b/app/views/server/layouts/application.html.erb @@ -32,7 +32,7 @@ </main> <%= render "admin/layouts/themes/pure/commands" %> <%= render "admin/layouts/themes/pure/footer" %> - <%= javascript_include_tag 'admin/pure' %> + <%= javascript_include_tag 'server' %> <%= render 'bugsnag' %> </body> </html> diff --git a/app/views/server/websites/manage_versions.html.erb b/app/views/server/websites/manage_versions.html.erb index b993c8818..90eb99a75 100644 --- a/app/views/server/websites/manage_versions.html.erb +++ b/app/views/server/websites/manage_versions.html.erb @@ -44,7 +44,7 @@ sync_theme_version_server_website_path(website), method: :post, remote: true, - class: button_classes if website.url.present? && website.theme_version_url.present? %> + class: "#{button_classes} js-sync-theme-version" if website.url.present? && website.theme_version_url.present? %> <%= link_to t('server_admin.websites.buttons.theme.update'), update_theme_server_website_path(website), method: :post, @@ -58,8 +58,11 @@ </div> <% content_for :action_bar_left do %> + <%= link_to "Synchroniser toutes les versions de thème", + "#", + class: "#{button_classes} js-sync-all-theme-versions" %> <%= link_to "Tout mettre à jour", - update_all_themes_server_websites_path(current_scopes), + clean_and_rebuild_all_websites_server_websites_path(current_scopes), method: :post, class: button_classes %> <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 6e2adf9f0..a8a3bc2e9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -337,8 +337,8 @@ en: theme: sync: Sync version update: Update theme + clean_and_rebuild_all_websites_notice: All themes will be updated. This can take a few minutes. sync_theme_version_notice: The theme's version of %{website} has been synced - update_all_themes_notice: All themes will be updated. This can take a few minutes. update_theme_notice: The theme of %{website} will be updated in a moment seo: SEO simple_form: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 9ec5a600c..bcdc970a2 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -144,7 +144,7 @@ fr: summary: label: Résumé hint: Un texte court, comme un chapô pour un article. Ne mettez pas tout le contenu ici, pour ça, il y a les blocs ! - translation: + translation: button: Traduire avec LibreTranslate done: Traduction effectuée ! Merci de relire avant d'enregistrer. running: Traduction en cours @@ -337,8 +337,8 @@ fr: theme: sync: Synchroniser la version update: Mettre à jour le thème + clean_and_rebuild_all_websites_notice: Tous les thèmes vont être mis à jour. Cela peut prendre quelques minutes. sync_theme_version_notice: La version du thème de %{website} a été synchronisée - update_all_themes_notice: Tous les thèmes vont être mis à jour. Cela peut prendre quelques minutes. update_theme_notice: Le thème de %{website} va être mis à jour dans quelques instants seo: SEO simple_form: diff --git a/config/routes/server.rb b/config/routes/server.rb index 311ba5d90..daf21fe4a 100644 --- a/config/routes/server.rb +++ b/config/routes/server.rb @@ -4,7 +4,7 @@ namespace :server do resources :websites do collection do get :manage_versions - post :update_all_themes + post :clean_and_rebuild_all_websites end member do post :sync_theme_version -- GitLab