kono_utils 0.15.15 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +17 -78
  3. data/app/assets/javascripts/kono_utils/core.coffee +477 -0
  4. data/app/assets/stylesheets/kono_utils/{_kono_styles.css.scss → core.css.scss} +1 -16
  5. data/app/policies/kono_utils/base_editing_policy_concern.rb +52 -3
  6. data/app/policies/kono_utils/base_search_form_policy_concern.rb +25 -0
  7. data/config/initializers/mysql.rb +2 -2
  8. data/config/locales/it.yml +3 -1
  9. data/lib/generators/kono_utils/install/install_generator.rb +44 -0
  10. data/lib/generators/templates/base_editing_controller.template +3 -0
  11. data/lib/generators/templates/base_editing_helper.template +3 -0
  12. data/lib/generators/templates/base_editing_policy.template +4 -0
  13. data/lib/generators/templates/initializer.rb +3 -1
  14. data/lib/kono_utils.rb +29 -18
  15. data/lib/kono_utils/application_core_helper.rb +524 -0
  16. data/lib/kono_utils/application_enum_helper.rb +53 -0
  17. data/lib/kono_utils/application_helper.rb +4 -578
  18. data/lib/kono_utils/base_editing_core_helper.rb +194 -0
  19. data/lib/kono_utils/base_editing_helper.rb +3 -186
  20. data/lib/kono_utils/base_search.rb +32 -19
  21. data/lib/kono_utils/concerns.rb +12 -10
  22. data/lib/kono_utils/concerns/active_record_translation.rb +8 -4
  23. data/lib/kono_utils/concerns/active_storage_remover_helper.rb +61 -0
  24. data/lib/kono_utils/concerns/base_editing.rb +199 -53
  25. data/lib/kono_utils/configuration.rb +18 -0
  26. data/lib/kono_utils/engine.rb +15 -6
  27. data/lib/kono_utils/paginate_proxer.rb +17 -0
  28. data/lib/kono_utils/search_form_builder.rb +24 -0
  29. data/lib/kono_utils/version.rb +1 -1
  30. data/spec/dummy/.gitignore +2 -0
  31. data/spec/dummy/app/assets/config/manifest.js +2 -0
  32. data/spec/dummy/app/assets/javascripts/application.js +2 -0
  33. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  34. data/spec/dummy/app/controllers/base_editing_controller.rb +3 -0
  35. data/spec/dummy/app/controllers/users_controller.rb +2 -0
  36. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  37. data/spec/dummy/app/helpers/base_editing_helper.rb +3 -0
  38. data/spec/dummy/app/models/application_record.rb +5 -0
  39. data/spec/dummy/app/models/user.rb +2 -0
  40. data/spec/dummy/app/policies/application_policy.rb +49 -0
  41. data/spec/dummy/app/policies/base_editing_policy.rb +4 -0
  42. data/spec/dummy/app/policies/user_policy.rb +23 -0
  43. data/spec/dummy/bin/rails +1 -1
  44. data/spec/dummy/bin/setup +20 -13
  45. data/spec/dummy/bin/update +31 -0
  46. data/spec/dummy/bin/yarn +11 -0
  47. data/spec/dummy/config/application.rb +15 -17
  48. data/spec/dummy/config/environment.rb +1 -1
  49. data/spec/dummy/config/environments/development.rb +31 -11
  50. data/spec/dummy/config/environments/production.rb +26 -16
  51. data/spec/dummy/config/environments/test.rb +10 -6
  52. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  53. data/spec/dummy/config/initializers/assets.rb +6 -3
  54. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  55. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  56. data/spec/dummy/config/initializers/kono_utils.rb +5 -0
  57. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -0
  58. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  59. data/spec/dummy/config/locales/en.yml +10 -0
  60. data/spec/dummy/config/routes.rb +3 -52
  61. data/spec/dummy/config/storage.yml +34 -0
  62. data/spec/dummy/db/migrate/20190716093114_create_users.rb +11 -0
  63. data/spec/dummy/db/schema.rb +23 -0
  64. data/spec/dummy/package.json +5 -0
  65. data/spec/dummy/spec/models/user_spec.rb +5 -0
  66. data/spec/dummy/yarn.lock +21 -0
  67. metadata +83 -144
  68. data/app/assets/javascripts/kono_utils/utilities.coffee +0 -481
  69. data/app/assets/stylesheets/kono_utils/utils.css.scss +0 -4
  70. data/app/input/bs_aceeditor_input.rb +0 -53
  71. data/app/input/bs_autocomplete_input.rb +0 -60
  72. data/app/input/bs_datepicker_input.rb +0 -16
  73. data/app/input/bs_datetimepicker_input.rb +0 -80
  74. data/app/input/bs_file_download_input.rb +0 -35
  75. data/app/input/bs_image_input.rb +0 -35
  76. data/app/input/bs_label_with_container_input.rb +0 -22
  77. data/app/input/bs_location_picker_input.rb +0 -95
  78. data/app/input/bs_readonly_input.rb +0 -52
  79. data/app/input/bs_timepicker_input.rb +0 -14
  80. data/app/views/kono_utils/application/_search_panel.html.erb +0 -36
  81. data/app/views/kono_utils/base_editing/_edit.html.erb +0 -3
  82. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +0 -3
  83. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +0 -3
  84. data/app/views/kono_utils/base_editing/_form.html.erb +0 -15
  85. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +0 -2
  86. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +0 -3
  87. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +0 -3
  88. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  89. data/app/views/kono_utils/base_editing/_new.html.erb +0 -3
  90. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +0 -3
  91. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +0 -3
  92. data/app/views/kono_utils/base_editing/_search_form.html.erb +0 -1
  93. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +0 -1
  94. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +0 -1
  95. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +0 -1
  96. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +0 -1
  97. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +0 -1
  98. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +0 -1
  99. data/app/views/kono_utils/base_editing/application/edit.html.erb +0 -1
  100. data/app/views/kono_utils/base_editing/application/new.html.erb +0 -1
  101. data/app/views/kono_utils/base_editing/edit.html.erb +0 -1
  102. data/app/views/kono_utils/base_editing/index.html.erb +0 -36
  103. data/app/views/kono_utils/base_editing/new.html.erb +0 -1
  104. data/lib/kono_utils/encoder.rb +0 -47
  105. data/lib/kono_utils/fiscal_code.rb +0 -47
  106. data/lib/kono_utils/params_hash_array.rb +0 -37
  107. data/lib/kono_utils/percentage.rb +0 -60
  108. data/lib/kono_utils/tmp_file.rb +0 -81
  109. data/lib/kono_utils/virtual_model.rb +0 -22
  110. data/lib/tasks/kono_utils_tasks.rake +0 -4
  111. data/spec/lib/kono_utils/fiscal_code_spec.rb +0 -56
  112. data/vendor/assets/javascripts/EventEmitter.js +0 -473
