oxen_printer 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +31 -0
  6. data/Rakefile +8 -0
  7. data/app/controllers/oxen/print_jobs_controller.rb +10 -0
  8. data/app/controllers/oxen/printers_controller.rb +33 -0
  9. data/app/jobs/background_printer_job.rb +14 -0
  10. data/app/models/ox_print_job.rb +47 -0
  11. data/app/models/ox_printable.rb +17 -0
  12. data/app/models/ox_printer.rb +36 -0
  13. data/app/policies/oxen/print_job_policy.rb +51 -0
  14. data/app/views/oxen/print_jobs/_form.html.haml +45 -0
  15. data/app/views/oxen/print_jobs/_print_job.html.haml +3 -0
  16. data/app/views/oxen/print_jobs/_print_jobs.html.haml +11 -0
  17. data/app/views/oxen/print_jobs/_printer_print_job.html.haml +12 -0
  18. data/app/views/oxen/print_jobs/_printer_print_jobs.html.haml +11 -0
  19. data/app/views/oxen/print_jobs/_show.html.haml +0 -0
  20. data/app/views/oxen/printers/_account_printer.html.haml +11 -0
  21. data/app/views/oxen/printers/_account_printers.html.haml +14 -0
  22. data/app/views/oxen/printers/_form.html.haml +31 -0
  23. data/app/views/oxen/printers/_new.html.haml +68 -0
  24. data/app/views/oxen/printers/_printer.html.haml +3 -0
  25. data/app/views/oxen/printers/_printers.html.haml +11 -0
  26. data/app/views/oxen/printers/_user_printer.html.haml +18 -0
  27. data/app/views/oxen/printers/_user_printers.html.haml +14 -0
  28. data/app/views/oxen/printers/create.html.haml +5 -0
  29. data/bin/rails +12 -0
  30. data/config/locales/da.yml +7 -0
  31. data/config/routes.rb +47 -0
  32. data/lib/action_printer.rb +90 -0
  33. data/lib/c4_label_print_provider.rb +215 -0
  34. data/lib/generators/printer/install_generator.rb +14 -0
  35. data/lib/generators/printer/printer_generator.rb +27 -0
  36. data/lib/generators/printer/templates/print_job.rb +21 -0
  37. data/lib/generators/printer/templates/printable.rb +13 -0
  38. data/lib/generators/printer/templates/printer.rb +15 -0
  39. data/lib/java_pdf/LICENSE +71 -0
  40. data/lib/java_pdf/LICENSE-LGPL-2.1.txt +504 -0
  41. data/lib/java_pdf/LICENSE-W3C-TEST +28 -0
  42. data/lib/java_pdf/README +92 -0
  43. data/lib/java_pdf/about.jar +0 -0
  44. data/lib/java_pdf/barbecue-1.5-beta1.jar +0 -0
  45. data/lib/java_pdf/barcodeprinter.jar +0 -0
  46. data/lib/java_pdf/browser.jar +0 -0
  47. data/lib/java_pdf/core-renderer-minimal.jar +0 -0
  48. data/lib/java_pdf/core-renderer.jar +0 -0
  49. data/lib/java_pdf/docbook.jar +0 -0
  50. data/lib/java_pdf/iText-2.0.8.jar +0 -0
  51. data/lib/java_pdf/itext-paulo-155.jar +0 -0
  52. data/lib/java_pdf/lib/LICENSE +71 -0
  53. data/lib/java_pdf/lib/LICENSE-LGPL-2.1.txt +504 -0
  54. data/lib/java_pdf/lib/LICENSE-W3C-TEST +28 -0
  55. data/lib/java_pdf/lib/README +92 -0
  56. data/lib/java_pdf/lib/core-renderer-minimal.jar +0 -0
  57. data/lib/java_pdf/lib/core-renderer.jar +0 -0
  58. data/lib/java_pdf/lib/iText-2.0.8.jar +0 -0
  59. data/lib/java_pdf/lib/itext-paulo-155.jar +0 -0
  60. data/lib/java_pdf/lib/minium.jar +0 -0
  61. data/lib/java_pdf/minium.jar +0 -0
  62. data/lib/java_pdf/pd4ml_demo.jar +0 -0
  63. data/lib/java_pdf/ss_css2.jar +0 -0
  64. data/lib/java_pdf/svg.jar +0 -0
  65. data/lib/oxen_printer.rb +8 -0
  66. data/lib/oxen_printer/cab_printer.rb +101 -0
  67. data/lib/oxen_printer/csv_printer.rb +12 -0
  68. data/lib/oxen_printer/engine.rb +19 -0
  69. data/lib/oxen_printer/html_printer.rb +12 -0
  70. data/lib/oxen_printer/label_printer.rb +12 -0
  71. data/lib/oxen_printer/pdf_printer.rb +66 -0
  72. data/lib/oxen_printer/version.rb +3 -0
  73. data/lib/print_drivers.rb +94 -0
  74. data/lib/print_engine.rb +135 -0
  75. data/lib/tasks/oxen_printer_tasks.rake +4 -0
  76. data/oxen_printer.gemspec +25 -0
  77. metadata +163 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c8b8e99849e31af9b25993ea35b7733e77fe7dae
