Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#988 Add color to Calculator #997

Merged
merged 13 commits into from
Dec 5, 2024
2 changes: 1 addition & 1 deletion app/controllers/account/calculators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def collect_fields_for_kind(kind)

def calculator_params
params.require(:calculator).permit(
:id, :en_name, :uk_name,
:id, :en_name, :uk_name, :color,
formulas_attributes: [:id, :expression, :en_label, :uk_label, :calculator_id, :en_unit, :uk_unit, :_destroy],
fields_attributes: [:id, :en_label, :uk_label, :var_name, :kind, :_destroy,
categories_attributes: [:id, :en_name, :uk_name, :price, :_destroy]]
Expand Down
2 changes: 2 additions & 0 deletions app/models/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: calculators
#
# id :bigint not null, primary key
# color :string default("#000000")
# en_name :string default(""), not null
# slug :string
# uk_name :string default(""), not null
Expand Down Expand Up @@ -35,6 +36,7 @@ class Calculator < ApplicationRecord
validates :en_name, :uk_name, presence: true
validates :en_name, :uk_name, length: { minimum: 3, maximum: 50 }
validates :slug, presence: true, uniqueness: true
validates :color, format: { with: /\A#[0-9a-fA-F]{6}\z/ }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а де тести?))


def self.ransackable_attributes(auth_object = nil)
["created_at", "id", "name", "preferable", "slug", "updated_at", "uuid"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="nested-fields">
<%= f.input :color, as: :color, label: 'Choose a Color for Calculator Page:', input_html: { class: 'form-control form-control-color p-2', style: 'width: 7rem; height: 3.5rem;' } %>
</div>
3 changes: 3 additions & 0 deletions app/views/account/calculators/partials/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<div class="my-auto col-12 has-float-label">
<%= f.input :en_name, label: "Calculator Name:", class: 'form-control' %>
<%= f.input :uk_name, label: "Uk Calculator Name:", class: 'form-control' %>
<div id="fields" class="space-y-4">
<%= render "account/calculators/partials/color_selector", f: f %>
</div>

<!-- formula input-->
<div id="formulas" class="space-y-4">
Expand Down
9 changes: 3 additions & 6 deletions app/views/calculators/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<%# TODO: Delete this and use user provided value %>
<% color = "#088F8F" %>

<%# TODO: Delete this and use user provided value %>
<% calculator_image = "scales.png" %>

<div style="--calculator-color: <%= color %>">
<div style="--calculator-color: <%= @calculator.color %>">
<div class="rounded jumbotron jumbotron-fluid position-relative">
<h1 class="pt-6 text-2xl font-semibold text-center font-sans dynamic-text-color">Calculator <%= @calculator.name %> <%= @text %></h1>
<div class="flex-wrap d-flex justify-content-around calculator_wrap ms-5">
Expand All @@ -15,13 +12,13 @@
<div class="pb-2 input_lable"><%= form.label field.var_name, field.label %></div>
<% if field.kind == 'number' %>
<div class="flex-row rounded flex-item w-100 age_wrapper form_fild">
<%= form.number_field "inputs[#{field.var_name}]",
<%= form.number_field "inputs[#{field.var_name}]",
placeholder: field.label,
class: "required rounded w-100 calculator-field"
%>
</div>
<% else %>
<%= form.select "inputs[#{field.var_name}]",
<%= 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" %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241201141708_add_color_to_calculators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddColorToCalculators < ActiveRecord::Migration[7.2]
def change
add_column :calculators, :color, :string, default: "#000000"
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_11_19_192344) do
ActiveRecord::Schema[7.2].define(version: 2024_12_01_141708) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand Down Expand Up @@ -49,6 +49,7 @@
t.string "slug"
t.string "uk_name", default: "", null: false
t.string "en_name", default: "", null: false
t.string "color", default: "#000000"
t.index ["slug"], name: "index_calculators_on_slug", unique: true
end

Expand Down
1 change: 1 addition & 0 deletions spec/factories/calculators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: calculators
#
# id :bigint not null, primary key
# color :string default("#000000")
# en_name :string default(""), not null
# slug :string
# uk_name :string default(""), not null
Expand Down
1 change: 1 addition & 0 deletions spec/models/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: calculators
#
# id :bigint not null, primary key
# color :string default("#000000")
# en_name :string default(""), not null
# slug :string
# uk_name :string default(""), not null
Expand Down