Skip to content

Commit

Permalink
Add i18n to quick links, remove old implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Novruu committed Nov 16, 2024
1 parent 2b7c9b0 commit 749141b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
8 changes: 5 additions & 3 deletions app/controllers/admin/divisions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Admin::DivisionsController < Admin::AdminController
include TranslationSaveable
before_action :find_division, only: %i[show update destroy]

def select
Expand Down Expand Up @@ -77,8 +78,8 @@ def update
@division.update(division_params)
@division.qb_department = ::Accounting::QB::Department.find(qb_department_id) if qb_department_id.present?
if @division.save
if division_params[:quick_links].present?
redirect_to "/admin/dashboard_beta"
if (translation_params(:quick_links) & division_params.keys.map(&:to_sym)).any?
redirect_to request.referrer, notice: I18n.t(:notice_updated)
else
redirect_to admin_division_path(@division), notice: I18n.t(:notice_updated)
end
Expand All @@ -104,7 +105,8 @@ def destroy
def prep_division_params(action)
permitted = [:name, :description, :logo, :logo_text, :membership_status, :short_name, :homepage, :logo_cache,
:default_currency_id, :qb_department_id, :public, :banner_fg_color, :banner_bg_color,
:accent_main_color, :accent_fg_color, :public_primary_color, :public_secondary_color, :public_accent_color, :notify_on_new_logs, :quick_links, locales: []]
:accent_main_color, :accent_fg_color, :public_primary_color, :public_secondary_color,
:public_accent_color, :notify_on_new_logs, locales: []] + translation_params(:quick_links)
permitted << :parent_id if action == :create
params.require(:division).permit(permitted)
end
Expand Down
43 changes: 43 additions & 0 deletions app/helpers/translations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,48 @@ def translatable_inputs(&block)

out
end

def translatable_inputs_locale(&block)
object_name = object.model_name.singular

# This css variable is a nasty workarond
css = %Q{
<style>
.quick-notes.show-view .language-block,
.quick-notes.show-view .language-block legend {
display: none;
}
}.html_safe

out = %Q{
<div class="languages" data-content-translatable="#{object_name}">
<input class="deleted-locales" name="#{object_name}[deleted_locales][]" type="hidden" />
}.html_safe
# TODO: Fix this to only show defined locales again
I18n.available_locales.each do |l|
# .row is added to language-block to address styling problems
out += %Q{
<div class="language-block row" data-locale="#{l}">
<fieldset>
<legend>#{name_for_locale(l)}</legend>
}.html_safe

out += template.capture { yield l }

out += "</fieldset></div>".html_safe

css += %Q{
html[lang*="#{l}"] .quick-notes.show-view .language-block[data-locale="#{l}"] {
display: block;
border: none;
padding: 0;
}
}.html_safe
end

css += "</style>".html_safe
out += "</div>#{css}".html_safe
out
end
end
end
3 changes: 3 additions & 0 deletions app/models/division.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Division < ApplicationRecord
include DivisionBased
include Translatable

MEMBERSHIP_STATUS_OPTIONS = %w(ally apprentice lending full).freeze

Expand Down Expand Up @@ -55,6 +56,8 @@ class Division < ApplicationRecord
delegate :connected?, to: :qb_connection, prefix: :quickbooks, allow_nil: true
delegate :company_name, to: :qb_connection, prefix: :quickbooks, allow_nil: true

translates :quick_links

attr_accessor :qb_department_id # allows this field in simple_form

def self.root_id
Expand Down
12 changes: 8 additions & 4 deletions app/views/admin/dashboard_beta/_quicklinks_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
- popover_options = {placement: 'left'}

= error_notification(f)


= f.input :quick_links, label: false, hint: false, as: :summernote
.view-element = sanitize(@division.quick_links)
= f.input_field :quick_links, label: false, hint: false, as: :summernote

= f.translatable_inputs_locale do |l|
= f.input :"quick_links_#{l}", label: false
.view-element = sanitize @division.send("quick_links_#{l}").to_s
= f.input_field :"quick_links_#{l}",
as: :summernote,
input_html: {rows: 3},
label: false

.actions.form-element
= f.button :submit, t('update'), class: 'update-action btn btn-primary'
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20241105192112_add_quicklinks_to_divisions.rb

This file was deleted.

3 changes: 1 addition & 2 deletions 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.define(version: 2024_11_05_192112) do
ActiveRecord::Schema.define(version: 2024_05_20_210320) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -208,7 +208,6 @@
t.string "public_secondary_color"
t.string "qb_parent_class_id"
t.boolean "qb_read_only", default: true, null: false
t.string "quick_links"
t.string "short_name"
t.datetime "updated_at", null: false
t.index ["currency_id"], name: "index_divisions_on_currency_id"
Expand Down

0 comments on commit 749141b

Please sign in to comment.