-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ed1086
commit 60d7f6e
Showing
11 changed files
with
177 additions
and
116 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
app/components/admin/settings/contact_group/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% @contact_group.each do |setting| %> | ||
<% if setting.format == 'array' and setting.code == 'code_of_technical_contact' %> | ||
<%= component 'settings/tech_contact_field', form: form, setting: setting %> | ||
<% else %> | ||
<fieldset class="space-y-5"> | ||
<%= component 'form/checkbox_with_description', form: form, attribute: "[settings][#{setting.id}", label_name: setting.code, description: setting.description, value: setting.value == 'true' %> | ||
</fieldset> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Admin | ||
module Settings | ||
module ContactGroup | ||
class Component < ApplicationViewComponent | ||
attr_reader :contact_group, :form | ||
|
||
def initialize(contact_group:, form:) | ||
@contact_group = contact_group | ||
@form = form | ||
end | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
app/components/admin/settings/invoice_group/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% @invoice_group.each do |setting| %> | ||
<div class='flex items-center space-y-2'> | ||
|
||
<div class='w-52'> | ||
<%= form.label setting.code, class: 'block text-sm font-bold text-gray-700' %> | ||
</div> | ||
<div class="relative mt-1 rounded-md shadow-md border border-gray-300 w-96"> | ||
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3"> | ||
<%= heroicon 'cog', variant: :solid, options: { class: 'h-5 w-5 text-gray-400' } %> | ||
</div> | ||
<%= form.text_field "[settings][#{setting.id}", placeholder: t(".#{setting.code}"), value: setting.value, class: 'block w-full rounded-md border-gray-300 pl-10 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm py-2' %> | ||
</div> | ||
<%= form.hidden_field :id, value: "[settings][#{setting.id}" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Admin | ||
module Settings | ||
module InvoiceGroup | ||
class Component < ApplicationViewComponent | ||
attr_reader :invoice_group, :form | ||
|
||
def initialize(invoice_group:, form:) | ||
@invoice_group = invoice_group | ||
@form = form | ||
end | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
app/components/admin/settings/registrar_group/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<% @registrar_group.each do |setting| %> | ||
|
||
<div class='flex items-center space-y-2'> | ||
<div class='w-52'> | ||
<%= form.label setting.code, class: 'block text-sm font-bold text-gray-700' %> | ||
</div> | ||
<% if setting.format == 'array' and setting.code == 'default_nameserver_records' %> | ||
<%= component 'settings/array_field', form: form, setting: setting %> | ||
<% elsif setting.format == 'hash' %> | ||
<%= component 'settings/hash_field', form: form, setting: setting %> | ||
<% elsif setting.format == 'boolean' %> | ||
|
||
<fieldset class="space-y-5"> | ||
<%= component 'form/checkbox_with_description', form: form, attribute: "[settings][#{setting.id}", label_name: setting.code, description: setting.description, value: setting.value == 'true' %> | ||
</fieldset> | ||
|
||
<% else %> | ||
|
||
<div class="relative mt-1 rounded-md shadow-md border border-gray-300 w-96"> | ||
<div class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3"> | ||
<%= heroicon 'cog', variant: :solid, options: { class: 'h-5 w-5 text-gray-400' } %> | ||
</div> | ||
<%= form.text_field "[settings][#{setting.id}", placeholder: t(".#{setting.code}"), value: setting.value, class: 'block w-full rounded-md border-gray-300 pl-10 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm py-2' %> | ||
</div> | ||
|
||
<% end %> | ||
<%= form.hidden_field :id, value: "[settings][#{setting.id}" %> | ||
</div> | ||
<% end %> |
14 changes: 14 additions & 0 deletions
14
app/components/admin/settings/registrar_group/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Admin | ||
module Settings | ||
module RegistrarGroup | ||
class Component < ApplicationViewComponent | ||
attr_reader :registrar_group, :form | ||
|
||
def initialize(registrar_group:, form:) | ||
@registrar_group = registrar_group | ||
@form = form | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Admin | ||
class SettingUpdaterService | ||
attr_reader :params | ||
|
||
def initialize(params) | ||
@params = params | ||
end | ||
|
||
def update | ||
updated = true | ||
errors = [] | ||
|
||
casted_settings.each do |id, setting_params| | ||
setting = Setting.find_by(id: id) | ||
|
||
if setting.update!(setting_params) | ||
next | ||
else | ||
updated = false | ||
errors += setting.errors.full_messages | ||
end | ||
end | ||
|
||
return updated, errors | ||
end | ||
|
||
private | ||
|
||
def casted_settings | ||
settings_values = {} | ||
|
||
params.require(:settings).permit! | ||
|
||
params[:settings].each do |k, v| | ||
setting = Setting.find_by(id: k) | ||
|
||
next unless setting | ||
|
||
formatted_value = format_setting_value(v, setting.format) | ||
settings_values[setting.id] = { value: formatted_value } | ||
end | ||
|
||
settings_values | ||
end | ||
|
||
def format_setting_value(value, format_type) | ||
case format_type | ||
when 'boolean' | ||
(value.to_s == 'true').to_s | ||
when 'integer' | ||
value.to_i | ||
when 'float' | ||
value.to_f | ||
when 'hash' | ||
value.is_a?(ActionController::Parameters) ? value.to_unsafe_h.to_json : value | ||
when 'array' | ||
if value.is_a?(Array) && value.first.is_a?(ActionController::Parameters) | ||
value.map(&:to_unsafe_h).to_json | ||
else | ||
value.to_json | ||
end | ||
else | ||
value | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters