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 Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #name ⇒ String readonly
- #printer_id ⇒ Integer 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 ⇒ void
-
.warehouse ⇒ ActiveRecord::Relation<PrintProfile>
A relation of PrintProfiles that are warehouse.
Instance Method Summary collapse
- #bin_options_for_select ⇒ void
- #duplex_options_for_select ⇒ void
- #job_type_for_select ⇒ void
- #paper_options_for_select ⇒ void
- #print(content, content_type: :pdf_base64, quantity: 1) ⇒ void
- #print_upload(upload, quantity: 1) ⇒ void
-
#to_partial_path ⇒ Object
Partial lives under
app/views/crm/print_profiles/, not the conventionalapp/views/print_profiles/. - #to_print_options ⇒ void
- #to_s ⇒ String
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#name ⇒ String (readonly)
51 |
# File 'app/models/print_profile.rb', line 51 validates :name, presence: true |
#printer_id ⇒ Integer (readonly)
53 |
# File 'app/models/print_profile.rb', line 53 validates :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
47 |
# File 'app/models/print_profile.rb', line 47 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
48 |
# File 'app/models/print_profile.rb', line 48 scope :online, -> { joins(:printer).where(printers: { state: 'online' }) } |
.select_options ⇒ void
This method returns an undefined value.
57 58 59 |
# File 'app/models/print_profile.rb', line 57 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
46 |
# File 'app/models/print_profile.rb', line 46 scope :warehouse, -> { where(job_type: %w[shipping_document shipping_label upc_label]) } |
Instance Method Details
#bin_options_for_select ⇒ void
This method returns an undefined value.
74 75 76 |
# File 'app/models/print_profile.rb', line 74 def [['Default', '']] + printer.bins.map { |b| [b, b] } end |
#duplex_options_for_select ⇒ void
This method returns an undefined value.
67 68 69 70 71 |
# File 'app/models/print_profile.rb', line 67 def return [] unless printer.duplex? [['Default', '']] + %w[long-edge short-edge].map { |o| [o.titleize, o] } end |
#employee_record ⇒ EmployeeRecord?
40 |
# File 'app/models/print_profile.rb', line 40 belongs_to :employee_record, optional: true |
#job_type_for_select ⇒ void
This method returns an undefined value.
79 80 81 |
# File 'app/models/print_profile.rb', line 79 def job_type_for_select [['Default', '']] + PrintProfile.job_types.keys.map { |k| [k.titleize, k] } end |
#paper_options_for_select ⇒ void
This method returns an undefined value.
62 63 64 |
# File 'app/models/print_profile.rb', line 62 def printer.capabilities.dig('papers', 'table')&.keys || [] end |
#print(content, content_type: :pdf_base64, quantity: 1) ⇒ void
101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/print_profile.rb', line 101 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) ⇒ void
89 90 91 |
# File 'app/models/print_profile.rb', line 89 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?
38 |
# File 'app/models/print_profile.rb', line 38 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 ⇒ void
This method returns an undefined value.
114 115 116 117 118 119 120 121 122 |
# File 'app/models/print_profile.rb', line 114 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 ⇒ String
125 126 127 |
# File 'app/models/print_profile.rb', line 125 def to_s "#{printer.computer_name} > #{printer.name} > #{name}" end |