@@ -0,0 +1,18 @@
1
+ module KonoUtils
2
+ class Configuration
3
+ attr_accessor :google_api_key
4
+ attr_accessor :application_helper_includes
5
+ attr_accessor :base_editing_helper_includes
6
+ attr_accessor :pagination_proxer
7
+
8
+ #@return [KonoUtils::SearchFormBuilder]
9
+ attr_accessor :search_form_builder
10
+
11
+ def initialize
12
+ @application_helper_includes = []
13
+ @base_editing_helper_includes = []
14
+ @pagination_proxer = PaginateProxer
15
+ @search_form_builder = SearchFormBuilder
16
+ end
17
+ end
18
+ end
@@ -1,18 +1,27 @@
1
1
  module KonoUtils
2
2
  class Engine < ::Rails::Engine
3
3
 
4
- require 'bootstrap3-datetimepicker-rails'
5
- require 'momentjs-rails'
6
- require 'font-awesome-rails'
7
- require 'rails-assets-bootstrap-treeview'
8
- require 'will_paginate'
9
- require 'will_paginate-bootstrap'
10
4
  require 'rdiscount'
5
+ require 'pundit'
6
+ require 'kono_utils_helpers'
11
7
 
12
8
 
13
9
  initializer 'kono_utils.append_views', :group => :all do |app|
