oxen_printer 0.4.11 → 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 340746cbd0ae2f5b42b4a107cfad60536344c0d2
4
- data.tar.gz: 2f5c4a6d37163862c201f48a806a39d59236a7bb
3
+ metadata.gz: bbb31d72afc67fdee1748c50729fe79f7ee43f64
4
+ data.tar.gz: 8f8be2f610b980398c0281ea95d74be5a57fb92c
5
5
  SHA512:
6
- metadata.gz: 075756650f64d9a6c174aaa4f1a28210fef375602a97368895db2742d7d04ebdec6b87d656b8e919b6bdd43e503a1a8c60b460082f360c5d227c4cd213db7f67
7
- data.tar.gz: 26fc948fd43ac1f86a700a19c4bdec3190baba26228987e4ddcee9aa899b1f13d0b534f3d6419c4a855214fd45b274ec76a84fa0f3974f2d240a05816db8a6ac
6
+ metadata.gz: 162540fd74bbd08e9a5beb9a412b84a22c589ca40c8e1a11ad7279be673cbc33a81e864509cd0703f9dbcfa73875a21737ae201dbed3b9b339a2810832825d45
7
+ data.tar.gz: 7ddbcac29040716547d66adba669d9db9331bf88cf254e6e7e221b5efbd122c10b7116d0d48839de67ec8828ca19f6a18912840cd67cdb84d001d56963f5e662
@@ -0,0 +1,39 @@
1
+ class Oxen::PrintserversController < AbstractResourcesController
2
+ skip_before_filter :authenticate_user!, only: :port
3
+
4
+ def port
5
+ authorize Printserver.new
6
+ unless params[:mac].blank?
7
+ port = Printserver.find_by_mac_addr(params[:mac])
8
+ if !port
9
+ port = 'port not found!'
10
+ else
11
+ port = port.active ? port.port : 'printserver er ikke aktiv!'
12
+ end
13
+ render plain: port
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def set_fab_button_options
20
+
21
+ opt = { items: {}}
22
+ case params[:action]
23
+ when 'edit','update'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }
24
+ when 'show'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }
25
+ # when 'index'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }
26
+ end
27
+
28
+ @fab_button_options = opt
29
+ end
30
+
31
+ # Never trust parameters from the scary internet, only allow the white list through.
32
+ def resource_params
33
+ params[:printserver][:mac_addr] = params[:printserver][:mac_addr].strip.gsub( / /, ':') rescue ''
34
+ params[:printserver][:account_id] = current_user.admin? ? (params[:parent_id] || params[:printserver][:account_id]) : current_user.account.id
35
+ params.require(:printserver).permit(:parent, :parent_id, :account_id, :location, :lokation, :mac_addr, :port, :active)
36
+ end
37
+
38
+
39
+ end
@@ -0,0 +1,21 @@
1
+ class OxPrintserver < AbstractResource
2
+ self.table_name = 'printservers'
3
+ establish_connection ((Rails.env=="development") ? :dev_oxen_tables : :oxen_tables )
4
+
5
+ has_paper_trail
6
+
7
+ belongs_to :account
8
+ has_many :printers, dependent: :destroy
9
+
10
+ validates :mac_addr, presence: true
11
+ validates :port, presence: true
12
+
13
+ scope :active, -> { where(active: true) }
14
+
15
+ def list_title
16
+ location
17
+ end
18
+
19
+
20
+
21
+ end
@@ -1,3 +1,3 @@
1
- %tr{ id: "tr-#{resource.id}"}
1
+ %tr{ id: "tr-#{resource_class}-#{resource.id}"}
2
2
  %td= link_to resource.name, resource
3
3
  %td= show_resource_delete_icon resource, '/admin/print_jobs'
@@ -1,4 +1,4 @@
1
- %tr{ id: "tr-#{print_job.id}"}
1
+ %tr{ id: "tr-#{resource_class}-#{resource.id}"}
2
2
  %td= link_to parent.name, parent