4
+ data.tar.gz: 1a157f785dacf2ceb2a0af3c2233e5f7b64f2e81
5
+ SHA512:
6
+ metadata.gz: 4e327c1dc8249c157df3b6107c7407487aa1c781aa7b36718541ff66f8b411b15c91d60d9831fe3e7a2a7b5f47c4fafaa63cec436f5369df77603bf72cbc7a65
7
+ data.tar.gz: 2cf69fb037bba5aa9dda1ad2570e56f0487479b2bfe80a747216c737b5043d24471b22bd7da9894e8abdac538a05433d487a03a5c9109ece52ac9f03d53c3f79
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *gem
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in oxen_printer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Walther H Diechmann
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # OxenPrinter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'oxen_printer'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install oxen_printer
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/oxen_printer/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+
3
+ #require "bundler/gem_tasks"
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
@@ -0,0 +1,10 @@
1
+ class Oxen::PrintJobsController < AbstractResourcesController
2
+ private
3
+ # Never trust parameters from the scary internet, only allow the white list through.
4
+ # "printer"=>{"name"=>"Label", "cups_printer"=>"havehuset_label", "command"=>"lp %2 %3", "paper"=>"A4", "active"=>"1"}}
5
+ def resource_params
6
+ params[:print_job][:account_id] = current_user.admin? ? params[:parent_id] : current_user.account.id
7
+ params.require(:print_job).permit(:account_id, :printer_id, :printed_by_id, :printed_by_type, :view_template_path, :name, :printing_class, :print_driver, :print_format, :state, :paper, :copies, :print_sql)
8
+ end
9
+
10
+ end
@@ -0,0 +1,33 @@
1
+ class Oxen::PrintersController < AbstractResourcesController
2
+
3
+ def update
4
+ authorize resource
5
+ flash[:notice] = t('.success.updated', resource: resource_class.to_s ) if resource.update_attributes(resource_params) && update_parenthood
6
+ respond_with resource, location: "/admin/accounts/#{resource.account.id}"
7
+ rescue Exception => e
8
+ scoop_from_error e
9
+ end
10
+
11
+
12
+ private
13
+
14
+ def set_fab_button_options
15
+
16
+ opt = { items: {}}
17
+ case params[:action]
18
+ when 'edit','update'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }
19
+ when 'show'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }
20
+ when 'index'; opt[:items].merge! list: { ajax: 'get', icon: 'list', class: 'blue', url: "/admin/accounts/#{resource.account.id}" }
21
+ end
22
+
23
+ @fab_button_options = opt
24
+ end
25
+
26
+ # Never trust parameters from the scary internet, only allow the white list through.
27
+ # "printer"=>{"name"=>"Label", "cups_printer"=>"havehuset_label", "command"=>"lp %2 %3", "paper"=>"A4", "active"=>"1"}}
28
+ def resource_params
29
+ params[:printer][:account_id] = current_user.admin? ? params[:parent_id] : current_user.account.id
30
+ params.require(:printer).permit(:account_id, :active, :name, :cups_printer, :command, :paper)
31
+ end
32
+
33
+ end
@@ -0,0 +1,14 @@
1
+ class BackgroundPrinterJob < OxJob
2
+ queue_as :printing
3
+
4
+ # [#<PrintJob id: 28, account_id: 1, printer_id: 7, printed_by_id: 1, printed_by_type: "User", view_template_path: "/record.html.haml",
5
+ # name: "Account print at 13-10-2015", printing_class: "Account", print_driver: "pdf", print_format: "sheet", state: "drafted",
6
+ # paper: "A4", copies: 1, print_sql: "SELECT `accounts`.* FROM `accounts` WHERE (`accoun...", created_at: "2015-10-13 14:19:10",
7
+ # updated_at: "2015-10-13 14:19:10">, {:queue=>"printing", :account_id=>1}, {:account_id=>1}
8
+ # ]
9
+ def perform job, *args
10
+ job.update_column :state, I18n.t( "#{job.class.to_s.underscore.pluralize}.performing")
11
+ job.perform args
12
+ end
13
+
14
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: UTF-8
2
+ #/* - - - - - - - - - - - - - - - - - - - - -
3
+ #
4
+ # Title : WEB Appliances Crest Inc, Web Form Framework
5
+ # Author : Enrique Phillips
6
+ # URL : http://www.wac.bz
7
+ #
8
+ #- - - - - - - - - - - - - - - - - - - - - */
9
+
10
+ require 'print_drivers'
11
+
12
+ # The <b>PrintJob</b> model holds all relevant information in regards to the PrintJob
13
+ # It is possible to create a PrintJob for any other model that needs to be able to print.
14
+ class OxPrintJob < AbstractResource
15
+ self.table_name = 'print_jobs'
16
+ establish_connection ((Rails.env=="development") ? :dev_oxen_tables : :oxen_tables )
17
+
18
+ has_paper_trail
19
+
20
+ validates :name, presence: true
21
+
22
+ belongs_to :printer
23
+ belongs_to :account
24
+ belongs_to :printed_by, polymorphic: true
25
+
26
+ include Exceptions
27
+ include PrintDrivers
28
+
29
+ # has_paper_trail :ignore => [:state, :cups_state]
30
+
31
+ scope :stated, ->(pap) { where(state: pap) }
32
+ scope :queued, ->{ where(print_jobs.state >> ['processing','printing']) }
33
+
34
+ # Temporary attribute for the print_job object to hold the instanciated printer (PdfPrinter, HtmlPrinter, CsvPrinter etc.)
35
+ attr_accessor :action_printer, :snap_shot, :download
36
+
37
+ #
38
+ # enabling background printing - via OxJob & ActiveJob & DelayedJob
39
+ def perform *args
40
+ context = args[0].delete(:context)
41
+ if !download
42
+ print_with rendered_on(args)
43
+ else
44
+ send_with( rendered_on(args), context) if context
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ class OxPrintable < AbstractResource
2
+ self.table_name = 'printables'
3
+ establish_connection ((Rails.env=="development") ? :dev_oxen_tables : :oxen_tables )
4
+
5
+ has_paper_trail
6
+
7
+ belongs_to :account
8
+ belongs_to :printer
9
+ belongs_to :printable, polymorphic: true
10
+
11
+ before_save :set_account
12
+
13
+ def set_account
14
+ self.account = printer.account
15
+ end
16
+
17
+ end
@@ -0,0 +1,36 @@
1
+ class OxPrinter < AbstractResource
2
+ self.table_name = 'printers'
3
+ establish_connection ((Rails.env=="development") ? :dev_oxen_tables : :oxen_tables )
4
+
5
+ attr_accessor :snap_shot
6
+
7
+ has_paper_trail
8
+
9
+ has_many :printables, foreign_key: 'printer_id', dependent: :destroy
10
+ has_many :users, through: :printables, source: :printable, source_type: 'User'
11
+
12
+ validates :name, presence: true
13
+
14
+ scope :active, -> { where(active: true) }
15
+ scope :preferred_printer, ->{ where("printables.preferred=1")}
16
+ scope :on_paper, -> (pap){ where(paper: pap )}
17
+
18
+ def list_title
19
+ name
20
+ end
21
+
22
+ def preferred? parent
23
+ printables.where(printable: parent).first.preferred?
24
+ end
25
+
26
+ def prefer parent
27
+ parent.printables.each{ |p| p.update_columns(preferred: false) }
28
+ printables.where(printable: parent).first.update_columns( preferred: true )
29
+ end
30
+
31
+ def defer parent
32
+ printables.where(printable: parent).first.update_columns( preferred: false )
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,51 @@
1
+ module Oxen
2
+ class PrintJobPolicy < AbstractResourcePolicy
3
+
4
+ class Scope < Scope
5
+ def resolve
6
+ if current_user.nil?
7
+ super
8
+ elsif current_user.admin?
9
+ scope.all
10
+ else
11
+ scope.where(id: current_user.account.id)
12
+ end
13
+ end
14
+ end
15
+
16
+
17
+
18
+ def new?
19
+ current_user.admin?
20
+ end
21
+
22
+ def index?
23
+ @current_user.admin? || @current_user.account_admin?
24
+ end
25
+
26
+ def create?
27
+ @current_user.admin?
28
+ end
29
+
30
+ def show?
31
+ @current_user.admin? or @current_user.account==@model
32
+ end
33
+
34
+ def edit?
35
+ @current_user.admin? or @current_user.account==@model
36
+ end
37
+
38
+ def update?
39
+ @current_user.admin? or @current_user.account==@model
40
+ end
41
+
42
+ def destroy?
43
+ @current_user.admin?
44
+ end
45
+
46
+ def print?
47
+ @current_user.admin? || @current_user.account_admin?
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,45 @@
1
+ = simple_form_for(resource) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ -# - if current_user.admin? and params[:controller] =~ /service/
6
+ -# / %input{ name: 'parent_id', collection: policy_scope(Account), class: :validate}
7
+ -# - else
8
+ %input{ type: :hidden, name: 'parent', value: 'Account' }
9
+ %input{ type: :hidden, name: 'parent_id', value: f.object.account.id }
10
+
11
+ .row
12
+ = f.input :printer, required: true, disabled: @disabled
13
+
14
+ .row
15
+ = f.input :printed_by_id, required: true, disabled: @disabled
16
+
17
+ .row
18
+ = f.input :printed_by_type, required: true, disabled: @disabled
19
+
20
+ .row
21
+ = f.input :view_template_path, required: true, disabled: @disabled
22
+
23
+ .row
24
+ = f.input :name, required: true, disabled: @disabled
25
+
26
+ .row
27
+ = f.input :printing_class, required: true, disabled: @disabled
28
+
29
+ .row
30
+ = f.input :print_driver, required: true, disabled: @disabled
31
+
32
+ .row
33
+ = f.input :print_format, required: true, disabled: @disabled
34
+
35
+ .row
36
+ = f.input :state, required: true, disabled: @disabled
37
+
38
+ .row
39
+ = f.input :paper, required: true, disabled: @disabled
40
+
41
+ .row
42
+ = f.input :copies, required: true, disabled: @disabled
43
+
44
+ .row
45
+ = f.input :print_sql, required: true, disabled: @disabled
@@ -0,0 +1,3 @@
1
+ %tr{ id: "tr-#{resource.id}"}
2
+ %td= link_to resource.name, resource
3
+ %td= show_resource_delete_icon resource, '/admin/print_jobs'
@@ -0,0 +1,11 @@
1
+ .row
2
+ .col.s12
3
+ %table.responsive-table.hoverable.striped.resources_table
4
+ %thead
5
+ %tr
6
+ %th{ :"data-field"=>"name"}= t('.name')
7
+ %th= t(:delete)
8
+
9
+ %tbody#printers.resources_list
10
+ - resources.each do |print_job|
11
+ = render partial: 'print_job', locals: { resource: print_job }
@@ -0,0 +1,12 @@
1
+ %tr{ id: "tr-#{print_job.id}"}
2
+ %td= link_to parent.name, parent
3
+ %td= link_to print_job.name, print_job
4
+ %td= show_resource_delete_icon print_job, '/admin/print_jobs'
5
+ -# - if parent? && parent_name == 'users'
6
+ -# %td
7
+ -# - if user.printers.include? printer
8
+ -# = link_to detach_url( user,printer), class: 'attached green-text', title: t('detach_printers') do
9
+ -# %i.material-icons layers
10
+ -# - else
11
+ -# = link_to attach_url( user,printer), class: 'detached red-text', title: t('attach_printers') do
12
+ -# %i.material-icons layers_clear
@@ -0,0 +1,11 @@
1
+ .row{ style: "margin-top: 60px"}
2
+ .col.s12{ style: "height: 250px; overflow: scroll"}
3
+ %table.responsive-table.hoverable.striped.resources_table
4
+ %thead
5
+ %tr
6
+ %th{ :"data-field"=>"name"}= t('.name')
7
+ %th= t(:delete)
8
+
9
+ %tbody#account_printers.resources_list
10
+ - resource.print_jobs.each do |print_job|
11
+ = render partial: 'oxen/print_jobs/printer_print_job', locals: { print_job: print_job, parent: resource, parent_id: resource.id }
File without changes
@@ -0,0 +1,11 @@
1
+ %tr{ id: "tr-#{printer.id}"}
2
+ %td= link_to printer.name, printer
3
+ %td= show_resource_delete_icon printer, '/admin/printers'
4
+ -# - if parent? && parent_name == 'users'
5
+ -# %td
6
+ -# - if user.printers.include? printer
7
+ -# = link_to detach_url( user,printer), class: 'attached green-text', title: t('detach_printers') do
8
+ -# %i.material-icons layers
9
+ -# - else
10
+ -# = link_to attach_url( user,printer), class: 'detached red-text', title: t('attach_printers') do
11
+ -# %i.material-icons layers_clear
@@ -0,0 +1,14 @@
1
+ .row
2
+ .col.s12{ style: "height: 250px; overflow: scroll"}
3
+ %table.responsive-table.hoverable.striped.resources_table
4
+ %thead
5
+ %tr
6
+ %th{ :"data-field"=>"name"}= t('.name')
7
+ %th= t(:delete)
8
+
9
+ - if parent?
10
+ %th= t('attach_detach_printer')
11
+
12
+ %tbody#account_printers.resources_list
13
+ - resource.printers.each do |printer|
14
+ = render partial: 'printers/account_printer', locals: { printer: printer, parent: resource, parent_id: resource.id }
@@ -0,0 +1,31 @@
1
+ = simple_form_for(resource) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ -# - if current_user.admin? and params[:controller] =~ /service/
6
+ -# / %input{ name: 'parent_id', collection: policy_scope(Account), class: :validate}
7
+ -# - else
8
+ %input{ type: :hidden, name: 'parent', value: 'Account' }
9
+ %input{ type: :hidden, name: 'parent_id', value: f.object.account.id }
10
+
11
+ .row
12
+ = f.input :name
13
+
14
+ .row
15
+ = f.input :cups_printer, placeholder: t('.cups_printer'), required: true, disabled: @disabled
16
+
17
+ .row
18
+ = f.input :command, placeholder: t('.cups_cmd'), required: true, disabled: @disabled
19
+
20
+ .row
21
+ = f.input :paper, placeholder: t('.paper')'Angiv papirtypen, exvis: Letter, A4', required: true, disabled: @disabled
22
+
23
+ .row
24
+ .input-field.col.s4
25
+ %label{ style: "margin-top: -20px"}= t('.service_active')
26
+ .switch
27
+ %label
28
+ = t(:passive)
29
+ =f.check_box :active, disabled: @disabled
30
+ %span.lever
31
+ = t(:active)