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

Added notes to constructor #987

Open
wants to merge 7 commits into
base: calculators-constructor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ gem "rails_db", "~> 2.4"
gem "meta-tags"
gem "inline_svg"
gem "breadcrumbs_on_rails"
gem "tinymce-rails"
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ GEM
thor (1.3.2)
tilt (2.4.0)
timeout (0.4.1)
tinymce-rails (7.5.1)
railties (>= 3.1.1)
turbo-rails (2.0.11)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
Expand Down Expand Up @@ -710,6 +712,7 @@ DEPENDENCIES
standard (~> 1.0)
stimulus-rails
tailwindcss-rails (~> 2.0)
tinymce-rails
tzinfo-data
web-console (>= 4.1.0)
webdrivers (~> 5.3.1)
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/account/calculators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def collect_fields_for_kind(kind)

def calculator_params
params.require(:calculator).permit(
:id, :en_name, :uk_name,
:id, :en_name, :uk_name, :ukranian_additional_notes,
:english_additional_notes,
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
16 changes: 16 additions & 0 deletions app/javascript/controllers/tinymce_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['input']

connect() {
let config = Object.assign({ target: this.inputTarget }, TinyMCERails.configuration.default )
tinymce.init(config)

}

disconnect () {
tinymce.remove()
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

порівняй тут гарно код і винеси конфіги в getter, також юзай 2 пробіли, а не 4 і думаю можна без object assign, просто обʼєкт заюзати

2 changes: 2 additions & 0 deletions app/models/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ 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 :english_additional_notes, length: { maximum: 500 }
validates :ukranian_additional_notes, length: { maximum: 500 }
Copy link
Collaborator

Choose a reason for hiding this comment

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

ну диви, ти молодець, що додала валідацію, але тут не враховані теги, тобто я напишу одну букву, а довжина її буде 7 символів, бо буде огорнута в як мінімум тег p, отож потрібно дещо специфічну валіадацію зробити


def self.ransackable_attributes(auth_object = nil)
["created_at", "id", "name", "preferable", "slug", "updated_at", "uuid"]
Expand Down
2 changes: 2 additions & 0 deletions app/views/account/calculators/partials/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
</div>
</div>
</div>

<%= render "account/calculators/partials/tinymce_form", f: f %>

<div class="button-group d-flex">
<%= f.button :submit, t('account.calculators.new.create_calculator_button'), class: 'btn btn-green me-2 height-auto w-auto' %>
Expand Down
14 changes: 14 additions & 0 deletions app/views/account/calculators/partials/_tinymce_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= tinymce_assets %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%= tinymce_assets %>
<%= tinymce_assets %>

Copy link
Collaborator

Choose a reason for hiding this comment

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

align that all

<div data-controller="tinymce">
<div class="pt-4">
<%= f.label :ukranian_additional_notes, t("account.calculators.new.ukranian_additional_notes") %>
<%= f.text_area :ukranian_additional_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %>
</div>

<div class="pt-4 pb-4">
<%= f.label :english_additional_notes, "English Additional Notes" %>
Copy link
Contributor

Choose a reason for hiding this comment

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

то саме

Copy link
Collaborator

Choose a reason for hiding this comment

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

локалізація

<%= f.text_area :english_additional_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %>
</div>
</div>

<%= tinymce %>
2 changes: 2 additions & 0 deletions config/locales/en/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ en:
update_calculator_button: "Update calculator"
new:
create_calculator_button: "Create calculator"
ukranian_additional_notes: "Додаткові нотатки українською"
english_additional_notes: "Додаткові нотатки англійською"
feature_flags:
submit_button: "Save"
new_calculator_design:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/uk/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ uk:
prohibited_to_update: " перешкоджають оновленню калькулятора"
prohibited_to_save: " перешкоджають збереженню калькулятора"
error: "помилки"
ukranian_additional_notes: "Ukrainian Additional Notes"
english_additional_notes: "English Additional Notes"
site_settings:
edit:
meta-title: "Налаштування сайту"
Expand Down
8 changes: 8 additions & 0 deletions config/tinymce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
height: 300
width: 800
menubar: false
toolbar:
- undo redo | blocks | bold italic | alignleft aligncenter alignright | bullist numlist outdent indent | removeformat
plugins:
- insertdatetime lists media table code wordcount
license_key: 'gpl'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddLanguageNotesToCalculators < ActiveRecord::Migration[7.2]
def change
change_table :calculators, bulk: true do |t|
t.text :ukranian_additional_notes
t.text :english_additional_notes
end
end
end
4 changes: 3 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_07_140542) do
ActiveRecord::Schema[7.2].define(version: 2024_11_21_165300) 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,8 @@
t.string "slug"
t.string "uk_name", default: "", null: false
t.string "en_name", default: "", null: false
t.text "ukranian_additional_notes"
t.text "english_additional_notes"
t.index ["slug"], name: "index_calculators_on_slug", unique: true
end

Expand Down
2 changes: 2 additions & 0 deletions spec/models/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
it { is_expected.to validate_length_of(:uk_name).is_at_least(3).is_at_most(50) }
it { is_expected.to validate_presence_of(:slug) }
it { is_expected.to validate_uniqueness_of(:slug) }
it { is_expected.to validate_length_of(:english_additional_notes).is_at_most(500) }
it { is_expected.to validate_length_of(:ukranian_additional_notes).is_at_most(500) }
end

describe "associations" do
Expand Down
Loading