rails_admin_deposit 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 676885ab9f14271b0f121b66f4db5ca5fa1d8f49d7d4d8eb5b11a35ccbe5c692
4
+ data.tar.gz: d24003aeb03687febb0a8626e7f0d2f937e86a61da42bed7d7bf6992a213d0f2
5
+ SHA512:
6
+ metadata.gz: 52f0531237f63c282da9029c4aacad87a30c492d7a427114fa2bc49c6f477233a72ef1a569a1890be5017fffdba95ff44188d38ed97b3c86d8d7d2746689dad4
7
+ data.tar.gz: 9ee2b05c5263f4568287859235ef5fb9ee57776540888ba7f9a99049cf5e17c8a02a0a614227e647699eb66794174387185a5050a20f24d168a10d39e816bd96
data/MIT-LICENSE ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # RailsAdminDeposit
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_deposit'
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_deposit
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).
data/Rakefile ADDED
@@ -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 = 'RailsAdminDeposit'
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
File without changes
@@ -0,0 +1 @@
1
+ <%=render 'thecore_dataentry_with_date_start_and_end', not_before: false, not_after_date_only: true%>
@@ -0,0 +1,5 @@
1
+ RailsAdmin.config do |config|
2
+ config.actions do
3
+ deposit
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+
2
+ en:
3
+ barcode_not_contains_kind: Barcode does not contain Paste's kind
4
+ depositated: Barcode %{barcode} recorded as in deposit
5
+ item_already_exists: Item already exists
6
+ object_not_found_going_on: Item can be stored
7
+ not_before: Must be used not before
8
+ not_after: Must be used after
9
+ admin:
10
+ actions:
11
+ deposit:
12
+ title: "Deposit"
13
+ menu: "Deposit"
14
+ breadcrumb: "Deposit"
15
+ link: "Deposit"
16
+ bulk_link: "Deposit"
17
+ done: "Deposited"
@@ -0,0 +1,18 @@
1
+
2
+ it:
3
+ barcode_not_contains_kind: Il codice a barre non contiene il tipo di pasta
4
+ depositated: Codice a barre %{barcode} registrato come depositato
5
+ item_already_exists: L'elemento esiste
6
+ object_not_found_going_on: L'elemento può essere depositato
7
+ thecore_dataentry_with_date_start_and_end:
8
+ not_before: Da usare dopo il
9
+ not_after: Da usare prima del
10
+ admin:
11
+ actions:
12
+ deposit:
13
+ title: "Deposito"
14
+ menu: "Deposito"
15
+ breadcrumb: "Deposito"
16
+ link: "Deposito"
17
+ bulk_link: "Deposito"
18
+ done: "Depositato"
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,108 @@
1
+ require "rails_admin_deposit/engine"
2
+
3
+ module RailsAdminDeposit
4
+ # Your code goes here...
5
+ end
6
+
7
+ require 'rails_admin/config/actions'
8
+
9
+ module RailsAdmin
10
+ module Config
11
+ module Actions
12
+ class Deposit < Base
13
+ RailsAdmin::Config::Actions.register(self)
14
+
15
+
16
+ register_instance_option :object_level do
17
+ false
18
+ end
19
+ # This ensures the action only shows up for Users
20
+ register_instance_option :visible? do
21
+ # visible only if authorized and if the object has a defined method
22
+ authorized? #&& bindings[:abstract_model].model == ChosenItem && bindings[:abstract_model].model.column_names.include?("barcode")
23
+ end
24
+ # We want the action on members, not the Users collection
25
+ register_instance_option :member do
26
+ false
27
+ end
28
+
29
+ register_instance_option :collection do
30
+ false
31
+ end
32
+ register_instance_option :root? do
33
+ true
34
+ end
35
+
36
+ register_instance_option :breadcrumb_parent do
37
+ [nil]
38
+ end
39
+
40
+ register_instance_option :link_icon do
41
+ 'icon-barcode'
42
+ end
43
+ # You may or may not want pjax for your action
44
+ register_instance_option :pjax? do
45
+ true
46
+ end
47
+
48
+ register_instance_option :controller do
49
+ Proc.new do # In modo che venga valutata ogni volta che viene chiamata
50
+ if request.xhr? && !params["_pjax"]# Nel caso si voglia usare anche una interazione javascript
51
+ if params[:what_to_do] == "data-action" && !params[:data].blank?
52
+ # Here I have params[:data] and params[:barcode] set
53
+ # in params[:data] I can find the not_before and not_after params
54
+ # which I need
55
+ expiration_date = DateTime.parse(params[:data][:not_after]).beginning_of_day unless params[:data][:not_after].blank?
56
+ created_item = Item.create name: params[:data][:barcode], code: params[:data][:barcode], kind: Kind.find_by_code(params[:data][:barcode].split[0]), state: State.find_by(name: :deposit) do |i|
57
+ i.expiration_date = expiration_date unless expiration_date.blank?
58
+ end
59
+ if created_item.valid?
60
+ message = { message: I18n.t(:depositated, barcode: params[:data][:barcode]) }
61
+ message[:not_after] = expiration_date unless expiration_date.blank?
62
+ status = 200
63
+ else
64
+ # Cannot create
65
+ message = { error: created_item.errors }
66
+ message[:not_after] = expiration_date unless expiration_date.blank?
67
+ status = 400
68
+ end
69
+ else
70
+ if params[:barcode].blank?
71
+ message = { error: "#{I18n.t(:barcode_cannot_be_empty)}" }
72
+ status = 400
73
+ else
74
+ item = Item.where(code: params[:barcode]).first
75
+ # Se il barcode esiste già come elemento, allora è un errore
76
+ # Perchè la fase di deposito è la prima, non deve esistere nel sistema
77
+ unless item.blank?
78
+ message = { error: "#{I18n.t(:item_already_exists)}: #{params[:barcode]}" }
79
+ status = 404
80
+ else
81
+ # Se non esiste, allora mando avanti il processo:
82
+ # - controllo che il barcode scansionato, contenga il codice di un kind di pasta conosciuto
83
+ unless Kind.pluck(:code).any? { |word| params[:barcode].include?(word) }
84
+ # --- Se non è così, allora errore
85
+ message = { error: "#{I18n.t(:barcode_not_contains_kind)}: #{params[:barcode]}" }
86
+ status = 404
87
+ else
88
+ # --- Se è così, continua:
89
+ # ----- ritorno ok e chiedo la data di expiration e di not before
90
+ # ----- a quel punto, dando ok, posso procedere al salvataggio
91
+ # not_before = DateTime.now + Settings.ns('phases_models').not_before.hours
92
+ not_after = params[:parameters][:not_after].presence || DateTime.now # + Settings.ns('phases_models').not_after.hours
93
+ message = { info: "#{I18n.t(:object_not_found_going_on)}", barcode: params[:barcode], not_after: not_after }
94
+ status = 200
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ render json: MultiJson.dump(message), status: status
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+
@@ -0,0 +1,4 @@
1
+ module RailsAdminDeposit
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminDeposit
2
+ VERSION = '1.1.6'.freeze
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_admin_deposit do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_deposit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Gabriele Tassoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: phases_models
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
+ - !ruby/object:Gem::Dependency
28
+ name: thecore_dataentry_with_date_start_and_end
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 Description of RailsAdminDeposit.
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/rails_admin_deposit_manifest.js
52
+ - app/views/rails_admin/main/deposit.html.erb
53
+ - config/initializers/rails_admin_add_deposit_action.rb
54
+ - config/locales/deposit.en.yml
55
+ - config/locales/deposit.it.yml
56
+ - config/routes.rb
57
+ - lib/rails_admin_deposit.rb
58
+ - lib/rails_admin_deposit/engine.rb
59
+ - lib/rails_admin_deposit/version.rb
60
+ - lib/tasks/rails_admin_deposit_tasks.rake
61
+ homepage: https://www.taris.it
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.7.7
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Thecorized RailsAdminDeposit.
85
+ test_files: []