From 8d3ead5e4958b4d7c3bb3cb579ccdfc62a5abc18 Mon Sep 17 00:00:00 2001 From: alexy78 Date: Thu, 28 Nov 2024 16:43:22 +0200 Subject: [PATCH] Added notes to constructor --- Gemfile | 1 + Gemfile.lock | 3 +++ .../account/calculators_controller.rb | 3 ++- app/javascript/controllers/tinymce_controller.js | 16 ++++++++++++++++ app/models/calculator.rb | 2 ++ .../account/calculators/partials/_form.html.erb | 2 ++ .../calculators/partials/_tinymce_form.html.erb | 14 ++++++++++++++ config/tinymce.yml | 8 ++++++++ ...21165300_add_language_notes_to_calculators.rb | 8 ++++++++ db/schema.rb | 4 +++- spec/models/calculator_spec.rb | 2 ++ 11 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 app/javascript/controllers/tinymce_controller.js create mode 100644 app/views/account/calculators/partials/_tinymce_form.html.erb create mode 100644 config/tinymce.yml create mode 100644 db/migrate/20241121165300_add_language_notes_to_calculators.rb 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 dec87775d..f0f918ecd 100644 --- a/app/controllers/account/calculators_controller.rb +++ b/app/controllers/account/calculators_controller.rb @@ -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]] diff --git a/app/javascript/controllers/tinymce_controller.js b/app/javascript/controllers/tinymce_controller.js new file mode 100644 index 000000000..30c7ef112 --- /dev/null +++ b/app/javascript/controllers/tinymce_controller.js @@ -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() + } + } + diff --git a/app/models/calculator.rb b/app/models/calculator.rb index 05d304683..6c61cff4c 100644 --- a/app/models/calculator.rb +++ b/app/models/calculator.rb @@ -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: 150 } + validates :ukranian_additional_notes, length: { maximum: 150 } 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..a20a54886 --- /dev/null +++ b/app/views/account/calculators/partials/_tinymce_form.html.erb @@ -0,0 +1,14 @@ + <%= tinymce_assets %> +
+
+ <%= f.label :ukranian_additional_notes, "Ukrainian Additional Notes" %> + <%= f.text_area :ukranian_additional_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %> +
+ +
+ <%= f.label :english_additional_notes, "English Additional Notes" %> + <%= f.text_area :english_additional_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %> +
+
+ + <%= tinymce %> \ No newline at end of file diff --git a/config/tinymce.yml b/config/tinymce.yml new file mode 100644 index 000000000..f5e83a25e --- /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' \ No newline at end of file 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 d530131b1..55b557872 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_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" @@ -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 2a4940887..9bf69de8e 100644 --- a/spec/models/calculator_spec.rb +++ b/spec/models/calculator_spec.rb @@ -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(150) } + it { is_expected.to validate_length_of(:ukranian_additional_notes).is_at_most(150) } end describe "associations" do