tramway-core 1.18.1 → 1.18.3.1

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: 88f57e54e293b5c5a85a88563762fd8c26df2ccbcb6eedebcb8ad1636d19ab08
4
- data.tar.gz: 721461846180ea4eb78ebdbc314029be09ff3c391c995900ef0d2a498236af62
3
+ metadata.gz: 54caa49641af517f7999adde3d7f7f757b528456b0d1a7e999de0af99419b08a
4
+ data.tar.gz: 1ebba7d8790d3dfd465dfd3dbe4f9118bb235f09b3daed23d4914a442f673aa4
5
5
  SHA512:
6
- metadata.gz: b641dc9b842fb20fef05c90a73ed0007ddb9804b45cef8e6b74b2c6eea99e6610580d79450a7ef121a53a373685369addb83078e0db5e658c2129306c542c62c
7
- data.tar.gz: 7f19244857938c969c03e52d49c063d34b52e25e4aad17d9bdee41bc7d12b2e650f241ec51a2f6a90ce71ab2cc2fd5409ac5d26857c59b464d44a095632d69c8
6
+ metadata.gz: 9e5e6af1ec6aaed1a8abca8347ccdfcc871e753e520a4b39fbaf24f1b30fa44a723e876c5c3cb25f9426d5411a311fc3e4399f33b3f1aa0a156c3234049bfa31
7
+ data.tar.gz: d38c5cdaaedf73eeb3eadbae99405852afd4aecb50e6c4b406b4e8e0ea9903c59644b9b1c558eb66623a49e82e4279b0241ad957fbe2443385ef9199e3db3907
data/README.md CHANGED
@@ -46,6 +46,7 @@ Interface: `uploader(attribute_name, uploader_name, **options)`
46
46
  * uploader_name - **short** uploader name. You need to connect uploaders which are compatible with Tramway. Available uploaders:
47
47
  * :photo - you can see it [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/photo_uploader.rb)
48
48
  * :file - you can see it [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/file_uploader.rb)
49
+ * :ico - you can see [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/ico_uploader.rb)
49
50
  * options - you are available to set options for uploaders exactly for this model. Available options:
50
51
  * versions - **only for :photo**. Set needed versions for file to be cropped. If empty - 0 zero versions will be used. All versions you can see [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/photo_uploader.rb)
51
52
  * extensions - whitelist of file extensions. If empty will be used default whitelist from the uploaders (links above)
@@ -181,7 +182,7 @@ copy_to_clipboard "some_id" # some_id is HTML id of element. Content of this ele
181
182
  #### 1. Generate model that you to use. We create Organization, for example
182
183
 
183
184
  ```shell
184
- rails g model organization name:text public_name:text tagline:text address:text phone:text coordinates:point state: text favicon:text # remember! State field is required, if you use tramway-admin
185
+ rails g tramway:core:application
185
186
  rails db:migrate
186
187
  ```
187
188
 
@@ -15,4 +15,8 @@ class Tramway::Core::ApplicationController < ActionController::Base
15
15
  def model_class
16
16
  params[:model].constantize
17
17
  end
18
+
19
+ def authenticated_user
20
+ (defined?(current_user) && current_user.try(:model)) || (defined?(current_admin) && current_admin.model)
21
+ end
18
22
  end
@@ -68,6 +68,10 @@ class Tramway::Core::ApplicationDecorator
68
68
  def model_name
69
69
  model_class.try(:model_name)
70
70
  end
71
+
72
+ def list_filters
73
+ {}
74
+ end
71
75
  end
72
76
 
73
77
  def link
@@ -29,12 +29,17 @@ module Tramway::Core::Associations::ClassHelper
29
29
  def define_main_association_method(association_name, decorator)
30
30
  define_method association_name do
31
31
  association = object.class.reflect_on_association(association_name)
32
+ type = association_type(association)
33
+ return if association_has_one_without_object(object, association_name, type)
34
+
32
35
  check_association object, association_name, association
33
36
  decorator_class_name = decorator || decorator_class_name(class_name(association))
34
- if association_type(association).in? %i[has_many has_and_belongs_to_many]
35
- return associations_collection(object, association_name, decorator_class_name)
37
+ case type
38
+ when :has_many, :has_and_belongs_to_many
39
+ associations_collection(object, association_name, decorator_class_name)
40
+ when :belongs_to, :has_one
41
+ decorator_class_name.decorate(association_object(object, association_name))
36
42
  end
37
- return decorator_class_name.decorate object.send association_name if association_type(association) == :belongs_to
38
43
  end
