Class: Printer
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 Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Class Method Summary
collapse
Instance Method Summary
collapse
-
#bins ⇒ Object
-
#collate? ⇒ Boolean
-
#color? ⇒ Boolean
-
#duplex? ⇒ Boolean
-
#full_name_array ⇒ Object
-
#medias ⇒ Object
-
#print(content, content_type: :pdf_uri, name: nil, source: nil, payload: {}) ⇒ Object
-
#print_upload(upload, bin: nil, quantity: 1, duplex: 'long-edge', rotate: nil, fit_to_page: nil) ⇒ Object
-
#to_partial_path ⇒ Object
Partial lives under app/views/crm/printers/, not the conventional app/views/printers/.
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
config
#after_commit
#publish_event
Class Method Details
.print_node_client ⇒ Object
45
46
47
48
49
|
# File 'app/models/printer.rb', line 45
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 ⇒ Object
41
42
43
|
# File 'app/models/printer.rb', line 41
def self.refresh_printer_list
Printers::RefreshPrinters.new.process
end
|
.select_options ⇒ Object
37
38
39
|
# File 'app/models/printer.rb', line 37
def self.select_options
order(:name).pluck(:name, :id)
end
|
Instance Method Details
#bins ⇒ Object
51
52
53
|
# File 'app/models/printer.rb', line 51
def bins
capabilities['bins']
end
|
#collate? ⇒ Boolean
59
60
61
|
# File 'app/models/printer.rb', line 59
def collate?
capabilities['collate'].to_b
end
|
#color? ⇒ Boolean
63
64
65
|
# File 'app/models/printer.rb', line 63
def color?
capabilities['color'].to_b
end
|
#duplex? ⇒ Boolean
67
68
69
|
# File 'app/models/printer.rb', line 67
def duplex?
capabilities['duplex'].to_b
end
|
#full_name_array ⇒ Object
71
72
73
|
# File 'app/models/printer.rb', line 71
def full_name_array
[print_node_id, store&.name, computer_name, name, state].filter_map(&:presence)
end
|
55
56
57
|
# File 'app/models/printer.rb', line 55
def medias
capabilities['medias']
end
|
#print(content, content_type: :pdf_uri, name: nil, source: nil, payload: {}) ⇒ Object
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
83
84
85
86
87
88
|
# File 'app/models/printer.rb', line 83
def print(content, content_type: :pdf_uri, name: nil, source: nil, payload: {})
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>
34
|
# File 'app/models/printer.rb', line 34
has_many :print_profiles, dependent: :destroy
|
#print_upload(upload, bin: nil, quantity: 1, duplex: 'long-edge', rotate: nil, fit_to_page: nil) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/models/printer.rb', line 90
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}"
options = {}
options['bin'] = bin if bin.present?
options['duplex'] = duplex if duplex.present?
options['rotate'] = rotate if rotate.present?
options['fit_to_page'] = fit_to_page unless fit_to_page.nil?
options['copies'] = quantity
payload = {
options: options,
expireAfter: 120_000
}
ext = File.extname(upload.attachment_name)
name = "#{upload.category}_#{upload.id}#{ext}"
print(pdf_uri, name: name, payload: payload, content_type: :pdf_uri)
end
|
35
|
# File 'app/models/printer.rb', line 35
belongs_to :store, optional: true
|
#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
|