Skip to content

Commit 9be48d2

Browse files
committed
Primerise the admin Email notifications page
1 parent 322290c commit 9be48d2

File tree

2 files changed

+139
-90
lines changed

2 files changed

+139
-90
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module Admin
32+
module Settings
33+
class MailNotificationsSettingForm < ApplicationForm
34+
include ::Settings::FormHelper
35+
36+
settings_form do |f|
37+
if @deliveries
38+
f.text_field name: :mail_from, input_width: :medium
39+
f.check_box name: :bcc_recipients
40+
f.check_box name: :plain_text_mail
41+
f.select_list name: :emails_salutation,
42+
values: [
43+
[User.human_attribute_name(:firstname), :firstname],
44+
[I18n.t("mail.salutation_full_name"), :name]
45+
],
46+
input_width: :medium
47+
48+
f.fieldset_group(title: "#{I18n.t(:setting_emails_header)} & #{I18n.t(:setting_emails_footer)}", mt: 4) do |fg|
49+
fg.multi_language_text_select(name: :emails_header)
50+
fg.multi_language_text_select(name: :emails_footer)
51+
end
52+
end
53+
54+
unless OpenProject::Configuration["email_delivery_configuration"] == "legacy"
55+
email_methods = %i[smtp sendmail]
56+
email_methods += [:letter_opener] if Rails.env.development?
57+
58+
f.fieldset_group(title: I18n.t(:text_setup_mail_configuration), mt: 4) do |fg|
59+
fg.select_list(
60+
name: :email_delivery_method,
61+
values: email_methods.map { |m| [m.to_s, m] },
62+
input_width: :small,
63+
data: {
64+
show_when_value_selected_target: "cause",
65+
target_name: "email_delivery_method_settings"
66+
}
67+
)
68+
end
69+
70+
f.group(
71+
hidden: { true => Setting.email_delivery_method != :smtp },
72+
data: {
73+
show_when_value_selected_target: "effect",
74+
target_name: "email_delivery_method_settings",
75+
value: "smtp"
76+
}
77+
) do |smtp|
78+
smtp.text_field(name: :smtp_address, input_width: :medium)
79+
smtp.text_field(name: :smtp_port, type: :number, input_width: :xsmall)
80+
smtp.text_field(name: :smtp_domain, input_width: :medium)
81+
smtp.select_list(name: :smtp_authentication,
82+
values: %i[none plain login cram_md5].map { |m| [m.to_s, m] },
83+
input_width: :small)
84+
smtp.text_field(name: :smtp_user_name, input_width: :medium)
85+
smtp.text_field(name: :smtp_password, input_width: :medium)
86+
smtp.check_box(name: :smtp_enable_starttls_auto)
87+
smtp.check_box(name: :smtp_ssl)
88+
end
89+
90+
f.group(
91+
hidden: { true => Setting.email_delivery_method != :sendmail },
92+
data: {
93+
show_when_value_selected_target: "effect",
94+
target_name: "email_delivery_method_settings",
95+
value: "sendmail"
96+
}
97+
) do |sendmail|
98+
sendmail.text_field(name: :sendmail_location)
99+
sendmail.text_field(name: :sendmail_arguments)
100+
end
101+
end
102+
103+
f.submit
104+
end
105+
106+
def initialize(deliveries:)
107+
super()
108+
109+
@deliveries = deliveries
110+
end
111+
end
112+
end
113+
end

app/views/admin/settings/mail_notifications_settings/show.html.erb

Lines changed: 26 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -40,98 +40,34 @@ See COPYRIGHT and LICENSE files for more details.
4040
end
4141
%>
4242

