oxen_printer 0.4.9 → 0.4.11

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: ccc96e760b55fdbc7c035dfd03d880cf6d7ff47f
4
- data.tar.gz: 71462500f21a098ea8355a8aa97ef87d0cc13bb5
3
+ metadata.gz: 340746cbd0ae2f5b42b4a107cfad60536344c0d2
4
+ data.tar.gz: 2f5c4a6d37163862c201f48a806a39d59236a7bb
5
5
  SHA512:
6
- metadata.gz: 55f4764eee03eac1cd77439e82176a30aa7c53c777be10400d046056073534834988eb92f15f2967f34a12ff19a53d6fca462f8e6e4d75ba64af74803e9d790b
7
- data.tar.gz: 86d248ea702636eb9675068ff40be5ebd34893012c7a204c8bd2674b2ba94a32fbfb1aeda94c7e69a9d26710ef8e6b023b5374ce8ced23e115f86093621d0b3d
6
+ metadata.gz: 075756650f64d9a6c174aaa4f1a28210fef375602a97368895db2742d7d04ebdec6b87d656b8e919b6bdd43e503a1a8c60b460082f360c5d227c4cd213db7f67
7
+ data.tar.gz: 26fc948fd43ac1f86a700a19c4bdec3190baba26228987e4ddcee9aa899b1f13d0b534f3d6419c4a855214fd45b274ec76a84fa0f3974f2d240a05816db8a6ac
@@ -1,3 +1,3 @@
1
- %tr{ id: "tr-#{resource_class}-#{resource.id}"}
1
+ %tr{ id: "tr-#{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-#{resource_class}-#{resource.id}"}
1
+ %tr{ id: "tr-#{print_job.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-#{resource_class}-#{printer.id}"}
1
+ %tr{ id: "tr-#{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_class}-#{resource.id}"}
1
+ %tr{ id: "tr-#{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-#{resource_class}-#{printer.id}"}
1
+ %tr{ id: "tr-#{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,8 +126,11 @@ class ActionPrinter < ActionView::Base
126
126
  end
127
127
 
128
128
  def print_print prn, print_job, args
129
+ paper = args.delete(:paper)
129
130
  args[:copies] ||= 1
130
- cmd = build_print_cmd prn, args
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 )
131
134
  if args[:copies].to_i > 1
132
135
  cmdargs = cmd.split(" ")
133
136
  f = cmdargs.pop
@@ -142,13 +145,6 @@ class ActionPrinter < ActionView::Base
142
145
  return `#{cmd}`
143
146
  end
144
147
 
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
-
152
148
  def logit( log_type, msg )
153
149
  Rails.logger.send(log_type, "[OXEN] #{Time.now} [#{log_type.to_s}] #{msg}")
154
150
  end
@@ -1,3 +1,3 @@
1
1
  module OxenPrinter
2
- VERSION = "0.4.9"
2
+ VERSION = "0.4.11"
3
3
  end
data/lib/print_engine.rb CHANGED
@@ -53,76 +53,11 @@ 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
-
122
56
  def self.included(base)
123
57
 
124
58
  #
125
59
  def base.print_list(options={})
60
+
126
61
  raise NoContextFound.new('ViewContext missing!') if options[:context].blank?
127
62
  options[:print] ||= {}
128
63
  options[:print][:collation] = 'list'
@@ -214,21 +149,21 @@ module PrintEngine
214
149
  #
215
150
  # find the best printer for the job
216
151
  def base.default_printer usr, printer_name, paper=nil
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?
152
+ if printer_name=="default"
222
153
  if paper.nil?
223
- usr.printers.active.preferred_printer.first or raise NoPreferredPrintersFound.new('No preferred printers found!')
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!')
224
156
  else
225
- usr.printers.active.preferred_printer.on_paper(paper).first || usr.printers.on_paper(paper).first or raise NoPreferredPrintersFound.new('No preferred printers found!')
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!')
226
159
  end
160
+ else
161
+ printer = Printer.active.find_by( 'name like ?', "%#{printer_name.downcase}%")
227
162
  end
228
- # # usr.printers.where{ (printownerables.preferred==true) & (printownerables.preferred==true) }
229
- #
230
- # # raise PrintJobPrinterNotAvailableError
231
- # printer || Printer.first
163
+ # usr.printers.where{ (printownerables.preferred==true) & (printownerables.preferred==true) }
164
+
165
+ # raise PrintJobPrinterNotAvailableError
166
+ printer || Printer.first
232
167
  end
233
168
 
234
169
  def base.set_resource_sql(resources,params)
@@ -244,5 +179,70 @@ module PrintEngine
244
179
  end
245
180
 
246
181
  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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxen_printer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9
4
+ version: 0.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Walther H Diechmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oxen_job
@@ -69,13 +69,11 @@ 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
73
72
  - app/jobs/background_printer_job.rb
74
73
  - app/mailers/printer_mailer.rb
75
74
  - app/models/ox_print_job.rb
76
75
  - app/models/ox_printable.rb
77
76
  - app/models/ox_printer.rb
78
- - app/models/ox_printserver.rb
79
77
  - app/models/ox_template.rb
80
78
  - app/policies/oxen/print_job_policy.rb
81
79
  - app/views/layouts/1mailer.html.haml
@@ -1,39 +0,0 @@
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
@@ -1,21 +0,0 @@
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