egov_utils 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62a3bb3945d7477f7ea854dad437e3ee90e92314
4
- data.tar.gz: '0941f20def3bb8c65e07af94961dea9669e31c2e'
3
+ metadata.gz: 3bee9e427897dfb93fc4f42d0b146def3c4cdd0c
4
+ data.tar.gz: 625f0ca14a939d628e64b2cff3ba81d3fdadc74d
5
5
  SHA512:
6
- metadata.gz: bef0cd8b502f832ca3dbfc0c05662ead83ce9a5fdfcbefdc6ed4d262defe9b51a7ebcd7daa53bba55cff0d0e036e472081a368105e7cd1f655e70f3a926342e6
7
- data.tar.gz: 00b53ade30c51f8d562dd77e11a29cf0db4e275c88b5b86558c82da9743bf72c10a9819fb238800ec242830fda3a35c8b629d5086a65d89d5d8ad8ce935c0169
6
+ metadata.gz: b9a9f694b7d5e2ee741ae28fb7459fe0242921b76a53e0a113d629e8dba33510faee48f826c08577a9c06009106ddcedf0d48e78b24af168b91b11c7cab3e390
7
+ data.tar.gz: e352cfd5672c519d8363b5c69a576e2f6b9e7ccacb6a341b3f9236c0d9ea1620fd84c5278024879c44d2db6c42017041510368796981512b58cac7bacf9b1f46
data/README.md CHANGED
@@ -14,6 +14,9 @@ To be done:
14
14
  * ISDS SSO integration
15
15
 
16
16
  ## Usage
