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 :integer
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)
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_print_options ⇒ Object
- #to_s ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Class Method Details
.in_store_id ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are in store id. Active Record Scope
34 |
# File 'app/models/print_profile.rb', line 34 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
35 |
# File 'app/models/print_profile.rb', line 35 scope :online, -> { joins(:printer).where(printers: { state: 'online' }) } |
.select_options ⇒ Object
40 41 42 |
# File 'app/models/print_profile.rb', line 40 def self. all.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
33 |
# File 'app/models/print_profile.rb', line 33 scope :warehouse, -> { where(job_type: %w(shipping_document shipping_label upc_label)) } |
Instance Method Details
#bin_options_for_select ⇒ Object
53 54 55 |
# File 'app/models/print_profile.rb', line 53 def [['Default','']] + printer.bins.map{|b| [b,b]} end |
#duplex_options_for_select ⇒ Object
48 49 50 51 |
# File 'app/models/print_profile.rb', line 48 def return [] unless printer.duplex? [['Default','']] + ['long-edge','short-edge'].map{|o| [o.titleize, o]} end |
#employee_record ⇒ EmployeeRecord
29 |
# File 'app/models/print_profile.rb', line 29 belongs_to :employee_record, optional: true |
#job_type_for_select ⇒ Object
57 58 59 |
# File 'app/models/print_profile.rb', line 57 def job_type_for_select [['Default', '']] + PrintProfile.job_types.keys.map{|k| [k.titleize, k]} end |
#paper_options_for_select ⇒ Object
44 45 46 |
# File 'app/models/print_profile.rb', line 44 def printer.capabilities.dig('papers','table')&.keys || [] end |
#print(content, content_type: :pdf_base64, quantity: 1) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/print_profile.rb', line 65 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: 120000, qty: quantity.to_i } printer.print(content, content_type: content_type, payload: payload) end |
#print_upload(upload, quantity: 1) ⇒ Object
61 62 63 |
# File 'app/models/print_profile.rb', line 61 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
28 |
# File 'app/models/print_profile.rb', line 28 belongs_to :printer, optional: true |
#to_print_options ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/models/print_profile.rb', line 78 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
88 89 90 |
# File 'app/models/print_profile.rb', line 88 def to_s "#{printer.computer_name} > #{printer.name} > #{name}" end |