thecore_print_commons 2.1.2 → 2.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/concerns/api/printer.rb +32 -0
- data/app/models/printer.rb +2 -53
- data/app/workers/print_worker.rb +4 -70
- data/config/initializers/abilities_thecore_print_commons_concern.rb +0 -14
- data/db/seeds.rb +0 -1
- metadata +2 -7
- data/app/models/concerns/api/print_job.rb +0 -30
- data/app/models/concerns/rails_admin/print_job.rb +0 -19
- data/app/models/print_job.rb +0 -10
- data/db/migrate/20160407141529_create_print_jobs.rb +0 -10
- data/db/migrate/20160407152547_add_fields_to_print_job.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ea66f408d04dee9a18484a617f170c16ca1e74ce5011b87b2063b25cfd86c0b
|
4
|
+
data.tar.gz: 85566448eaa20b0601a4b82e17f5d668bfefdb1e3b565c099d91bf066e463228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4ee226bad981af3220ba0eb1dda3a4699c1967c45278a2e18fccfdca5494bbcced4a0f6f0cedaa608badb5702db4164bbddc9cfd23989c80df9a2ac9c84606a
|
7
|
+
data.tar.gz: 4abcbc5eea0f199b71696b2075ef3b23c4af111c1d9d51bb2c636fa7928f302f860c4494212dbb74def14d89e50713fb33c6cbd09d738dd73a3c3af78aaf4d43
|
@@ -41,5 +41,37 @@ module Api::Printer
|
|
41
41
|
::PrintWorker.perform_async(printer.ip, printer.port, text)
|
42
42
|
{ info: "Print job sent in background to #{printer.ip} on port #{printer.port}" }
|
43
43
|
end
|
44
|
+
|
45
|
+
def self.custom_action_printer_status params
|
46
|
+
printer = Printer.find(params[:id])
|
47
|
+
ip = printer.ip
|
48
|
+
port = printer.port
|
49
|
+
begin
|
50
|
+
s = Socket.tcp ip, port, connect_timeout: 0.5
|
51
|
+
# Must create intepolation between item and template
|
52
|
+
# Printer.template può essere anche
|
53
|
+
# una parola di comando epr chiedere lo stato della stampante, solo nel caso sia ok,
|
54
|
+
# Allora mando la stampa
|
55
|
+
s.puts("~hs")
|
56
|
+
# Attende per la risposta (si mette in wait)
|
57
|
+
response = []
|
58
|
+
while (response_text = s.gets)
|
59
|
+
response << response_text
|
60
|
+
break if response.count == 3
|
61
|
+
end
|
62
|
+
s.close
|
63
|
+
# Rails.logger.info "PrintIt: RESPONSE: #{response.inspect}"
|
64
|
+
first = response[0].split(",")
|
65
|
+
second = response[1].split(",")
|
66
|
+
return "HEAD UP" if second[2].to_i == 1
|
67
|
+
return "RIBBON OUT" if second[3].to_i == 1
|
68
|
+
return "PAPER OUT" if first[1].to_i == 1
|
69
|
+
return "PAUSE" if first[2].to_i == 1
|
70
|
+
return "OK"
|
71
|
+
rescue
|
72
|
+
Rails.logger.info "PrintIt: STATUS: UNREACHABLE"
|
73
|
+
return "UNREACHABLE"
|
74
|
+
end
|
75
|
+
end
|
44
76
|
end
|
45
77
|
end
|
data/app/models/printer.rb
CHANGED
@@ -1,52 +1,8 @@
|
|
1
1
|
class Printer < ApplicationRecord
|
2
2
|
include Api::Printer
|
3
3
|
include RailsAdmin::Printer
|
4
|
-
#serialize :translation, Hash
|
5
|
-
|
6
|
-
# before_save :check_if_unique_default
|
7
|
-
# validates :qty, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
8
|
-
# validates :translation, presence: true
|
9
|
-
|
10
|
-
# def template_enum
|
11
|
-
# PrintTemplate.descendants
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# # Array holding all the roles
|
15
|
-
# USED = %i[
|
16
|
-
# bundle
|
17
|
-
# commission
|
18
|
-
# ]
|
19
|
-
#
|
20
|
-
# def used_in_enum
|
21
|
-
# # Do not EDIT below this line
|
22
|
-
# USED.each_with_index.map {|a,i| [I18n.t("used_in.#{a.to_sym}"), (i+1).to_s]}
|
23
|
-
# end
|
24
|
-
# def has_section? section
|
25
|
-
# # example called from cancan's app/models/ability.rb
|
26
|
-
# # if user.has_role? :admin
|
27
|
-
#
|
28
|
-
# # for roles array stored in db... take each value, see if it matches the second column in the roles_enum array, if so, retu the 1st col of the enum as a uprcase,space_to_underscore,symbol .
|
29
|
-
# USED[self.used_in.to_i - 1].to_s == section.to_s
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# def self.assigned_to section
|
33
|
-
# where(used_in: (USED.index(section.to_sym) + 1))
|
34
|
-
# end
|
35
|
-
|
36
|
-
# Usable with CUPS (STUB)
|
37
|
-
# def ip_enum
|
38
|
-
# # Getting from CUPS the list of configured printers
|
39
|
-
# if Settings.ns(:printer_commons).cups_server.blank? || ['127.0.0.1', 'localhost'].include?(Settings.ns(:printer_commons).cups_server)
|
40
|
-
# # Local Cups server
|
41
|
-
# CupsPrinter.get_all_printer_names
|
42
|
-
# else
|
43
|
-
# # Remote Cups server
|
44
|
-
# CupsPrinter.get_all_printer_names hostname: Settings.ns(:printer_commons).cups_server
|
45
|
-
# end
|
46
|
-
# end
|
47
4
|
|
48
5
|
belongs_to :print_template, inverse_of: :printers
|
49
|
-
has_many :print_jobs, dependent: :destroy, inverse_of: :printer
|
50
6
|
|
51
7
|
validates :name, presence: true
|
52
8
|
validates :ip, presence: true
|
@@ -55,18 +11,11 @@ class Printer < ApplicationRecord
|
|
55
11
|
|
56
12
|
def online?
|
57
13
|
begin
|
58
|
-
Socket.tcp(self.ip,
|
14
|
+
Socket.tcp(self.ip, self.port, connect_timeout: 0.5).close
|
59
15
|
rescue
|
60
16
|
return false
|
61
17
|
end
|
62
18
|
true
|
63
19
|
end
|
64
|
-
|
65
|
-
|
66
|
-
# private
|
67
|
-
# def check_if_unique_default
|
68
|
-
# if self.default?
|
69
|
-
# Printer.where.not(id: self.id)
|
70
|
-
# end
|
71
|
-
# end
|
20
|
+
|
72
21
|
end
|
data/app/workers/print_worker.rb
CHANGED
@@ -2,78 +2,12 @@ require 'ipaddr'
|
|
2
2
|
require 'socket'
|
3
3
|
class PrintWorker
|
4
4
|
include Sidekiq::Worker
|
5
|
-
sidekiq_options retry: false
|
5
|
+
sidekiq_options retry: false, queue: "#{ENV["COMPOSE_PROJECT_NAME"]}_default"
|
6
6
|
|
7
7
|
# ZPL print
|
8
8
|
def perform ip, port, text
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
if status == "OK"
|
13
|
-
begin
|
14
|
-
streamSock = TCPSocket.new ip, port
|
15
|
-
streamSock.send text, 0
|
16
|
-
streamSock.close
|
17
|
-
print_job_status = true
|
18
|
-
rescue
|
19
|
-
@pjob.update(iserror: true, description: "PRINTER ERROR: TIMEOUT")
|
20
|
-
print_job_status = false
|
21
|
-
end
|
22
|
-
else
|
23
|
-
@pjob.update(iserror: true, description: "PRINTER ERROR: #{status}")
|
24
|
-
print_job_status = false
|
25
|
-
end
|
26
|
-
# '~hs alla posizione 56 per 8 caratteri la quantità di etichette rimaste'
|
27
|
-
total = text.scan(/~PQ(\d+)/).last.first.to_i rescue 0
|
28
|
-
@pjob.update(printed: (print_job_status ? total : 0)) # Se risultato true, allora ha stampato tutto, altrimenti non ha stampato nulla
|
29
|
-
@pjob.update(total: total) # In realtà è inutile, ora manda tutto quello che può alla stampante, solo lei può andare storta
|
30
|
-
@pjob.update(finished: print_job_status)
|
9
|
+
streamSock = Socket.tcp ip, port, connect_timeout: 0.5
|
10
|
+
streamSock.send text, 0
|
11
|
+
streamSock.close
|
31
12
|
end
|
32
|
-
|
33
|
-
def check_status printer
|
34
|
-
begin
|
35
|
-
s = TCPSocket.new(printer, 9100)
|
36
|
-
# Must create intepolation between item and template
|
37
|
-
# Printer.template può essere anche
|
38
|
-
# una parola di comando epr chiedere lo stato della stampante, solo nel caso sia ok,
|
39
|
-
# Allora mando la stampa
|
40
|
-
s.puts("~hs")
|
41
|
-
# Attende per la risposta (si mette in wait)
|
42
|
-
response = []
|
43
|
-
while (response_text = s.gets)
|
44
|
-
response << response_text
|
45
|
-
break if response.count == 3
|
46
|
-
end
|
47
|
-
s.close
|
48
|
-
Rails.logger.info "PrintIt: RESPONSE: #{response.inspect}"
|
49
|
-
first = response[0].split(",")
|
50
|
-
second = response[1].split(",")
|
51
|
-
return "HEAD UP" if second[2].to_i == 1
|
52
|
-
return "RIBBON OUT" if second[3].to_i == 1
|
53
|
-
return "PAPER OUT" if first[1].to_i == 1
|
54
|
-
return "PAUSE" if first[2].to_i == 1
|
55
|
-
return "OK"
|
56
|
-
rescue
|
57
|
-
Rails.logger.info "PrintIt: STATUS: UNREACHABLE"
|
58
|
-
return "UNREACHABLE"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# This is for cups only
|
63
|
-
# def perform printer_cups_name, text
|
64
|
-
# # if Settings.ns(:printer_commons).cups_server.blank? || ['127.0.0.1', 'localhost'].contains(Settings.ns(:printer_commons).cups_server)
|
65
|
-
# # printer = CupsPrinter.new printer_cups_name
|
66
|
-
# # printer.print_data text, 'text/plain'
|
67
|
-
# # printer.close
|
68
|
-
# # else
|
69
|
-
# print_file = "/tmp/print-#{printer_cups_name}-#{Time.now.strftime '%Y%m%d%H%M%S%L'}"
|
70
|
-
# puts "Creating temp file: #{print_file}"
|
71
|
-
# IO.write(print_file, text)
|
72
|
-
# # CupsPrinter.new printer_cups_name, hostname: Settings.ns(:printer_commons).cups_server
|
73
|
-
# # printer.print_data text, 'text/plain', hostname: Settings.ns(:printer_commons).cups_server
|
74
|
-
# puts "Printing with lp command on #{printer_cups_name} of #{Settings.ns(:printer_commons).cups_server} "
|
75
|
-
# `cupsenable "#{printer_cups_name}";lp -d "#{printer_cups_name}" -h "#{Settings.ns(:printer_commons).cups_server}" -o raw "#{print_file}"`
|
76
|
-
# File.delete print_file
|
77
|
-
# # end
|
78
|
-
# end
|
79
13
|
end
|
@@ -2,21 +2,7 @@ module Abilities
|
|
2
2
|
class ThecorePrintCommon
|
3
3
|
include CanCan::Ability
|
4
4
|
def initialize user
|
5
|
-
cannot [:destroy, :create, :update, :show], [PrintJob]
|
6
|
-
# if user
|
7
|
-
# cannot :edi
|
8
|
-
# # if the user is logged in, it can do certain tasks regardless his role
|
9
|
-
# if user.admin?
|
10
|
-
# # if the user is an admin, it can do a lot of things, usually
|
11
|
-
# end
|
12
|
-
|
13
|
-
# if user.has_role? :role
|
14
|
-
# # a specific role, brings specific powers
|
15
|
-
# end
|
16
|
-
# end
|
17
5
|
end
|
18
6
|
end
|
19
7
|
end
|
20
8
|
|
21
|
-
# # include the extension
|
22
|
-
# TheCoreAbilities.send(:include, ThecorePrintCommonAbilitiesConcern)
|
data/db/seeds.rb
CHANGED
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: 2.1.
|
4
|
+
version: 2.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thecore_background_jobs
|
@@ -35,13 +35,10 @@ files:
|
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
37
|
- app/assets/config/thecore_print_commons_manifest.js
|
38
|
-
- app/models/concerns/api/print_job.rb
|
39
38
|
- app/models/concerns/api/print_template.rb
|
40
39
|
- app/models/concerns/api/printer.rb
|
41
|
-
- app/models/concerns/rails_admin/print_job.rb
|
42
40
|
- app/models/concerns/rails_admin/print_template.rb
|
43
41
|
- app/models/concerns/rails_admin/printer.rb
|
44
|
-
- app/models/print_job.rb
|
45
42
|
- app/models/print_template.rb
|
46
43
|
- app/models/printer.rb
|
47
44
|
- app/workers/print_worker.rb
|
@@ -53,8 +50,6 @@ files:
|
|
53
50
|
- config/locales/telnet_print.it.yml
|
54
51
|
- config/routes.rb
|
55
52
|
- db/migrate/20160323152041_create_printers.rb
|
56
|
-
- db/migrate/20160407141529_create_print_jobs.rb
|
57
|
-
- db/migrate/20160407152547_add_fields_to_print_job.rb
|
58
53
|
- db/migrate/20160413115407_add_temperature_to_printer.rb
|
59
54
|
- db/migrate/20160519093702_create_print_templates.rb
|
60
55
|
- db/migrate/20160519124051_add_print_template_id_to_printer.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Api::PrintJob
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
# Use @@json_attrs to drive json rendering for
|
6
|
-
# API model responses (index, show and update ones).
|
7
|
-
# For reference:
|
8
|
-
# https://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html
|
9
|
-
# The object passed accepts only these keys:
|
10
|
-
# - only: list [] of model fields to be shown in JSON serialization
|
11
|
-
# - except: exclude these fields from the JSON serialization, is a list []
|
12
|
-
# - methods: include the result of some method defined in the model
|
13
|
-
# - include: include associated models, it's an object {} which also accepts the keys described here
|
14
|
-
cattr_accessor :json_attrs
|
15
|
-
@@json_attrs = ::ModelDrivenApi.smart_merge (json_attrs || {}), {}
|
16
|
-
|
17
|
-
# Here you can add custom actions to be called from the API
|
18
|
-
# The action must return an serializable (JSON) object.
|
19
|
-
# Here you can find an example, in the API could be called like:
|
20
|
-
#
|
21
|
-
# GET /api/v2/:model/:id?do=test&custom_parameter=hello
|
22
|
-
#
|
23
|
-
# Please uncomment it to test with a REST client.
|
24
|
-
# Please take note on the fact that, if the do params is test, the custom
|
25
|
-
# action definition must be, like below self.custom_action_test.
|
26
|
-
# def self.custom_action_test id=nil, params=nil
|
27
|
-
# { test: [ :first, :second, :third ], id: id, params: params}
|
28
|
-
# end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module RailsAdmin::PrintJob
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
included do
|
4
|
-
# Here You can define the RailsAdmin DSL
|
5
|
-
rails_admin 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
|
-
list do
|
15
|
-
field :printed_on_total
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/app/models/print_job.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
class AddFieldsToPrintJob < ActiveRecord::Migration[4.2]
|
2
|
-
def change
|
3
|
-
add_column :print_jobs, :iserror, :boolean, default: false
|
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
|