From 179cf941f1f3ffe6bd39fd65151f0543e89cb74f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Mon, 3 Jul 2023 15:57:14 +0200 Subject: [PATCH] server_admin : update theme --- app/controllers/server/websites_controller.rb | 14 ++++++++++++-- app/views/server/websites/_list.html.erb | 5 ++++- .../websites/{refresh.js.erb => sync_theme.js.erb} | 0 config/locales/en.yml | 7 ++++++- config/locales/fr.yml | 7 ++++++- config/routes/server.rb | 5 ++++- db/schema.rb | 5 ++--- 7 files changed, 34 insertions(+), 9 deletions(-) rename app/views/server/websites/{refresh.js.erb => sync_theme.js.erb} (100%) diff --git a/app/controllers/server/websites_controller.rb b/app/controllers/server/websites_controller.rb index 4bb90fbb8..98d468be3 100644 --- a/app/controllers/server/websites_controller.rb +++ b/app/controllers/server/websites_controller.rb @@ -1,4 +1,5 @@ class Server::WebsitesController < Server::ApplicationController + before_action :load_website, only: [:sync_theme, :update_theme] has_scope :for_theme_version has_scope :for_production @@ -10,9 +11,18 @@ class Server::WebsitesController < Server::ApplicationController add_breadcrumb Communication::Website.model_name.human(count: 2), server_websites_path end - def refresh - @website = Communication::Website.find params[:id] + def sync_theme @website.get_current_theme_version! end + def update_theme + @website.update_theme_version + redirect_back(fallback_location: server_websites_path, notice: t('server_admin.websites.update_theme_notice', website: @website.to_s)) + end + + protected + + def load_website + @website = Communication::Website.find params[:id] + end end diff --git a/app/views/server/websites/_list.html.erb b/app/views/server/websites/_list.html.erb index dab2389a5..6a10330f0 100644 --- a/app/views/server/websites/_list.html.erb +++ b/app/views/server/websites/_list.html.erb @@ -25,7 +25,10 @@ <td class="js-version"><%= link_to website.theme_version, website.theme_version_url, target: :_blank if website.theme_version_url.present? %></td> <td><%= link_to website.university, [:server, website.university] %></td> <td><%= l website.created_at.to_date %></td> - <td><%= link_to "Sync version", refresh_server_website_path(website), method: :post, remote: true, class: button_classes if website.url.present? %></td> + <td> + <%= link_to t('server_admin.websites.buttons.sync'), sync_theme_server_website_path(website), method: :post, remote: true, class: button_classes if website.url.present? %> + <%= link_to t('server_admin.websites.buttons.update'), update_theme_server_website_path(website), method: :post, class: button_classes if website.url.present? && website.github? %> + </td> </tr> <% end %> </tbody> diff --git a/app/views/server/websites/refresh.js.erb b/app/views/server/websites/sync_theme.js.erb similarity index 100% rename from app/views/server/websites/refresh.js.erb rename to app/views/server/websites/sync_theme.js.erb diff --git a/config/locales/en.yml b/config/locales/en.yml index 6ca4a3f26..6fac2d55b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -279,8 +279,13 @@ en: reset: Reset save: Save search: Search - server: Server select_language: Select language + server_admin: + websites: + buttons: + sync: Sync + update: Update + update_theme_notice: The theme of %{website} will be updated in a moment seo: SEO simple_form: error_notification: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index e81511ce4..e8249aca4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -280,7 +280,12 @@ fr: save: Enregistrer search: Rechercher select_language: Sélectionnez une langue - server: Serveur + server_admin: + websites: + buttons: + sync: Sync + update: Mettre à jour + update_theme_notice: Le thème de %{website} va être mis à jour dans quelques instants seo: SEO simple_form: error_notification: diff --git a/config/routes/server.rb b/config/routes/server.rb index 576fba530..4cdd80979 100644 --- a/config/routes/server.rb +++ b/config/routes/server.rb @@ -2,7 +2,10 @@ namespace :server do resources :universities resources :languages resources :websites, only: :index do - post :refresh, on: :member + member do + post :sync_theme + post :update_theme + end end resources :blocks, only: [:index, :show] do post :resave, on: :member diff --git a/db/schema.rb b/db/schema.rb index 2e6b80e8a..5dac26fc9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -105,8 +105,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_03_103209) do t.datetime "updated_at", null: false t.string "title" t.boolean "published", default: true - t.uuid "communication_website_id" t.uuid "heading_id" + t.uuid "communication_website_id" t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["communication_website_id"], name: "index_communication_blocks_on_communication_website_id" t.index ["heading_id"], name: "index_communication_blocks_on_heading_id" @@ -223,7 +223,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_03_103209) do t.text "home_sentence" t.text "sass" t.text "css" - t.boolean "allow_experiences_modification", default: true t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["university_id"], name: "index_communication_extranets_on_university_id" end @@ -465,7 +464,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_03_103209) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end - create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + create_table "communication_website_permalinks", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false t.string "about_type", null: false -- GitLab