Class: Printer

Inherits:
ApplicationRecord show all
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

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

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_listvoid

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_optionsvoid

This method returns an undefined value.



40
41
42
# File 'app/models/printer.rb', line 40

def self.select_options
  order(:name).pluck(:name, :id)
end

Instance Method Details

#binsvoid

This method returns an undefined value.



57
58
59
# File 'app/models/printer.rb', line 57

def bins
  capabilities['bins']
end

#collate?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/printer.rb', line 67

def collate?
  capabilities['collate'].to_b
end

#color?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/printer.rb', line 72

def color?
  capabilities['color'].to_b
end

#duplex?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/models/printer.rb', line 77

def duplex?
  capabilities['duplex'].to_b
end

#full_name_arrayvoid

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

#mediasvoid

This method returns an undefined value.



62
63
64
# File 'app/models/printer.rb', line 62

def medias
  capabilities['medias']
end

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

Parameters:

  • content (Object)
  • content_type (Object) (defaults to: :pdf_uri)
  • name (Object) (defaults to: nil)
  • source (Object) (defaults to: nil)
  • payload (Object) (defaults to: {})


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

Returns:



35
# File 'app/models/printer.rb', line 35

has_many :print_profiles, dependent: :destroy

Parameters:

  • upload (Object)
  • bin (Object) (defaults to: nil)
  • quantity (Object) (defaults to: 1)
  • duplex (Object) (defaults to: 'long-edge')
  • rotate (Object) (defaults to: nil)
  • fit_to_page (Object) (defaults to: nil)
  • upload (Object)
  • bin (Object) (defaults to: nil)
  • quantity (Object) (defaults to: 1)
  • duplex (Object) (defaults to: 'long-edge')
  • rotate (Object) (defaults to: nil)
  • fit_to_page (Object) (defaults to: nil)

Returns:

  • (void)
  • (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
  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

#storeStore?

Returns:



37
# File 'app/models/printer.rb', line 37

belongs_to :store, optional: true

#to_partial_pathObject

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