rails_admin_opening 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d1a919857d9c40dba56986c2f128a7722d1c6f4d54c4af10f6fa66ada62011b4
4
+ data.tar.gz: c9cb08579cc9b623d3ff7ba0fd4ed5eafcb8d53cf7cbdcf9a7b6c411d8f298e9
5
+ SHA512:
6
+ metadata.gz: 322db7944f604e60a60efc81fed7ce11b44a7cdbbf1eb95b8d24c9dfca1c3a5b5edf12014e3028b1b39138701b2191806061f964267c534fd88b5a1065711fbe
7
+ data.tar.gz: e285373831e34939ef9fee5038dabaab3fb3150c91bdb9e61a85a97f74c9d6568105af3248e44d7c64c3a191bcfe21c01b2850a507429b082591dcbf3b06480d
@@ -0,0 +1,20 @@
1
+ Copyright 2017 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
+ # RailsAdminOpening
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 'rails_admin_opening'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install rails_admin_opening
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](http://opensource.org/licenses/MIT).
@@ -0,0 +1,34 @@
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 = 'RailsAdminOpening'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ require 'bundler/gem_tasks'
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1 @@
1
+ <%=render "higher_level/barcode_simple_scan", hide_action: true%>
@@ -0,0 +1,5 @@
1
+ RailsAdmin.config do |config|
2
+ config.actions do
3
+ opening
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+
2
+ Rails.application.configure do
3
+ config.after_initialize do
4
+ require 'rails_admin_opening_states_changer'
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+
2
+ en:
3
+ not_right_timeframe: The item %{barcode} cannot be picked up, operation performed at %{now} not allowed because putside timeframe %{not_before} - %{not_after}
4
+ timeframe_error: Error! Timeframe
5
+ not_found_error: Error! Not found
6
+ not_saved_error: Error! Not Saved
7
+ success_save: Successfully saved
8
+ barcode_state_not: ITEM NOT HANDLED CORRECTLY - REPORT TO SUPERVISOR, PLEASE
9
+ item_state_not_changed_to: Item state not changed to %{state}
10
+ item_correctly_state_changed: Item state changed to %{state}
11
+ current_item_state: Current Item state is %{state}
12
+ barcode_not_exists: Barcode does not exists
13
+ item_expired: ITEM EXPIRED - REPORT TO CHIEF SUPERVISOR FOR DISPOSAL, PLEASE
14
+ admin:
15
+ actions:
16
+ opening:
17
+ title: "Opening"
18
+ menu: "Opening"
19
+ breadcrumb: "Opening"
20
+ link: "Opening"
21
+ bulk_link: "Opening"
22
+ done: "Opened"
@@ -0,0 +1,24 @@
1
+
2
+ it:
3
+ not_right_timeframe: L'elemento %{barcode} non può essere maneggiato, operazione eseguita da %{user} alle %{now} non permessa in quanto non compresa fra %{not_before} e %{not_after}
4
+ timeframe_error: Errore.
5
+ not_found_error: Errore.
6
+ not_saved_error: Errore.
7
+ success_save: Salvato.
8
+ barcode_state_not: Il Barattolo non è nello stato %{state}
9
+ item_state_not_changed_to: Non ho potuto eseguire un(a) %{state} alle %{at} (%{user})
10
+ item_correctly_state_changed: Eseguito/a correttamente un(a) %{state} alle %{at} (%{user})
11
+ current_item_state: Elemento correntemente nello stato %{state}
12
+ barcode_not_exists: Codice a barre non esistente
13
+ item_expired: BARATTOLO SCADUTO - CONSEGNARE AL CAPO REPARTO PER IL CORRETTO SMALTIMENTO
14
+ # dont_use_before: Barattolo non utilizzabile %{not_before}
15
+ dont_use_before: "Barattolo %{barcode}\r\nNON UTILIZZARE prima delle %{not_before_time} del %{not_before_date}, mancano %{distance_before}\r\nUTILIZZARE ENTRO le %{not_after_time} del %{not_after_date}\r\n"
16
+ admin:
17
+ actions:
18
+ opening:
19
+ title: "Apertura"
20
+ menu: "Apertura"
21
+ breadcrumb: "Apertura"
22
+ link: "Apertura"
23
+ bulk_link: "Apertura"
24
+ done: "Aperto"
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,69 @@
1
+ require "rails_admin_pick_up"
2
+
3
+ require "rails_admin_opening/engine"
4
+
5
+ module RailsAdminOpening
6
+ # Your code goes here...
7
+ end
8
+
9
+ require 'rails_admin/config/actions'
10
+
11
+ module RailsAdmin
12
+ module Config
13
+ module Actions
14
+ class Opening < Base
15
+ RailsAdmin::Config::Actions.register(self)
16
+
17
+
18
+ register_instance_option :object_level do
19
+ false
20
+ end
21
+ # This ensures the action only shows up for Users
22
+ register_instance_option :visible? do
23
+ # visible only if authorized and if the object has a defined method
24
+ authorized? #&& bindings[:abstract_model].model == ChosenItem && bindings[:abstract_model].model.column_names.include?("barcode")
25
+ end
26
+ # We want the action on members, not the Users collection
27
+ register_instance_option :member do
28
+ false
29
+ end
30
+
31
+ register_instance_option :collection do
32
+ false
33
+ end
34
+ register_instance_option :root? do
35
+ true
36
+ end
37
+
38
+ register_instance_option :breadcrumb_parent do
39
+ # if root?
40
+ # [:dashboard]
41
+ # elsif collection?
42
+ # [:index, bindings[:abstract_model]]
43
+ # elsif member?
44
+ # [:show, bindings[:abstract_model], bindings[:object]]
45
+ # end
46
+ [nil]
47
+ end
48
+
49
+ register_instance_option :link_icon do
50
+ 'icon-barcode'
51
+ end
52
+ # You may or may not want pjax for your action
53
+ register_instance_option :pjax? do
54
+ true
55
+ end
56
+
57
+ register_instance_option :controller do
58
+ Proc.new do # In modo che venga valutata ogni volta che viene chiamata
59
+ if request.xhr? && !params["_pjax"]# Nel caso si voglia usare anche una interazione javascript
60
+ message, status = CheckOrChangeStatus.perform params[:barcode], :pick_up, :opening, _current_user.id
61
+
62
+ render json: MultiJson.dump(message), status: status
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,4 @@
1
+ module RailsAdminOpening
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminOpening
2
+ VERSION = '1.2.4'.freeze
3
+ end
@@ -0,0 +1,135 @@
1
+ include ActionView::Helpers::DateHelper
2
+ module CheckOrChangeStatus
3
+ def self.log(title, description, passed, item_id, user_id)
4
+ puts "LOGGING:"
5
+ puts "TITLE: #{title}"
6
+ puts "DESC: #{description}"
7
+ puts "PASSED: #{passed}"
8
+ puts "ITEM ID: #{item_id}"
9
+ puts "USER ID: #{user_id}"
10
+ Check.create! title: title, description: description, passed: passed, item_id: item_id, user_id: user_id
11
+ end
12
+ def self.perform(barcode, before, after, user_id, filename_date_part = "%Y%m%d_%H%M%S.%L")
13
+ # "%d%m%Y_%H%M%S"
14
+ username = User.find(user_id).username
15
+ current_time = Time.now.strftime(filename_date_part)
16
+ puts "PASSED PARAMS: "
17
+ puts "- BARCODE: #{barcode}"
18
+ puts "- before: #{before}"
19
+ puts "- after: #{after}"
20
+ puts "- user_id: #{user_id}"
21
+ if barcode.blank?
22
+ message = {error: "#{I18n.t(:barcode_cannot_be_empty)}"}
23
+ status = 400
24
+ return [message, status]
25
+ else
26
+ # Only if the Item exists and is in status deposited
27
+ item = Item.find_by(code: barcode)
28
+
29
+ if item.blank?
30
+ message = {error: "#{I18n.t(:barcode_not_exists)}: #{barcode}"}
31
+ status = 404
32
+ return [message, status]
33
+ else
34
+ puts "Checking if it's in previous state"
35
+ puts "BEFORE: #{before}"
36
+ puts "- STATE IDS FROM DB: #{State.where(name: before).pluck(:id).inspect}"
37
+ puts "- item.state_id: #{item.state_id}"
38
+ if !State.where(name: before).pluck(:id).include?(item.state_id)
39
+ #error
40
+ message = {error: "#{I18n.t(:barcode_state_not, after: I18n.t("admin.actions.#{after}.title"), state: I18n.t("admin.actions.#{before}.done"), at: current_time, user: username)}"}
41
+ status = 404
42
+ log I18n.t(:not_found_error), message[:error], false, item.id, user_id
43
+ return [message, status]
44
+ else
45
+ # Item exists, but are we in the right timeframe?
46
+ # Now must be between not_before_time and expiration_date
47
+ now = Time.now
48
+ if !item.not_after_time.blank? && item.not_after_time < now
49
+ # (!item.not_before_time.blank? || !item.expiration_date.blank?) && (item.not_before_time > now || item.expiration_date < now)
50
+ # error
51
+ # create the error file (need specs)
52
+ xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
53
+ <error>
54
+ <code>#{barcode.split[1]}</code>
55
+ <not_before>#{item.not_before_time.strftime("%H:%M")}</not_before>
56
+ <not_after>#{item.not_after_time.strftime("%d/%m/%y")}</not_after>
57
+ <survey_at>#{now}</survey_at>
58
+ </error>\n"
59
+ File.open(File.expand_path("#{Settings.ns("errors").save_path}/timeframe_error_#{current_time}.xml"), "w") { |f| f.write(xml_string) }
60
+ message = {error: "#{I18n.t(:item_expired)}"}
61
+ status = 401
62
+
63
+ log I18n.t(:timeframe_error), message[:error], false, item.id, user_id
64
+ return [message, status]
65
+ end
66
+ if !item.not_before_time.blank? && item.not_before_time > now
67
+ # #{created_item.not_after_time.strftime("%H:%M")} del #{created_item.not_after_time.strftime("%d/%m/%y")}\r\n"
68
+ message = {error: "#{I18n.t(:dont_use_before,
69
+ now: I18n.l(now),
70
+ user: username,
71
+ not_before: I18n.l(item.not_before_time),
72
+ not_after: I18n.l(item.not_after_time),
73
+ not_before_time: item.not_before_time.strftime("%H:%M"),
74
+ not_before_date: item.not_before_time.strftime("%d/%m/%y"),
75
+ not_after_time: item.not_after_time.strftime("%H:%M"),
76
+ not_after_date: item.not_after_time.strftime("%d/%m/%y"),
77
+ distance_before: distance_of_time_in_words_to_now(item.not_before_time),
78
+ distance_after: distance_of_time_in_words_to_now(item.not_after_time),
79
+ barcode: barcode)}"}
80
+ status = 401
81
+
82
+ log I18n.t(:timeframe_error), message[:error], false, item.id, user_id
83
+ return [message, status]
84
+ end
85
+ # It exists and is deposited, Thus I set it to picked up
86
+ item.state_id = State.find_by(name: after).id
87
+ if !item.save
88
+ # --- Se non è così, allora errore
89
+ message = {error: "#{I18n.t(:item_state_not_changed_to, state: I18n.t("admin.actions.#{after}.title"), at: current_time, user: username)} (#{item.errors.full_messages.inspect})"}
90
+ status = 404
91
+ log I18n.t(:not_saved_error), message[:error], false, item.id, user_id
92
+ return [message, status]
93
+ else
94
+ # --- If it managed to save, then
95
+ message = {info: "#{I18n.t(:item_correctly_state_changed, state: I18n.t("admin.actions.#{after}.title"), at: current_time, user: username)}", barcode: barcode}
96
+ log I18n.t(:success_save), message[:info], true, item.id, user_id
97
+ status = 200
98
+ return [message, status]
99
+ end
100
+ end
101
+
102
+ end
103
+ end
104
+ end
105
+
106
+ def self.check(barcode)
107
+ if barcode.blank?
108
+ message = {error: "#{I18n.t(:barcode_cannot_be_empty)}"}
109
+ status = 400
110
+ else
111
+ # Only if the Item exists and is in status deposited
112
+ item = Item.find_by(code: barcode)
113
+
114
+ if item.blank?
115
+ message = {error: "#{I18n.t(:barcode_not_exists)}: #{barcode}"}
116
+ status = 404
117
+ else
118
+ # It exists, Thus I return the relevant info for printing
119
+ now = Time.now
120
+ message = {
121
+ info: "#{I18n.t(:current_item_state, state: PhasesModels.compute_states(item))}",
122
+ used: (!item.not_after_time.blank? && item.not_after_time < now),
123
+ expired: (!item.expiration_date.blank? && item.expiration_date < now),
124
+ not_before: item.not_before_time,
125
+ not_after: item.not_after_time,
126
+ expiration_date: item.expiration_date,
127
+ states: item.checks,
128
+ barcode: barcode
129
+ }
130
+ status = 200
131
+ end
132
+ end
133
+ [message, status]
134
+ end
135
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_admin_opening do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_opening
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.4
5
+ platform: ruby
6
+ authors:
7
+ - Gabriele Tassoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails_admin_pick_up
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ description: 'Thecorized: Description of RailsAdminOpening.'
28
+ email:
29
+ - gabriele.tassoni@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/rails_admin_opening_manifest.js
38
+ - app/views/rails_admin/main/opening.html.erb
39
+ - config/initializers/rails_admin_add_opening_action.rb
40
+ - config/initializers/rails_admin_opening_after_init.rb
41
+ - config/locales/opening.en.yml
42
+ - config/locales/opening.it.yml
43
+ - config/routes.rb
44
+ - lib/rails_admin_opening.rb
45
+ - lib/rails_admin_opening/engine.rb
46
+ - lib/rails_admin_opening/version.rb
47
+ - lib/rails_admin_opening_states_changer.rb
48
+ - lib/tasks/rails_admin_opening_tasks.rake
49
+ homepage: https://www.taris.it
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.0.1
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: 'Thecorized: Summary of RailsAdminOpening.'
72
+ test_files: []