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 all 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 @@ -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]]
Expand Down
20 changes: 20 additions & 0 deletions app/javascript/controllers/tinymce_controller.js
Original file line number Diff line number Diff line change
@@ -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
}
}
}
11 changes: 11 additions & 0 deletions app/models/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
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 }

Check warning on line 41 in app/models/calculator.rb

View check run for this annotation

Codecov / codecov/patch

app/models/calculator.rb#L41

Added line #L41 was not covered by tests
}

validates :ukranian_additional_notes,
length: {
maximum: 500,
tokenizer: ->(string) { ActionController::Base.helpers.strip_tags(string).chars }

Check warning on line 47 in app/models/calculator.rb

View check run for this annotation

Codecov / codecov/patch

app/models/calculator.rb#L47

Added line #L47 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

use method to do that and test it

}

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, t("account.calculators.new.english_additional_notes") %>
<%= f.text_area :english_additional_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %>
</div>
</div>

<%= tinymce %>
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<%# TODO: Delete this if %>
<% if false %>
<% if calculator.ukranian_additional_notes.present? || calculator.english_additional_notes.present? %>
<section class="description-section">
<div class="description-block">
<%# TODO: ADD text here %>
<div class="description-section">
<% if I18n.locale == :uk %>
<%= raw calculator.ukranian_additional_notes %>
<% else %>
<%= raw calculator.english_additional_notes %>
<% end %>
</div>
Comment on lines +4 to +8
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
<% if I18n.locale == :uk %>
<%= raw calculator.ukranian_additional_notes %>
<% else %>
<%= raw calculator.english_additional_notes %>
<% end %>
<%== calculator.notes %>

then you have:
uk_notes
en_notes
and Translatable concern in a model

</section>
<% end %>
2 changes: 1 addition & 1 deletion app/views/calculators/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
<%= turbo_frame_tag "calc-results" %>
</div>

<%= render "calculators/partials/show/constructor_calculator_description" %>
<%= render "calculators/partials/show/constructor_calculator_description", calculator: @calculator %>
2 changes: 2 additions & 0 deletions config/locales/en/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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 @@ -361,6 +361,8 @@ uk:
prohibited_to_update: " перешкоджають оновленню калькулятора"
prohibited_to_save: " перешкоджають збереженню калькулятора"
error: "помилки"
ukranian_additional_notes: "Додаткові нотатки українською"
english_additional_notes: "Додаткові нотатки англійською"
Copy link
Collaborator

Choose a reason for hiding this comment

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

у нас же нема основних нотаток)

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_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"
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 @@ -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
Expand Down