diff --git a/app/assets/stylesheets/components/admin-menu.css b/app/assets/stylesheets/components/admin-menu.css index 19c7a4ccd..e0beae534 100644 --- a/app/assets/stylesheets/components/admin-menu.css +++ b/app/assets/stylesheets/components/admin-menu.css @@ -4,7 +4,7 @@ } .admin-menu-burger-button { - @apply xl:hidden flex items-center text-success pt-7 pr-4 ml-auto + @apply xl:hidden flex items-center text-success pt-4 pr-8 ml-auto } .locale-button { @@ -12,7 +12,7 @@ } .admin-menu-list { - @apply flex flex-col xl:flex-row mt-8 xl:mx-2 space-y-6 xl:space-y-0 + @apply flex flex-col xl:flex-row items-center ml-auto } } diff --git a/app/assets/stylesheets/components/header.css b/app/assets/stylesheets/components/header.css index 709887732..cd77434fd 100644 --- a/app/assets/stylesheets/components/header.css +++ b/app/assets/stylesheets/components/header.css @@ -1,12 +1,16 @@ @layer components { .page-header { - @apply w-full xl:max-w-fit h-auto mx-auto mb-2.5 flex border-b-2 border-gray justify-center; + @apply w-full xl:max-w-fit mx-auto mb-4 flex border-b-2 border-gray justify-center; } .tab { @apply flex-row xl:flex whitespace-nowrap uppercase text-sm text-white border-b-2 border-transparent transition duration-500 ease-in-out hover:border-success py-6 px-4; } + .tab-main-page { + @apply flex-row xl:flex whitespace-nowrap uppercase text-sm text-white border-b-2 border-transparent transition duration-500 ease-in-out hover:border-success py-4 px-6; + } + .header-btns { @apply inline w-auto ml-2 min-w-fit; } diff --git a/app/controllers/account/categories_controller.rb b/app/controllers/account/categories_controller.rb index bd13c0bcc..7cbd6db84 100644 --- a/app/controllers/account/categories_controller.rb +++ b/app/controllers/account/categories_controller.rb @@ -4,8 +4,9 @@ class Account::CategoriesController < Account::BaseController load_and_authorize_resource def index - @q = collection.ransack(params[:q]) - @categories = @q.result.page(params[:page]) + @q = collection.ransack(params[:q]) + @categories = @q.result.page(params[:page]) + @search_attribute = :"#{I18n.locale}_name_cont" end def new @@ -56,6 +57,6 @@ def resource end def category_params - params.require(:category).permit(:name, :priority, :preferable) + params.require(:category).permit(:uk_name, :en_name, :priority, :preferable) end end diff --git a/app/models/category.rb b/app/models/category.rb index 4a8af8ca6..12fe85631 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -12,6 +12,9 @@ # preferable :boolean default: false # class Category < ApplicationRecord + include Translatable + translates :name + PRIORITY_RANGE = 0..10 enum preferable: { not_preferable: false, preferable: true } @@ -21,15 +24,15 @@ class Category < ApplicationRecord has_many :category_categoryables, dependent: :restrict_with_exception has_many :categoryables, through: :category_categoryables - validates :name, presence: true - validates :name, + validates :uk_name, :en_name, presence: true + validates :uk_name, :en_name, length: { minimum: 3, maximum: 30 }, format: { with: /\A[\p{L}0-9\s'-]+\z/i }, uniqueness: { case_sensitive: false }, allow_blank: true validates :priority, numericality: { greater_than_or_equal_to: 0 } - scope :ordered_by_name, -> { order(:name) } + scope :ordered_by_name, -> { order(:uk_name) } scope :ordered_by_priority, -> { order(:priority) } scope :unsigned_categories, ->(product) { where.not(id: product.categories_by_prices) } @@ -49,6 +52,6 @@ class Category < ApplicationRecord } def self.ransackable_attributes(auth_object = nil) - ["created_at", "id", "name", "priority", "updated_at"] + ["created_at", "id", "#{I18n.locale}_name", "priority", "updated_at"] end end diff --git a/app/models/concerns/translatable.rb b/app/models/concerns/translatable.rb new file mode 100644 index 000000000..126696b9c --- /dev/null +++ b/app/models/concerns/translatable.rb @@ -0,0 +1,26 @@ +module Translatable + extend ActiveSupport::Concern + + class_methods do + def translates(*attributes) + attributes.each do |attribute| + define_method(attribute) do + translation_for(attribute) + end + end + end + end + + private + + def translation_for(attribute) + locale_attr = "#{I18n.locale}_#{attribute}" + default_locale_attr = "#{I18n.default_locale}_#{attribute}" + + if respond_to?(locale_attr) + public_send(locale_attr) + elsif respond_to?(default_locale_attr) + public_send(default_locale_attr) + end + end +end diff --git a/app/models/product.rb b/app/models/product.rb index 590d71a7d..2967e8430 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -42,7 +42,7 @@ def price_by_category(category) end def find_or_build_price_for_category(category) - prices.find_by(category: category) || prices.build(category: category) + prices.find { |p| p.category_id == category.id } || prices.build(category: category) end def build_unsigned_categories diff --git a/app/views/account/categories/edit.html.erb b/app/views/account/categories/edit.html.erb index 5f5a3f0da..54d857a93 100644 --- a/app/views/account/categories/edit.html.erb +++ b/app/views/account/categories/edit.html.erb @@ -2,7 +2,8 @@ <%= simple_form_for @category, url: { action: "update" }, html: { novalidate: false } do |f| %>
- <%= f.input :name, class: "form-control col-sm-11", required: true %> + <%= f.input :uk_name, class: "form-control col-sm-11", required: true %> + <%= f.input :en_name, class: "form-control col-sm-11", required: true %> <%= f.input :priority, collection: Category::PRIORITY_RANGE, wrapper: :custom_vertical_select %> <% if @unfilled_categories&.exclude?(@category) %>
diff --git a/app/views/account/categories/index.html.erb b/app/views/account/categories/index.html.erb index 9742a90f5..e6dbaacf1 100644 --- a/app/views/account/categories/index.html.erb +++ b/app/views/account/categories/index.html.erb @@ -5,7 +5,7 @@ <%= render partial: "account/shared/search_form", locals: { q: @q, search_url: account_categories_path, - search_attribute: :name_cont + search_attribute: @search_attribute } %>
diff --git a/app/views/account/categories/new.html.erb b/app/views/account/categories/new.html.erb index f16c39b90..f9f6156d6 100644 --- a/app/views/account/categories/new.html.erb +++ b/app/views/account/categories/new.html.erb @@ -1,14 +1,15 @@ -<%= simple_form_for @category, url: { action: 'create' }, html: { novalidate: false } do |f| %> +<%= simple_form_for @category, url: { action: "create" }, html: { novalidate: false } do |f| %>
- <%= f.input :name, class: 'form-control col-sm-11' %> + <%= f.input :uk_name, class: "form-control col-sm-11" %> + <%= f.input :en_name, class: "form-control col-sm-11" %> <%= f.input :priority, collection: Category::PRIORITY_RANGE, wrapper: :custom_vertical_select %>
- <%= f.submit t('.form.create_category_button'), class: 'btn btn-green me-2' %> - <%= link_to account_categories_path, class: 'btn btn-danger d-flex align-items-center justify-content-center' do %> - <%= t('buttons.cancel') %> + <%= f.submit t(".form.create_category_button"), class: "btn btn-green me-2" %> + <%= link_to account_categories_path, class: "btn btn-danger d-flex align-items-center justify-content-center" do %> + <%= t("buttons.cancel") %> <% end %>
<% end %> diff --git a/app/views/account/shared/_navigation.html.erb b/app/views/account/shared/_navigation.html.erb index 1ae3e7583..2809b9431 100644 --- a/app/views/account/shared/_navigation.html.erb +++ b/app/views/account/shared/_navigation.html.erb @@ -2,48 +2,51 @@