tramway-core 1.16 → 1.16.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b65406e59a86c298559e164d9e16a55b62f83b20ecba159b86b682aa9af037bc
4
- data.tar.gz: 7a4177835f457e7b5c48f59c0980965c3c05052d75d3f52b2c1f7a9a4f270ca9
3
+ metadata.gz: 43002acf65a91407b1d149325e917c6b6e35296b9a56a6f3f6183f97e25d264a
4
+ data.tar.gz: 6df6dc5a6d61303f92ab8fcd949a5495c42a762b73ef35e848338600d25f9141
5
5
  SHA512:
6
- metadata.gz: 480f307ce1de6c9202e5a9d42539df4f34b8374037c5d643ab61592374f592fddeb63890eb094e61ee6c667660088121feb0158bf7b374c605d3a3236ac4bf77
7
- data.tar.gz: 5e96737dabbb4aace66cc0123ea1d59c0b7cd11aad65ce544153213394c359accd6544d6f3515dbbd4a98b5ec7d5639e4a2c208b79d3f452639630b5591ac919
6
+ metadata.gz: 8fbedfbc412d573935a63c98ed8dae98d2f1c7b42b6549df1f72d774edce4520bb510dbd6fcf592efb897d5723f1095e4c31c824ee560ec20cf475885f515124
7
+ data.tar.gz: 3366f0507b64d89f498786f63dbdb4e606125f9b5f2a3d66c893065ee77986c8b0025b22aaf76677aadc75ea2999e8ce6fead5c6275cf7807fab633e6db9c3f4
data/README.md CHANGED
@@ -12,6 +12,7 @@ tramway-core - это ядро проекта [tramway](https://github.com/ulmic
12
12
  ```ruby
13
13
  gem 'tramway-core'
14
14
  gem 'audited'
15
+ gem 'clipboard-rails'
15
16
  ```
16
17
 
17
18
  ```shell
@@ -81,6 +82,31 @@ def field_type
81
82
  end
82
83
  ```
83
84
 
85
+ ## Other helpers
86
+
87
+ ### CopyToClipboardHelper
88
+
89
+ [app/helpers/tramway/core/copy_to_clipboard_helper.rb](https://github.com/ulmic/tramway-dev/blob/develop/tramway-core/app/helpers/tramway/core/copy_to_clipboard_helper.rb)
90
+
91
+ #### Install
92
+
93
+ ```ruby
94
+ include ::Tramway::Core::CopyToClipboardHelper
95
+ ```
96
+
97
+ #### How to use it
98
+
99
+ It will show you in the view in bootstrap styles with font-awesome `copy` icon.
100
+
101
+ Something like this:
102
+
103
+ ![copy_to_clipboard_button](https://raw.githubusercontent.com/ulmic/tramway-dev/develop/tramway-core/docs/copy_to_clipboard_button.png)
104
+
105
+ ```ruby
106
+ copy_to_clipboard "some_id" # some_id is HTML id of element. Content of this element will be copied to the clipboard after pressing the button
107
+ ```
108
+
109
+
84
110
  # Базовые классы
85
111
 
86
112
  * ApplicationDecorator - Базовый класс декоратора. В него по умолчанию включены `ActionView::Helpers` и `ActionView::Context` и `FontAwesome5` (версия гема FontAwesome, которая поддерживает 5 версию шрифта). `FontAwesome` считается в `Tramway` основным шрифтом для иконок.
@@ -1,9 +1,10 @@
1
1
  #= require jquery
2
2
  #= require jquery_ujs
3
- #= require popper
3
+ #= require bootstrap
4
4
  #= require bootstrap-datepicker-1.8.0
5
5
  #= require bootstrap-datepicker-1.8.0.ru.min
6
6
  #= require font_awesome5
7
+ #= require clipboard
7
8
  #= require_tree .
8
9
 
9
10
  window.i18n_locale = (locale) ->
@@ -28,3 +29,5 @@ $(document).ready ->
28
29
  anchor = $(this).data('anchor')
29
30
  unless $(anchor).offset() == undefined
30
31
  $(window).scrollTop $(anchor).offset().top
32
+
33
+ clipboard = new Clipboard '.clipboard-btn'
@@ -11,9 +11,7 @@ module Tramway
11
11
  end
12
12
 
13
13
  def load_extensions
14
- if defined? ::Tramway::Extensions
15
- ::Tramway::Extensions.load
16
- end
14
+ ::Tramway::Extensions.load if defined? ::Tramway::Extensions
17
15
  end
18
16
  end
19
17
  end
@@ -6,6 +6,7 @@ class Tramway::Core::ApplicationDecorator
6
6
  include ActionView::Helpers
7
7
  include ActionView::Context
8
8
  include ::FontAwesome5::Rails::IconHelper
9
+ include ::Tramway::Core::CopyToClipboardHelper
9
10
 
10
11
  def initialize(object)
11
12
  @object = object
@@ -15,11 +15,11 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
15
15
 
16
16
  def image_view(original, thumb: nil, filename: nil)
17
17
  if original.present?
18
- thumb ||= original.small
19
- filename ||= original.path.split('/').last
20
- src_thumb = if thumb.is_a?(CarrierWave::Uploader::Base)
18
+ thumb ||= original.is_a?(CarrierWave::Uploader::Base) ? original.small : nil
19
+ filename ||= original.is_a?(CarrierWave::Uploader::Base) ? original.path&.split('/')&.last : nil
20
+ src_thumb = if thumb&.is_a?(CarrierWave::Uploader::Base)
21
21
  thumb.url
22
- elsif thumb.match(%r{^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|(?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))$})
22
+ elsif thumb&.match(%r{^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|(?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))$})
23
23
  "data:image/jpeg;base64,#{thumb}"
24
24
  else
25
25
  thumb
@@ -33,12 +33,12 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
33
33
  end
34
34
  content_tag(:div) do
35
35
  begin
36
- concat image_tag src_thumb
36
+ concat image_tag src_thumb || src_original
37
37
  rescue NoMethodError => e
38
38
  error = Tramway::Error.new plugin: :core, method: :image_view, message: "You should mount PhotoUploader to your model. Just add `mount_uploader \#{attribute_name}, PhotoUploader` to your model. #{e.message}"
39
39
  raise error.message
40
40
  end
41
- concat link_to(fa_icon(:download), src_original, class: 'btn btn-success', download: filename)
41
+ concat link_to(fa_icon(:download), src_original, class: 'btn btn-success', download: filename) if filename
42
42
  end
43
43
  end
44
44
  end
@@ -0,0 +1,13 @@
1
+ module Tramway
2
+ module Core
3
+ module CopyToClipboardHelper
4
+ def copy_to_clipboard(id)
5
+ button_tag class: 'btn btn-info clipboard-btn',
6
+ data: { clipboard_action: 'copy', clipboard_target: "##{id}" },
7
+ style: 'margin-left: 15px' do
8
+ fa_icon 'copy'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -19,11 +19,15 @@ module Tramway
19
19
  end
20
20
 
21
21
  scope :active, -> { where state: :active }
22
- scope :created_by_user, -> (user_id) { joins(:audits).where('audits.action = \'create\' AND audits.user_id = ?', user_id) }
23
- scope :admin_scope, -> (_arg) { all }
22
+ scope :created_by_user, ->(user_id) { joins(:audits).where('audits.action = \'create\' AND audits.user_id = ?', user_id) }
23
+ scope :admin_scope, ->(_arg) { all }
24
24
 
25
25
  include ::PgSearch::Model
26
26
 
27
+ def creator
28
+ audits.where(action: :create).first.user
29
+ end
30
+
27
31
  # FIXME: detect inhertited locales
28
32
  class << self
29
33
  def human_attribute_name(attribute_name, *_args)
@@ -2,6 +2,6 @@
2
2
 
3
3
  class FileUploader < ApplicationUploader
4
4
  def extension_white_list
5
- %w[pdf doc docx xls csv xlsx jpg]
5
+ %w[pdf doc docx xls csv xlsx jpg svg png jpeg gif]
6
6
  end
7
7
  end
@@ -4,7 +4,7 @@ module Tramway
4
4
  module Collections
5
5
  module Helper
6
6
  def collection_list_by(name:)
7
- begin
7
+ begin
8
8
  require name # needed to load class name with collection
9
9
  rescue LoadError
10
10
  raise "No such file #{name}. You should create file in the `lib/#{name}.rb` or elsewhere you want"
@@ -23,11 +23,11 @@ module Tramway
23
23
  if @application&.model_class.present?
24
24
  begin
25
25
  @application.model_class.first
26
- rescue
26
+ rescue StandardError
27
27
  nil
28
28
  end
29
29
  else
30
- @application
30
+ @application
31
31
  end
32
32
  end
33
33
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.16'
5
+ VERSION = '1.16.1.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.16'
4
+ version: 1.16.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-26 00:00:00.000000000 Z
11
+ date: 2020-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audited
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 4.2.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: clipboard-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: enumerize
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -346,6 +360,7 @@ files:
346
360
  - app/forms/tramway/core/extendable_form.rb
347
361
  - app/forms/tramway/core/extended_application_form.rb
348
362
  - app/forms/tramway/core/form_creator.rb
363
+ - app/helpers/tramway/core/copy_to_clipboard_helper.rb
349
364
  - app/helpers/tramway/core/title_helper.rb
350
365
  - app/inputs/date_picker_input.rb
351
366
  - app/models/tramway/core/application_record.rb