Skip to content

Commit

Permalink
Merge pull request #58 from internetee/domain-form-issues
Browse files Browse the repository at this point in the history
Fixed domain form
  • Loading branch information
vohmar authored Sep 8, 2022
2 parents bfa1392 + 35ad836 commit 2af7fea
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 42 deletions.
12 changes: 6 additions & 6 deletions app/assets/stylesheets/form/form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
margin-left: auto;
display: flex;
align-items: center;
a {
text-decoration: underline;
+ a {
margin-left: 10px;
}
}
a {
text-decoration: underline;
+ a {
margin-left: 10px;
}
}
}
&:not(:last-child) {
margin-bottom: 20px;
Expand Down
47 changes: 28 additions & 19 deletions app/controllers/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,32 +176,41 @@ def domain_payload
transfer_code: domain_params[:transfer_code],
registrant: domain_params[:registrant],
period: domain_params[:period],
contacts: if domain_params[:contacts_attributes].present?
domain_params[:contacts_attributes].values.reject { |c| c[:code].blank? }
end,
nameservers: if domain_params[:nameservers_attributes].present?
domain_params[:nameservers_attributes].values
.reject { |n| n[:hostname].blank? }
.map do |ns_attr|
{
id: ns_attr[:id],
hostname: ns_attr[:hostname],
ipv4: ns_attr[:ipv4].split(','),
ipv6: ns_attr[:ipv6].split(','),
action: ns_attr[:action],
}
end
end,
dns_keys: if domain_params[:dnskeys_attributes].present?
domain_params[:dnskeys_attributes].values.reject { |d| d[:public_key].blank? }
end,
contacts: contacts_attributes(domain_params),
nameservers: nameservers_attributes(domain_params),
dns_keys: dnskeys_attributes(domain_params),
legal_document: transform_legal_doc_params(domain_params[:legal_document]),
batch_file: parse_csv(domain_params[:batch_file]),
exp_date: domain_params[:exp_date],
}
end
# rubocop:enable Metrics/MethodLength

def contacts_attributes(domain_params)
return [] if domain_params[:contacts_attributes].blank?

domain_params[:contacts_attributes].values.reject { |c| c[:code].blank? }
end

def nameservers_attributes(domain_params)
return [] if domain_params[:nameservers_attributes].blank?

domain_params[:nameservers_attributes].values.reject { |n| n[:hostname].blank? }
.map do |ns_attr|
{
id: ns_attr[:id], hostname: ns_attr[:hostname],
ipv4: ns_attr[:ipv4].split(','), ipv6: ns_attr[:ipv6].split(','),
action: ns_attr[:action]
}
end
end

def dnskeys_attributes(domain_params)
return [] if domain_params[:dnskeys_attributes].blank?

domain_params[:dnskeys_attributes].values.reject { |d| d[:public_key].blank? }
end

def parse_csv(params)
return if params.blank?

Expand Down
17 changes: 10 additions & 7 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ class App {
new FileUpload(elem);
});