39
44
  end
40
45
  end
@@ -36,6 +36,23 @@ module Tramway::Core::Associations::ObjectHelper
36
36
  end
37
37
 
38
38
  def add_association_form_class_name(object, association_name)
39
- "Admin::#{object.class.to_s.pluralize}::Add#{association_name.to_s.camelize.singularize}Form".constantize
39
+ form_class = "Admin::#{object.class.to_s.pluralize}::Add#{association_name.to_s.camelize.singularize}Form"
40
+
41
+ begin
42
+ form_class.constantize
43
+ rescue StandardError
44
+ Tramway::Error.raise_error(
45
+ :tramway, :core, :associations, :object_helper, :habtm_add_class_not_defined,
46
+ class: form_class, association_name: association_name
47
+ )
48
+ end
49
+ end
50
+
51
+ def association_has_one_without_object(object, association_name, association_type)
52
+ association_type == :has_one && object.send(association_name).nil?
53
+ end
54
+
55
+ def association_object(object, association_name)
56
+ object.send association_name
40
57
  end
41
58
  end
@@ -2,9 +2,10 @@
2
2
 
3
3
  module Tramway::Core::Inputs::AssociationsHelper
4
4
  def build_collection_for_association(form_object, property)
5
+ user = defined?(current_user) ? current_user : current_admin
5
6
  full_class_name_association = form_object.class.full_class_name_association(property)
6
7
  check_valid_association full_class_name_association
7
- full_class_name_association.active.send("#{current_user.role}_scope", current_user.id).map do |obj|
8
+ full_class_name_association.active.send("#{user.role}_scope", user.id).map do |obj|
8
9
  decorator_class(full_class_name_association).decorate obj
9
10
  end.sort_by(&:name)
10
11
  end
@@ -2,8 +2,9 @@
2
2
 
3
3
  module Tramway::Core::Inputs::PolymorphicAssociationsHelper
4
4
  def build_collection_for_polymorphic_association(form_object, property)
5
+ user = defined?(current_user) ? current_user : current_admin
5
6
  object_names = full_class_names(form_object, property).map do |class_name|
6
- class_name.active.send("#{current_user.role}_scope", current_user.id).map do |obj|
7
+ class_name.active.send("#{user.role}_scope", user.id).map do |obj|
7
8
  decorator_class(class_name).decorate obj
8
9
  end
9
10
  end.flatten
@@ -12,7 +12,7 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
12
12
  state :removed
13
13
 
14
14
  event :remove do
15
- transition active: :remove
15
+ transition active: :removed
16
16
  end
17
17
  end
18
18
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IcoUploader < ApplicationUploader
4
+ def extension_whitelist
5
+ model.class.file_extensions || %w[ico]
6
+ end
7
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.18.1'
5
+ VERSION = '1.18.3.1'
6
6
  end
7
7
  end
@@ -21,6 +21,8 @@ class Tramway::Error < RuntimeError
21
21
  def raise_error(*coordinates, **options)
22
22
  @errors ||= YAML.load_file("#{Tramway::Core.root}/yaml/errors.yml").with_indifferent_access
23
23
  error = @errors.dig(*coordinates)
24
+ raise 'Error is not defined in YAML' unless error
25
+
24
26
  options.each do |pair|
25
27
  error.gsub!("%{#{pair[0]}}", pair[1].to_s)
26
28
  end
@@ -29,6 +29,7 @@ tramway:
29
29
  associations:
30
30
  object_helper:
31
31
  please_specify_association_name: "Please, specify `%{association_name}` association class_name in %{object_class} model. For example: `has_many :%{association_name}, class_name: '%{association_class_name}'`"
32
+ habtm_add_class_not_defined: "You should define class `%{class}` to be able add and remove `%{association_name}`"
32
33
  class_helper:
33
34
  model_does_not_have_association: "Model %{object_class} does not have association named `%{association_name}`"
34
35
  application_decorator:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.1
4
+ version: 1.18.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-26 00:00:00.000000000 Z
12
+ date: 2020-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: audited
@@ -361,6 +361,7 @@ files:
361
361
  - app/models/tramway/core/application_record.rb
362
362
  - app/uploaders/application_uploader.rb
363
363
  - app/uploaders/file_uploader.rb
364
+ - app/uploaders/ico_uploader.rb
364
365
  - app/uploaders/image_defaults.rb
365
366
  - app/uploaders/photo_uploader.rb
366
367
  - app/views/tramway/core/404.haml