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 25 commits into
base: calculators-constructor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8d3ead5
Added notes to constructor
alexy78 Nov 28, 2024
c7f5226
Added spaces
alexy78 Nov 28, 2024
8fde9ed
Fixed some comments
alexy78 Nov 28, 2024
5bf308a
updated test
alexy78 Nov 29, 2024
8235899
Resolved merge conflicts
alexy78 Dec 1, 2024
f53c539
updated partial for showpage and changed validations
alexy78 Dec 2, 2024
953013a
Added space to controller
alexy78 Dec 2, 2024
bb1bfe5
notes translateble+tests
DanielVajnagi Dec 26, 2024
1f0d03a
cop
DanielVajnagi Dec 26, 2024
cf8bd38
Merge branch 'calculators-constructor' into 950-additional-notes
DanielVajnagi Dec 26, 2024
1511258
cop
DanielVajnagi Dec 26, 2024
c0fc923
Update spec/models/calculator_spec.rb
DanielVajnagi Jan 2, 2025
c63e201
xss
DanielVajnagi Jan 14, 2025
3b01ccb
Merge branch '950-additional-notes' of https://github.com/ita-social-…
DanielVajnagi Jan 14, 2025
0a60823
fix
DanielVajnagi Jan 14, 2025
bf3d5f6
moved to helper
DanielVajnagi Jan 15, 2025
371b7d0
fix
DanielVajnagi Jan 15, 2025
ac76ba2
Sanitize helper tests
DanielVajnagi Jan 18, 2025
dd9271c
rubocop fixes
DanielVajnagi Jan 18, 2025
58f96aa
Merge branch 'calculators-constructor' into 950-additional-notes
DanielVajnagi Jan 18, 2025
477d2b2
remove instance variable in tests
DanielVajnagi Jan 20, 2025
8c7b500
Update calculators_helper_spec.rb
DanielVajnagi Jan 20, 2025
317d9b3
moved tinymce form on top of the page, to the calculators info container
DanielVajnagi Jan 20, 2025
2513033
rails_helper missing fix
DanielVajnagi Jan 20, 2025
1180df7
rubocop fix
DanielVajnagi Jan 20, 2025
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, :color,
:id, :en_name, :uk_name, :uk_notes,
:en_notes, :color,
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: 10 additions & 1 deletion app/models/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Calculator < ApplicationRecord

friendly_id :en_name, use: :sequentially_slugged

translates :name
translates :name, :notes