14
10
  ActionController::Base.append_view_path KonoUtils::Engine.root.join("app", "views", "kono_utils")
15
11
  end
16
12
 
13
+
14
+ initializer 'kono_utils.append_helpers', :group => :all do |app|
15
+ KonoUtils.configure do |c|
16
+ c.application_helper_includes << KonoUtils::ApplicationCoreHelper
17
+ c.application_helper_includes << KonoUtils::ApplicationEnumHelper
18
+ c.base_editing_helper_includes << KonoUtils::BaseEditingCoreHelper
19
+ end
20
+ end
21
+
22
+ initializer 'kono_utils.appen_custom_format', :group => :all do |app|
23
+ Mime::Type.register Mime[:js].to_s, :inject
24
+ end
25
+
17
26
  end
18
27
  end
@@ -0,0 +1,17 @@
1
+ module KonoUtils
2
+ ##
3
+ # Simple PORO to proxyng the pagination operations
4
+ class PaginateProxer
5
+
6
+ attr_accessor :collection
7
+
8
+ def initialize(collection)
9
+ @collection = collection
10
+ end
11
+
12
+ def paginate(params={})
13
+ raise "TO Override with the correct pagination method of the gem used"
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module KonoUtils
2
+ ##
3
+ # PORO che si occupa di fare da proxy nella generazione della form della ricerca.
4
+ # Questa classe è designata a staccare la logica del modello della ricerca dalla logica del controller e view
5
+ class SearchFormBuilder
6
+
7
+ #@return [KonoUtils::BaseSearch] o una classe derivata
8
+ attr_reader :search
9
+
10
+ # @param [KonoUtils::BaseSearch] search
11
+ def initialize(search)
12
+ @search = search
13
+ end
14
+
15
+
16
+ ##
17
+ # Costruisce la path per fare le richieste, oppure false nel caso non sia stata configurata
18
+ # @return [String,FalseClass]
19
+ def search_path
20
+ Rails.application.routes.url_helpers.polymorphic_path(search) rescue false
21
+ end
22
+
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module KonoUtils
2
- VERSION = '0.15.15'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ public/assets
@@ -0,0 +1,2 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
@@ -10,4 +10,6 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
+ //= require jquery/dist/jquery
14
+ //= require kono_utils/utilities
13
15
  //= require_tree .
@@ -2,4 +2,14 @@ class ApplicationController < ActionController::Base
2
2
  # Prevent CSRF attacks by raising an exception.
3
3
  # For APIs, you may want to use :null_session instead.
4
4
  protect_from_forgery with: :exception
5
+
6
+
7
+ private
8
+
9
+ ##
10
+ # Semplificazione in sviluppo di un possibile utente
11
+ def current_user
12
+ User.first || User.create(username: 'mario', surname: 'rossi',email:"example@tld.it")
13
+ end
14
+
5
15
  end
@@ -0,0 +1,3 @@
1
+ class BaseEditingController < ApplicationController
2
+ include KonoUtils::Concerns::BaseEditing
3
+ end
@@ -0,0 +1,2 @@
1
+ class UsersController < BaseEditingController
2
+ end
@@ -1,2 +1,3 @@
1
1
  module ApplicationHelper
2
+ include KonoUtils::ApplicationHelper
2
3
  end