3
3
  %td= link_to print_job.name, print_job
4
4
  %td= show_resource_delete_icon print_job, '/admin/print_jobs'
@@ -1,4 +1,4 @@
1
- %tr{ id: "tr-#{printer.id}"}
1
+ %tr{ id: "tr-#{resource_class}-#{printer.id}"}
2
2
  %td= link_to printer.name, printer
3
3
  %td= show_resource_delete_icon printer, '/admin/printers'
4
4
  -# - if parent? && parent_name == 'users'
@@ -1,3 +1,3 @@
1
- %tr{ id: "tr-#{resource.id}"}
1
+ %tr{ id: "tr-#{resource_class}-#{resource.id}"}
2
2
  %td= link_to resource.name, resource
3
3
  %td= show_resource_delete_icon resource, '/admin/printers'
@@ -1,4 +1,4 @@
1
- %tr{ id: "tr-#{printer.id}"}
1
+ %tr{ id: "tr-#{resource_class}-#{printer.id}"}
2
2
  %td= link_to printer.name, printer
3
3
  %td= show_resource_delete_icon printer, '/admin/printers'
4
4
  - if parent?
@@ -126,11 +126,8 @@ class ActionPrinter < ActionView::Base
126
126
  end
127
127
 
128
128
  def print_print prn, print_job, args
129
- paper = args.delete(:paper)
130
129
  args[:copies] ||= 1
131
- pdf_path = pdf_file_path.split("/")[-1]
132
- pap = paper || prn.paper
133
- cmd = prn.command.gsub( /\$1/, prn.cups_printer ).gsub( /\$2/, pap ).gsub( /\$3/, pdf_file_path ).gsub( /\$4/, pdf_path )
130
+ cmd = build_print_cmd prn, args
134
131
  if args[:copies].to_i > 1
135
132
  cmdargs = cmd.split(" ")
136
133
  f = cmdargs.pop
@@ -145,6 +142,13 @@ class ActionPrinter < ActionView::Base
145
142
  return `#{cmd}`
146
143
  end
147
144
 
145
+ def build_print_cmd prn, args
146
+ cups = !prn.printserver ? prn.cups_printer : "#{prn.cups_printer} -h 10.0.0.26:4#{prn.printserver.port}"
147
+ pdf_path = pdf_file_path.split("/")[-1]
148
+ paper = args.delete(:paper) || prn.paper
149
+ prn.command.gsub( /\$1/, cups ).gsub( /\$2/, paper ).gsub( /\$3/, pdf_file_path ).gsub( /\$4/, pdf_path )
150
+ end
151
+
148
152
  def logit( log_type, msg )
149
153
  Rails.logger.send(log_type, "[OXEN] #{Time.now} [#{log_type.to_s}] #{msg}")
150
154
  end
@@ -1,3 +1,3 @@
1
1
  module OxenPrinter
2
- VERSION = "0.4.11"
2
+ VERSION = "0.4.12"
3
3
  end
data/lib/print_engine.rb CHANGED
@@ -53,11 +53,76 @@ module PrintEngine
53
53
 
54
54
  include Exceptions
55
55
 