has_many :fields, dependent: :destroy
has_many :formulas, dependent: :destroy
Expand All @@ -36,9 +36,18 @@ 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 :en_notes, :uk_notes,
length: {
maximum: 500,
tokenizer: :strip_tags_and_tokenize
}
validates :color, format: { with: /\A#[0-9a-fA-F]{6}\z/ }

def self.ransackable_attributes(auth_object = nil)
["created_at", "id", "name", "preferable", "slug", "updated_at", "uuid"]
end

def strip_tags_and_tokenize(string)
ActionController::Base.helpers.strip_tags(string).chars
end
end
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 @@ -37,6 +37,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 :uk_notes, t("account.calculators.new.uk_notes") %>
<%= f.text_area :uk_notes, data: { tinymce_target: "input" }, class: "tinymce", rows: 20, cols: 60 %>
</div>

<div class="pt-4 pb-4">
<%= f.label :en_notes, t("account.calculators.new.en_notes") %>
<%= f.text_area :en_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,7 @@
<%# TODO: Delete this if %>
<% if false %>
<% if calculator.uk_notes.present? || calculator.en_notes.present? %>
<section class="description-section">
<div class="description-block">
<%# TODO: ADD text here %>
<div class="description-section">
<%= sanitize(calculator.notes, tags: %w[p strong em ul li a div span img], attributes: %w[href target class src alt style]) %>
</div>
Copy link
Collaborator

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.

і не юзай цей %, то зло

</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 @@ -38,4 +38,4 @@
<% end %>
</div>

<%= render "calculators/partials/show/constructor_calculator_description" %>
<%= render "calculators/partials/show/constructor_calculator_description", calculator: @calculator %>
10 changes: 6 additions & 4 deletions config/locales/en/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ en:
use_less_link: https://zerowastelviv.org.ua/en/zero-waste-nappies-en/
mhc_description_block:
mhc_description_block_html:
"These data are approximate, and exact values may vary depending on your individual needs and habits.
"These data are approximate, and exact values may vary depending on your individual needs and habits.
Using reusable menstrual products can significantly reduce waste and serve as a cost-effective alternative to disposable options.
You can optimize the use of these products at any stage, which will help lower expenses and increase comfort.
We recommend exploring methods for the effective use of reusable menstrual products and learning about their benefits.
More %{information_link} about the calculations regarding the quantity and cost of these products can be found in our materials
You can optimize the use of these products at any stage, which will help lower expenses and increase comfort.
We recommend exploring methods for the effective use of reusable menstrual products and learning about their benefits.
More %{information_link} about the calculations regarding the quantity and cost of these products can be found in our materials
or by %{contact_link} with your questions."
information_link_text: "detailed information"
contact_link_text: "contacting us"
Expand Down Expand Up @@ -473,6 +473,8 @@ en:
no_fields_yet_label: "No fields yet"
update_calculator_button: "Update calculator"
new:
uk_notes: "Ukrainian Notes"
en_notes: "English Notes"
create_calculator_button: "Save calculator"
feature_flags:
submit_button: "Save"
Expand Down
12 changes: 7 additions & 5 deletions config/locales/uk/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ uk:
use_less_link: "https://zerowastelviv.org.ua/zero-waste-nappies/"
mhc_description_block:
mhc_description_block_html:
"Ці дані є орієнтовними, і точні значення можуть варіюватися залежно від ваших індивідуальних потреб та звичок.
Використання багаторазових менструальних засобів може значно зменшити кількість відходів і стати економічно
вигідною альтернативою одноразовим продуктам. Ви можете оптимізувати використання цих засобів на будь-якому етапі,
що дозволить знизити витрати та підвищити комфорт. Ми рекомендуємо ознайомитися з методами ефективного використання
багаторазових менструальних продуктів та їх перевагами. Більш %{information_link} про розрахунки кількості та вартості
"Ці дані є орієнтовними, і точні значення можуть варіюватися залежно від ваших індивідуальних потреб та звичок.
Використання багаторазових менструальних засобів може значно зменшити кількість відходів і стати економічно
вигідною альтернативою одноразовим продуктам. Ви можете оптимізувати використання цих засобів на будь-якому етапі,
що дозволить знизити витрати та підвищити комфорт. Ми рекомендуємо ознайомитися з методами ефективного використання
багаторазових менструальних продуктів та їх перевагами. Більш %{information_link} про розрахунки кількості та вартості
цих продуктів можна знайти в наших матеріалах або звернувшись %{contact_link} з вашими питаннями."
information_link_text: "детальну інформацію"
contact_link_text: "до нас"
Expand Down Expand Up @@ -361,6 +361,8 @@ uk:
prohibited_to_update: " перешкоджають оновленню калькулятора"
prohibited_to_save: " перешкоджають збереженню калькулятора"
error: "помилки"
uk_notes: "Нотатки українською"
en_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 :uk_notes
t.text :en_notes
end
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
t.string "uk_name", default: "", null: false
t.string "en_name", default: "", null: false
t.string "color", default: "#8fba3b"
t.text "uk_notes"
t.text "en_notes"
t.index ["slug"], name: "index_calculators_on_slug", unique: true
end

Expand Down
14 changes: 14 additions & 0 deletions spec/models/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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(:en_notes).is_at_most(500) }
it { is_expected.to validate_length_of(:uk_notes).is_at_most(500) }
it { is_expected.to allow_value("#123abc").for(:color) }
it { is_expected.to allow_value("#ABCDEF").for(:color) }
it { is_expected.not_to allow_value("123abc").for(:color) }
Expand All @@ -41,4 +43,16 @@
it { is_expected.to have_many(:fields).dependent(:destroy) }
it { is_expected.to have_many(:formulas).dependent(:destroy) }
end

describe "#strip_tags_and_tokenize" do
let(:stripped_content) { Calculator.new.strip_tags_and_tokenize(content) }

context "when contents is simple" do
let(:content) { "<p>#{"a" * 500}</p>" }

it "ensures the stripped content length is correct" do
expect(stripped_content.length).to eq(500)
end
end
end
end
Loading