-
Notifications
You must be signed in to change notification settings - Fork 11
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
Show calculator #946
Show calculator #946
Changes from 8 commits
5f32ef7
23737db
d834981
1ee7b9b
388b39d
5eb6205
a37b9c8
e5ac62e
8698894
46accf2
192d2cc
500bacc
fca1ba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
def show | ||
@calculator = resource | ||
@result = params[:result] | ||
end | ||
|
||
def calculate | ||
|
@@ -45,6 +46,6 @@ | |
end | ||
|
||
def resource | ||
collection.friendly.find(params[:slug]) | ||
collection.find(params[:slug]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а чому шукає слаг, але скоуп френдлі видаляється? |
||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,9 +29,9 @@ | |||||
</thead> | ||||||
<tbody class="admin-table-links"> | ||||||
<% @calculators.each do |calculator| %> | ||||||
<tr class="<%= calculator.preferable? ? "table-success" : "text-inherit" %>"> | ||||||
<tr > | ||||||
<td><%= calculator.id %></td> | ||||||
<td><%= calculator.name %></td> | ||||||
<td><%= calculator.en_name %></td> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<td><%= calculator.slug %></td> | ||||||
<td class="text-center"><%= link_to icon('fa-solid', 'eye'), account_calculator_path(slug: calculator) %></td> | ||||||
<td class="text-center"><%= link_to icon('fa-solid', 'edit'), edit_account_calculator_path(slug: calculator) %></td> | ||||||
|
loqimean marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||
<div class="container place-items-center"> | ||||||||
<h1 class="text-4xl font-bold">Calculator <%= @calculator.en_name %></h1><br> | ||||||||
|
||||||||
<%= form_with url: calculate_account_calculator_path(slug: @calculator.slug || @calculator.id) do |form| %> | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
<% @calculator.fields.each do |field| %> | ||||||||
<div class="space-y-4 form-inputs"> | ||||||||
<h1><%= form.label field.var_name, field.en_label %></h1> | ||||||||
<% if field.field_type == 'number' %> | ||||||||
<%= form.number_field "inputs[#{field.var_name}]", placeholder: field.en_label %> | ||||||||
<% else %> | ||||||||
<%= form.select "inputs[#{field.var_name}]", options_from_collection_for_select(field.categories, :price, :en_name) %> | ||||||||
<% end %> | ||||||||
</div><br> | ||||||||
<% end %> | ||||||||
<div class="mt-6 form-actions"> | ||||||||
<%= form.submit "Calculate", class: "bg-blue-500 text-white font-semibold px-4 py-2 rounded hover:bg-blue-700" %> | ||||||||
</div> | ||||||||
<% end %> | ||||||||
|
||||||||
<% if @result.present? %> | ||||||||
<p>Result: <%= @result %></p> | ||||||||
<% end %> | ||||||||
</div> |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class UpdateCalculators < ActiveRecord::Migration[7.2] | ||
def up | ||
change_table :calculators, bulk: true do |t| | ||
t.remove :uuid, :name, :preferable | ||
t.string :uk_name, null: false, default: "" | ||
t.string :en_name, null: false, default: "" | ||
end | ||
end | ||
|
||
def down | ||
change_table :calculators, bulk: true do |t| | ||
t.string :uuid | ||
t.string :name | ||
t.boolean :preferable, null: false, default: false | ||
|
||
t.remove :uk_name | ||
t.remove :en_name | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
class ChangeFields < ActiveRecord::Migration[7.2] | ||
def change | ||
remove_columns :fields, :uuid, :selector, :type, :label, :name, :value, :from, :to, :kind, :unit | ||
def up | ||
change_table :fields, bulk: true do |t| | ||
t.remove :uuid, type: :string | ||
t.remove :selector, type: :string | ||
t.remove :type, type: :string | ||
t.remove :label, type: :string | ||
t.remove :name, type: :string | ||
t.remove :value, type: :string | ||
t.remove :from, type: :integer | ||
t.remove :to, type: :integer | ||
t.remove :kind, type: :string | ||
t.remove :unit, type: :string | ||
t.remove :calculator_id, type: :integer | ||
|
||
add_column :fields, :uk_label, :string, null: false | ||
add_column :fields, :en_label, :string, null: false | ||
add_column :fields, :var_name, :string, null: false | ||
add_column :fields, :field_type, :string, null: false | ||
t.string :uk_name, null: false, default: "" | ||
t.string :en_name, null: false, default: "" | ||
t.string :var_name, null: false, default: "" | ||
t.string :field_type, null: false, default: "" | ||
|
||
t.references :calculator, foreign_key: true, null: false, default: 0 | ||
end | ||
|
||
change_column_default :fields, :calculator_id, from: 0, to: nil | ||
end | ||
|
||
def down | ||
change_table :fields, bulk: true do |t| | ||
t.string :uuid | ||
t.string :selector | ||
t.string :type | ||
t.string :label | ||
t.string :name | ||
t.string :value | ||
t.integer :from | ||
t.integer :to | ||
t.string :kind | ||
t.string :unit | ||
t.integer :calculator_id | ||
|
||
t.remove :uk_name | ||
t.remove :en_name | ||
t.remove :var_name | ||
t.remove :field_type | ||
|
||
t.remove_references :calculator, foreign_key: true | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,23 @@ | ||
class ChangeCategories < ActiveRecord::Migration[7.2] | ||
def change | ||
remove_columns :categories, :priority, :preferable | ||
add_column :categories, :price, :float, null: false | ||
def up | ||
change_table :categories, bulk: true do |t| | ||
t.remove :preferable, type: :boolean | ||
|
||
add_reference :categories, :field, null: false, foreign_key: true | ||
t.float :price, null: false, default: 0.0 | ||
|
||
t.references :field, null: false, foreign_key: true, default: 0 | ||
|
||
t.boolean :preferable, null: false, default: false | ||
end | ||
|
||
change_column_default :categories, :field_id, nil | ||
end | ||
|
||
def down | ||
change_table :categories, bulk: true do |t| | ||
t.remove :preferable, type: :boolean | ||
|
||
t.remove :pricet.remove_references :field, foreign_key: true | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тестів нема + юзай ресурс
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не дуже розумію, що це за результат з парамсів?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SEO-friendly урла залишена з попердньої реалізації.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
що це ще таке?? ну Наталя, як ми юзаємо ресурс?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я і не казав забирати слаг