diff --git a/Gemfile b/Gemfile index b485664a4..255b8954a 100644 --- a/Gemfile +++ b/Gemfile @@ -124,3 +124,4 @@ gem "rails_db", "~> 2.4" gem "meta-tags" gem "inline_svg" gem "breadcrumbs_on_rails" +gem "tinymce-rails" diff --git a/Gemfile.lock b/Gemfile.lock index 5627f30fb..41ca6bdea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) diff --git a/app/controllers/account/calculators_controller.rb b/app/controllers/account/calculators_controller.rb index c4d6bb1a5..afadcd9cf 100644 --- a/app/controllers/account/calculators_controller.rb +++ b/app/controllers/account/calculators_controller.rb @@ -81,7 +81,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]] diff --git a/app/javascript/controllers/tinymce_controller.js b/app/javascript/controllers/tinymce_controller.js new file mode 100644 index 000000000..7dfe9af84 --- /dev/null +++ b/app/javascript/controllers/tinymce_controller.js @@ -0,0 +1,20 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + static targets = ['input'] + + connect() { + tinymce.init(this.tinymceConfig) + } + + disconnect() { + tinymce.remove() + } + + get tinymceConfig() { + return { + target: this.inputTarget, + ...TinyMCERails.configuration.default + } + } +} diff --git a/app/models/calculator.rb b/app/models/calculator.rb index d6e72e586..50c3d2cfa 100644 --- a/app/models/calculator.rb +++ b/app/models/calculator.rb @@ -35,6 +35,17 @@ 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, + tokenizer: ->(string) { ActionController::Base.helpers.strip_tags(string).chars } + } + + validates :ukranian_additional_notes, + length: { + maximum: 500, + tokenizer: ->(string) { ActionController::Base.helpers.strip_tags(string).chars } + } def self.ransackable_attributes(auth_object = nil) ["created_at", "id", "name", "preferable", "slug", "updated_at", "uuid"] diff --git a/app/views/account/calculators/partials/_form.html.erb b/app/views/account/calculators/partials/_form.html.erb index 781d15c5d..1327f9ebe 100644 --- a/app/views/account/calculators/partials/_form.html.erb +++ b/app/views/account/calculators/partials/_form.html.erb @@ -25,6 +25,8 @@ + + <%= render "account/calculators/partials/tinymce_form", f: f %>
<%= f.button :submit, t('account.calculators.new.create_calculator_button'), class: 'btn btn-green me-2 height-auto w-auto' %> diff --git a/app/views/account/calculators/partials/_tinymce_form.html.erb b/app/views/account/calculators/partials/_tinymce_form.html.erb new file mode 100644 index 000000000..267124032 --- /dev/null +++ b/app/views/account/calculators/partials/_tinymce_form.html.erb @@ -0,0 +1,14 @@ + <%= tinymce_assets %> +
+
+ <%= 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 %> +
+ +
+ <%= f.label :english_additional_notes, t("account.calculators.new.english_additional_notes") %> + <%= f.text_area :english_additional_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %> +
+
+ + <%= tinymce %> diff --git a/app/views/calculators/partials/show/_constructor_calculator_description.erb b/app/views/calculators/partials/show/_constructor_calculator_description.erb index fed35215a..a289c57c4 100644 --- a/app/views/calculators/partials/show/_constructor_calculator_description.erb +++ b/app/views/calculators/partials/show/_constructor_calculator_description.erb @@ -1,8 +1,11 @@ -<%# TODO: Delete this if %> -<% if false %> +<% if calculator.ukranian_additional_notes.present? || calculator.english_additional_notes.present? %>
-
- <%# TODO: ADD text here %> +
+ <% if I18n.locale == :uk %> + <%= raw calculator.ukranian_additional_notes %> + <% else %> + <%= raw calculator.english_additional_notes %> + <% end %>
<% end %> diff --git a/app/views/calculators/show.html.erb b/app/views/calculators/show.html.erb index 82295fe22..bee96bfc0 100644 --- a/app/views/calculators/show.html.erb +++ b/app/views/calculators/show.html.erb @@ -37,4 +37,4 @@ <%= turbo_frame_tag "calc-results" %>
-<%= render "calculators/partials/show/constructor_calculator_description" %> +<%= render "calculators/partials/show/constructor_calculator_description", calculator: @calculator %> diff --git a/config/locales/en/en.yml b/config/locales/en/en.yml index 1ccf13530..6c1bcbdc3 100644 --- a/config/locales/en/en.yml +++ b/config/locales/en/en.yml @@ -474,6 +474,8 @@ en: update_calculator_button: "Update calculator" new: create_calculator_button: "Create calculator" + ukranian_additional_notes: "Ukrainian Additional Notes" + english_additional_notes: "English Additional Notes" feature_flags: submit_button: "Save" new_calculator_design: diff --git a/config/locales/uk/uk.yml b/config/locales/uk/uk.yml index 06f683b9e..50a45b600 100644 --- a/config/locales/uk/uk.yml +++ b/config/locales/uk/uk.yml @@ -361,6 +361,8 @@ uk: prohibited_to_update: " перешкоджають оновленню калькулятора" prohibited_to_save: " перешкоджають збереженню калькулятора" error: "помилки" + ukranian_additional_notes: "Додаткові нотатки українською" + english_additional_notes: "Додаткові нотатки англійською" site_settings: edit: meta-title: "Налаштування сайту" diff --git a/config/tinymce.yml b/config/tinymce.yml new file mode 100644 index 000000000..182c17965 --- /dev/null +++ b/config/tinymce.yml @@ -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' diff --git a/db/migrate/20241121165300_add_language_notes_to_calculators.rb b/db/migrate/20241121165300_add_language_notes_to_calculators.rb new file mode 100644 index 000000000..3ad19e5f8 --- /dev/null +++ b/db/migrate/20241121165300_add_language_notes_to_calculators.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index e9e42b813..cc0ed65b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_11_21_165300) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -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 diff --git a/spec/models/calculator_spec.rb b/spec/models/calculator_spec.rb index 6be5b5005..734927bb5 100644 --- a/spec/models/calculator_spec.rb +++ b/spec/models/calculator_spec.rb @@ -28,6 +28,8 @@ it { is_expected.to validate_presence_of(:uk_name) } it { is_expected.to validate_length_of(:uk_name).is_at_least(3).is_at_most(50) } 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