generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'calculators-constructor' into 988-add-calculator-color
- Loading branch information
Showing
5 changed files
with
103 additions
and
50 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/javascript/controllers/constructors_form_indexing_controller.js
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,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}`; | ||
} | ||
}); | ||
} | ||
} |
17 changes: 10 additions & 7 deletions
17
app/views/account/calculators/partials/_category_fields.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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
<div class="nested-fields"> | ||
<%= 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" %> | ||
</div> | ||
<fieldset class="bordered nested-fields"> | ||
<legend class="admin-legend">Category <span data-constructors-form-indexing-target="index">1</span></legend> | ||
<div> | ||
<%= 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" %> | ||
</div> | ||
</fieldset> |
47 changes: 29 additions & 18 deletions
47
app/views/account/calculators/partials/_field_fields.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 |
---|---|---|
@@ -1,21 +1,32 @@ | ||
<div class="nested-fields" data-controller="field-type"> | ||
<%= 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" } } | ||
) %> | ||
<fieldset class="bordered nested-fields"> | ||
<legend class="admin-legend">Field <span data-constructors-form-indexing-target="index">1</span></legend> | ||
|
||
<div data-controller="field-type"> | ||
<%= 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" } } | ||
) %> | ||
|
||
<div class="hidden category-fields" data-field-type-target="categoryFields"> | ||
<%= f.simple_fields_for :categories do |category_fields| %> | ||
<%= render "account/calculators/partials/category_fields", f: category_fields %> | ||
<% end %> | ||
<%= link_to_add_association "+ Add Category", f, :categories, partial: "account/calculators/partials/category_fields", class: "underline" %> | ||
<fieldset class="bordered" data-controller="constructors-form-indexing" | ||
data-action="cocoon:after-insert->constructors-form-indexing#afterInsert cocoon:after-remove->constructors-form-indexing#afterRemove"> | ||
<legend class="admin-legend">Categories</legend> | ||
|
||
<%= f.simple_fields_for :categories do |category_fields| %> | ||
<%= render "account/calculators/partials/category_fields", f: category_fields %> | ||
<% end %> | ||
<div class="links"> | ||
<%= link_to_add_association "+ Add Category", f, :categories, partial: "account/calculators/partials/category_fields", class: "underline" %> | ||
</div> | ||
</fieldset> | ||
</div> | ||
|
||
<%= link_to_remove_association "- Remove Field", f, class: "text-red-500 underline" %> | ||
</div> | ||
|
||
<%= link_to_remove_association "- Remove Field", f, class: "text-red-500 underline" %> | ||
</div> | ||
</fieldset> |
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
19 changes: 11 additions & 8 deletions
19
app/views/account/calculators/partials/_formula_fields.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<div class="nested-fields"> | ||
<%= f.input :en_label, label: "Formula Label:" %> | ||
<%= f.input :uk_label, label: "Uk Formula Label:" %> | ||
<%= f.input :expression, label: "Formula Expression:" %> | ||
<fieldset class="bordered nested-fields"> | ||
<legend class="admin-legend">Formula <span data-constructors-form-indexing-target="index">1</span></legend> | ||
<div> | ||
<%= 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" %> | ||
</div> | ||
<%= link_to_remove_association "- Remove Formula", f, class: "text-red-500 underline" %> | ||
</div> | ||
</fieldset> |