@@ -0,0 +1,3 @@
1
+ module BaseEditingHelper
2
+ include KonoUtils::BaseEditingHelper
3
+ end
@@ -0,0 +1,5 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ include KonoUtils::Concerns::ActiveRecordTranslation
3
+
4
+ self.abstract_class = true
5
+ end
@@ -0,0 +1,2 @@
1
+ class User < ApplicationRecord
2
+ end
@@ -0,0 +1,49 @@
1
+ class ApplicationPolicy
2
+ attr_reader :user, :record
3
+
4
+ def initialize(user, record)
5
+ @user = user
6
+ @record = record
7
+ end
8
+
9
+ def index?
10
+ false
11
+ end
12
+
13
+ def show?
14
+ false
15
+ end
16
+
17
+ def create?
18
+ false
19
+ end
20
+
21
+ def new?
22
+ create?
23
+ end
24
+
25
+ def update?
26
+ false
27
+ end
28
+
29
+ def edit?
30
+ update?
31
+ end
32
+
33
+ def destroy?
34
+ false
35
+ end
36
+
37
+ class Scope
38
+ attr_reader :user, :scope
39
+
40
+ def initialize(user, scope)
41
+ @user = user
42
+ @scope = scope
43
+ end
44
+
45
+ def resolve
46
+ scope.all
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,4 @@
1
+ class BaseEditingPolicy < ApplicationPolicy
2
+ include KonoUtils::BaseEditingPolicyConcern
3
+
4
+ end
@@ -0,0 +1,23 @@
1
+ class UserPolicy < BaseEditingPolicy
2
+
3
+ def index?
4
+ true
5
+ end
6
+
7
+ def show?
8
+ true
9
+ end
10
+
11
+ def create?
12
+ true
13
+ end
14
+
15
+ def update?
16
+ true
17
+ end
18
+
19
+ def destroy?
20
+ true
21
+ end
22
+
23
+ end
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
3
  require_relative '../config/boot'
4
4
  require 'rails/commands'
@@ -1,29 +1,36 @@
1
1
  #!/usr/bin/env ruby
2
- require 'pathname'
2
+ require 'fileutils'
3
+ include FileUtils
3
4
 
4
5
  # path to your application root.
5
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+ APP_ROOT = File.expand_path('..', __dir__)
6
7
 
7
- Dir.chdir APP_ROOT do
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
8
13
  # This script is a starting point to setup your application.
9
- # Add necessary setup steps to this file:
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
10
19
 
11
- puts "== Installing dependencies =="
12
- system "gem install bundler --conservative"
13
- system "bundle check || bundle install"
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
14
22
 
15
23
  # puts "\n== Copying sample files =="
16
- # unless File.exist?("config/database.yml")
17
- # system "cp config/database.yml.sample config/database.yml"
24
+ # unless File.exist?('config/database.yml')
25
+ # cp 'config/database.yml.sample', 'config/database.yml'
18
26
  # end
19
27
 
20
28
  puts "\n== Preparing database =="
21
- system "bin/rake db:setup"
29
+ system! 'bin/rails db:setup'
22
30
 
23
31
  puts "\n== Removing old logs and tempfiles =="
24
- system "rm -f log/*"
25
- system "rm -rf tmp/cache"
32
+ system! 'bin/rails log:clear tmp:clear'
26
33
 
27
34
  puts "\n== Restarting application server =="
28
- system "touch tmp/restart.txt"
35
+ system! 'bin/rails restart'
29
36
  end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a way to update your development environment automatically.
14
+ # Add necessary update steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ puts "\n== Updating database =="
24
+ system! 'bin/rails db:migrate'
25
+
26
+ puts "\n== Removing old logs and tempfiles =="
27
+ system! 'bin/rails log:clear tmp:clear'
28
+
29
+ puts "\n== Restarting application server =="
30
+ system! 'bin/rails restart'
31
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path('..', __dir__)
3
+ Dir.chdir(APP_ROOT) do
4
+ begin
5
+ exec "yarnpkg", *ARGV
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
@@ -1,32 +1,30 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require_relative 'boot'
2
2
 
3
+ require "rails"
3
4
  # Pick the frameworks you want:
5
+ require "active_model/railtie"
6
+ require "active_job/railtie"
4
7
  require "active_record/railtie"
8
+ require "active_storage/engine"
5
9
  require "action_controller/railtie"
