Skip to content

Commit

Permalink
Added notes to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexy78 committed Nov 28, 2024
1 parent b1bb9aa commit 8d3ead5
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 2 deletions.
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()
}
}

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: 150 }
validates :ukranian_additional_notes, length: { maximum: 150 }

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 %>
<div data-controller="tinymce">
<div class="pt-4">
<%= f.label :ukranian_additional_notes, "Ukrainian 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" %>
<%= f.text_area :english_additional_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %>
</div>
</div>

<%= tinymce %>
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(150) }
it { is_expected.to validate_length_of(:ukranian_additional_notes).is_at_most(150) }
end

describe "associations" do
Expand Down

0 comments on commit 8d3ead5

Please sign in to comment.