thecore_print_commons 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 548cb34ddf27ecb7f1b9b3692432f975282529a0
4
+ data.tar.gz: ebcaefd79b9ea9fbf5f5cf1c2776bf64b572493b
5
+ SHA512:
6
+ metadata.gz: b4b32cf47eaac6b6a7c3fcfea1fd9459f57eb027884344ffd5bb6df398fa320d09bcfb1aab1939a28715b82f3fd1779eb01efdacb1b10e59d5ea23b52f80d986
7
+ data.tar.gz: b8783b57b95879ca9669394e4eb37052554bf1f380da69c4211c3c3a004a1e1700ecdca6527b4f992ff7dd34db5d715ac0a4a00806ca5624ab1a58c2030cc061
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Gabriele Tassoni
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # ThecorePrintCommons
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'thecore_print_commons'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install thecore_print_commons
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ThecorePrintCommons'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ load 'rails/tasks/statistics.rake'
18
+
19
+ require 'bundler/gem_tasks'
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,49 @@
1
+ class PrintTemplate < ApplicationRecord
2
+ has_many :printers, inverse_of: :print_template
3
+
4
+ # def translate args
5
+ # # Rails.logger.info("COME CAZZO SEI FATTO? #{args.inspect}")
6
+ # temp = template.clone
7
+ # temp.gsub!("TEMPERATURE", args[:temperature].to_s)
8
+ # number_of_barcodes.times.with_index do |i|
9
+ # #Rails.logger.debug "MAMAMAMA! #{args[:items][i]}"
10
+ # item = (ChosenItem.find(args[:items][i]) rescue false)
11
+ # HashWithIndifferentAccess.new(YAML.load(translation_matrix)).each_pair do |k, v|
12
+ # Rails.logger.debug "ITEM: #{item.inspect} AND THE STRING: #{v}"
13
+ # temp.gsub!(k, item.is_a?(FalseClass) ? "" : v.split(".").inject(item, :send))
14
+ # end
15
+ # # Rails.logger.debug "MAMAMAMA! #{item.inspect}"
16
+ # # Se item è stringa vuota (quindi non ha .barcode), allora ritorna il campo FD remmato
17
+ # temp.gsub!("BARCODE#{i.to_s.rjust(2, '0')}", (item.barcode rescue "BARCODE#{i.to_s.rjust(2, '0')}"))
18
+ # end
19
+ # # Deleting the lines with BARCODE\d\d in them
20
+ # pivot = ""
21
+ # temp.each_line do |el|
22
+ # pivot += el if /BARCODE\d\d/.match(el).blank?
23
+ # end
24
+ # Rails.logger.info pivot
25
+ # pivot
26
+ # end
27
+
28
+ RailsAdmin.config do |config|
29
+ config.model 'PrintTemplate' do
30
+ navigation_label I18n.t("admin.settings.label")
31
+ navigation_icon 'fa fa-file-text'
32
+ parent Printer
33
+
34
+ field :name
35
+ field :description
36
+ field :number_of_barcodes
37
+
38
+ edit do
39
+ field :template
40
+ field :translation_matrix
41
+ end
42
+
43
+ show do
44
+ field :template
45
+ field :translation_matrix
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,66 @@
1
+ class Printer < ApplicationRecord
2
+ #serialize :translation, Hash
3
+
4
+ has_many :print_jobs, dependent: :destroy, inverse_of: :printer
5
+ belongs_to :print_template, inverse_of: :printers
6
+
7
+ validates :name, presence: true
8
+ validates :ip, presence: true
9
+ validates :temperature, presence: true
10
+
11
+ # before_save :check_if_unique_default
12
+ # validates :qty, presence: true, numericality: { only_integer: true, greater_than: 0 }
13
+ # validates :translation, presence: true
14
+
15
+ # def template_enum
16
+ # PrintTemplate.descendants
17
+ # end
18
+ #
19
+ # # Array holding all the roles
20
+ # USED = %i[
21
+ # bundle
22
+ # commission
23
+ # ]
24
+ #
25
+ # def used_in_enum
26
+ # # Do not EDIT below this line
27
+ # USED.each_with_index.map {|a,i| [I18n.t("used_in.#{a.to_sym}"), (i+1).to_s]}
28
+ # end
29
+ # def has_section? section
30
+ # # example called from cancan's app/models/ability.rb
31
+ # # if user.has_role? :admin
32
+ #
33
+ # # 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 .
34
+ # USED[self.used_in.to_i - 1].to_s == section.to_s
35
+ # end
36
+ #
37
+ # def self.assigned_to section
38
+ # where(used_in: (USED.index(section.to_sym) + 1))
39
+ # end
40
+
41
+ RailsAdmin.config do |config|
42
+ config.model 'Printer' do
43
+ navigation_label I18n.t("admin.settings.label")
44
+ navigation_icon 'fa fa-print'
45
+
46
+ field :name
47
+ field :ip
48
+ field :default, :toggle
49
+ field :temperature
50
+ field :print_template
51
+ field :description
52
+
53
+ list do
54
+ configure :description do
55
+ visible false
56
+ end
57
+ end
58
+ end
59
+ end
60
+ # private
61
+ # def check_if_unique_default
62
+ # if self.default?
63
+ # Printer.where.not(id: self.id)
64
+ # end
65
+ # end
66
+ end
@@ -0,0 +1,68 @@
1
+ require 'ipaddr'
2
+ class PrintWorker
3
+ include Sidekiq::Worker
4
+ def perform printer, text
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
41
+ begin
42
+ s = TCPSocket.new(printer, 9100)
43
+ # Must create intepolation between item and template
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"
63
+ rescue
64
+ Rails.logger.info "PrintIt: STATUS: UNREACHABLE"
65
+ return "UNREACHABLE"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+
2
+ require 'active_support/concern'
3
+
4
+ module ThecorePrintCommonAbilitiesConcern
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ def thecore_print_commons_abilities user
8
+ if user
9
+ # if the user is logged in, it can do certain tasks regardless his role
10
+ if user.admin?
11
+ # if the user is an admin, it can do a lot of things, usually
12
+ end
13
+
14
+ if user.has_role? :role
15
+ # a specific role, brings specific powers
16
+ end
17
+ cannot [ :create, :update, :destroy, :show, :clone ], PrintJob
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ # include the extension
24
+ TheCoreAbilities.send(:include, ThecorePrintCommonAbilitiesConcern)
@@ -0,0 +1,5 @@
1
+
2
+ Rails.application.configure do
3
+ config.after_initialize do
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ it:
2
+ activerecord:
3
+ models:
4
+ printer:
5
+ one: Stampante
6
+ other: Stampanti
7
+ print_job:
8
+ one: Lavoro di Stampa
9
+ other: Lavori di Stampa
10
+ print_template:
11
+ one: Modello di Stampa
12
+ other: Modelli di Stampa
13
+ attributes:
14
+ printer:
15
+ name: Nome
16
+ description: Descrizione
17
+ ip: Indirizzo IP
18
+ template: Modello di Stampa
19
+ qty: Quantità di Barcode Presenti nel Modello di Stampa
20
+ translation: Matrice di trasformazione
21
+ used_in: Da usare nella Sezione
22
+ print_job:
23
+ finished: Terminata?
24
+ printer: Stampante
25
+ iserror: Errore?
26
+ description: Descrizione
27
+ printed: Stampate
28
+ total: Totale
29
+ created_at: Orario
30
+ print_template:
31
+ name: Nome
32
+ description: Descrizione
33
+ template: Modello ZPL
34
+ number_of_barcodes: Numero di Codici a Barre
35
+ translation_matrix: Matrice di Traduzione
@@ -0,0 +1,11 @@
1
+
2
+ en:
3
+ admin:
4
+ actions:
5
+ telnet_print:
6
+ title: "Telnet Print"
7
+ menu: "Telnet Print for %{model_label} '%{object_label}'"
8
+ breadcrumb: "Telnet Print"
9
+ link: "Telnet Print"
10
+ bulk_link: "Telnet Print selected %{model_label_plural}"
11
+ done: "Telnet Printed"
@@ -0,0 +1,13 @@
1
+ it:
2
+ admin:
3
+ actions:
4
+ telnet_print:
5
+ title: "Stampa Barcode di Rete"
6
+ menu: "Stampa per %{model_label} '%{object_label}'"
7
+ breadcrumb: "Stampa Barcode"
8
+ link: "Stampa Barcode"
9
+ bulk_link: "Stampa barcode: %{model_label_plural}"
10
+ done: "Stampato"
11
+ used_in:
12
+ bundle: Sovracollo
13
+ commission: Barca (Commessa)
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,17 @@
1
+ class CreatePrinters < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :printers do |t|
4
+ t.string :name
5
+ t.text :description
6
+ t.string :ip
7
+ t.text :template
8
+ t.integer :qty
9
+ t.text :translation
10
+
11
+ t.timestamps null: false
12
+ end
13
+ add_index :printers, :name
14
+ add_index :printers, :description
15
+ add_index :printers, :ip
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ class CreatePrintJobs < ActiveRecord::Migration[4.2]
2
+ def change
3
+ create_table :print_jobs do |t|
4
+ t.boolean :finished
5
+ t.references :printer, index: true, foreign_key: true
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,5 @@
1
+ class ChangeColumnErrorsToPrintJob < ActiveRecord::Migration[4.2]
2
+ def change
3
+ rename_column :print_jobs, :errors, :iserror
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddTemperatureToPrinter < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :printers, :temperature, :integer
4
+ end
5
+ end
@@ -0,0 +1,13 @@
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
@@ -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 AddDefaultToPrinter < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :printers, :default, :boolean, default: false
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :thecore_print_commons do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ require "thecore_print_commons/engine"
2
+
3
+ require 'thecore'
4
+ module ThecorePrintCommons
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,14 @@
1
+ module ThecorePrintCommons
2
+ class Engine < ::Rails::Engine
3
+
4
+ initializer 'thecore_print_commons.add_to_migrations' do |app|
5
+ unless app.root.to_s == root.to_s
6
+ # APPEND TO MAIN APP MIGRATIONS FROM THIS GEM
7
+ config.paths['db/migrate'].expanded.each do |expanded_path|
8
+ app.config.paths['db/migrate'] << expanded_path
9
+ end
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module ThecorePrintCommons
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thecore_print_commons
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriele Tassoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thecore
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thecore_background_jobs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ description: Thecorized thecore_print_commons full description.
42
+ email:
43
+ - gabriele.tassoni@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/config/thecore_print_commons_manifest.js
52
+ - app/models/print_job.rb
53
+ - app/models/print_template.rb
54
+ - app/models/printer.rb
55
+ - app/workers/print_worker.rb
56
+ - config/initializers/abilities_thecore_print_commons_concern.rb
57
+ - config/initializers/after_initialize_for_thecore_print_commons.rb
58
+ - config/locales/telnet_print.activerecord.it.yml
59
+ - config/locales/telnet_print.en.yml
60
+ - config/locales/telnet_print.it.yml
61
+ - config/routes.rb
62
+ - 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
+ - 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
+ - db/migrate/20160629140729_add_default_to_printer.rb
70
+ - lib/tasks/thecore_print_commons_tasks.rake
71
+ - lib/thecore_print_commons.rb
72
+ - lib/thecore_print_commons/engine.rb
73
+ - lib/thecore_print_commons/version.rb
74
+ homepage: https://github.com/gabrieletassoni/thecore
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.14
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Thecorized thecore_print_commons
98
+ test_files: []