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' of github.com:ita-social-proje…
…cts/ZeroWaste into 978-rounding-results-to-2-decimal-places
- Loading branch information
Showing
27 changed files
with
316 additions
and
104 deletions.
There are no files selected for viewing
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
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
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}`; | ||
} | ||
}); | ||
} | ||
} |
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
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> |
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
34 changes: 21 additions & 13 deletions
34
app/views/calculators/partials/_calculation_results.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,14 +1,22 @@ | ||
<h2 class="mt-4 text-2xl font-bold text-white underline">Calculation Results</h2> | ||
<div class="mt-2 space-y-2 text-white"> | ||
<% results.each do |result| %> | ||
<div class="flex gap-2 text-lg font-medium"> | ||
<h3> | ||
<%= result[:label] %> | ||
</h3> | ||
= | ||
<p> | ||
<%= result[:result] %> | ||
</p> | ||
</div> | ||
<% end %> | ||
<%# TODO: Delete this and use user provided value%> | ||
<% formula_image = "money_to_spent_2.png" %> | ||
|
||
<div class="calculation-results rounded jumbotron jumbotron-fluid position-relative"> | ||
<h2 class="pt-6 text-2xl font-semibold text-center dynamic-text-color">Calculation Results</h2> | ||
<div class="jumbotron calculation-results result main-result-container result-container"> | ||
<% results.each do |result| %> | ||
<div> | ||
<%= image_tag "#{formula_image}", class: "img-margin", alt: "icon" %> | ||
<p class="dynamic-text-color"> | ||
<%= result[:result] %> | ||
</p> | ||
<p class="text-2xl dynamic-text-color"> | ||
<%= result[:unit] %> | ||
</p> | ||
<p class="diapers-font-text"> | ||
<%= result[:label] %> | ||
</p> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
8 changes: 8 additions & 0 deletions
8
app/views/calculators/partials/show/_constructor_calculator_description.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,8 @@ | ||
<%# TODO: Delete this if %> | ||
<% if false %> | ||
<section class="description-section"> | ||
<div class="description-block"> | ||
<%# TODO: ADD text here %> | ||
</div> | ||
</section> | ||
<% end %> |
Oops, something went wrong.