TMP commit
This commit is contained in:
@@ -6,8 +6,8 @@ class GenerateContractsZipJob < ApplicationJob
|
|||||||
before_perform do |job|
|
before_perform do |job|
|
||||||
@project = job.arguments.first
|
@project = job.arguments.first
|
||||||
@download = job.arguments.second
|
@download = job.arguments.second
|
||||||
release_type = job.arguments.third
|
@release_type = job.arguments.third
|
||||||
@folder_name = "#{@project.name.parameterize}_#{get_release_name(release_type).gsub('_', '-')}"
|
@folder_name = "#{@project.name.parameterize}_#{get_release_name(@release_type).gsub('_', '-')}"
|
||||||
@download.update!(name: @folder_name, status: :pending)
|
@download.update!(name: @folder_name, status: :pending)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -20,6 +20,10 @@ class GenerateContractsZipJob < ApplicationJob
|
|||||||
files.each do |attachment|
|
files.each do |attachment|
|
||||||
zipfile.add(attachment, File.join("#{dir}/", attachment))
|
zipfile.add(attachment, File.join("#{dir}/", attachment))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
csv_file = generate_csv releases
|
||||||
|
puts ">>>>> GENERATED ====="
|
||||||
|
zipfile.get_output_stream("#{@folder_name}.csv") { |f| f.puts(csv_file) }
|
||||||
end
|
end
|
||||||
|
|
||||||
@download.file.attach(io: File.open(zipfile_name), filename: "#{@folder_name}.zip")
|
@download.file.attach(io: File.open(zipfile_name), filename: "#{@folder_name}.zip")
|
||||||
@@ -43,6 +47,21 @@ class GenerateContractsZipJob < ApplicationJob
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def generate_csv(releases)
|
||||||
|
puts "==== 1 ====="
|
||||||
|
release_class = Object.const_get @release_type
|
||||||
|
puts "==== 2 ====="
|
||||||
|
headers = release_class.csv_headers
|
||||||
|
|
||||||
|
CSV.generate(headers: true) do |csv|
|
||||||
|
csv << headers
|
||||||
|
releases.each do |release|
|
||||||
|
csv_row_data = release.to_csv_row
|
||||||
|
csv << csv_row_data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_release_name(release_type)
|
def get_release_name(release_type)
|
||||||
release_type.constantize.model_name.plural
|
release_type.constantize.model_name.plural
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class AcquiredMediaRelease < ApplicationRecord
|
|||||||
include Signable
|
include Signable
|
||||||
include Syncable
|
include Syncable
|
||||||
include PersonName
|
include PersonName
|
||||||
|
include CsvExportable
|
||||||
|
|
||||||
has_many :file_infos, as: :releasable, dependent: :destroy
|
has_many :file_infos, as: :releasable, dependent: :destroy
|
||||||
|
|
||||||
|
|||||||
77
app/models/concerns/csv_exportable.rb
Normal file
77
app/models/concerns/csv_exportable.rb
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module CsvExportable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
COMMON_HEADERS = %i[notes tags signed_at].freeze
|
||||||
|
COMMON_VALUES = %w[clean_notes clean_tags signed_on].freeze
|
||||||
|
|
||||||
|
ACQUIRED_MEDIA_HEADERS = %i[name file_infos_count].freeze + COMMON_HEADERS
|
||||||
|
ACQUIRED_MEDIA_VALUES = %w[name file_count].freeze + COMMON_VALUES
|
||||||
|
|
||||||
|
APPEARANCE_HEADERS = %i[name contact_info].freeze + COMMON_HEADERS
|
||||||
|
APPEARANCE_VALUES = %w[name contact_info].freeze + COMMON_VALUES
|
||||||
|
|
||||||
|
HEADERS = {
|
||||||
|
acquired_media_release: ACQUIRED_MEDIA_HEADERS,
|
||||||
|
appearance_release: APPEARANCE_HEADERS
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
VALUES = {
|
||||||
|
acquired_media_release: ACQUIRED_MEDIA_VALUES,
|
||||||
|
appearance_release: APPEARANCE_VALUES
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
included do
|
||||||
|
class << self
|
||||||
|
def csv_headers
|
||||||
|
puts "HEADERS ===="
|
||||||
|
plural_class_name = self.name.underscore.pluralize
|
||||||
|
headers = HEADERS[self.name.underscore.to_sym]
|
||||||
|
|
||||||
|
headers.map do |header|
|
||||||
|
I18n.t("#{plural_class_name}.index.table_headers.#{header}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_csv_row
|
||||||
|
puts "==== = CSV ROW"
|
||||||
|
v = VALUES[self.class.name.underscore.to_sym].map do |function|
|
||||||
|
send(function)
|
||||||
|
end
|
||||||
|
puts v
|
||||||
|
v
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def file_count
|
||||||
|
self.file_infos.any? ? self.file_infos.size : I18n.t('acquired_media_releases.acquired_media_release.no_media')
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact_info
|
||||||
|
contact_info = ''
|
||||||
|
contact_info += "#{person_address}; " if person_address.present?
|
||||||
|
contact_info += "#{person_phone}; " if person_phone.present?
|
||||||
|
contact_info += "#{person_email}" if person_email.present?
|
||||||
|
contact_info.delete_suffix '; '
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean_notes
|
||||||
|
notes = ''
|
||||||
|
self.notes.order_by_recent.each do |note|
|
||||||
|
notes += "#{note.content}(#{note.email}), "
|
||||||
|
end
|
||||||
|
notes.delete_suffix ', '
|
||||||
|
end
|
||||||
|
|
||||||
|
def clean_tags
|
||||||
|
tags = ''
|
||||||
|
self.tags.each do |tag|
|
||||||
|
tags += "#{tag.name}, "
|
||||||
|
end
|
||||||
|
tags.delete_suffix ', '
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -49,6 +49,7 @@ en:
|
|||||||
search: Search
|
search: Search
|
||||||
empty: Acquired Media Releases will appear here
|
empty: Acquired Media Releases will appear here
|
||||||
table_headers:
|
table_headers:
|
||||||
|
name: Name
|
||||||
file_infos_count: No. Files
|
file_infos_count: No. Files
|
||||||
notes: Notes
|
notes: Notes
|
||||||
signed_at: Date Signed
|
signed_at: Date Signed
|
||||||
@@ -151,6 +152,8 @@ en:
|
|||||||
empty: Appearance Releases will appear here
|
empty: Appearance Releases will appear here
|
||||||
imported_appearance_release_missing_attachment: Person photo or contract missing for imported appearance release
|
imported_appearance_release_missing_attachment: Person photo or contract missing for imported appearance release
|
||||||
table_headers:
|
table_headers:
|
||||||
|
name: Name
|
||||||
|
contact_info: Contact info
|
||||||
notes: Notes
|
notes: Notes
|
||||||
signed_at: Date Signed
|
signed_at: Date Signed
|
||||||
tags: Tags
|
tags: Tags
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ es:
|
|||||||
heading: Person Photo (ES)
|
heading: Person Photo (ES)
|
||||||
index:
|
index:
|
||||||
imported_appearance_release_missing_attachment: Person photo or contract missing for imported appearance release (ES)
|
imported_appearance_release_missing_attachment: Person photo or contract missing for imported appearance release (ES)
|
||||||
|
table_headers:
|
||||||
|
name: ""
|
||||||
|
contact_info: ""
|
||||||
|
tags: ""
|
||||||
|
notes: ""
|
||||||
|
signed_at: ""
|
||||||
shared:
|
shared:
|
||||||
imported_appearance_release_contract_name: Contrato Importado
|
imported_appearance_release_contract_name: Contrato Importado
|
||||||
imported_appearance_release_headshot_name: Retrato Importado
|
imported_appearance_release_headshot_name: Retrato Importado
|
||||||
@@ -464,3 +470,13 @@ es:
|
|||||||
production_elements_logs: Production Elements Logs, and more (ES)
|
production_elements_logs: Production Elements Logs, and more (ES)
|
||||||
reduces_labor_cost: Reduces labor costs (ES)
|
reduces_labor_cost: Reduces labor costs (ES)
|
||||||
simplifies_cue_sheets: Simplifies Music Cue Sheets, Graphic Cue Sheets (ES)
|
simplifies_cue_sheets: Simplifies Music Cue Sheets, Graphic Cue Sheets (ES)
|
||||||
|
acquired_media_releases:
|
||||||
|
index:
|
||||||
|
table_headers:
|
||||||
|
name: Name (ES)
|
||||||
|
file_infos_count: No. Files (ES)
|
||||||
|
notes: Notes (ES)
|
||||||
|
signed_at: Date Signed (ES)
|
||||||
|
tags: Tags (ES)
|
||||||
|
acquired_media_release:
|
||||||
|
no_media: No Media (ES)
|
||||||
|
|||||||
Reference in New Issue
Block a user