thecore_print_commons 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/app/models/printer.rb +5 -5
- data/app/workers/print_worker.rb +6 -62
- data/lib/thecore_print_commons.rb +3 -0
- data/lib/thecore_print_commons/version.rb +1 -1
- metadata +16 -9
- data/app/models/print_job.rb +0 -16
- data/app/models/print_template.rb +0 -52
- data/db/migrate/20160407141529_create_print_jobs.rb +0 -10
- data/db/migrate/20160407152547_add_fields_to_print_job.rb +0 -9
- data/db/migrate/20160407181202_change_column_errors_to_print_job.rb +0 -5
- data/db/migrate/20160519093702_create_print_templates.rb +0 -13
- data/db/migrate/20160519124051_add_print_template_id_to_printer.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b0bc42cfcd52643cc6969d1c01ee83f66b7228d
|
4
|
+
data.tar.gz: a5290b56a7c9c0dfb4a786289b56a43ccb34db83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b0b8a85f04f109051373ae141e60d0c89d4f6855aa0a7506284836bc3cbe8670a2d527eea606f91680074c0144b3783846d29b0c11e4d12fa10d94095e063d
|
7
|
+
data.tar.gz: d51fad54ac14533fd04848b0a94d3f956b3faf7d6ca1602bf09cc6f9be626c61898c2ebddbf2a366424db013138a850acbfd5be8c1ca0eff3fac8487bfbaabc2
|
data/README.md
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
# ThecorePrintCommons
|
2
|
-
|
2
|
+
This gem brings cups interaction into Thecore apps, allowing printing on all configured printers (be they local or remote), using cups' standardized interface.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
|
5
|
+
Add all the needed printers and be sure you can print on them.
|
6
|
+
to add printers to CUPS you can use http://localhost:631, but before it could be bettere to relax a bit
|
7
|
+
the authentications needed for adding printers, to do so, please edit /etc/cups/cupsd.conf and replace all the Authentication directives with Authentication None.
|
8
|
+
|
9
|
+
When you enter the printers section and add a new printer in Thecore backend, you'll just see available (through cups) printers and you can just select one of these.
|
6
10
|
|
7
11
|
## Installation
|
12
|
+
First of all, please install libcups2-dev:
|
13
|
+
|
14
|
+
```shell
|
15
|
+
sudo apt install libcups2-dev
|
16
|
+
```
|
17
|
+
|
8
18
|
Add this line to your application's Gemfile:
|
9
19
|
|
10
20
|
```ruby
|
data/app/models/printer.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
class Printer < ApplicationRecord
|
2
2
|
#serialize :translation, Hash
|
3
3
|
|
4
|
-
has_many :print_jobs, dependent: :destroy, inverse_of: :printer
|
5
|
-
belongs_to :print_template, inverse_of: :printers
|
6
|
-
|
7
4
|
validates :name, presence: true
|
8
5
|
validates :ip, presence: true
|
9
|
-
validates :temperature, presence: true
|
10
6
|
|
11
7
|
# before_save :check_if_unique_default
|
12
8
|
# validates :qty, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
@@ -38,6 +34,11 @@ class Printer < ApplicationRecord
|
|
38
34
|
# where(used_in: (USED.index(section.to_sym) + 1))
|
39
35
|
# end
|
40
36
|
|
37
|
+
def ip_enum
|
38
|
+
# Getting from CUPS the list of configured printers
|
39
|
+
CupsPrinter.get_all_printer_names
|
40
|
+
end
|
41
|
+
|
41
42
|
RailsAdmin.config do |config|
|
42
43
|
config.model 'Printer' do
|
43
44
|
navigation_label I18n.t("admin.settings.label")
|
@@ -47,7 +48,6 @@ class Printer < ApplicationRecord
|
|
47
48
|
field :ip
|
48
49
|
field :default, :toggle
|
49
50
|
field :temperature
|
50
|
-
field :print_template
|
51
51
|
field :description
|
52
52
|
|
53
53
|
list do
|
data/app/workers/print_worker.rb
CHANGED
@@ -1,68 +1,12 @@
|
|
1
1
|
require 'ipaddr'
|
2
2
|
class PrintWorker
|
3
3
|
include Sidekiq::Worker
|
4
|
-
def perform
|
5
|
-
# Checking status only for telnet printers, samba ones cannot be checked
|
6
|
-
is_telnet_printer = IPAddr.new(printer).ipv4? rescue false
|
7
|
-
status = if is_telnet_printer
|
8
|
-
check_status(printer)
|
9
|
-
else
|
10
|
-
"OK"
|
11
|
-
end
|
12
|
-
if status == "OK"
|
13
|
-
begin
|
14
|
-
if is_telnet_printer
|
15
|
-
# Use TCPSocket
|
16
|
-
TCPSocket.new(printer, 9100) do |s|
|
17
|
-
# Rails.logger.debug "TEMPERATURE: #{text}"
|
18
|
-
s.puts(text)
|
19
|
-
end
|
20
|
-
# @printed += 1
|
21
|
-
return true
|
22
|
-
else
|
23
|
-
# Use File.open to print on a windows share
|
24
|
-
# Must be in this format: "\\\\host\\share"
|
25
|
-
# remember to escape \
|
26
|
-
File.open(printer) do |f|
|
27
|
-
f.print(text)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
rescue
|
31
|
-
@pjob.update(iserror: true, description: "PRINTER ERROR: TIMEOUT")
|
32
|
-
return false
|
33
|
-
end
|
34
|
-
else
|
35
|
-
@pjob.update(iserror: true, description: "PRINTER ERROR: #{status}")
|
36
|
-
return false
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def check_status printer
|
4
|
+
def perform printer_cups_name, text
|
41
5
|
begin
|
42
|
-
|
43
|
-
|
44
|
-
# Printer.template può essere anche
|
45
|
-
# una parola di comando epr chiedere lo stato della stampante, solo nel caso sia ok,
|
46
|
-
# Allora mando la stampa
|
47
|
-
s.puts("~HS")
|
48
|
-
# Attende per la risposta (si mette in wait)
|
49
|
-
response = []
|
50
|
-
while (response_text = s.gets)
|
51
|
-
response << response_text
|
52
|
-
break if response.count == 3
|
53
|
-
end
|
54
|
-
s.close
|
55
|
-
Rails.logger.info "PrintIt: RESPONSE: #{response.inspect}"
|
56
|
-
first = response[0].split(",")
|
57
|
-
second = response[1].split(",")
|
58
|
-
return "HEAD UP" if second[2].to_i == 1
|
59
|
-
return "RIBBON OUT" if second[3].to_i == 1
|
60
|
-
return "PAPER OUT" if first[1].to_i == 1
|
61
|
-
return "PAUSE" if first[2].to_i == 1
|
62
|
-
return "OK"
|
6
|
+
printer = CupsPrinter.new printer_cups_name
|
7
|
+
printer.print_data text, 'text/plain'
|
63
8
|
rescue
|
64
|
-
|
65
|
-
return "UNREACHABLE"
|
9
|
+
Rails.logger.debug("PRINTER #{printer_cups_name} ERROR: TIMEOUT")
|
66
10
|
end
|
67
|
-
|
68
|
-
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecore_print_commons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thecore
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cupsffi
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
41
55
|
description: Thecorized thecore_print_commons full description.
|
42
56
|
email:
|
43
57
|
- gabriele.tassoni@gmail.com
|
@@ -49,8 +63,6 @@ files:
|
|
49
63
|
- README.md
|
50
64
|
- Rakefile
|
51
65
|
- app/assets/config/thecore_print_commons_manifest.js
|
52
|
-
- app/models/print_job.rb
|
53
|
-
- app/models/print_template.rb
|
54
66
|
- app/models/printer.rb
|
55
67
|
- app/workers/print_worker.rb
|
56
68
|
- config/initializers/abilities_thecore_print_commons_concern.rb
|
@@ -60,12 +72,7 @@ files:
|
|
60
72
|
- config/locales/telnet_print.it.yml
|
61
73
|
- config/routes.rb
|
62
74
|
- db/migrate/20160323152041_create_printers.rb
|
63
|
-
- db/migrate/20160407141529_create_print_jobs.rb
|
64
|
-
- db/migrate/20160407152547_add_fields_to_print_job.rb
|
65
|
-
- db/migrate/20160407181202_change_column_errors_to_print_job.rb
|
66
75
|
- db/migrate/20160413115407_add_temperature_to_printer.rb
|
67
|
-
- db/migrate/20160519093702_create_print_templates.rb
|
68
|
-
- db/migrate/20160519124051_add_print_template_id_to_printer.rb
|
69
76
|
- db/migrate/20160629140729_add_default_to_printer.rb
|
70
77
|
- lib/tasks/thecore_print_commons_tasks.rake
|
71
78
|
- lib/thecore_print_commons.rb
|
data/app/models/print_job.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class PrintJob < ApplicationRecord
|
2
|
-
belongs_to :printer, inverse_of: :print_jobs
|
3
|
-
|
4
|
-
RailsAdmin.config do |config|
|
5
|
-
config.model 'PrintJob' do
|
6
|
-
# rails_admin do
|
7
|
-
navigation_label I18n.t("admin.settings.label")
|
8
|
-
navigation_icon 'fa fa-check-square'
|
9
|
-
parent Printer
|
10
|
-
|
11
|
-
field :printer
|
12
|
-
field :created_at
|
13
|
-
field :description
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
class PrintTemplate < ApplicationRecord
|
2
|
-
has_many :printers, inverse_of: :print_template
|
3
|
-
|
4
|
-
validates :name, presence: true
|
5
|
-
validates :template, presence: true
|
6
|
-
|
7
|
-
# def translate args
|
8
|
-
# # Rails.logger.info("COME CAZZO SEI FATTO? #{args.inspect}")
|
9
|
-
# temp = template.clone
|
10
|
-
# temp.gsub!("TEMPERATURE", args[:temperature].to_s)
|
11
|
-
# number_of_barcodes.times.with_index do |i|
|
12
|
-
# #Rails.logger.debug "MAMAMAMA! #{args[:items][i]}"
|
13
|
-
# item = (ChosenItem.find(args[:items][i]) rescue false)
|
14
|
-
# HashWithIndifferentAccess.new(YAML.load(translation_matrix)).each_pair do |k, v|
|
15
|
-
# Rails.logger.debug "ITEM: #{item.inspect} AND THE STRING: #{v}"
|
16
|
-
# temp.gsub!(k, item.is_a?(FalseClass) ? "" : v.split(".").inject(item, :send))
|
17
|
-
# end
|
18
|
-
# # Rails.logger.debug "MAMAMAMA! #{item.inspect}"
|
19
|
-
# # Se item è stringa vuota (quindi non ha .barcode), allora ritorna il campo FD remmato
|
20
|
-
# temp.gsub!("BARCODE#{i.to_s.rjust(2, '0')}", (item.barcode rescue "BARCODE#{i.to_s.rjust(2, '0')}"))
|
21
|
-
# end
|
22
|
-
# # Deleting the lines with BARCODE\d\d in them
|
23
|
-
# pivot = ""
|
24
|
-
# temp.each_line do |el|
|
25
|
-
# pivot += el if /BARCODE\d\d/.match(el).blank?
|
26
|
-
# end
|
27
|
-
# Rails.logger.info pivot
|
28
|
-
# pivot
|
29
|
-
# end
|
30
|
-
|
31
|
-
RailsAdmin.config do |config|
|
32
|
-
config.model 'PrintTemplate' do
|
33
|
-
navigation_label I18n.t("admin.settings.label")
|
34
|
-
navigation_icon 'fa fa-file-text'
|
35
|
-
parent Printer
|
36
|
-
|
37
|
-
field :name
|
38
|
-
field :description
|
39
|
-
field :number_of_barcodes
|
40
|
-
|
41
|
-
edit do
|
42
|
-
field :template
|
43
|
-
field :translation_matrix
|
44
|
-
end
|
45
|
-
|
46
|
-
show do
|
47
|
-
field :template
|
48
|
-
field :translation_matrix
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class AddFieldsToPrintJob < ActiveRecord::Migration[4.2]
|
2
|
-
def change
|
3
|
-
add_column :print_jobs, :errors, :boolean
|
4
|
-
add_column :print_jobs, :description, :string
|
5
|
-
add_index :print_jobs, :description
|
6
|
-
add_column :print_jobs, :printed, :integer
|
7
|
-
add_column :print_jobs, :total, :integer
|
8
|
-
end
|
9
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreatePrintTemplates < ActiveRecord::Migration[4.2]
|
2
|
-
def change
|
3
|
-
create_table :print_templates do |t|
|
4
|
-
t.string :name
|
5
|
-
t.text :description
|
6
|
-
t.text :template
|
7
|
-
t.integer :number_of_barcodes
|
8
|
-
t.text :translation_matrix
|
9
|
-
|
10
|
-
t.timestamps null: false
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|