Halfway through table redesign, saving to revert to working version

This commit is contained in:
Jason Jordan
2026-03-05 11:30:24 -05:00
parent ea07afb751
commit b5a1517330
86 changed files with 1286 additions and 884 deletions
-10
View File
@@ -1,10 +0,0 @@
class CardException < ApplicationRecord
belongs_to :employer
has_many :card_exception_items
accepts_nested_attributes_for :card_exception_items, allow_destroy: true, reject_if: :all_blank
VALID_TYPES = ['zipcode', 'state', 'family_id']
validates :type, inclusion: { in: VALID_TYPES,
message: "%{value} is not a valid exception type" }
end
-3
View File
@@ -1,3 +0,0 @@
class CardProvider < ApplicationRecord
has_many :employers
end
-3
View File
@@ -1,3 +0,0 @@
class CardRx < ApplicationRecord
has_many :employers
end
+27 -75
View File
@@ -1,29 +1,6 @@
class Employer < ApplicationRecord
has_many :members
has_many :plans, dependent: :destroy
accepts_nested_attributes_for :plans, allow_destroy: true, reject_if: :all_blank
has_many :alternate_network_logos, dependent: :destroy
accepts_nested_attributes_for :alternate_network_logos, allow_destroy: true, reject_if: :all_blank
has_many :employer_card_logos, dependent: :destroy
accepts_nested_attributes_for :employer_card_logos
has_many :card_logo_files, through: :employer_card_logos
has_one :employer_brand_logo, -> { where(logo_type: 'employer') },
class_name: 'EmployerCardLogo',
dependent: :destroy
has_one :employer_logo, through: :employer_brand_logo, source: :card_logo_file
has_many :network_images, -> { where(logo_type: 'network') },
class_name: 'EmployerCardLogo',
dependent: :destroy
has_many :network_logos, through: :network_images, source: :card_logo_file
belongs_to :card_provider, optional: true
belongs_to :card_rx, optional: true
has_many :card_exceptions, dependent: :destroy
accepts_nested_attributes_for :card_exceptions, allow_destroy: true, reject_if: :all_blank
has_one :id_card_setup, class_name: 'IdCard::Setup'
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
@@ -33,37 +10,37 @@ class Employer < ApplicationRecord
# before_save :process_employer_logo
# before_save :process_employer_logo, if: :employer_logo_filename_changed?
before_save :create_slug, if: :new_record?
after_save :process_employer_logo, if: :saved_change_to_employer_logo_filename?
# after_save :process_employer_logo, if: :saved_change_to_employer_logo_filename?
def process_employer_logo
# if self.employer_logo.present? && !self.employer_logo.is_a?(String)
# self.card_logo_files.new(
# filename: self.employer_logo.filename,
# logo_type: 'employer',
# image: self.employer_logo.data,
# pl_plan_key: self.pl_plan_key || ""
# )
# end
if self.employer_logo_filename.present? && self.employer_logo_filename.is_a?(String)
image_file = CardLogoFile.find_by(filename: self.employer_logo_filename)
if image_file.present?
if self.employer_brand_logo.present?
self.employer_brand_logo.update(card_logo_file: image_file)
else
self.create_employer_brand_logo(card_logo_file: image_file, logo_type: 'employer')
end
end
# def process_employer_logo
# # if self.employer_logo.present? && !self.employer_logo.is_a?(String)
# # self.card_logo_files.new(
# # filename: self.employer_logo.filename,
# # logo_type: 'employer',
# # image: self.employer_logo.data,
# # pl_plan_key: self.pl_plan_key || ""
# # )
# # end
# if self.employer_logo_filename.present? && self.employer_logo_filename.is_a?(String)
# image_file = CardLogoFile.find_by(filename: self.employer_logo_filename)
# if image_file.present?
# if self.employer_brand_logo.present?
# self.employer_brand_logo.update(card_logo_file: image_file)
# else
# self.create_employer_brand_logo(card_logo_file: image_file, logo_type: 'employer')
# end
# end
end
end
# end
# end
def create_slug
self.slug = employer_trim_name(self.name).parameterize
end
def name_to_logo_filename(extension)
self.employer_trim_name(self.name).titleize.gsub(/\s+/, '').concat('Logo').concat(extension.downcase)
end
# def name_to_logo_filename(extension)
# self.employer_trim_name(self.name).titleize.gsub(/\s+/, '').concat('Logo').concat(extension.downcase)
# end
def employer_trim_name(name)
regex_source = Regexp.union(["health", "plan", "the", "inc", "llc"]).source
@@ -74,35 +51,10 @@ class Employer < ApplicationRecord
def self.permitted_params(params)
params.require(:employer).permit(
:name,
:slug,
:group_number,
:pl_plan_key,
:effective_date,
:employer_logo_filename,
:network_provider,
:default_network_logo,
:single_card_template,
:card_provider_id,
:card_rx_id,
plans_attributes: [
:id,
:title,
:pb_product_key,
:_destroy,
plan_benefits_attributes: [
:id,
:benefit_desc,
:benefit,
:sequence,
:_destroy,
]
],
alternate_network_logos_attributes: [
:id,
:network_logo,
:exception_type,
:exception_value,
:_destroy
]
:effective_date
)
end
+5
View File
@@ -0,0 +1,5 @@
module IdCard
def self.table_name_prefix
"id_card_"
end
end
+14
View File
@@ -0,0 +1,14 @@
class IdCard::EmployerLogo < ApplicationRecord
before_save :calculate_aspect_ratio, if: :image_data_changed?
private
def calculate_aspect_ratio
image_io = StringIO.new(self.image_data)
width, height = FastImage.size(image_io)
image_ratio = width.to_f / height
if image_ratio
self.aspect_ratio = image_ratio.round(2)
end
end
end
+10
View File
@@ -0,0 +1,10 @@
class IdCard::Exception < ApplicationRecord
belongs_to :id_card_setup
has_many :id_card_exception_items
accepts_nested_attributes_for :id_card_exception_items, allow_destroy: true, reject_if: :all_blank
VALID_TYPES = ['zipcode', 'state', 'family_id']
validates :type, inclusion: { in: VALID_TYPES,
message: "%{value} is not a valid exception type" }
end
@@ -1,7 +1,7 @@
class CardExceptionItem < ApplicationRecord
belongs_to :card_exception
belongs_to :card_logo_file, optional: true
belongs_to :card_provider, optional: true
class IdCard::ExceptionItem < ApplicationRecord
belongs_to :id_card_exception
belongs_to :id_card_network_logo, optional: true
belongs_to :id_card_provider_section, optional: true
validate :only_one_exception_field_present
+11
View File
@@ -0,0 +1,11 @@
class IdCard::NetworkLogo < ApplicationRecord
before_save :round_aspect_ratio
private
def round_aspect_ratio
if self.aspect_ratio.present?
self.aspect_ratio = self.aspect_ratio.round(2)
end
end
end
+33
View File
@@ -0,0 +1,33 @@
class IdCard::Plan < ApplicationRecord
belongs_to :id_card_setup
has_many :id_card_plan_benefits, dependent: :destroy
accepts_nested_attributes_for :id_card_plan_benefits, allow_destroy: true, reject_if: :all_blank
# after_initialize :create_default_benefits, if: :new_record?
def self.permitted_params(params)
params.require(:id_card_plan).permit(
:title,
:pb_product_key,
:pl_plan_key,
:_destroy,
id_card_plan_benefits_attributes: [
:id,
:benefit_desc,
:benefit,
:sequence,
:_destroy,
]
)
end
private
def build_and_create_default_benefits
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
benefits.each do |ben|
id_card_plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
end
end
end
+3
View File
@@ -0,0 +1,3 @@
class IdCard::PlanBenefit < ApplicationRecord
belongs_to :id_card_plan
end
@@ -1,4 +1,4 @@
class SampleIdCard < ApplicationRecord
class IdCard::PrintData < ApplicationRecord
STRING_ATTRIBUTES = %w[provider_line_1 provider_line_2 provider_line_3 provider_line_4 provider_line_5 provider_line_6 provider_line_7 provider_line_8 provider_line_9 provider_line_10 provider_line_11 claim_to_1 claim_to_2 claim_to_3 claim_to_4 claim_to_5 claim_to_6 claim_to_7 claim_to_8 claim_to_9 claim_to_10 claim_to_11 dependent_1 dependent_2 dependent_3 dependent_4 dependent_5 dependent_6 dependent_7 dependent_8]
+3
View File
@@ -0,0 +1,3 @@
class IdCard::ProviderSection < ApplicationRecord
end
+3
View File
@@ -0,0 +1,3 @@
class IdCard::RxSection < ApplicationRecord
end
+27
View File
@@ -0,0 +1,27 @@
class IdCard::Setup < ApplicationRecord
belongs_to :employer
belongs_to :id_card_employer_logo
belongs_to :id_card_network_logo
belongs_to :id_card_provider_section
belongs_to :id_card_rx_section
has_many :card_exceptions, dependent: :destroy
# def employer_logo_filename
# self.id_card_employer_logo.filename
# end
# def network_logo_filename
# self.id_card_network_logo.filename
# end
def self.permitted_params(params)
params.require(:id_card_setup).permit(
:print_name,
:network_provider,
:card_template,
:rx_group_number,
:id_card_employer_logo_id
)
end
end
-18
View File
@@ -1,18 +0,0 @@
class Plan < ApplicationRecord
belongs_to :employer
has_many :plan_benefits, dependent: :destroy
accepts_nested_attributes_for :plan_benefits, allow_destroy: true, reject_if: :all_blank
# after_initialize :create_default_benefits, if: :new_record?
private
def build_and_create_default_benefits
benefits = IdCardBenefitsTemplate.find_by(title: "BLANK").id_card_benefits.sort_by(&:sequence)
benefits.each do |ben|
plan_benefits.new(benefit_desc: ben.benefit_desc, sequence: ben.sequence)
end
end
end
-3
View File
@@ -1,3 +0,0 @@
class PlanBenefit < ApplicationRecord
belongs_to :plan
end