43+
<% unless @deliveries %>
44+
<%=
45+
render Primer::Alpha::Banner.new(scheme: :default) do
46+
t(:text_email_delivery_not_configured)
47+
end
48+
%>
49+
<% end %>
50+
4351
<%=
44-
styled_form_tag(
45-
admin_settings_mail_notifications_path,
52+
settings_primer_form_with(
53+
url: admin_settings_mail_notifications_path,
54+
scope: :settings,
4655
method: :patch,
47-
data: { controller: "show-when-value-selected" }
48-
) do
56+
data: { turbo: false,
57+
controller: "show-when-value-selected" }
58+
) do |form|
59+
render Admin::Settings::MailNotificationsSettingForm.new(form, deliveries: @deliveries)
60+
end
4961
%>
50-
<% if @deliveries %>
51-
<section class="form--section">
52-
<div class="form--field"><%= setting_text_field :mail_from, size: 60, container_class: "-middle" %></div>
53-
<div class="form--field"><%= setting_check_box :bcc_recipients %></div>
54-
<div class="form--field"><%= setting_check_box :plain_text_mail %></div>
55-
<div class="form--field">
56-
<%= setting_select :emails_salutation,
57-
[
58-
[User.human_attribute_name(:firstname), :firstname],
59-
[t("mail.salutation_full_name"), :name]
60-
],
61-
container_class: "-middle" %>
62-
</div>
63-
</section>
64-
65-
<fieldset id="emails_decorators" class="form--fieldset">
66-
<legend class="form--fieldset-legend"><%= t(:setting_emails_header) %>
67-
& <%= I18n.t(:setting_emails_footer) %></legend>
68-
<%= render Settings::TextSettingComponent.new(I18n.locale, name: "emails_header") %>
69-
<%= render Settings::TextSettingComponent.new(I18n.locale, name: "emails_footer") %>
70-
</fieldset>
71-
<% else %>
72-
<div class="nodata">
73-
<%= simple_format(t(:text_email_delivery_not_configured)) %>
74-
</div>
75-
<% end %>
76-
77-
<%
78-
email_methods = %i[smtp sendmail]
79-
email_methods << :letter_opener if Rails.env.development?
80-
%>
81-
<%= content_tag :fieldset, class: "form--fieldset" do %>
82-
<legend class="form--fieldset-legend"><%= t(:text_setup_mail_configuration) %></legend>
83-
<div class="form--field">
84-
<%=
85-
setting_select(
86-
:email_delivery_method,
87-
email_methods,
88-
container_class: "-slim",
89-
data: {
90-
show_when_value_selected_target: "cause",
91-
target_name: "email_delivery_method_settings"
92-
}
93-
)
94-
%>
95-
</div>
96-
<div
97-
data-show-when-value-selected-target="effect"
98-
data-target-name="email_delivery_method_settings"
99-
data-value="smtp"
100-
<%= "hidden" unless Setting.email_delivery_method == :smtp %>>
101-
<div class="form--field"><%= setting_text_field :smtp_address, container_class: "-middle" %></div>
102-
<div class="form--field"><%= setting_text_field :smtp_port, size: 6, container_class: "-xslim" %></div>
103-
<div class="form--field"><%= setting_text_field :smtp_domain, container_class: "-middle" %></div>
104-
<div class="form--field"><%= setting_select(:smtp_authentication, %i[none plain login cram_md5], container_class: "-slim") %></div>
105-
<div class="form--field"><%= setting_text_field :smtp_user_name, container_class: "-middle" %></div>
106-
<div class="form--field"><%= setting_password :smtp_password, container_class: "-middle" %></div>
107-
<div class="form--field"><%= setting_check_box :smtp_enable_starttls_auto %></div>
108-
<div class="form--field"><%= setting_check_box :smtp_ssl %></div>
109-
</div>
110-
<div
111-
data-show-when-value-selected-target="effect"
112-
data-target-name="email_delivery_method_settings"
113-
data-value="sendmail"
114-
<%= "hidden" unless Setting.email_delivery_method == :sendmail %>>
115-
<div class="form--field"><%= setting_text_field :sendmail_location %></div>
116-
<div class="form--field"><%= setting_text_field :sendmail_arguments %></div>
117-
</div>
118-
<div
119-
data-show-when-value-selected-target="effect"
120-
data-target-name="email_delivery_method_settings"
121-
data-value="letter_opener"
122-
<%= "hidden" unless Setting.email_delivery_method == :letter_opener %>>
123-
<p>Letter opener is used to render emails as a file in your Rails tmp folder. Mails will automatically open in
124-
your browser if supported.</p>
125-
</div>
126-
<% end unless OpenProject::Configuration['email_delivery_configuration'] == 'legacy' %>
127-
128-
<%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %>
12962

130-
<% if @deliveries %>
131-
<div style="float:none;display:inline-block;font-weight:bold;">
132-
<%= link_to t(:label_send_test_email),
133-
{ controller: "/admin", action: "test_email" },
134-
data: { turbo_method: :post } %>
135-
</div>
136-
<% end %>
63+
<% if @deliveries %>
64+
<%= render Primer::Beta::Link.new(
65+
href: test_email_admin_index_path,
66+
data: { turbo_method: :post },
67+
font_weight: :bold,
68+
display: :block,
69+
mt: 3
70+
) do
71+
t(:label_send_test_email)
72+
end %>
13773
<% end %>

0 commit comments

Comments
 (0)