document.getElementById('per_page').onchange = function(evt){
var value = evt.target.value;
// if(value){window.location='?per_page='+value;}
var per_page_select = document.getElementById('per_page');
if (per_page_select) {
per_page_select.onchange = function(evt){
var value = evt.target.value;
// if(value){window.location='?per_page='+value;}

const urlParams = new URLSearchParams(window.location.search);
urlParams.set('per_page', value);
window.location.search = urlParams;
};
const urlParams = new URLSearchParams(window.location.search);
urlParams.set('per_page', value);
window.location.search = urlParams;
};
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/javascript/controllers/nested_form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export default class extends Controller {
const content = this[type + "TemplateTarget"].innerHTML.replace(/NEW_RECORD/g, num_elements + 1);
this[type + "TargetTarget"].insertAdjacentHTML("beforebegin", content);
const last = Array.from(
document.querySelectorAll(this[type + 'SelectorWrapperValue'])
document.querySelectorAll(this[type + 'SelectorWrapperValue'])
).pop();
last.querySelectorAll('select:not(.flatpickr-monthDropdown-months)').forEach(elem => {
new Select(elem, {});
new Select(elem, {});
});
}
}
Expand All @@ -40,7 +40,7 @@ export default class extends Controller {
let type = e.target.dataset.value;
const wrapper = e.target.closest(this[type + 'SelectorWrapperValue']);
let num_elements = this.numberOfVisibleElements(this[type + 'SelectorWrapperValue']);
if (num_elements > 1) {
if (num_elements > 0) {
if (wrapper.dataset.newRecord === 'true') {
wrapper.remove();
} else {
Expand Down
2 changes: 2 additions & 0 deletions app/services/api_connector/domains/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def ns_attrs(nameservers)
end

def contacts(contacts, type)
return [] unless contacts

contacts.select { |c| c[:type] == type }.pluck(:code)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/domains/partials/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div class="col-md-4 col-xs-12">
<template data-nested-form-target="nameserverTemplate">
<%= render 'domains/partials/form/nameservers', k: 'NEW_RECORD',
v: '',
v: {},
removable: true %>
</template>
<% @domain_params[:nameservers_attributes].each do |k, v| %>
Expand All @@ -40,7 +40,7 @@
<div class="col-md-4 col-xs-12">
<template data-nested-form-target="dnskeyTemplate">
<%= render 'domains/partials/form/dns_keys', k: 'NEW_RECORD',
v: '',
v: {},
removable: true %>
</template>
<% @domain_params[:dnskeys_attributes].each do |k, v| %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/domains/partials/form/_dns_keys.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="form--wrapper dnskey-nested-form-wrapper", data-new-record="<%= k == 'NEW_RECORD' %>">
<div class="form--header">
<h3><%= "#{t('domains.form.dns_key')} #{k if k != 1}" %></h3>
<h3><%= "#{t('domains.form.dnskey')} #{k if k != 1}" %></h3>
<div class="form--header--actions">
<%= render 'domains/partials/form/action_links', type: 'dnskey',
removable: removable %>
Expand Down Expand Up @@ -44,6 +44,6 @@
</div>
</div>
</div>
<%= hidden_field_tag "domain[dnskeys_attributes][#{k}][id]", v['id'] if v['id'] %>
<%= hidden_field_tag "domain[dnskeys_attributes][#{k}][id]", v['id'] if v['id'] %>
<%= hidden_field_tag "domain[dnskeys_attributes][#{k}][action]", 'add' %>
</div>
2 changes: 1 addition & 1 deletion app/views/domains/partials/form/_nameservers.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
</div>
</div>
</div>
<%= hidden_field_tag "domain[nameservers_attributes][#{k}][id]", v['id'] if v['id'] %>
<%= hidden_field_tag "domain[nameservers_attributes][#{k}][id]", v['id'] if v['id'] %>
<%= hidden_field_tag "domain[nameservers_attributes][#{k}][action]", 'add' %>
</div>
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ en:
save: "Save"
choose: "Choose"
add_more: "Add more"
add_new: "Add new"
delete: "Delete"
add: "Add"
pay: "Pay"
Expand Down Expand Up @@ -156,7 +157,7 @@ en:
admin: "Admin"
nameserver: "Nameserver"
hostname: "Hostname"
dns_key: "DNS key"
dnskey: "DNS key"
flags: "Flags"
protocol: "Protocol"
algorithm: "Algorithm"
Expand Down
3 changes: 2 additions & 1 deletion config/locales/et.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ et:
save: "Salvesta"
choose: "Vali"
add_more: "Lisa veel"
add_new: "Lisa uus"
delete: "Kustuta"
add: "Lisa"
pay: "Maksa"
Expand Down Expand Up @@ -157,7 +158,7 @@ et:
admin: "Admin"
nameserver: "Nimeserver"
hostname: "Hostinimi"
dns_key: "DNSKEY kirje"
dnskey: "DNSKEY kirje"
flags: "Lipud"
protocol: "Protokoll"
algorithm: "Algoritm"
Expand Down

0 comments on commit 2af7fea

Please sign in to comment.