Skip to content

compatibility with redmine 5 #13

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This plugin allows Redmine users to select themes in their account settings. The

## Compatibility

This plugin version is compatible only with Redmine 2.1.x and later.
This plugin version is compatible only with Redmine 4.x and later.

## Installation

Expand Down
10 changes: 6 additions & 4 deletions app/views/users/_user_specific_theme.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %>
<p><%= pref_fields.select :ui_theme, Redmine::Themes.themes.collect { |t| [t.name, t.id] },
{ include_blank: true } %></p>
<% end %>
<p>
<%= label_tag :user_preference_attributes_ui_theme, l(:field_ui_theme) %><br>
<%= select_tag 'pref[ui_theme]',
options_for_select(Redmine::Themes.themes.map { |theme| [theme.name, theme.id] },
@pref[:ui_theme]), include_blank: true %>
</p>
11 changes: 8 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
name 'Redmine User-Specific Theme Plugin'
description 'This plugin allows users to set Redmine themes in the account settings.'
author 'Restream'
version '1.2.0'
version '1.3.0'
url 'https://github.com/Restream/redmine_user_specific_theme'

requires_redmine :version_or_higher => '2.1'
requires_redmine :version_or_higher => '4.0.0'


end

require 'redmine_user_specific_theme'
require_relative 'lib/redmine_user_specific_theme/hooks/view_hooks'
require_relative 'lib/redmine_user_specific_theme/patches/user_preference_patch'
require_relative 'lib/redmine_user_specific_theme/patches/application_helper_patch'
require_relative 'lib/redmine_user_specific_theme'
16 changes: 4 additions & 12 deletions lib/redmine_user_specific_theme.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
module RedmineUserSpecificTheme
end

require_dependency 'redmine_user_specific_theme/hooks/view_hooks'
require_dependency 'redmine_user_specific_theme/patches/user_preference_patch'
require_dependency 'redmine_user_specific_theme/patches/application_helper_patch'

ActionDispatch::Callbacks.to_prepare do

unless UserPreference.included_modules.include?(RedmineUserSpecificTheme::Patches::UserPreferencePatch)
UserPreference.send :prepend, RedmineUserSpecificTheme::Patches::UserPreferencePatch
end
MyController.prepend RedmineUserSpecificTheme::Patches::UserPreferencePatch unless MyController.included_modules.include?(RedmineUserSpecificTheme::Patches::UserPreferencePatch)

unless ApplicationHelper.included_modules.include?(RedmineUserSpecificTheme::Patches::ApplicationHelperPatch)
ApplicationHelper.send :include, RedmineUserSpecificTheme::Patches::ApplicationHelperPatch
end

end
RedmineApp::Application.config.after_initialize do
ApplicationHelper.prepend(RedmineUserSpecificTheme::Patches::ApplicationHelperPatch)
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ module RedmineUserSpecificTheme::Patches
module ApplicationHelperPatch
extend ActiveSupport::Concern

included do
alias_method_chain :current_theme, :user_specific
alias_method_chain :body_css_classes, :user_specific
end

def current_theme_with_user_specific
user_theme = Redmine::Themes.theme(User.current.pref.ui_theme)
def current_theme
user_theme = super
user_theme = Redmine::Themes.theme(User.current.pref.others[:ui_theme])
user_theme || Redmine::Themes.theme(Setting.ui_theme)
end

def body_css_classes_with_user_specific
css_classes = body_css_classes_without_user_specific
user_theme = Redmine::Themes.theme(User.current.pref.ui_theme)
def body_css_classes
css_classes = super
user_theme = Redmine::Themes.theme(User.current.pref.others[:ui_theme])
user_theme ?
css_classes.gsub(/theme-\S+/, "theme-#{user_theme.name}") :
css_classes
css_classes.gsub(/theme-\S+/, "theme-#{user_theme.name}") :
css_classes
end

end
Expand Down
28 changes: 9 additions & 19 deletions lib/redmine_user_specific_theme/patches/user_preference_patch.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
require_dependency 'user_preference'
require_dependency 'my_controller'

module RedmineUserSpecificTheme
module Patches
module UserPreferencePatch

def self.prepended(base)
base.class_eval do
if defined? safe_attributes
safe_attributes :ui_theme
end
def account
Rails.logger.info "Account with theme patch applied"
if request.put? && params[:pref]
theme = params[:pref][:ui_theme]
User.current.pref.others[:ui_theme] = theme if theme
User.current.pref.save
Rails.logger.info "Saved theme: #{theme}"
end
end

def ui_theme
self[:ui_theme]
end

def ui_theme=(val)
self[:ui_theme] = val
end

def ui_theme?
ui_theme.blank?
super
end

end
Expand Down