6
10
  require "action_mailer/railtie"
7
11
  require "action_view/railtie"
12
+ # require "action_cable/engine"
8
13
  require "sprockets/railtie"
9
- # require "rails/test_unit/railtie"
14
+ require "rails/test_unit/railtie"
10
15
 
16
+ # Require the gems listed in Gemfile, including any gems
17
+ # you've limited to :test, :development, or :production.
11
18
  Bundler.require(*Rails.groups)
12
- require "kono_utils"
13
19
 
14
20
  module Dummy
15
21
  class Application < Rails::Application
16
- # Settings in config/environments/* take precedence over those specified here.
17
- # Application configuration should go into files in config/initializers
18
- # -- all .rb files in that directory are automatically loaded.
19
-
20
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
21
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
22
- # config.time_zone = 'Central Time (US & Canada)'
23
-
24
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
25
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
26
- # config.i18n.default_locale = :de
22
+ # Initialize configuration defaults for originally generated Rails version.
23
+ config.load_defaults 6.0
27
24
 
28
- # Do not swallow errors in after_commit/after_rollback callbacks.
29
- config.active_record.raise_in_transactional_callbacks = true
25
+ # Settings in config/environments/* take precedence over those specified here.
26
+ # Application configuration can go into files in config/initializers
27
+ # -- all .rb files in that directory are automatically loaded after loading
28
+ # the framework and any gems in your application.
30
29
  end
31
30
  end
32
-
@@ -1,5 +1,5 @@
1
1
  # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
2
+ require_relative 'application'
3
3
 
4
4
  # Initialize the Rails application.
5
5
  Rails.application.initialize!
@@ -9,33 +9,53 @@ Rails.application.configure do
9
9
  # Do not eager load code on boot.
10
10
  config.eager_load = false
11
11
 
12
- # Show full error reports and disable caching.
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
12
+ # Show full error reports.
13
+ config.consider_all_requests_local = true
14
+
15
+ # Enable/disable caching. By default caching is disabled.
16
+ # Run rails dev:cache to toggle caching.
17
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
18
+ config.action_controller.perform_caching = true
19
+
20
+ config.cache_store = :memory_store
21
+ config.public_file_server.headers = {
22
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
23
+ }
24
+ else
25
+ config.action_controller.perform_caching = false
26
+
27
+ config.cache_store = :null_store
28
+ end
29
+
30
+ # Store uploaded files on the local file system (see config/storage.yml for options)
31
+ config.active_storage.service = :local
15
32
 
16
33
  # Don't care if the mailer can't send.
17
34
  config.action_mailer.raise_delivery_errors = false
18
35
 
36
+ config.action_mailer.perform_caching = false
37
+
19
38
  # Print deprecation notices to the Rails logger.
20
39
  config.active_support.deprecation = :log
21
40
 
22
41
  # Raise an error on page load if there are pending migrations.
23
42
  config.active_record.migration_error = :page_load
24
43
 
44
+ # Highlight code that triggered database queries in logs.
45
+ config.active_record.verbose_query_logs = true
46
+
25
47
  # Debug mode disables concatenation and preprocessing of assets.
26
48
  # This option may cause significant delays in view rendering with a large
27
49
  # number of complex assets.
28
50
  config.assets.debug = true
29
51
 
30
- # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
- # yet still be able to expire them through the digest params.
32
- config.assets.digest = true
33
-
34
- # Adds additional error checking when serving assets at runtime.
35
- # Checks for improperly declared sprockets dependencies.
36
- # Raises helpful error messages.
37
- config.assets.raise_runtime_errors = true
52
+ # Suppress logger output for asset requests.
53
+ config.assets.quiet = true
38
54
 
39
55
  # Raises error for missing translations
40
56
  # config.action_view.raise_on_missing_translations = true
57
+
58
+ # Use an evented file watcher to asynchronously detect changes in source code,
59
+ # routes, locales, etc. This feature depends on the listen gem.
60
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
41
61
  end