17
+
18
+ Detailed developers documentation can be found at [Documentation](https://git.servis.justice.cz/libraries/egov_utils-rails/wikis/Documentation).
19
+
17
20
  Framework uses configuration in file config/config.yml
18
21
 
19
22
  ### LDAP
@@ -21,3 +21,4 @@
21
21
  //= require i18n/translations
22
22
  //= require egov_utils/eGovUtilities
23
23
  //= require egov_utils/roles
24
+ //= require egov_utils/file_uid
@@ -0,0 +1,65 @@
1
+ $ = jQuery
2
+
3
+ $.widget 'egov_utils.fileUid',
4
+ options:
5
+ available_agendas: ['T', 'TN']
6
+
7
+ _create: ()->
8
+ that = this
9
+
10
+ @container = $('<span></span>', class: 'egov-file-uid', style: 'position: relative; display: block;')
11
+ @file_uid_gui = @_create_file_uid_gui()
12
+
13
+ @container.insertAfter(@element)
14
+ @container.append(@element).append(@file_uid_gui)
15
+
16
+ @element.css(position: 'absolute', top: 0, left: 0, 'background-color': 'transparent')
17
+
18
+ @form = @element.closest('form')
19
+ @form.on 'submit', (evt)->
20
+ that.element.val(that.getValue())
21
+
22
+ if @element.val() != ''
23
+ this.setValue( @element.val() )
24
+
25
+ _destroy: ()->
26
+ @element.attr('style', '')
27
+ @element.insertAfter(@container)
28
+ @container.remove()
29
+
30
+
31
+ _create_file_uid_gui: (default_value)->
32
+ container = $('<div></div>', class: 'court_file_uid input-group')
33
+ @parts = [
34
+ $('<input type="text" name="senat" class="form-control senat"><input type="hidden" value="-">'),
35
+ $('<select type="text" name="agenda" class="form-control agenda"></select>'),
36
+ $('<input type="hidden" value="-"><input type="text" name="cislo_pripadu" class="form-control cislo_pripadu"><div class="input-group-addon">/</div><input type="hidden" value="/">'),
37
+ $('<input type="text" class="form-control">')
38
+ ]
39
+ for agenda in @options.available_agendas
40
+ @parts[1].append('<option value="'+agenda+'">'+agenda+'</option>')
41
+
42
+ for part in @parts
43
+ container.append(part)
44
+ container
45
+
46
+ setValue: (value)->
47
+ if value.indexOf('/') < 0
48
+ console.warn('Value for file uid has to have a "/" in it')
49
+ return false
50
+ flvl_ary = value.split('/')
51
+ @parts[@parts.length - 1].val(flvl_ary[1])
52
+ slvl_ary = flvl_ary[0].split('-')
53
+ if slvl_ary.length != 3
54
+ console.warn('Value for file uid has to have 2times "-" in it')
55
+ return false
56
+
57
+ @file_uid_gui.find('.senat').val(slvl_ary[0])
58
+ @file_uid_gui.find('.agenda').val(slvl_ary[1])
59
+ @file_uid_gui.find('.cislo_pripadu').val(slvl_ary[2])
60
+
61
+ getValue: ()->
62
+ value = ''
63
+ @file_uid_gui.find(':input').each (i, part)->
64
+ value += $(part).val()
65
+ value
@@ -2,7 +2,7 @@ module EgovUtils
2
2
  class Person < ApplicationRecord
3
3
 
4
4
  validates :firstname, :lastname, :birth_date, presence: true
5
- validates :birth_date, uniqueness: { scope: [:firstname, :lastname] }
5
+ validates :birth_date, uniqueness: { scope: [:firstname, :lastname] }, birthday: true
6
6
 
7
7
  def fullname
8
8
  firstname.to_s + ' ' + lastname.to_s
@@ -0,0 +1,7 @@
1
+ class BirthdayValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ return if options[:allow_nil] && value.presence.nil?
4
+ record.errors.add(attribute, :in_past) if !value || value >= Time.now.to_date
5
+ record.errors.add(attribute, :after_1920) if !value || value <= Date.new(1930, 1, 1)
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class FileuidValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ return if options[:allow_nil] && value.presence.nil?
4
+ unless value =~ /\A\d+-\w{1,4}-\d+\/\d{4}\z/i
5
+ record.errors.add(attribute, (options[:message] || :fileuid_format))
6
+ end
7
+ end
8
+ end
@@ -5,11 +5,13 @@ $ ->
5
5
  create_attributes ||= {}
6
6
  %>
7
7
 
8
- $('body').off 'egov:submitted'
9
- $('body').on 'egov:submitted', '#modal', (evt, data)->
8
+ after_modal_submit = (evt, data)->
10
9
  grid = $("#<%= grid_id %>").swidget()
11
10
  grid.dataSource.read()
12
11
 
12
+ $('body').off 'egov:submitted', after_modal_submit
13
+ $('body').on 'egov:submitted', '#modal', after_modal_submit
14
+
13
15
  <%# would be a bit cleaner to give the filled form to the shield grid create method, then send the form by ajax %>
14
16
  createRecord = (evt)->
15
17
  $.ajax('<%= new_polymorphic_path(schema.model, create_attributes.merge(format: :js)) %>')
@@ -1,3 +1,3 @@
1
1
  = form.text_field(:firstname)
2
2
  = form.text_field(:lastname)
3
- = form.date_field(:birth_date, data: {'date-view-mode' => 'decades'})
3
+ = form.date_field(:birth_date, data: {'date-view-mode' => 'decades', 'date-min-date' => Date.new(1920, 1, 1).to_s, 'date-max-date' => Date.today.to_s, 'date-use-current' => false, 'date-view-date' => Date.new(1950, 1, 1).to_s })
@@ -2,6 +2,6 @@
2
2
  - flash.each do |name, msg|
3
3
  - if msg.is_a?(String)
4
4
  %div{:class => "alert alert-#{name.to_s == 'notice' ? "info" : "alert"} alert-dismissible fade show", "role" => "alert"}
5
- %button.close{'type' => 'button', 'data-dissmis' => 'alert'}
5
+ %button.close{'type' => 'button', 'data-dismiss' => 'alert'}
6
6
  %span{'aria-hidden' => 'true'}= raw '&times;'
7
7
  = msg
@@ -55,6 +55,7 @@ cs:
55
55
  profile:
56
56
  too_many_authors: Příliš mnoho autorů
57
57
 
58
+
58
59
  labels: &my_labels
59
60
  user:
60
61
  password: Heslo
@@ -89,3 +90,6 @@ cs:
89
90
  messages:
90
91
  ico_format: Není správný formát IČO
91
92
  email_format: není e-mail
93
+ in_past: Musí být v minulosti
94
+ after_1920: Musí být po roce 1920
95
+ fileuid_format: Nesprávný tvar spisové značky
@@ -0,0 +1,15 @@
1
+ require 'egov_utils/helpers/tags/fileuid_field'
2
+
3
+ module BootstrapForm
4
+ module Fileuid
5
+
6
+ def fileuid_field(method, options={})
7
+ form_group_builder(method, options) do
8
+ prepend_and_append_input(options) do
9
+ @template.fileuid_field(@object_name, method, objectify_options(options))
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -55,18 +55,26 @@ module EgovUtils
55
55
  # end
56
56
  end
57
57
 
58
+ initializer 'egov_utils.view_helpers' do
59
+ ActiveSupport.on_load(:action_view) do
60
+ require 'egov_utils/helpers/form_helper'
61
+ include ::EgovUtils::Helpers::FormHelper
62
+ end
63
+ end
64
+
58
65
  initializer 'egov_utils.bootstrap_form' do
59
66
  require 'bootstrap_form'
60
67
 
61
68
  require 'bootstrap_form/helpers/bootstrap4'
62
69
  require 'bootstrap_form/datetimepicker'
70
+ require 'bootstrap_form/fileuid'
63
71
  BootstrapForm::Helpers::Bootstrap.__send__(:prepend, BootstrapForm::Helpers::Bootstrap4)
64
72
 
65
73
  BootstrapForm::DATE_FORMAT = 'DD/MM/YYYY'
66
74
  ruby_format_string = BootstrapForm::DATE_FORMAT.gsub('YYYY', "%Y").gsub('MM', "%m").gsub('DD', "%d")
67
75
 
68
76
  BootstrapForm::FormBuilder.__send__(:prepend, BootstrapForm::Datetimepicker)
69
-
77
+ BootstrapForm::FormBuilder.__send__(:prepend, BootstrapForm::Fileuid)
70
78
 
71
79
  ActionView::Helpers::Tags::DateField.redefine_method(:format_date) do |value|
72
80
  value.try(:strftime, ruby_format_string)
@@ -81,5 +89,11 @@ module EgovUtils
81
89
  # Rails.application.reload_routes!
82
90
  # OmniAuth.config.path_prefix = "#{Rails.application.routes.named_routes[:egov_utils].path.spec.to_s}/auth"
83
91
  # end
92
+
93
+ initializer 'egov_utils.initialize_factory_paths', after: 'factory_bot.set_factory_paths' do
94
+ if bot_module = 'FactoryBot'.safe_constantize
95
+ FactoryBot.definition_file_paths << EgovUtils::Engine.root.join('spec', 'factories')
96
+ end
97
+ end
84
98
  end
85
99
  end
@@ -0,0 +1,14 @@
1
+ module EgovUtils
2
+ module Helpers
3
+ module FormHelper
4
+
5
+ # Returns an input tag of the "fileuid" type tailored for accessing a specified attribute (identified by +method+) on an object
6
+ # assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
7
+ # hash with +options+.
8
+ def fileuid_field(object_name, method, options = {})
9
+ Tags::FileuidField.new(object_name, method, self, options).render
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ module EgovUtils
2
+ module Helpers
3
+ module Tags
4
+ class FileuidField < ActionView::Helpers::Tags::TextField
5
+
6
+ def render
7
+ res = super
8
+ res << @template_object.javascript_tag(javascript_str(@options))
9
+ res
10
+ end
11
+
12
+ private
13
+ def all_agendas
14
+ ['T', 'Tm', 'INS', 'E'] # a dalsi
15
+ end
16
+
17
+ def javascript_str(options)
18
+ agendas = all_agendas
19
+ agendas &= @options.delete('agendas') if @options['agendas']
20
+ index = name_and_id_index(options)
21
+ tag_id = @options.fetch("id") { tag_id(index) }
22
+
23
+ str = "$(function(){"
24
+ str << " $('##{tag_id}').fileUid({ available_agendas: #{ agendas.to_json } });"
25
+ str << " var destroy_evt_method = function(evt){"
26
+ str << " $('##{tag_id}').fileUid('destroy');"
27
+ str << " $(document).off('turbolinks:before-cache', destroy_evt_method);"
28
+ str << " };"
29
+ str << " $(document).on('turbolinks:before-cache', destroy_evt_method);"
30
+ str << "});"
31
+ pp str
32
+ str
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ module EgovUtils
2
+ module TestUtils
3
+ module ControllerHelpers
4
+
5
+ def default_user(params={})
6
+ user = FactoryBot.create(:egov_utils_user, params)
7
+ user
8
+ end
9
+
10
+ def admin_user
11
+ default_user(roles: ['admin'])
12
+ end
13
+
14
+ def basic_user
15
+ default_user(roles: ['user'])
16
+ end
17
+
18
+ def anonymous_user
19
+ u = default_user
20
+ allow(user).to receive(:persisted?).and_return(false)
21
+ u
22
+ end
23
+
24
+ def sign_in(user = basic_user)
25
+ allow(controller).to receive(:find_current_user).and_return(user)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.1.12'
2
+ VERSION = '0.1.13'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -276,6 +276,7 @@ files:
276
276
  - app/assets/config/egov_utils_manifest.js
277
277
  - app/assets/javascripts/egov_utils/application.js
278
278
  - app/assets/javascripts/egov_utils/eGovUtilities.coffee.erb
279
+ - app/assets/javascripts/egov_utils/file_uid.coffee
279
280
  - app/assets/javascripts/egov_utils/groups.js
280
281
  - app/assets/javascripts/egov_utils/roles.coffee.erb
281
282
  - app/assets/javascripts/egov_utils/setup_locale.coffee.erb
@@ -314,7 +315,9 @@ files:
314
315
  - app/schemas/egov_utils/address_schema.rb
315
316
  - app/schemas/egov_utils/person_schema.rb
316
317
  - app/schemas/egov_utils/user_schema.rb
318
+ - app/validators/birthday_validator.rb
317
319
  - app/validators/email_validator.rb
320
+ - app/validators/fileuid_validator.rb
318
321
  - app/validators/ico_validator.rb
319
322
  - app/views/common/_grid.html.coffee
320
323
  - app/views/common/_modal.html.haml
@@ -342,11 +345,15 @@ files:
342
345
  - db/migrate/20170809150646_create_egov_utils_people.rb
343
346
  - db/migrate/20170824111701_create_egov_utils_groups.rb
344
347
  - lib/bootstrap_form/datetimepicker.rb
348
+ - lib/bootstrap_form/fileuid.rb
345
349
  - lib/bootstrap_form/helpers/bootstrap4.rb
346
350
  - lib/egov_utils.rb
347
351
  - lib/egov_utils/auth_source.rb
348
352
  - lib/egov_utils/engine.rb
349
353
  - lib/egov_utils/has_audit_trail.rb
354
+ - lib/egov_utils/helpers/form_helper.rb
355
+ - lib/egov_utils/helpers/tags/fileuid_field.rb
356
+ - lib/egov_utils/test_utils/controller_helpers.rb
350
357
  - lib/egov_utils/user_utils/application_controller_patch.rb
351
358
  - lib/egov_utils/user_utils/role.rb
352
359
  - lib/egov_utils/version.rb