Class: PrintProfile
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PrintProfile
- Defined in:
- app/models/print_profile.rb
Overview
== Schema Information
Table name: print_profiles
Database name: primary
id :integer not null, primary key
bin :string
duplex :string
fit_to_page :boolean
job_type :enum
name :string not null
paper :string
rotate :integer
employee_record_id :integer
printer_id :integer not null
Indexes
index_print_profiles_on_employee_record_id (employee_record_id)
index_print_profiles_on_printer_id (printer_id)
Foreign Keys
fk_rails_... (employee_record_id => employee_records.id)
fk_rails_... (printer_id => printers.id)
Constant Summary
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #name ⇒ Object readonly
- #printer_id ⇒ Object readonly
Belongs to collapse
Class Method Summary collapse
-
.in_store_id ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are in store id.
-
.online ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are online.
- .select_options ⇒ Object
-
.warehouse ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are warehouse.
Instance Method Summary collapse
- #bin_options_for_select ⇒ Object
- #duplex_options_for_select ⇒ Object
- #job_type_for_select ⇒ Object
- #paper_options_for_select ⇒ Object
- #print(content, content_type: :pdf_base64, quantity: 1) ⇒ Object
- #print_upload(upload, quantity: 1) ⇒ Object
-
#to_partial_path ⇒ Object
Partial lives under
app/views/crm/print_profiles/, not the conventionalapp/views/print_profiles/. - #to_print_options ⇒ Object
- #to_s ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#name ⇒ Object (readonly)
48 |
# File 'app/models/print_profile.rb', line 48 validates :name, :printer_id, presence: true |
#printer_id ⇒ Object (readonly)
48 |
# File 'app/models/print_profile.rb', line 48 validates :name, :printer_id, presence: true |
Class Method Details
.in_store_id ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are in store id. Active Record Scope
45 |
# File 'app/models/print_profile.rb', line 45 scope :in_store_id, ->(store_id) { joins(:printer).where(printers: { store_id: store_id }) } |
.online ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are online. Active Record Scope
46 |
# File 'app/models/print_profile.rb', line 46 scope :online, -> { joins(:printer).where(printers: { state: 'online' }) } |
.select_options ⇒ Object
51 52 53 |
# File 'app/models/print_profile.rb', line 51 def self. eager_load(:printer).order(Printer[:name], :name).map { |pp| ["#{pp.printer.name} > #{pp.name}", pp.id] } end |
.warehouse ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are warehouse. Active Record Scope
44 |
# File 'app/models/print_profile.rb', line 44 scope :warehouse, -> { where(job_type: %w[shipping_document shipping_label upc_label]) } |
Instance Method Details
#bin_options_for_select ⇒ Object
65 66 67 |
# File 'app/models/print_profile.rb', line 65 def [['Default', '']] + printer.bins.map { |b| [b, b] } end |
#duplex_options_for_select ⇒ Object
59 60 61 62 63 |
# File 'app/models/print_profile.rb', line 59 def return [] unless printer.duplex? [['Default', '']] + %w[long-edge short-edge].map { |o| [o.titleize, o] } end |
#employee_record ⇒ EmployeeRecord
38 |
# File 'app/models/print_profile.rb', line 38 belongs_to :employee_record, optional: true |
#job_type_for_select ⇒ Object
69 70 71 |
# File 'app/models/print_profile.rb', line 69 def job_type_for_select [['Default', '']] + PrintProfile.job_types.keys.map { |k| [k.titleize, k] } end |
#paper_options_for_select ⇒ Object
55 56 57 |
# File 'app/models/print_profile.rb', line 55 def printer.capabilities.dig('papers', 'table')&.keys || [] end |
#print(content, content_type: :pdf_base64, quantity: 1) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/models/print_profile.rb', line 77 def print(content, content_type: :pdf_base64, quantity: 1) # https://www.printnode.com/en/docs/api/curl#printjobs # normally printer should listen to the copies option but with dymo label that's not the case = # .merge(copies: quantity.to_i) payload = { options: , expireAfter: 120_000, qty: quantity.to_i } printer.print(content, content_type: content_type, payload: payload) end |
#print_upload(upload, quantity: 1) ⇒ Object
73 74 75 |
# File 'app/models/print_profile.rb', line 73 def print_upload(upload, quantity: 1) printer.print_upload(upload, bin: bin, duplex: duplex, quantity: quantity, rotate: rotate, fit_to_page: fit_to_page) end |
#printer ⇒ Printer
37 |
# File 'app/models/print_profile.rb', line 37 belongs_to :printer, optional: true |
#to_partial_path ⇒ Object
Partial lives under app/views/crm/print_profiles/, not the
conventional app/views/print_profiles/. Override so
render @print_profiles (or render print_profile) resolves from
any controller, not just Crm::PrintProfilesController.
33 34 35 |
# File 'app/models/print_profile.rb', line 33 def to_partial_path 'crm/print_profiles/print_profile' end |
#to_print_options ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'app/models/print_profile.rb', line 89 def { bin: bin.presence, duplex: duplex.presence, rotate: rotate.presence, fit_to_page: fit_to_page.to_b, paper: paper.presence }.compact end |
#to_s ⇒ Object
99 100 101 |
# File 'app/models/print_profile.rb', line 99 def to_s "#{printer.computer_name} > #{printer.name} > #{name}" end |