viniBaxter-spa-belongs_to_search 3.0.0 → 4.0.0

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
  SHA256:
3
- metadata.gz: e7ce5dffd0c5733ad3ebe868743b8aa1773cf6b8066413a5f01ba0cba983ceaa
4
- data.tar.gz: 1f1aea2e11ba7b39d667b1cf0f8773c3bcf69b612d4bf69ae4f6df5728fe3e85
3
+ metadata.gz: 21bd66ea93cecee59a3be518a78b388725692d5fdbe235c4ea4e3886a47bb543
4
+ data.tar.gz: 6a9c066f9a8a4641bc788af8215a9f9c105646933ec29e9eeb8683f2e9f4b9af
5
5
  SHA512:
6
- metadata.gz: 103805aca66dfa50c937f02b644c52c22f1f25e2ac4f8bfc1480f9bfd5ee5fcf98c12d8bcfbe36caec7f972d9e4b4dabfab20f977c8fc4ed6f0d672afac284c8
7
- data.tar.gz: 1dda43ff313ad178f4236b2935523b9c6dc7d9431e7a19e4b91006967028c9ac35a960401ee9099be7f50e09905900e2e675b885178a8eafaf86ce15fb7507e9
6
+ metadata.gz: ca3e44a61026c27fe947c0063bb21ae1693ebabe35a3716f1652171bceeef890761f0f1222e9e4a2c5b5e8756eec211752cddf89b2f4960555aef09198affe60
7
+ data.tar.gz: 193c6f96e5ac78d93a882fe2c2f2776ad519970bd213aeeb8ece8050948188788ed552f7794228f9d1230bdae5d5614080be46fa52f57be5964b3ced42eb5ed4
@@ -17,7 +17,7 @@ that displays all possible records to associate with.
17
17
  <%= f.label field.permitted_attribute %>
18
18
  </div>
19
19
  <div class="field-unit__field">
20
- <% if field.associated_class == Package %>
20
+ <% if field.associated_class == Place %>
21
21
  <%= render(
22
22
  partial: "fields/belongs_to_search/scope_package",
23
23
  locals: {
@@ -6,7 +6,7 @@
6
6
  <%= options_for_select(
7
7
  # field.associated_resource_options,
8
8
 
9
- field.belong_to_scope_package(current_owner, field.associated_class),
9
+ field.belong_to_scope_place(current_owner, field.associated_class),
10
10
  field.selected_option) %>
11
11
  <% end %>
12
12
  </div>
@@ -15,17 +15,23 @@ module Administrate
15
15
  super
16
16
  end
17
17
 
18
- def belong_to_scope_package(current_user, model)
18
+ def belong_to_scope_place(current_user, model)
19
+ puts model
19
20
  # model is Package
20
21
  # create a room need package reference
21
- model_variable = model.to_s.underscore.pluralize #=> packages
22
+ model_variable = model.to_s.underscore.pluralize #=> places
22
23
  # so we scope the current user packages
23
24
  # methode send(...) t.ly/56cI
24
- scoped_model = current_user.send(model_variable).pluck(:id)
25
- candidates = Package.find(*scoped_model) # => array of Packages
26
- # but we need an activeRecordRelation and no an array
25
+ if current_user.admin? || current_user.super_admin?
26
+ scoped_model = model.all.pluck(:id)
27
+ else
28
+ scoped_model = current_user.send(model_variable).pluck(:id)
29
+ end
30
+
31
+ candidates = Place.find(*scoped_model) # => array of Places
32
+ # but we need an activeRecordRelation and no an array
27
33
  # let transform that array to an activeRecordRelation here t.ly/2D0A
28
- candidates_activeRecord = Package.where(id: candidates.map(&:id)) # => Package::ActiveRecord_Relation
34
+ candidates_activeRecord = Place.where(id: candidates.map(&:id)) # => Place::ActiveRecord_Relation
29
35
 
30
36
  [nil] + candidates_activeRecord.map do |resource|
31
37
  [display_candidate_resource(resource), resource.send(primary_key)]
@@ -34,9 +40,9 @@ module Administrate
34
40
  end
35
41
 
36
42
  def associated_resource_options
37
- # candidate_resources is Package::ActiveRecord_Relation
43
+ # candidate_resources is Place::ActiveRecord_Relation
38
44
  [nil] + candidate_resources.map do |resource|
39
- # resource is #=> Package
45
+ # resource is #=> Place
40
46
  [display_candidate_resource(resource), resource.send(primary_key)]
41
47
  end
42
48
  end
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'viniBaxter-spa-belongs_to_search'
6
- gem.version = '3.0.0'.freeze
6
+ gem.version = '4.0.0'.freeze
7
7
  gem.authors = ['Klas Eskilson']
8
8
  gem.email = ['vinybaxter@gmail;com']
9
9
  gem.homepage = 'https://github.com/fishbrain/administrate-field-belongs_to_search'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viniBaxter-spa-belongs_to_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klas Eskilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate