thecore_print_commons 2.0.4 → 2.0.5

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
  SHA256:
3
- metadata.gz: 20490e2bec2c6919724f04c00661c14d12f204586d72ac01d9bd7f3c45530cc0
4
- data.tar.gz: 1d7557c8e12cd17654946c8c349f2a4599f19ace38d24aff12bb0b96b5bfab89
3
+ metadata.gz: 9f3ed9656158d431f6b333cad8a2cff5765e156aa6ac79adebdbbb43b762b3fa
4
+ data.tar.gz: d102212098bbe2893ef2df934727f3b7156a871d935281270dab00d500743034
5
5
  SHA512:
6
- metadata.gz: 27956ae172465597f1d504728d57ca1fcfbc993e20baec5eccd47c174934fea7fba9aae3218cc4c693e99075c5ba5fdc7a28b04fb47cbcdd9dfa0a259a34df5d
7
- data.tar.gz: c0018f9793689d4ca15539869c3701afd7773d0f333fa6fda133cc86c80b1305dc7cbc3e7537a9fbf2076e776f5dd0d503e91df2276779e0af82ed6581c618c0
6
+ metadata.gz: f0dcf1b245cff90c369119f50fa5bf7484e6e73f2d36766c98fd918b63ecd3ab8e11fa9bf2dfe5acdcb132dbedb8dae020588c0246ca44829175dd58390f27a3
7
+ data.tar.gz: 3d91398f7df48f4edb37a39e46fc20f46f26f41df4d2693d97d724c2f2147223433eda906842ecc4abe486e07c111e7711104cbaa6680332d90b02394862c8ed
@@ -0,0 +1,30 @@
1
+ module Api::PrintTemplate
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
@@ -0,0 +1,43 @@
1
+ module Api::Printer
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
+
30
+ def self.custom_action_print id
31
+ # Example Usage:
32
+ # item = ::Item.joins(:projects).where(projects: {id: params[:order_id].to_i}).first
33
+ # printer = ::Printer.where(supplier_id: current_user.supplier_id, default: true).first
34
+ # single_text = "#{printer.print_template.template.gsub("%DESCRIPTION%", item.description)}"
35
+ # text = single_text * params[:quantity].to_i
36
+ # # Preso l'ordine mi recupero l'item e ne stampo la quantità richiesta
37
+ # ::PrintWorker.perform_async(printer.ip, text)
38
+
39
+ ::PrintWorker.perform_async(printer.ip, printer.port, text)
40
+ { info: "Print job sent in background to #{printer.ip} on port #{printer.port}" }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ module RailsAdmin::PrintTemplate
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ # Here You can define the RailsAdmin DSL
5
+ rails_admin do
6
+ navigation_label I18n.t("admin.settings.label")
7
+ navigation_icon 'fa fa-file-text'
8
+ parent Printer
9
+
10
+ field :name
11
+ field :description
12
+
13
+ edit do
14
+ field :template
15
+ field :translation_matrix
16
+ end
17
+
18
+ show do
19
+ field :template
20
+ field :translation_matrix
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module RailsAdmin::Printer
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ # Here You can define the RailsAdmin DSL
5
+ rails_admin do
6
+ navigation_label I18n.t("admin.settings.label")
7
+ navigation_icon 'fa fa-print'
8
+
9
+ field :print_template
10
+ field :name
11
+ field :ip
12
+ field :port do
13
+ default_value do
14
+ 9100
15
+ end
16
+ end
17
+ field :default, :toggle
18
+ field :temperature
19
+ field :description
20
+
21
+ list do
22
+ configure :description do
23
+ visible false
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ class PrintTemplate < ApplicationRecord
2
+ include Api::PrintTemplate
3
+ include RailsAdmin::PrintTemplate
4
+
5
+ has_many :printers, inverse_of: :print_template
6
+
7
+ validates :name, presence: true
8
+ validates :template, presence: true
9
+
10
+ # def translate args
11
+ # # Rails.logger.info("COME CAZZO SEI FATTO? #{args.inspect}")
12
+ # temp = template.clone
13
+ # temp.gsub!("TEMPERATURE", args[:temperature].to_s)
14
+ # number_of_barcodes.times.with_index do |i|
15
+ # #Rails.logger.debug "MAMAMAMA! #{args[:items][i]}"
16
+ # item = (ChosenItem.find(args[:items][i]) rescue false)
17
+ # HashWithIndifferentAccess.new(YAML.load(translation_matrix)).each_pair do |k, v|
18
+ # Rails.logger.debug "ITEM: #{item.inspect} AND THE STRING: #{v}"
19
+ # temp.gsub!(k, item.is_a?(FalseClass) ? "" : v.split(".").inject(item, :send))
20
+ # end
21
+ # # Rails.logger.debug "MAMAMAMA! #{item.inspect}"
22
+ # # Se item è stringa vuota (quindi non ha .barcode), allora ritorna il campo FD remmato
23
+ # temp.gsub!("BARCODE#{i.to_s.rjust(2, '0')}", (item.barcode rescue "BARCODE#{i.to_s.rjust(2, '0')}"))
24
+ # end
25
+ # # Deleting the lines with BARCODE\d\d in them
26
+ # pivot = ""
27
+ # temp.each_line do |el|
28
+ # pivot += el if /BARCODE\d\d/.match(el).blank?
29
+ # end
30
+ # Rails.logger.info pivot
31
+ # pivot
32
+ # end
33
+
34
+ end
@@ -1,9 +1,8 @@
1
1
  class Printer < ApplicationRecord
