Add theme column to custom_styles table to save the currently used theme and show the correct one in the select field

pull/7966/head
Henriette Dinger 5 years ago
parent 02444a2a92
commit 8041925ea4
  1. 4
      app/assets/stylesheets/content/_forms.sass
  2. 2
      app/assets/stylesheets/openproject/_variables.scss.erb
  3. 9
      app/controllers/custom_styles_controller.rb
  4. 36
      app/views/custom_styles/show.html.erb
  5. 5
      db/migrate/20200114091135_add_theme_name_to_custom_styles.rb
  6. 2
      lib/open_project.rb
  7. 0
      lib/open_project/custom_styles/design.rb
  8. 2
      modules/bim_seeder/lib/open_project/bim_seeder/patches/design_patch.rb

@ -236,6 +236,10 @@ hr
fieldset.form--fieldset fieldset.form--fieldset
@extend %form--fieldset-or-section @extend %form--fieldset-or-section
&.-collapsible.collapsed
.-hide-when-collapsed
display: none
.form--fieldset-legend .form--fieldset-legend
@extend %form--fieldset-legend-or-section-title @extend %form--fieldset-legend-or-section-title
width: 100% width: 100%

@ -2,7 +2,7 @@
Depend on the design file so that this is recompiled on core changes. Depend on the design file so that this is recompiled on core changes.
Doesn't work for theme plugins, sorry :-/ just update the core design.rb as well to reload! Doesn't work for theme plugins, sorry :-/ just update the core design.rb as well to reload!
%> %>
<% depend_on Rails.root.join('lib', 'open_project', 'design.rb') %> <% depend_on Rails.root.join('lib', 'open_project', 'custom_styles', 'design.rb') %>
<%# <%#
Set defaults for the following variables Set defaults for the following variables

@ -37,6 +37,8 @@ class CustomStylesController < ApplicationController
def show def show
@custom_style = CustomStyle.current || CustomStyle.new @custom_style = CustomStyle.current || CustomStyle.new
@themes = OpenProject::CustomStyles::ColorThemes::THEMES.map { |val| val[:name] }
@current_theme = @custom_style.theme
end end
def upsale; end def upsale; end
@ -88,6 +90,7 @@ class CustomStylesController < ApplicationController
def update_colors def update_colors
variable_params = params[:design_colors].first variable_params = params[:design_colors].first
set_colors(variable_params) set_colors(variable_params)
set_theme(params)
redirect_to action: :show redirect_to action: :show
end end
@ -95,6 +98,7 @@ class CustomStylesController < ApplicationController
def update_themes def update_themes
variable_params = OpenProject::CustomStyles::ColorThemes::THEMES.find { |theme| theme[:name] == params[:theme] }[:colors] variable_params = OpenProject::CustomStyles::ColorThemes::THEMES.find { |theme| theme[:name] == params[:theme] }[:colors]
set_colors(variable_params) set_colors(variable_params)
set_theme(params)
redirect_to action: :show redirect_to action: :show
end end
@ -122,6 +126,11 @@ class CustomStylesController < ApplicationController
end end
end end
def set_theme(params)
@custom_style = CustomStyle.current
@custom_style.update(params.permit(:theme))
end
def require_ee_token def require_ee_token
unless EnterpriseToken.allows_to?(:define_custom_style) unless EnterpriseToken.allows_to?(:define_custom_style)
redirect_to custom_style_upsale_path redirect_to custom_style_upsale_path

@ -33,6 +33,23 @@ See docs/COPYRIGHT.rdoc for more details.
<%= error_messages_for 'custom_style' %> <%= error_messages_for 'custom_style' %>
<%= form_tag update_design_themes_path, method: :post, class: "form" do %>
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t('admin.custom_styles.color_themes') %></legend>
<div class="form--field">
<div class="form--field-container">
<%= styled_select_tag 'theme',
options_for_select(@themes, @current_theme),
container_class: '-slim' %>
</div>
</div>
<button type="submit" class="button"><%= I18n.t(:button_save) %></button>
</fieldset>
</section>
<% end %>
<%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %> <%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>
<section class="form--section"> <section class="form--section">
<fieldset class="form--fieldset"> <fieldset class="form--fieldset">
@ -137,23 +154,6 @@ See docs/COPYRIGHT.rdoc for more details.
</section> </section>
<% end %> <% end %>
<%= form_tag update_design_themes_path, method: :post, class: "form" do %>
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t('admin.custom_styles.color_themes') %></legend>
<div class="form--field">
<div class="form--field-container">
<%= styled_select_tag 'theme',
options_for_select(OpenProject::CustomStyles::ColorThemes::THEMES.map { |val| val[:name] }),
container_class: '-slim' %>
</div>
</div>
<button type="submit" class="button"><%= I18n.t(:button_save) %></button>
</fieldset>
</section>
<% end %>
<%= form_tag update_design_colors_path, method: :post, class: "form" do %> <%= form_tag update_design_colors_path, method: :post, class: "form" do %>
<section class="form--section"> <section class="form--section">
<fieldset class="form--fieldset -collapsible collapsed"> <fieldset class="form--fieldset -collapsible collapsed">
@ -181,7 +181,7 @@ See docs/COPYRIGHT.rdoc for more details.
</div> </div>
<% end %> <% end %>
<button type="submit" class="button"><%= I18n.t(:button_save) %></button> <button type="submit" class="button -hide-when-collapsed"><%= I18n.t(:button_save) %></button>
</fieldset> </fieldset>
</section> </section>

@ -0,0 +1,5 @@
class AddThemeNameToCustomStyles < ActiveRecord::Migration[6.0]
def change
add_column :custom_styles, :theme, :string, default: ""
end
end

@ -35,7 +35,7 @@ require 'open_project/custom_field_format'
require 'open_project/logging/log_delegator' require 'open_project/logging/log_delegator'
require 'redmine/mime_type' require 'redmine/mime_type'
require 'redmine/core_ext' require 'redmine/core_ext'
require 'open_project/design' require 'open_project/custom_styles/design'
require 'redmine/hook' require 'redmine/hook'
require 'open_project/hooks' require 'open_project/hooks'
require 'redmine/plugin' require 'redmine/plugin'

@ -1,4 +1,4 @@
require 'open_project/design' require 'open_project/custom_styles/design'
module OpenProject::BimSeeder module OpenProject::BimSeeder
module Patches module Patches

Loading…
Cancel
Save