diff --git a/app/javascript/controllers/constructors_form_indexing_controller.js b/app/javascript/controllers/constructors_form_indexing_controller.js new file mode 100644 index 000000000..9e5677b96 --- /dev/null +++ b/app/javascript/controllers/constructors_form_indexing_controller.js @@ -0,0 +1,26 @@ +import { Controller } from "@hotwired/stimulus" + +// Connects to data-controller="constructors-form-indexing" +export default class extends Controller { + static targets = ["index"]; + + afterInsert(event) { + const fieldsets = this.element.querySelectorAll(":scope > .nested-fields"); + const span = fieldsets[fieldsets.length - 1].querySelector("[data-constructors-form-indexing-target='index']") + + if (span) { + span.textContent = `${fieldsets.length}`; + } + } + + afterRemove(event) { + const fieldsets = this.element.querySelectorAll(":scope > .nested-fields"); + + fieldsets.forEach((fieldset, index) => { + const span = fieldset.querySelector("[data-constructors-form-indexing-target='index']"); + if (span) { + span.textContent = `${index + 1}`; + } + }); + } +} diff --git a/app/views/account/calculators/partials/_category_fields.html.erb b/app/views/account/calculators/partials/_category_fields.html.erb index b90a7a26d..ab81bb659 100644 --- a/app/views/account/calculators/partials/_category_fields.html.erb +++ b/app/views/account/calculators/partials/_category_fields.html.erb @@ -1,7 +1,10 @@ -
- <%= f.input :en_name, label: "Category Name:" %> - <%= f.input :uk_name, label: "Uk Category Name:" %> - <%= f.input :price, label: "Category Price:" %> - - <%= link_to_remove_association "- Remove Category", f, class: "text-red-500 underline" %> -
+
+ Category 1 +
+ <%= f.input :en_name, label: "Category Name:" %> + <%= f.input :uk_name, label: "Uk Category Name:" %> + <%= f.input :price, label: "Category Price:" %> + + <%= link_to_remove_association "- Remove Category", f, class: "text-red-500 underline" %> +
+
diff --git a/app/views/account/calculators/partials/_field_fields.html.erb b/app/views/account/calculators/partials/_field_fields.html.erb index 2df9d0d8e..3c86bf24b 100644 --- a/app/views/account/calculators/partials/_field_fields.html.erb +++ b/app/views/account/calculators/partials/_field_fields.html.erb @@ -1,21 +1,32 @@ -
- <%= f.input :en_label, label: "Field Label:" %> - <%= f.input :uk_label, label: "Uk Field Label:" %> - <%= f.input :var_name, label: "Variable Name:" %> - <%= f.input( - :kind, - collection: Field.kinds.keys.map { |key| [key.humanize, key] }, - prompt: "Select Field Type", - label: "Field Type:", - input_html: { data: { field_type_target: "fieldTypeSelect" } } - ) %> +
+ Field 1 + +
+ <%= f.input :en_label, label: "Field Label:" %> + <%= f.input :uk_label, label: "Uk Field Label:" %> + <%= f.input :var_name, label: "Variable Name:" %> + <%= f.input( + :kind, + collection: Field.kinds.keys.map { |key| [key.humanize, key] }, + prompt: "Select Field Type", + label: "Field Type:", + input_html: { data: { field_type_target: "fieldTypeSelect" } } + ) %> - - <%= link_to_remove_association "- Remove Field", f, class: "text-red-500 underline" %> -
+ + <%= link_to_remove_association "- Remove Field", f, class: "text-red-500 underline" %> +
+ diff --git a/app/views/account/calculators/partials/_form.html.erb b/app/views/account/calculators/partials/_form.html.erb index 781d15c5d..438b34288 100644 --- a/app/views/account/calculators/partials/_form.html.erb +++ b/app/views/account/calculators/partials/_form.html.erb @@ -1,27 +1,36 @@ <%= simple_form_for(@calculator, url: account_calculators_path) do |f| %>
- <%= f.input :en_name, label: "Calculator Name:", class: 'form-control' %> - <%= f.input :uk_name, label: "Uk Calculator Name:", class: 'form-control' %> +
+ Calculator + <%= f.input :en_name, label: "Calculator Name:", class: 'form-control' %> + <%= f.input :uk_name, label: "Uk Calculator Name:", class: 'form-control' %> +
- <%= f.simple_fields_for :formulas do |formula_fields| %> - <%= render "account/calculators/partials/formula_fields", f: formula_fields %> - <% end %> - +
+ <%= f.simple_fields_for :formulas do |formula_fields| %> + <%= render "account/calculators/partials/formula_fields", f: formula_fields %> + <% end %> + +
- <%= f.simple_fields_for :fields do |field_fields| %> - <%= render "account/calculators/partials/field_fields", f: field_fields %> - <% end %> - +
+ <%= f.simple_fields_for :fields do |field_fields| %> + <%= render "account/calculators/partials/field_fields", f: field_fields %> + <% end %> + +
diff --git a/app/views/account/calculators/partials/_formula_fields.html.erb b/app/views/account/calculators/partials/_formula_fields.html.erb index a0787f159..ce40536f6 100644 --- a/app/views/account/calculators/partials/_formula_fields.html.erb +++ b/app/views/account/calculators/partials/_formula_fields.html.erb @@ -1,10 +1,13 @@ -
- <%= f.input :en_label, label: "Formula Label:" %> - <%= f.input :uk_label, label: "Uk Formula Label:" %> - <%= f.input :expression, label: "Formula Expression:" %> +
+ Formula 1 +
+ <%= f.input :en_label, label: "Formula Label:" %> + <%= f.input :uk_label, label: "Uk Formula Label:" %> + <%= f.input :expression, label: "Formula Expression:" %> - <%= f.input :uk_unit, label: "Uk Unit Label:" %> - <%= f.input :en_unit, label: "Unit Label:" %> + <%= f.input :uk_unit, label: "Uk Unit Label:" %> + <%= f.input :en_unit, label: "Unit Label:" %> - <%= link_to_remove_association "- Remove Formula", f, class: "text-red-500 underline" %> -
+ <%= link_to_remove_association "- Remove Formula", f, class: "text-red-500 underline" %> +
+