2
+ include Api::Printer
3
+ include RailsAdmin::Printer
2
4
  #serialize :translation, Hash
3
5
 
4
- validates :name, presence: true
5
- validates :ip, presence: true
6
-
7
6
  # before_save :check_if_unique_default
8
7
  # validates :qty, presence: true, numericality: { only_integer: true, greater_than: 0 }
9
8
  # validates :translation, presence: true
@@ -34,35 +33,25 @@ class Printer < ApplicationRecord
34
33
  # where(used_in: (USED.index(section.to_sym) + 1))
35
34
  # end
36
35
 
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
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
47
 
48
- RailsAdmin.config do |config|
49
- config.model 'Printer' do
50
- navigation_label I18n.t("admin.settings.label")
51
- navigation_icon 'fa fa-print'
48
+ belongs_to :print_template, inverse_of: :printers
52
49
 
53
- field :name
54
- field :ip
55
- field :default, :toggle
56
- field :temperature
57
- field :description
50
+ validates :name, presence: true
51
+ validates :ip, presence: true
52
+ validates :port, presence: true
58
53
 
59
- list do
60
- configure :description do
61
- visible false
62
- end
63
- end
64
- end
65
- end
54
+
66
55
  # private
67
56
  # def check_if_unique_default
68
57
  # if self.default?
@@ -1,22 +1,31 @@
1
1
  require 'ipaddr'
2
+ require 'socket'
2
3
  class PrintWorker
3
4
  include Sidekiq::Worker
4
5
  sidekiq_options retry: false
5
6
 
6
- def perform printer_cups_name, text
7
- # if Settings.ns(:printer_commons).cups_server.blank? || ['127.0.0.1', 'localhost'].contains(Settings.ns(:printer_commons).cups_server)
8
- # printer = CupsPrinter.new printer_cups_name
9
- # printer.print_data text, 'text/plain'
10
- # printer.close
11
- # else
12
- print_file = "/tmp/print-#{printer_cups_name}-#{Time.now.strftime '%Y%m%d%H%M%S%L'}"
13
- puts "Creating temp file: #{print_file}"
14
- IO.write(print_file, text)
15
- # CupsPrinter.new printer_cups_name, hostname: Settings.ns(:printer_commons).cups_server
16
- # printer.print_data text, 'text/plain', hostname: Settings.ns(:printer_commons).cups_server
17
- puts "Printing with lp command on #{printer_cups_name} of #{Settings.ns(:printer_commons).cups_server} "
18
- `cupsenable "#{printer_cups_name}";lp -d "#{printer_cups_name}" -h "#{Settings.ns(:printer_commons).cups_server}" -o raw "#{print_file}"`
19
- File.delete print_file
20
- # end
7
+ # ZPL print
8
+ def perform ip, port, text
9
+ streamSock = TCPSocket.new ip, port
10
+ streamSock.send text, 0
11
+ streamSock.close
21
12
  end
