Class: Printer
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Printer
- Defined in:
- app/models/printer.rb
Overview
== Schema Information
Table name: printers
Database name: primary
id :integer not null, primary key
capabilities :jsonb
computer_name :string not null
name :string not null
state :string not null
created_at :datetime not null
updated_at :datetime not null
print_node_id :integer not null
store_id :integer
Indexes
index_printers_on_print_node_id (print_node_id)
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Has many collapse
Belongs to collapse
Class Method Summary collapse
Instance Method Summary collapse
- #bins ⇒ void
- #collate? ⇒ Boolean
- #color? ⇒ Boolean
- #duplex? ⇒ Boolean
- #full_name_array ⇒ void
- #medias ⇒ void
-
#print(content, content_type: :pdf_uri, name: nil, source: nil, payload: {}) ⇒ void
see https://www.printnode.com/docs/api/curl/ title: A title to give the PrintJob.
- #print_upload(upload, bin: nil, quantity: 1, duplex: 'long-edge', rotate: nil, fit_to_page: nil) ⇒ void
-
#to_partial_path ⇒ Object
Partial lives under
app/views/crm/printers/, not the conventionalapp/views/printers/.
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
Class Method Details
.print_node_client ⇒ void
This method returns an undefined value.
50 51 52 53 54 |
# File 'app/models/printer.rb', line 50 def self.print_node_client auth_key = Heatwave::Configuration.fetch(:print_node_auth_key) auth = PrintNode::Auth.new(auth_key) PrintNode::Client.new(auth) end |
.refresh_printer_list ⇒ void
This method returns an undefined value.
45 46 47 |
# File 'app/models/printer.rb', line 45 def self.refresh_printer_list Printers::RefreshPrinters.new.process end |
.select_options ⇒ void
This method returns an undefined value.
40 41 42 |
# File 'app/models/printer.rb', line 40 def self. order(:name).pluck(:name, :id) end |
Instance Method Details
#bins ⇒ void
This method returns an undefined value.
57 58 59 |
# File 'app/models/printer.rb', line 57 def bins capabilities['bins'] end |
#collate? ⇒ Boolean
67 68 69 |
# File 'app/models/printer.rb', line 67 def collate? capabilities['collate'].to_b end |
#color? ⇒ Boolean
72 73 74 |
# File 'app/models/printer.rb', line 72 def color? capabilities['color'].to_b end |
#duplex? ⇒ Boolean
77 78 79 |
# File 'app/models/printer.rb', line 77 def duplex? capabilities['duplex'].to_b end |
#full_name_array ⇒ void
This method returns an undefined value.
82 83 84 |
# File 'app/models/printer.rb', line 82 def full_name_array [print_node_id, store&.name, computer_name, name, state].filter_map(&:presence) end |
#medias ⇒ void
This method returns an undefined value.
62 63 64 |
# File 'app/models/printer.rb', line 62 def medias capabilities['medias'] end |
#print(content, content_type: :pdf_uri, name: nil, source: nil, payload: {}) ⇒ void
This method returns an undefined value.
see https://www.printnode.com/docs/api/curl/
title: A title to give the PrintJob. This is the name which will appear in the operating system's print queue.
content_type: Either 'pdf_uri', 'pdf_base64', 'raw_uri', 'raw_base64'
content: A uri accessible by the client when contentType is 'pdf_uri'.
or A base64 encoded representation of the pdf when contentType is 'pdf_base64'.
source: A text description of how the printjob was created or where the printjob originated.
options: An object describing various options which can be set for this PrintJob. See options. Printing options have no effect when raw printing.
https://github.com/PrintNode/PrintNode-Ruby/blob/master/examples/creating_a_printjob.rb
100 101 102 103 104 105 |
# File 'app/models/printer.rb', line 100 def print(content, content_type: :pdf_uri, name: nil, source: nil, payload: {}) # raise "Invalid pdf_uri" if content_type != :pdf_uri && (URI.parse(content) rescue nil).nil? source ||= "heatwave" print_job = PrintNode::PrintJob.new(print_node_id, name, content_type.to_s, content, source) self.class.print_node_client.create_printjob(print_job, payload) end |
#print_profiles ⇒ ActiveRecord::Relation<PrintProfile>
35 |
# File 'app/models/printer.rb', line 35 has_many :print_profiles, dependent: :destroy |
#print_upload(upload, bin: nil, quantity: 1, duplex: 'long-edge', rotate: nil, fit_to_page: nil) ⇒ void
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/printer.rb', line 121 def print_upload(upload, bin: nil, quantity: 1, duplex: 'long-edge', rotate: nil, fit_to_page: nil) t = upload.active_download_token pdf_uri = "https://#{CRM_HOSTNAME}/en-US/downloads/#{t}" # pdf_data = upload.attachment.data = {} ['bin'] = bin if bin.present? ['duplex'] = duplex if duplex.present? ['rotate'] = rotate if rotate.present? ['fit_to_page'] = fit_to_page unless fit_to_page.nil? ['copies'] = quantity payload = { options: , expireAfter: 120_000 } ext = File.extname(upload.) name = "#{upload.category}_#{upload.id}#{ext}" print(pdf_uri, name: name, payload: payload, content_type: :pdf_uri) end |
#to_partial_path ⇒ Object
Partial lives under app/views/crm/printers/, not the conventional
app/views/printers/. Override so render @printers (or
render printer) resolves from any controller, not just
Crm::PrintersController.
28 29 30 |
# File 'app/models/printer.rb', line 28 def to_partial_path 'crm/printers/printer' end |