Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark themes to the backend and a theme switching support #4999

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a simple form to send locale changes
  • Loading branch information
elia committed Nov 14, 2023
commit 38813230d0c4cc8a49efde2be6b65134b0bec94a
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ nav.menu {
}

.admin-navbar-selection {
margin: 0 1.5em;
padding: 0 1.5em;
width: 100%;
position: relative;
overflow: hidden;
display: inline-flex;
Expand All @@ -323,7 +324,7 @@ nav.menu {
padding: .5rem 0 .5rem .25rem;
}

.admin-nav-hidden & {
.admin-nav-hidden & {
position: relative;

select {
Expand Down
10 changes: 8 additions & 2 deletions backend/app/controllers/spree/admin/locale_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ def set
if locale_is_available?(requested_locale)
I18n.locale = requested_locale
session[set_user_language_locale_key] = requested_locale
render json: { locale: requested_locale, location: spree.admin_url }
respond_to do |format|
format.json { render json: { locale: requested_locale, location: spree.admin_url } }
format.html { redirect_back_or_to spree.admin_url, notice: t('spree.locale_changed') }
end
else
render json: { locale: I18n.locale }, status: 404
respond_to do |format|
format.json { render json: { locale: I18n.locale }, status: 404 }
format.html { redirect_back_or_to spree.admin_url, error: t('spree.error') }
end
end
end

Expand Down
28 changes: 13 additions & 15 deletions backend/app/views/spree/admin/shared/_locale_selection.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<% available_locales = Spree.i18n_available_locales %>
<% if available_locales.size > 1 %>
<label class="admin-navbar-selection admin-locale-selection">
<i class="fa fa-globe fa-fw" title="<%= I18n.t('spree.choose_dashboard_locale') %>"></i>
<select class="js-locale-selection custom-select fullwidth">
<%=
options_for_select(
available_locales.map do |locale|
[I18n.t('spree.i18n.this_file_language', locale: locale, default: locale.to_s, fallback: false), locale]
end.sort,
selected: I18n.locale,
)
%>
</select>
</label>
<% available_locale_options_for_select = Spree.i18n_available_locales.map {
[I18n.t('spree.i18n.this_file_language', locale: _1, default: _1.to_s, fallback: false), _1]
}.sort %>

<% if available_locale_options_for_select.size > 1 %>
<%= form_tag(admin_set_locale_path(format: :html), method: :put, style: "width: 100%;") do %>
<label class="admin-navbar-selection admin-locale-selection">
<i class="fa fa-globe fa-fw" title="<%= I18n.t('spree.choose_dashboard_locale') %>"></i>
<select class="custom-select fullwidth" onchange="this.form.requestSubmit()">
<%= options_for_select(available_locale_options_for_select, I18n.locale) %>
</select>
</label>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% available_locale_options_for_select = Spree.i18n_available_locales.map {
[I18n.t('spree.i18n.this_file_language', locale: _1, default: _1.to_s, fallback: false), _1]
}.sort %>

<% if available_locale_options_for_select.size > 1 %>
<li>
<%= form_tag(admin_set_locale_path(format: :html), method: :put, style: "width: 100%;") do %>
<label>
<svg aria-hidden="true"><use xlink:href="<%= image_path('spree/backend/themes/solidus_admin/remixicon.symbol.svg') %>#ri-global-line"></use></svg>
<select name="switch_to_locale" onchange="this.form.requestSubmit()">
<%= options_for_select(available_locale_options_for_select, selected: I18n.locale) %>
</select>
<svg aria-hidden="true"><use xlink:href="<%= image_path('spree/backend/themes/solidus_admin/remixicon.symbol.svg') %>#ri-expand-up-down-line"></use></svg>
</label>
<% end %>
</li>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,7 @@
</summary>

<ul>
<% if (available_locales = Spree.i18n_available_locales).any? %>
<li>
<label>
<svg aria-hidden="true"><use xlink:href="<%= image_path('spree/backend/themes/solidus_admin/remixicon.symbol.svg') %>#ri-global-line"></use></svg>
<select class="js-locale-selection">
<%= options_for_select(
available_locales
.map do |locale|
[
t(
"spree.i18n.this_file_language",
locale: locale,
default: locale.to_s,
fallback: false
),
locale
]
end
.sort,
selected: I18n.locale
) %>
</select>
<svg aria-hidden="true"><use xlink:href="<%= image_path('spree/backend/themes/solidus_admin/remixicon.symbol.svg') %>#ri-expand-up-down-line"></use></svg>
</label>
</li>
<% end %>
<%= render 'spree/admin/shared/locale_selection_solidus_admin' %>

<% if can?(:admin, spree_current_user) %>
<li data-hook="user-account-link">
Expand Down