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

[56339] Split content of Admin/Design page into separate tabs #16255

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
57ba340
use page header component in design page
bsatarnejad Jul 26, 2024
847bd25
Merge branch 'dev' into 56339-split-content-of-admin-design-page-into…
bsatarnejad Sep 4, 2024
edf70cd
create a new component for design page header
bsatarnejad Sep 4, 2024
5707420
create separate views for each tab
bsatarnejad Sep 4, 2024
ac2bdce
after each action it should be redirected to the current url
bsatarnejad Sep 5, 2024
63c069a
fix rubocop errors
bsatarnejad Sep 5, 2024
c7702d3
fix failing tests in custom styles controller spec
bsatarnejad Sep 9, 2024
91565cd
fix failing specs
bsatarnejad Sep 9, 2024
6edaadd
change header Advanced settings to Interface colours
bsatarnejad Sep 10, 2024
c032d46
add some description for interface colours
bsatarnejad Sep 10, 2024
e3d4e1b
change design header component to use tab helper
bsatarnejad Sep 12, 2024
babcc64
use partials for rendering tabs content
bsatarnejad Sep 12, 2024
343e87f
remove unnecessary pathes
bsatarnejad Sep 12, 2024
35e5940
add tab to the default url options
bsatarnejad Sep 13, 2024
74a56e1
test redirect to interface tab, when there is an ee token
bsatarnejad Sep 13, 2024
72c12f5
write a feature spec and remove unnecessary tests
bsatarnejad Sep 13, 2024
5889dac
change the test to check if it is in interface tab in the first page …
bsatarnejad Sep 17, 2024
0c959a9
change some specs
bsatarnejad Sep 17, 2024
897e27e
fix rubocup errors
bsatarnejad Sep 17, 2024
875d40b
fix rubocup errors
bsatarnejad Sep 18, 2024
809f6d9
add a test to check if the file is deleted
bsatarnejad Sep 18, 2024
e484a82
Merge branch 'dev' into 56339-split-content-of-admin-design-page-into…
bsatarnejad Sep 18, 2024
ef60a0f
Update app/components/admin/design_header_component.html.erb
bsatarnejad Sep 19, 2024
a419ae6
change nil to an empty array
bsatarnejad Sep 19, 2024
e1bfea1
fix rubocup warning and some spacing
bsatarnejad Sep 19, 2024
bd71e43
change test file name and uts description
bsatarnejad Sep 19, 2024
af1d6a9
fix some indentations
bsatarnejad Sep 19, 2024
38faf36
change colours to color in interface tab
bsatarnejad Sep 19, 2024
96481e2
change colour to color for custom styles description
bsatarnejad Sep 19, 2024
bdbb6e6
Merge branch 'dev' into 56339-split-content-of-admin-design-page-into…
bsatarnejad Sep 19, 2024
83a1730
Provide direction of redirect in spec
oliverguenther Sep 20, 2024
bf42337
add a test for a tab param
oliverguenther Sep 20, 2024
c98dcbf
fix failing tests due to string variable changes
bsatarnejad Sep 20, 2024
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
49 changes: 49 additions & 0 deletions app/components/admin/design_header_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) the OpenProject GmbH

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.

OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

See COPYRIGHT and LICENSE files for more details.

++#%>

<% helpers.html_title t(:label_administration), t(:label_custom_style), @title %>
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title { t(:label_custom_style) }
header.with_breadcrumbs([{ href: admin_index_path, text: t(:label_administration) },
t(:label_custom_style)])
header.with_description { t(:label_custom_style_description) }
header.with_tab_nav(label: nil) do |tab_nav|
tab_nav.with_tab(selected: @selected == 1, href: custom_style_path) do |tab|
tab.with_text { t(:"admin.custom_styles.tab_interface") }
end
tab_nav.with_tab(selected: @selected == 2, href: custom_style_branding_path) do |tab|
tab.with_text { t(:"admin.custom_styles.tab_branding") }
end
tab_nav.with_tab(selected: @selected == 3, href: custom_style_pdf_export_styles_path) do |tab|
tab.with_text { t(:"admin.custom_styles.tab_pdf_export_styles") }
end
end
end
%>
41 changes: 41 additions & 0 deletions app/components/admin/design_header_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++

module Admin
class DesignHeaderComponent < ApplicationComponent
def initialize(title:, selected:)
super
raise "selected must 1, 2 or 3" if [1, 2, 3].exclude?(selected)

@title = title
@selected = selected
end
end
end
27 changes: 17 additions & 10 deletions app/controllers/custom_styles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@

def upsale; end

def branding
@custom_style = CustomStyle.current || CustomStyle.new
@current_theme = @custom_style.theme
@theme_options = options_for_theme_select
end

def pdf_export_styles
@custom_style = CustomStyle.current || CustomStyle.new
@current_theme = @custom_style.theme
@theme_options = options_for_theme_select
EinLama marked this conversation as resolved.
Show resolved Hide resolved
end

def create
@custom_style = CustomStyle.create(custom_style_params)
if @custom_style.valid?
redirect_to custom_style_path
redirect_back(fallback_location: root_path)
else
flash[:error] = @custom_style.errors.full_messages
render action: :show
Expand All @@ -65,7 +77,7 @@
def update
@custom_style = get_or_create_custom_style
if @custom_style.update(custom_style_params)
redirect_to custom_style_path
redirect_back(fallback_location: root_path)
else
flash[:error] = @custom_style.errors.full_messages
render action: :show
Expand All @@ -81,7 +93,7 @@
@custom_style.export_cover_text_color = color
@custom_style.save
end
redirect_to custom_style_path
redirect_back(fallback_location: root_path)
end