56
+ #
57
+ #
58
+ # # list_title
59
+ # def list_title
60
+ # self.respond_to?( "name") ? self.name : "please define list_title on model (#{self.class.to_s})!"
61
+ # end
62
+ #
63
+ # # implement on relevant models
64
+ def find_template template, paper="A4"
65
+ raise 'you have to implement "def find_template(paper)" on your Model'
66
+ # 'label.html.haml'
67
+ end
68
+ #
69
+ #
70
+ #
71
+ # def set_print_defaults options
72
+ # options[:context] ||= ""
73
+ # options[:print_job][:download] = options[:print][:medium]=="download" || false
74
+ # options[:print_job][:print_driver] = spot_the_driver(options)
75
+ # options[:print_job][:paper] = options[:paper] || "A4"
76
+ # options[:print_job][:view_template_path] = find_template( options[:template], options[:paper] ) || params[:print_job][:view_template_path]
77
+ # options
78
+ # end
79
+ #
80
+
81
+ def print_label(options={})
82
+
83
+ options[:context] ||= ""
84
+ options[:print] ||= {}
85
+ options[:print][:collation] = 'record'
86
+ options[:print][:paper] ||= 'label'
87
+ options[:print][:output_type] ||= 'raw'
88
+
89
+ options = self.class.set_print_job_defaults [self], options
90
+ options[:print_job][:print_driver] = options[:print][:print_driver] || :cab
91
+ options[:print_job][:paper] = options[:print][:paper] || "label"
92
+ options[:print_job][:print_format] = options[:print][:collation] || 'record'
93
+ options[:print_job][:view_template_path] = "stock_items/print/zebra_stock_items_label.html.haml"
94
+
95
+ pj = self.class.print [self], options
96
+ end
97
+
98
+
99
+ # options[:print][:printer_name] = options[:print][:printer_name] || ''
100
+ # options[:user] = options[:user] || current_user
101
+
102
+
103
+ def print_record(options={})
104
+
105
+ options[:context] ||= ""
106
+ options[:print] ||= {}
107
+ options[:print][:collation] = 'record'
108
+ options[:print][:paper] ||= 'A4'
109
+ options[:print][:output_type] ||= 'pdf'
110
+
111
+ options = self.class.set_print_job_defaults [self], options
112
+ options[:print_job][:print_driver] = options[:print][:print_driver] || :pdf
113
+ options[:print_job][:paper] = options[:print][:paper] || "A4"
114
+ options[:print_job][:print_format] = options[:print][:collation] || 'record'
115
+ options[:print_job][:view_template_path] = "stock_items/print/slip.html.haml"
116
+
117
+ pj = self.class.print [self], options
118
+ end
119
+
120
+
121
+
56
122
  def self.included(base)
57
123
 
58
124
  #
59
125
  def base.print_list(options={})
60
-
61
126
  raise NoContextFound.new('ViewContext missing!') if options[:context].blank?
62
127
  options[:print] ||= {}
63
128
  options[:print][:collation] = 'list'
@@ -149,21 +214,21 @@ module PrintEngine
149
214
  #
150
215
  # find the best printer for the job
151
216
  def base.default_printer usr, printer_name, paper=nil
152
- if printer_name=="default"
217
+ if printer_name!="default"
218
+ return Printer.find(printer_name) if printer_name.to_i.to_s == printer_name
219
+ Printer.active.find_by( 'name like ?', "%#{printer_name.downcase}%") or raise NoPreferredPrintersFound.new('Printer with name not found!')
220
+ else
221
+ raise NoPreferredPrintersFound.new('No printers found!') if usr.printers.empty?
153
222
  if paper.nil?
154
- printer = (usr.printers.empty? ? nil : usr.printers.active.preferred_printer.first)
155
- printer = Printer.new() if printer.nil? #or raise NoPreferredPrintersFound.new('No preferred printers found!')
223
+ usr.printers.active.preferred_printer.first or raise NoPreferredPrintersFound.new('No preferred printers found!')
156
224
  else
157
- printer = (usr.printers.empty? ? nil : (usr.printers.active.preferred_printer.on_paper(paper).first || usr.printers.on_paper(paper).first ) )
158
- printer = Printer.new() if printer.nil? #or raise NoPreferredPrintersFound.new('No preferred printers found!')
225
+ usr.printers.active.preferred_printer.on_paper(paper).first || usr.printers.on_paper(paper).first or raise NoPreferredPrintersFound.new('No preferred printers found!')
159
226
  end
160
- else
161
- printer = Printer.active.find_by( 'name like ?', "%#{printer_name.downcase}%")
162
227
  end