13
+
14
+ # This is for cups only
15
+ # def perform printer_cups_name, text
16
+ # # if Settings.ns(:printer_commons).cups_server.blank? || ['127.0.0.1', 'localhost'].contains(Settings.ns(:printer_commons).cups_server)
17
+ # # printer = CupsPrinter.new printer_cups_name
18
+ # # printer.print_data text, 'text/plain'
19
+ # # printer.close
20
+ # # else
21
+ # print_file = "/tmp/print-#{printer_cups_name}-#{Time.now.strftime '%Y%m%d%H%M%S%L'}"
22
+ # puts "Creating temp file: #{print_file}"
23
+ # IO.write(print_file, text)
24
+ # # CupsPrinter.new printer_cups_name, hostname: Settings.ns(:printer_commons).cups_server
25
+ # # printer.print_data text, 'text/plain', hostname: Settings.ns(:printer_commons).cups_server
26
+ # puts "Printing with lp command on #{printer_cups_name} of #{Settings.ns(:printer_commons).cups_server} "
27
+ # `cupsenable "#{printer_cups_name}";lp -d "#{printer_cups_name}" -h "#{Settings.ns(:printer_commons).cups_server}" -o raw "#{print_file}"`
28
+ # File.delete print_file
29
+ # # end
30
+ # end
22
31
  end
@@ -0,0 +1,12 @@
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.text :translation_matrix
8
+
9
+ t.timestamps null: false
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddPrintTemplateIdToPrinter < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_reference :printers, :print_template, index: true, foreign_key: true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddPortToPrinter < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :printers, :port, :integer, default: 9100
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  require 'thecore_background_jobs'
2
- require 'cupsffi'
2
+ # require 'cupsffi'
3
3
  require "thecore_print_commons/engine"
4
4
 
5
5
  module ThecorePrintCommons
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.0.4
4
+ version: 2.0.5
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-03-16 00:00:00.000000000 Z
11
+ date: 2021-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thecore_background_jobs
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: cupsffi
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.1'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.1'
41
27
  description: Thecorized thecore_print_commons full description.
42
28
  email:
43
29
  - gabriele.tassoni@gmail.com
@@ -49,6 +35,11 @@ files:
49
35
  - README.md
50
36
  - Rakefile
51
37
  - app/assets/config/thecore_print_commons_manifest.js
38
+ - app/models/concerns/api/print_template.rb
39
+ - app/models/concerns/api/printer.rb
40
+ - app/models/concerns/rails_admin/print_template.rb
41
+ - app/models/concerns/rails_admin/printer.rb
42
+ - app/models/print_template.rb
52
43
  - app/models/printer.rb
53
44
  - app/workers/print_worker.rb
54
45
  - config/initializers/abilities_thecore_print_commons_concern.rb
@@ -60,7 +51,10 @@ files:
60
51
  - config/routes.rb
61
52
  - db/migrate/20160323152041_create_printers.rb
62
53
  - db/migrate/20160413115407_add_temperature_to_printer.rb
54
+ - db/migrate/20160519093702_create_print_templates.rb
55
+ - db/migrate/20160519124051_add_print_template_id_to_printer.rb
63
56
  - db/migrate/20160629140729_add_default_to_printer.rb
57
+ - db/migrate/20160629140730_add_port_to_printer.rb
64
58
  - db/seeds.rb
65
59
  - lib/tasks/thecore_print_commons_tasks.rake
66
60
  - lib/thecore_print_commons.rb
@@ -85,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
79
  - !ruby/object:Gem::Version
86
80
  version: '0'
87
81
  requirements: []
88
- rubygems_version: 3.0.3
82
+ rubygems_version: 3.0.3.1
89
83
  signing_key:
90
84
  specification_version: 4
91
85
  summary: Thecorized thecore_print_commons