def logo_download
Expand Down Expand Up @@ -134,27 +146,22 @@
redirect_to action: :show
end

def update_themes
theme = OpenProject::CustomStyles::ColorThemes.themes.find { |t| t[:theme] == params[:theme] }

call = ::Design::UpdateDesignService
.new(theme)
.call

call.on_success do
flash[:notice] = I18n.t(:notice_successful_update)
end

call.on_failure do
flash[:error] = call.message
end

redirect_to action: :show
end

def show_local_breadcrumb
false
redirect_back(fallback_location: root_path)
end

Check notice on line 164 in app/controllers/custom_styles_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/controllers/custom_styles_controller.rb#L149-L164 <Metrics/AbcSize>

Assignment Branch Condition size for update_themes is too high. [<5, 17, 2> 17.83/17]
Raw output
app/controllers/custom_styles_controller.rb:149:3: C: Metrics/AbcSize: Assignment Branch Condition size for update_themes is too high. [<5, 17, 2> 17.83/17]

private

Expand Down Expand Up @@ -204,6 +211,6 @@
end

@custom_style.send(remove_method)
redirect_to custom_style_path
redirect_back(fallback_location: root_path)
end
end
143 changes: 143 additions & 0 deletions app/views/custom_styles/branding.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) the OpenProject GmbH

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.

OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

See COPYRIGHT and LICENSE files for more details.

++#%>

<%=
render(Admin::DesignHeaderComponent.new(
title: t(:"admin.custom_styles.tab_branding"),
selected: 2,
))
%>
<%= 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_theme') %></legend>
<div class="form--field">
<div class="form--field-container">
<%= styled_select_tag 'theme',
options_for_select(@theme_options, @current_theme),
container_class: '-slim' %>
</div>
</div>

<%= styled_button_tag t(:button_save),
data:({ confirm: t('admin.custom_styles.theme_warning') } unless @current_theme.present?) %>
</fieldset>
</section>
<% end %>
<%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t(:label_custom_logo) %></legend>
<% if @custom_style.id && @custom_style.logo.present? %>
<div>
<%# Don't use image_tag here due to asset host %>
<%= tag('img', src: custom_style_logo_path(digest: @custom_style.digest, filename: @custom_style.logo_identifier), class: 'custom-logo-preview') %>
<%= link_to t(:button_delete),
custom_style_logo_delete_path,
method: :delete,
class: 'icon icon-delete confirm-form-submit' %>
</div>
<% end %>
<div class="grid-block">
<div class="form--field -required">
<div class="attachment_field form--field-container -vertical -shrink">
<div class="form--file-container">
<%= f.file_field :logo, required: true, class: "attachment_choose_file", size: "15" %>
</div>
</div>
<div class="form--field-instructions">
<%= t('text_custom_logo_instructions') %>
</div>
</div>
</div>
<%= styled_button_tag I18n.t(@custom_style.logo.present? ? :button_replace : :button_upload),
class: "button #{@custom_style.logo.blank? ? '-with-icon icon-add' : ''}" %>
</fieldset>
</section>
<% end %>
<%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t(:label_custom_favicon) %></legend>

<% if @custom_style.id && @custom_style.favicon.present? %>
<div>
<%= tag('img', src: custom_style_favicon_path(digest: @custom_style.digest, filename: @custom_style.favicon_identifier), class: 'custom-favicon-preview') %>
<%= link_to t(:button_delete),
custom_style_favicon_delete_path,
method: :delete,
class: 'icon icon-delete confirm-form-submit' %>
</div>
<% end %>
<div class="grid-block">
<div class="form--field -required">
<div class="attachment_field form--field-container -vertical -shrink">
<div class="form--file-container">
<%= f.file_field :favicon, required: true, class: "attachment_choose_file", size: "15" %>
</div>
</div>
<div class="form--field-instructions">
<%= t('text_custom_favicon_instructions') %>
</div>
</div>
</div>
<%= styled_button_tag t(@custom_style.favicon.present? ? :button_replace : :button_upload), class: "button #{@custom_style.favicon.blank? ? '-with-icon icon-add' : ''}" %>
</fieldset>
</section>
<% end %>
<%= form_for @custom_style, url: custom_style_path, html: { multipart: true, class: "form -vertical" } do |f| %>
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t(:label_custom_touch_icon) %></legend>
<% if @custom_style.id && @custom_style.touch_icon.present? %>
<div>
<%= tag('img', src: custom_style_touch_icon_path(digest: @custom_style.digest, filename: @custom_style.touch_icon_identifier), class: 'custom-touch-icon-preview') %>
<%= link_to t(:button_delete),
custom_style_touch_icon_delete_path,
method: :delete,
class: 'icon icon-delete confirm-form-submit' %>
</div>
<% end %>
<div class="grid-block">
<div class="form--field -required">
<div class="attachment_field form--field-container -vertical -shrink">
<div class="form--file-container">
<%= f.file_field :touch_icon, required: true, class: "attachment_choose_file", size: "15" %>
</div>
</div>
<div class="form--field-instructions">
<%= t('text_custom_touch_icon_instructions') %>
</div>
</div>
</div>
<%= styled_button_tag t(@custom_style.touch_icon.present? ? :button_replace : :button_upload), class: "button #{@custom_style.touch_icon.blank? ? '-with-icon icon-add' : ''}" %>
</fieldset>
</section>
<% end %>
Loading