163
- # usr.printers.where{ (printownerables.preferred==true) & (printownerables.preferred==true) }
164
-
165
- # raise PrintJobPrinterNotAvailableError
166
- printer || Printer.first
228
+ # # usr.printers.where{ (printownerables.preferred==true) & (printownerables.preferred==true) }
229
+ #
230
+ # # raise PrintJobPrinterNotAvailableError
231
+ # printer || Printer.first
167
232
  end
168
233
 
169
234
  def base.set_resource_sql(resources,params)
@@ -179,70 +244,5 @@ module PrintEngine
179
244
  end
180
245
 
181
246
  end
182
- #
183
- #
184
- # # list_title
185
- # def list_title
186
- # self.respond_to?( "name") ? self.name : "please define list_title on model (#{self.class.to_s})!"
187
- # end
188
- #
189
- # # implement on relevant models
190
- def find_template template, paper="A4"
191
- raise 'you have to implement "def find_template(paper)" on your Model'
192
- # 'label.html.haml'
193
- end
194
- #
195
- #
196
- #
197
- # def set_print_defaults options
198
- # options[:context] ||= ""
199
- # options[:print_job][:download] = options[:print][:medium]=="download" || false
200
- # options[:print_job][:print_driver] = spot_the_driver(options)
201
- # options[:print_job][:paper] = options[:paper] || "A4"
202
- # options[:print_job][:view_template_path] = find_template( options[:template], options[:paper] ) || params[:print_job][:view_template_path]
203
- # options
204
- # end
205
- #
206
-
207
- def print_label(options={})
208
-
209
- options[:context] ||= ""
210
- options[:print] ||= {}
211
- options[:print][:collation] = 'record'
212
- options[:print][:paper] ||= 'label'
213
- options[:print][:output_type] ||= 'raw'
214
-
215
- options = self.class.set_print_job_defaults [self], options
216
- options[:print_job][:print_driver] = options[:print][:print_driver] || :cab
217
- options[:print_job][:paper] = options[:print][:paper] || "label"
218
- options[:print_job][:print_format] = options[:print][:collation] || 'record'
219
- options[:print_job][:view_template_path] = "stock_items/print/zebra_stock_items_label.html.haml"
220
-
221
- pj = self.class.print [self], options
222
- end
223
-
224
-
225
- # options[:print][:printer_name] = options[:print][:printer_name] || ''
226
- # options[:user] = options[:user] || current_user
227
-
228
-
229
- def print_record(options={})
230
-
231
- options[:context] ||= ""
232
- options[:print] ||= {}
233
- options[:print][:collation] = 'record'
234
- options[:print][:paper] ||= 'A4'
235
- options[:print][:output_type] ||= 'pdf'
236
-
237
- options = self.class.set_print_job_defaults [self], options
238
- options[:print_job][:print_driver] = options[:print][:print_driver] || :pdf
239
- options[:print_job][:paper] = options[:print][:paper] || "A4"
240
- options[:print_job][:print_format] = options[:print][:collation] || 'record'
241
- options[:print_job][:view_template_path] = "stock_items/print/slip.html.haml"
242
-
243
- pj = self.class.print [self], options
244
- end
245
-
246
-
247
247
 
248
248
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxen_printer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Walther H Diechmann
@@ -69,11 +69,13 @@ files:
69
69
  - app/assets/javascripts/oxen_printer.js
70
70
  - app/controllers/oxen/print_jobs_controller.rb
71
71
  - app/controllers/oxen/printers_controller.rb
72
+ - app/controllers/oxen/printservers_controller.rb
72
73
  - app/jobs/background_printer_job.rb
73
74
  - app/mailers/printer_mailer.rb
74
75
  - app/models/ox_print_job.rb
75
76
  - app/models/ox_printable.rb
76
77
  - app/models/ox_printer.rb
78
+ - app/models/ox_printserver.rb
77
79
  - app/models/ox_template.rb
78
80
  - app/policies/oxen/print_job_policy.rb
79
81
  - app/views/layouts/1mailer.html.haml