rails_admin_telnet_print 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19be9e11aa1d67ab5f02487e19e268f61e151e47
4
+ data.tar.gz: 930b1588c1f6bd9fd77f7bc5a4c523b90ff06ea0
5
+ SHA512:
6
+ metadata.gz: cbdc26b7e4108e271d3178ea74f47061855aad70fbd170ba1d513522747dfd426e993cf75d0d79d22123100e19144f6a5dee0ade0c6b80ded5abfbbd96a0b136
7
+ data.tar.gz: fcbc1cc98f72717373df46bd5192e2d0853ebaccae93de64cc9475a6cee068892ce9852c24fe9f31cf253bf0b63d4144bf18978dbb1fc6ba8ea0ed34e2321a88
@@ -0,0 +1,20 @@
1
+ Copyright 2016 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,3 @@
1
+ = RailsAdminTelnetPrint
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,24 @@
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 = 'RailsAdminTelnetPrint'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,33 @@
1
+ class CancelJob < ApplicationJob
2
+ queue_as :default
3
+
4
+ # def perform(*args)
5
+
6
+ # Legenda errori:
7
+ # TIMEOUT: indirizzo della stampante non raggiungibile durante la stampa
8
+ # UNREACHABLE: indirizzo della stampante non raggiungibile durante il controllo dello stato della stampante
9
+ # HEAD UP: coperchio aperto
10
+ # RIBBON OUT: ribbon terminato
11
+ # PAPER OUT: carta terminata
12
+ # PAUSE: stampante in pausa
13
+ # OK: nessun errore
14
+
15
+ def perform model_name, id, printer_id
16
+ # Do something later
17
+ printer = Printer.find(printer_id.to_i)
18
+ send_to_printer printer.ip, "~ja"
19
+ end
20
+
21
+ def send_to_printer printer, text
22
+ begin
23
+ s = TCPSocket.new(printer, 9100)
24
+ # Rails.logger.debug "TEMPERATURE: #{text}"
25
+ s.puts(text)
26
+ s.close
27
+ @printed += 1
28
+ return true
29
+ rescue
30
+ return false
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,87 @@
1
+ class PrintItJob < ApplicationJob
2
+ queue_as :default
3
+ # Legenda errori:
4
+ # TIMEOUT: indirizzo della stampante non raggiungibile durante la stampa
5
+ # UNREACHABLE: indirizzo della stampante non raggiungibile durante il controllo dello stato della stampante
6
+ # HEAD UP: coperchio aperto
7
+ # RIBBON OUT: ribbon terminato
8
+ # PAPER OUT: carta terminata
9
+ # PAUSE: stampante in pausa
10
+ # OK: nessun errore
11
+
12
+ def perform model_name, id, printer_id
13
+ # Do something later
14
+ printer = Printer.find(printer_id.to_i)
15
+ print_template = printer.print_template
16
+ #Rails.logger.info "MOMERDA 2: #{model_name.constantize.inspect}"
17
+ header = model_name.constantize.find(id)
18
+ items = header.records_for_print(id).order(code: :asc)
19
+
20
+ pivot = []
21
+ @pjob = PrintJob.create(printer_id: printer.id, finished: false, iserror: false, total: ((items.count.to_f / print_template.number_of_barcodes).ceil rescue 0), printed: @printed)
22
+ # Spezzetto l'array degli items in gruppi di number_of_barcodes
23
+ # Rails.logger.info "BELLAAAAAAA! #{items.group_by.with_index{|_, i| i % print_template.number_of_barcodes}.values.inspect}"
24
+ items.each_slice(print_template.number_of_barcodes) do |item_group|
25
+ # Rails.logger.info "ITEMGROUP: #{item_group.inspect}"
26
+ barcodes = item_group.map(&:id)
27
+ barcodes = barcodes.fill("", barcodes.length..(print_template.number_of_barcodes - 1)) if print_template.number_of_barcodes > barcodes.length
28
+ # Rails.logger.info "AAAAHHHHHHHHHH: #{barcodes.inspect}"
29
+ pivot.push print_template.translate(header: header, items: barcodes, temperature: printer.temperature)
30
+ # Rails.logger.info "BARCODES: #{barcodes.inspect}"
31
+ # Se il risultato è un errore, allora mi fermo completamente e loggo il numero di particolari stampati
32
+ # Rails.logger.info "RISULTATO: #{result}"
33
+ end
34
+
35
+ result = pivot.empty? ? false : send_to_printer(printer.ip, pivot.join(""))
36
+ @pjob.update(printed: pivot.length)
37
+ @pjob.update(finished: result)
38
+ end
39
+
40
+ def send_to_printer printer, text
41
+ status = check_status(printer)
42
+ if status == "OK"
43
+ begin
44
+ s = TCPSocket.new(printer, 9100)
45
+ # Rails.logger.debug "TEMPERATURE: #{text}"
46
+ s.puts(text)
47
+ s.close
48
+ # @printed += 1
49
+ return true
50
+ rescue
51
+ @pjob.update(iserror: true, description: "PRINTER ERROR: TIMEOUT")
52
+ return false
53
+ end
54
+ else
55
+ @pjob.update(iserror: true, description: "PRINTER ERROR: #{status}")
56
+ return false
57
+ end
58
+ end
59
+
60
+ def check_status printer
61
+ begin
62
+ s = TCPSocket.new(printer, 9100)
63
+ # Must create intepolation between item and template
64
+ # Printer.template può essere anche
65
+ # una parola di comando epr chiedere lo stato della stampante, solo nel caso sia ok,
66
+ # Allora mando la stampa
67
+ s.puts("~hs")
68
+ # Attende per la risposta (si mette in wait)
69
+ response = []
70
+ while (response_text = s.gets)
71
+ response << response_text
72
+ break if response.count == 3
73
+ end
74
+ s.close
75
+ puts response.inspect
76
+ first = response[0].split(",")
77
+ second = response[1].split(",")
78
+ return "HEAD UP" if second[2].to_i == 1
79
+ return "RIBBON OUT" if second[3].to_i == 1
80
+ return "PAPER OUT" if first[1].to_i == 1
81
+ return "PAUSE" if first[2].to_i == 1
82
+ return "OK"
83
+ rescue
84
+ return "UNREACHABLE"
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,85 @@
1
+ class PrintSingleJob < ApplicationJob
2
+ queue_as :default
3
+ # Legenda errori:
4
+ # TIMEOUT: indirizzo della stampante non raggiungibile durante la stampa
5
+ # UNREACHABLE: indirizzo della stampante non raggiungibile durante il controllo dello stato della stampante
6
+ # HEAD UP: coperchio aperto
7
+ # RIBBON OUT: ribbon terminato
8
+ # PAPER OUT: carta terminata
9
+ # PAUSE: stampante in pausa
10
+ # OK: nessun errore
11
+
12
+ def perform model_name, id, printer_id, item_id
13
+ # Do something later
14
+ printer = Printer.find(printer_id.to_i)
15
+ print_template = printer.print_template
16
+ #Rails.logger.info "MOMERDA 2: #{model_name.constantize.inspect}"
17
+ header = model_name.constantize.find(id)
18
+ item = ChosenItem.find(item_id)
19
+ @printed = 0
20
+
21
+ @pjob = PrintJob.create(printer_id: printer.id, finished: false, iserror: false, total: 1, printed: @printed)
22
+ # Spezzetto l'array degli items in gruppi di number_of_barcodes
23
+ # Rails.logger.info "BELLAAAAAAA! #{items.group_by.with_index{|_, i| i % print_template.number_of_barcodes}.values.inspect}"
24
+
25
+ # Rails.logger.info "ITEMGROUP: #{item_group.inspect}"
26
+
27
+ # Rails.logger.info "AAAAHHHHHHHHHH: #{barcodes.inspect}"
28
+ translation = print_template.translate(header: header, items: [item.id], temperature: printer.temperature)
29
+ # Rails.logger.info "BARCODES: #{barcodes.inspect}"
30
+ result = send_to_printer printer.ip, translation
31
+ # Se il risultato è un errore, allora mi fermo completamente e loggo il numero di particolari stampati
32
+ # Rails.logger.info "RISULTATO: #{result}"
33
+ return unless result
34
+ @pjob.update(printed: @printed)
35
+ @pjob.update(finished: true)
36
+ end
37
+
38
+ def send_to_printer printer, text
39
+ status = check_status(printer)
40
+ if status == "OK"
41
+ begin
42
+ s = TCPSocket.new(printer, 9100)
43
+ # Rails.logger.debug "TEMPERATURE: #{text}"
44
+ s.puts(text)
45
+ s.close
46
+ @printed += 1
47
+ return true
48
+ rescue
49
+ @pjob.update(iserror: true, description: "PRINTER ERROR: TIMEOUT")
50
+ return false
51
+ end
52
+ else
53
+ @pjob.update(iserror: true, description: "PRINTER ERROR: #{status}")
54
+ return false
55
+ end
56
+ end
57
+
58
+ def check_status printer
59
+ begin
60
+ s = TCPSocket.new(printer, 9100)
61
+ # Must create intepolation between item and template
62
+ # Printer.template può essere anche
63
+ # una parola di comando epr chiedere lo stato della stampante, solo nel caso sia ok,
64
+ # Allora mando la stampa
65
+ s.puts("~hs")
66
+ # Attende per la risposta (si mette in wait)
67
+ response = []
68
+ while (response_text = s.gets)
69
+ response << response_text
70
+ break if response.count == 3
71
+ end
72
+ s.close
73
+ puts response.inspect
74
+ first = response[0].split(",")
75
+ second = response[1].split(",")
76
+ return "HEAD UP" if second[2].to_i == 1
77
+ return "RIBBON OUT" if second[3].to_i == 1
78
+ return "PAPER OUT" if first[1].to_i == 1
79
+ return "PAUSE" if first[2].to_i == 1
80
+ return "OK"
81
+ rescue
82
+ return "UNREACHABLE"
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,22 @@
1
+ class PrintJob < ApplicationRecord
2
+ belongs_to :printer, inverse_of: :print_jobs
3
+
4
+ def printed_on_total
5
+ "#{printed}/#{total}"
6
+ end
7
+
8
+ RailsAdmin.config do |config|
9
+ config.model 'PrintJob' do
10
+ # rails_admin do
11
+ navigation_label I18n.t("admin.settings.label")
12
+ navigation_icon 'fa fa-check-square'
13
+ parent Printer
14
+ weight 13
15
+
16
+ field :printer
17
+ field :created_at
18
+ field :description
19
+ field :printed_on_total
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,50 @@
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
+ weight 12
34
+
35
+ field :name
36
+ field :description
37
+ field :number_of_barcodes
38
+
39
+ edit do
40
+ field :template
41
+ field :translation_matrix
42
+ end
43
+
44
+ show do
45
+ field :template
46
+ field :translation_matrix
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,69 @@
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
+ validates :print_template, presence: true
11
+
12
+ # before_save :check_if_unique_default
13
+ # validates :qty, presence: true, numericality: { only_integer: true, greater_than: 0 }
14
+ # validates :translation, presence: true
15
+
16
+ # def template_enum
17
+ # PrintTemplate.descendants
18
+ # end
19
+ #
20
+ # # Array holding all the roles
21
+ # USED = %i[
22
+ # bundle
23
+ # commission
24
+ # ]
25
+ #
26
+ # def used_in_enum
27
+ # # Do not EDIT below this line
28
+ # USED.each_with_index.map {|a,i| [I18n.t("used_in.#{a.to_sym}"), (i+1).to_s]}
29
+ # end
30
+ # def has_section? section
31
+ # # example called from cancan's app/models/ability.rb
32
+ # # if user.has_role? :admin
33
+ #
34
+ # # 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 .
35
+ # USED[self.used_in.to_i - 1].to_s == section.to_s
36
+ # end
37
+ #
38
+ # def self.assigned_to section
39
+ # where(used_in: (USED.index(section.to_sym) + 1))
40
+ # end
41
+
42
+ RailsAdmin.config do |config|
43
+ config.model 'Printer' do
44
+ navigation_label I18n.t("admin.settings.label")
45
+ navigation_icon 'fa fa-print'
46
+ weight 11
47
+
48
+ field :name
49
+ field :ip
50
+ field :default, :toggle
51
+ field :temperature
52
+ field :print_template
53
+ # field :used_in
54
+ field :description
55
+
56
+ list do
57
+ configure :description do
58
+ visible false
59
+ end
60
+ end
61
+ end
62
+ end
63
+ # private
64
+ # def check_if_unique_default
65
+ # if self.default?
66
+ # Printer.where.not(id: self.id)
67
+ # end
68
+ # end
69
+ end
@@ -0,0 +1,60 @@
1
+ <%-unless params[:print_on].blank?%>
2
+ <div id="info-from-printer" class="well"></div>
3
+ <%-end%>
4
+
5
+ <%-unless @printers.blank?%>
6
+ <table class="table table-condensed">
7
+ <thead>
8
+ <tr>
9
+ <th class="header string_type">Nome</th>
10
+ <th class="header string_type">Descrizione</th>
11
+ <th class="header string_type">Indirizzo</th>
12
+ <th class="header string_type">Operazioni di Stampa</th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <%-@printers.each do |p|%>
17
+ <tr>
18
+ <td class="string_type"><%=p.name%></td>
19
+ <td class="string_type"><%=p.description%></td>
20
+ <td class="string_type"><%=p.ip%></td>
21
+ <td>
22
+ <%-if params[:item_id].blank? %>
23
+ <%=link_to "Stampa", rails_admin.telnet_print_path(model_name: @abstract_model.model_name.underscore, id: @object.id, print_on: p.id)%> |
24
+ <%=link_to "Annulla", rails_admin.telnet_print_path(cancel: p.id)%>
25
+ <%-else %>
26
+ <%-citem = ChosenItem.find(params[:item_id]) %>
27
+ <%=link_to "Stampa #{citem.barcode}", rails_admin.telnet_print_path(model_name: @abstract_model.model_name.underscore, id: @object.id, print_on: p.id, item_id: params[:item_id])%>
28
+ <%-end%>
29
+ </td>
30
+ </tr>
31
+ <%-end%>
32
+ </tbody>
33
+ </table>
34
+ <%-else%>
35
+ Nessuna Stampante <a href="<%=rails_admin.index_path(model_name: :printer)%>">configurata</a>
36
+ <%-end%>
37
+
38
+ <%-unless params[:print_on].blank?%>
39
+ <script type="text/javascript">
40
+ //<![CDATA[
41
+ function performAjaxCall(){
42
+ $.ajax({
43
+ type: "GET",// GET in place of POST,
44
+ url: "<%=rails_admin.telnet_print_path(model_name: @abstract_model.model_name.underscore, id: @object.id, print_on: params[:print_on])%>",
45
+ success: function (result) {
46
+ //do somthing here
47
+ $('#info-from-printer').html(result);
48
+ },
49
+ error: function (){
50
+ $('#info-from-printer').text("ERRORE: Non riesco a chiedere lo stato della stampa.");
51
+ }
52
+ });
53
+ }
54
+ (function(){
55
+ // do some stuff
56
+ setTimeout(performAjaxCall, 2000);
57
+ })();
58
+ //]]>
59
+ </script>
60
+ <%-end%>
@@ -0,0 +1,7 @@
1
+ TheCoreAbilities.module_eval do
2
+ def telnet_print_abilities user
3
+ if user && user.admin?
4
+ cannot [ :create, :update, :destroy, :show, :clone ], PrintJob
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ # TheCoreActions.module_eval do
2
+ # def telnet_print_action
3
+ # telnet_print
4
+ # end
5
+ # end
6
+
7
+ RailsAdmin.config do |config|
8
+ config.actions do
9
+ telnet_print
10
+ end
11
+ end
@@ -0,0 +1,36 @@
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
+ printed_on_total: Stampe Eseguite
31
+ print_template:
32
+ name: Nome
33
+ description: Descrizione
34
+ template: Modello ZPL
35
+ number_of_barcodes: Numero di Codici a Barre
36
+ 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,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,6 @@
1
+ class AddUsedInToPrinter < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :printers, :used_in, :string
4
+ add_index :printers, :used_in
5
+ end
6
+ 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,96 @@
1
+ require 'thecore'
2
+ require 'thecore_background_jobs'
3
+
4
+ # require 'models/print_job'
5
+ # require 'models/print_template'
6
+ # require 'models/printer'
7
+ #
8
+ # require 'jobs/application_job'
9
+ # require 'jobs/cancel_job'
10
+ # require 'jobs/print_it_job'
11
+ # require 'jobs/print_single_job'
12
+
13
+ require "rails_admin_telnet_print/engine"
14
+
15
+ module RailsAdminTelnetPrint
16
+ end
17
+
18
+ require 'rails_admin/config/actions'
19
+
20
+ module RailsAdmin
21
+ module Config
22
+ module Actions
23
+ class TelnetPrint < RailsAdmin::Config::Actions::Base
24
+ RailsAdmin::Config::Actions.register(self)
25
+
26
+ register_instance_option :object_level do
27
+ true
28
+ end
29
+
30
+ # This ensures the action only shows up for Users
31
+ register_instance_option :visible? do
32
+ # visible only if authorized and if the object has a defined method
33
+ authorized? && bindings[:object].respond_to?(:records_for_print)
34
+ end
35
+ # We want the action on members, not the Users collection
36
+ register_instance_option :member do
37
+ true
38
+ end
39
+
40
+ register_instance_option :collection do
41
+ false
42
+ end
43
+
44
+ register_instance_option :link_icon do
45
+ 'icon-print'
46
+ end
47
+ # You may or may not want pjax for your action
48
+ register_instance_option :pjax? do
49
+ false
50
+ end
51
+
52
+ register_instance_option :controller do
53
+ proc do
54
+ I18n.locale = :it
55
+ if request.xhr?
56
+ # Cerco l'informazione se c'è un qualche job in stampa
57
+ printer = Printer.find(params[:print_on])
58
+ job = PrintJob.where(printer_id: printer.id).order(updated_at: :desc).first
59
+
60
+ message = []
61
+ if job.blank?
62
+ message << "Nessun lavoro di stampa è mai stato inviato a questa stampante: <strong>#{printer.ip}</strong>"
63
+ else
64
+ number_of_prints = "#{job.printed}/#{job.total}"
65
+
66
+ message << "Ultimo lavoro di stampa: <strong>#{printer.ip}:</strong>"
67
+ message << (job.finished ? "<i>Stampa conclusa (#{number_of_prints})</i> " : "Stampa in corso #{number_of_prints}")
68
+ message << (job.iserror ? job.description : "Nessun errore rilevato")
69
+ message << "(#{I18n.l job.created_at})"
70
+ end
71
+
72
+ render html: message.join(" ").html_safe
73
+ else
74
+ # Se non è una xhr, allora è proprio l'invio di stampa
75
+ @printers = Printer.all # assigned_to(@abstract_model.model_name.downcase)
76
+ if !params[:print_on].blank?
77
+ # Visualizza la lista di stampanti diponibili
78
+ # Effettivmaente invia la stampa e torna poi alla index del modello di partenza
79
+ # @object è la commissione o sovracollo di partenza
80
+ PrintItJob.perform_later @abstract_model.model_name, @object.id, params[:print_on] if params[:item_id].blank?
81
+ # PrintSingleJob.perform_later @abstract_model.model_name, @object.id, params[:print_on], params[:item_id] if !params[:item_id].blank?
82
+ # redirect_to action: :index
83
+ unless params[:back_to].blank?
84
+ # http://localhost:3000/app/scan_item_barcode
85
+ redirect_to rails_admin.send(params[:back_to].to_sym, print_on: params[:print_on], chosen_item_id: @object.id)
86
+ end
87
+ elsif !params[:cancel].blank?
88
+ CancelJob.perform_later params[:cancel]
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,12 @@
1
+ module RailsAdminTelnetPrint
2
+ class Engine < ::Rails::Engine
3
+ # appending migrations to the main app's ones
4
+ initializer :append_migrations do |app|
5
+ unless app.root.to_s == root.to_s
6
+ config.paths["db/migrate"].expanded.each do |expanded_path|
7
+ app.config.paths["db/migrate"] << expanded_path
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminTelnetPrint
2
+ VERSION = '1.2.9'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_telnet_print
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.9
5
+ platform: ruby
6
+ authors:
7
+ - Gabriele Tassoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-08 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
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: The set of printers must be present in the database.
42
+ email:
43
+ - gabrieletassoni@taris.it
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - app/jobs/application_job.rb
52
+ - app/jobs/cancel_job.rb
53
+ - app/jobs/print_it_job.rb
54
+ - app/jobs/print_single_job.rb
55
+ - app/models/print_job.rb
56
+ - app/models/print_template.rb
57
+ - app/models/printer.rb
58
+ - app/views/rails_admin/main/telnet_print.html.erb
59
+ - config/initializers/telnet_print_abilities.rb
60
+ - config/initializers/telnet_print_actions.rb
61
+ - config/locales/telnet_print.activerecord.it.yml
62
+ - config/locales/telnet_print.en.yml
63
+ - config/locales/telnet_print.it.yml
64
+ - db/migrate/20160323152041_create_printers.rb
65
+ - db/migrate/20160327083832_add_used_in_to_printer.rb
66
+ - db/migrate/20160407141529_create_print_jobs.rb
67
+ - db/migrate/20160407152547_add_fields_to_print_job.rb
68
+ - db/migrate/20160407181202_change_column_errors_to_print_job.rb
69
+ - db/migrate/20160413115407_add_temperature_to_printer.rb
70
+ - db/migrate/20160519093702_create_print_templates.rb
71
+ - db/migrate/20160519124051_add_print_template_id_to_printer.rb
72
+ - db/migrate/20160629140729_add_default_to_printer.rb
73
+ - lib/rails_admin_telnet_print.rb
74
+ - lib/rails_admin_telnet_print/engine.rb
75
+ - lib/rails_admin_telnet_print/version.rb
76
+ homepage: https://www.taris.it
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.6.14
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Printing to a set of predefined IP printers.
100
+ test_files: []