From 9443c66873320418ba29f688517e8c1e9f69400c Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Sun, 22 Jan 2023 17:50:07 +0100
Subject: [PATCH] theme switcher

---
 app/assets/stylesheets/admin/pure/variables.sass | 10 +++++-----
 app/controllers/admin/application_controller.rb  |  5 +++++
 app/views/admin/dashboard/index.html.erb         | 13 +++++++++++++
 config/routes.rb                                 |  1 +
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/app/assets/stylesheets/admin/pure/variables.sass b/app/assets/stylesheets/admin/pure/variables.sass
index af50a5ca4..5fc44d493 100644
--- a/app/assets/stylesheets/admin/pure/variables.sass
+++ b/app/assets/stylesheets/admin/pure/variables.sass
@@ -26,11 +26,11 @@ $font-family-sans-serif: "Basier Square", sans-serif
 
 $grid-gutter-width: 64px
 
-$border-radius: 0
-$border-radius-sm: 0
-$border-radius-lg: 0
-$border-radius-xl: 0
-$border-radius-2xl: 0
+$border-radius: 2px
+$border-radius-sm: $border-radius
+$border-radius-lg: $border-radius
+$border-radius-xl: $border-radius
+$border-radius-2xl: $border-radius
 
 $card-border-width: 0
 $card-cap-bg: $color-background-alt
diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb
index e8e8c131e..3a0fedef6 100644
--- a/app/controllers/admin/application_controller.rb
+++ b/app/controllers/admin/application_controller.rb
@@ -3,6 +3,11 @@ class Admin::ApplicationController < ApplicationController
 
   before_action :load_filters, only: :index
 
+  def set_theme
+    current_user.update_column :admin_theme, params[:theme]
+    redirect_to admin_root_path
+  end
+
   protected
 
   def breadcrumb
diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb
index c851cdfd7..0ef2ba438 100644
--- a/app/views/admin/dashboard/index.html.erb
+++ b/app/views/admin/dashboard/index.html.erb
@@ -4,6 +4,19 @@
 <div class="row mb-5">
   <div class="col-md-6 pb-4">
     <%= panel title: t('hello', name: current_user.first_name) do %>
+      <% if current_admin_theme == 'appstack' %>
+        <p>
+          Osuny a un nouveau thème pour l'administration, "Pure". <br>
+          Voulez-vous l'essayer ?
+        </p>
+        <%= link_to 'Changer de thème', admin_set_theme_path(theme: 'pure'), method: :put, class: button_classes %>
+      <% else %>
+        <p>
+          Vous utilisez le thème "Pure" pour l'administration. <br>
+          Voulez-vous revenir au thème "Appstack" ?
+        </p>
+        <%= link_to 'Changer de thème', admin_set_theme_path(theme: 'appstack'), method: :put, class: button_classes %>
+      <% end %>
       <div class="text-end">
         <% if current_university.logo.attached? %>
           <%= image_tag current_university.logo, width: 120 %>
diff --git a/config/routes.rb b/config/routes.rb
index a7435c556..4677d2123 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -23,6 +23,7 @@ Rails.application.routes.draw do
       post 'resend_confirmation_email' => 'users#resend_confirmation_email', on: :member
       patch 'unlock' => 'users#unlock', on: :member
     end
+    put 'theme' => 'application#set_theme', as: :set_theme
     draw 'admin/administration'
     draw 'admin/communication'
     draw 'admin/education'
-- 
GitLab