diff --git a/app/assets/stylesheets/pages/calculator.scss b/app/assets/stylesheets/pages/calculator.scss
index 0dede5e06..1c8178664 100644
--- a/app/assets/stylesheets/pages/calculator.scss
+++ b/app/assets/stylesheets/pages/calculator.scss
@@ -16,6 +16,28 @@
font-style: normal;
transition: transform 0.5s ease-in-out;
max-width: 300px;
+ @include transition(all 0.5s ease-in-out);
+
+ &:hover {
+ background-color: $matte_lime_green;
+ }
+}
+
+.btn-nonito {
+ font-size: 14px;
+ letter-spacing: 2px;
+ text-transform: uppercase;
+ font-weight: 400;
+ font-family: "Nunito", sans-serif;
+ font-style: normal;
+}
+
+.dynamic-text-color {
+ color: var(--calculator-color);
+}
+
+.dynamic-background-color {
+ background-color: var(--calculator-color);
}
#calc {
@@ -61,6 +83,11 @@
margin-right: 0px;
}
+.calculator-field {
+ background-color: $light_gray !important;
+ border: 0;
+}
+
.flex-item {
display: flex;
flex-wrap: wrap;
diff --git a/app/assets/stylesheets/pages/feature_flags.scss b/app/assets/stylesheets/pages/feature_flags.scss
index a68714537..53a8ce168 100644
--- a/app/assets/stylesheets/pages/feature_flags.scss
+++ b/app/assets/stylesheets/pages/feature_flags.scss
@@ -41,7 +41,6 @@
}
input[type="submit"] {
- background-color: $success;
border: none;
border-radius: 4px;
color: #fff;
@@ -49,11 +48,6 @@ input[type="submit"] {
font-size: 16px;
padding: 10px;
min-width: 110px;
- @include transition(all 0.5s ease-in-out);
-
- &:hover {
- background-color: $matte_lime_green;
- }
}
.btn-grey {
diff --git a/app/controllers/calculators_controller.rb b/app/controllers/calculators_controller.rb
index 8e87d0e92..0901c96ed 100644
--- a/app/controllers/calculators_controller.rb
+++ b/app/controllers/calculators_controller.rb
@@ -14,6 +14,8 @@ def index
def show
@calculator = resource
+ add_breadcrumb t("breadcrumbs.home"), root_path
+ add_breadcrumb @calculator.name
end
def calculate
diff --git a/app/models/formula.rb b/app/models/formula.rb
index c8ef422cb..47713fda2 100644
--- a/app/models/formula.rb
+++ b/app/models/formula.rb
@@ -22,6 +22,8 @@
# fk_rails_... (calculator_id => calculators.id)
#
class Formula < ApplicationRecord
+ include Translatable
+
belongs_to :calculator
validates_with FormulaValidator
@@ -29,4 +31,6 @@ class Formula < ApplicationRecord
validates :uk_label, :en_label, :uk_unit, :en_unit, :expression, presence: true
validates :uk_label, :en_label, length: { minimum: 3, maximum: 50 }
validates :en_unit, :uk_unit, length: { minimum: 1, maximum: 30 }
+
+ translates :label, :unit
end
diff --git a/app/services/calculators/calculation_service.rb b/app/services/calculators/calculation_service.rb
index 081092b0f..e888d1f47 100644
--- a/app/services/calculators/calculation_service.rb
+++ b/app/services/calculators/calculation_service.rb
@@ -10,7 +10,7 @@ def perform
@calculator.formulas.map do |formula|
result = @dentaku.evaluate(formula.expression, @inputs)
- { label: formula.en_label, result: result }
+ { label: formula.label, result: result, unit: formula.unit }
end
end
end
diff --git a/app/views/calculators/partials/_calculation_results.html.erb b/app/views/calculators/partials/_calculation_results.html.erb
index 72c1d9215..14199c497 100644
--- a/app/views/calculators/partials/_calculation_results.html.erb
+++ b/app/views/calculators/partials/_calculation_results.html.erb
@@ -1,14 +1,22 @@
-
- <% results.each do |result| %>
-
-
- <%= result[:label] %>
-
- =
-
- <%= result[:result] %>
-
-
- <% end %>
+<%# TODO: Delete this and use user provided value%>
+<% formula_image = "money_to_spent_2.png" %>
+
+
+
Calculation Results
+
+ <% results.each do |result| %>
+
+ <%= image_tag "#{formula_image}", class: "img-margin", alt: "icon" %>
+
+ <%= result[:result] %>
+
+
+ <%= result[:unit] %>
+
+
+ <%= result[:label] %>
+
+
+ <% end %>
+
diff --git a/app/views/calculators/partials/show/_constructor_calculator_description.erb b/app/views/calculators/partials/show/_constructor_calculator_description.erb
new file mode 100644
index 000000000..fed35215a
--- /dev/null
+++ b/app/views/calculators/partials/show/_constructor_calculator_description.erb
@@ -0,0 +1,8 @@
+<%# TODO: Delete this if %>
+<% if false %>
+
+
+ <%# TODO: ADD text here %>
+
+
+<% end %>
diff --git a/app/views/calculators/show.html.erb b/app/views/calculators/show.html.erb
index 489f4f024..82295fe22 100644
--- a/app/views/calculators/show.html.erb
+++ b/app/views/calculators/show.html.erb
@@ -1,21 +1,40 @@
-
-
Calculator <%= @calculator.name %>
+<%# TODO: Delete this and use user provided value %>
+<% color = "#088F8F" %>
- <%= form_with url: calculate_calculator_path(@calculator) do |form| %>
- <% @calculator.fields.each do |field| %>
-
-
<%= form.label field.var_name, field.label %>
- <% if field.kind == 'number' %>
- <%= form.number_field "inputs[#{field.var_name}]", placeholder: field.label %>
- <% else %>
- <%= form.select "inputs[#{field.var_name}]", options_from_collection_for_select(field.categories, :price, :name) %>
- <% end %>
-
+<%# TODO: Delete this and use user provided value %>
+<% calculator_image = "scales.png" %>
+
+
+
+
Calculator <%= @calculator.name %> <%= @text %>
+
+
+ <%= form_with html: { class: "simple_form_calculator"}, url: calculate_calculator_path(@calculator) do |form| %>
+
+ <% @calculator.fields.each do |field| %>
+
<%= form.label field.var_name, field.label %>
+ <% if field.kind == 'number' %>
+
+ <%= form.number_field "inputs[#{field.var_name}]",
+ placeholder: field.label,
+ class: "required rounded w-100 calculator-field"
+ %>
+
+ <% else %>
+ <%= form.select "inputs[#{field.var_name}]",
+ options_from_collection_for_select(field.categories, :price, :name),
+ {},
+ class: "flex-row rounded flex-item w-100 form_fild calculator-field" %>
+ <% end %>
+ <% end %>
+ <%= form.submit "Calculate", class: "btn-nonito result-btn dynamic-background-color" %>
+
<% end %>
-
- <%= form.submit "Calculate", class: "bg-blue-500 text-white font-semibold px-4 py-2 rounded hover:bg-blue-700" %>
+ <%= image_tag calculator_image, class: "scales_img", alt: t(".image_alt") %>
- <% end %>
+
<%= turbo_frame_tag "calc-results" %>
+
+<%= render "calculators/partials/show/constructor_calculator_description" %>
diff --git a/config/locales/en/en.yml b/config/locales/en/en.yml
index 0c4a7bca0..728b2aea0 100644
--- a/config/locales/en/en.yml
+++ b/config/locales/en/en.yml
@@ -83,6 +83,7 @@ en:
month_error_msg: "Please, select month"
show:
welcome_header: "Welcome to ZeroWaste"
+ image_alt: "Scales"
buttons:
to_main: "To main"
calculate: "Calculate"
diff --git a/config/locales/uk/uk.yml b/config/locales/uk/uk.yml
index 05a4d3bf8..cbbc7c58d 100644
--- a/config/locales/uk/uk.yml
+++ b/config/locales/uk/uk.yml
@@ -65,6 +65,7 @@ uk:
will_buy_diapers: "Кількість підгузків, які ще будуть використані до моменту, коли дитина перейде на звичайну білизну"
money_spent: "Вартість використаних підгузків"
money_will_be_spent: "Вартість підгузків, які ще будуть використані до моменту, коли дитина перейде на звичайну білизну"
+ image_alt: "Ваги"
buttons:
to_main: "На головну"
calculate: "Розрахувати"
diff --git a/spec/helpers/calculators/calculation_service_helper_spec.rb b/spec/helpers/calculators/calculation_service_helper_spec.rb
new file mode 100644
index 000000000..1e81b43a8
--- /dev/null
+++ b/spec/helpers/calculators/calculation_service_helper_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require "rails_helper"
+
+RSpec.describe Calculators::CalculationService, type: :helper do
+ let(:calculator) { instance_double("Calculator", formulas: formulas) }
+ let(:formulas) do
+ [
+ Formula.new(en_label: "Addition", en_unit: "units", uk_label: "Додавання", uk_unit: "одиниці", expression: "x + y"),
+ Formula.new(en_label: "Multiplication", en_unit: "units", uk_label: "Множення", uk_unit: "одиниці", expression: "x * y")
+ ]
+ end
+ let(:inputs) { ActionController::Parameters.new({ x: 5, y: 3 }) }
+
+ before do
+ allow_any_instance_of(ApplicationHelper).to receive(:current_locale?).with(:en).and_return(locale_en)
+ end
+
+ describe "#perform" do
+ subject do
+ I18n.with_locale(locale_en ? :en : :uk) do
+ described_class.new(calculator, inputs).perform
+ end
+ end
+
+ context "when locale is English" do
+ let(:locale_en) { true }
+
+ it "returns results with English labels and units" do
+ expect(subject).to eq([
+ { label: "Addition", result: 8, unit: "units" },
+ { label: "Multiplication", result: 15, unit: "units" }
+ ])
+ end
+ end
+
+ context "when locale is Ukrainian" do
+ let(:locale_en) { false }
+
+ it "returns results with Ukrainian labels and units" do
+ expect(subject).to eq([
+ { label: "Додавання", result: 8, unit: "одиниці" },
+ { label: "Множення", result: 15, unit: "одиниці" }
+ ])
+ end
+ end
+ end
+end