ideyabox 0.1.7 → 0.1.8

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.
@@ -583,4 +583,8 @@ ol.sortable {
583
583
  .actions {margin-top: 0.5em; }
584
584
  padding-bottom: 1em;
585
585
  }
586
+ }
587
+ .admin_mini {
588
+ width: 160px;
589
+ height: 100px;
586
590
  }
@@ -0,0 +1,67 @@
1
+ module ArIdeyabox
2
+ # In model just add this line
3
+ # has_not_this :person, through: :professions_people, order: :title, by: :title, group_by: {play: :title}
4
+ # :order and :by - optionally
5
+ # :group_by is for group selectors, if you want grouping roles by play titles, just add group_by: {play: :title}
6
+
7
+ def visible
8
+ where(visible: true)
9
+ end
10
+
11
+ def by_position
12
+ order(:position)
13
+ end
14
+
15
+ def visible_by_position
16
+ visible.by_position
17
+ end
18
+
19
+ def first_el_tryer(object, by)
20
+ if by.class == Hash
21
+ object.try(by.keys[0]).try(by.values[0])
22
+ else
23
+ object.try(by)
24
+ end
25
+ end
26
+
27
+ def has_not_this(model_name, *args)
28
+ options = args.extract_options!
29
+ join_model = options[:through].to_s.singularize.camelize
30
+ self_id_sym = "#{self.to_s.underscore}_id".to_sym
31
+ array_first_el = options[:by] ? options[:by] : :title
32
+ group_by = options[:group_by]
33
+ includes = options[:includes]
34
+ model_name_id = "#{model_name}_id"
35
+
36
+ define_singleton_method("has_not_this_#{model_name}") do |ids|
37
+ excluded_ids = join_model.constantize.where(model_name_id.to_sym => ids).collect(&self_id_sym)
38
+ output = self.where{id << excluded_ids}
39
+ output = output.includes(includes) if includes
40
+ output = output.order(options[:order]) if options[:order]
41
+ if group_by
42
+ output = output.group_by{|a| first_el_tryer(a, group_by)}
43
+ output.delete(nil)
44
+ output.each do |key, value|
45
+ array = []
46
+ value.each do |el|
47
+ array << [first_el_tryer(el, array_first_el), el.id]
48
+ end
49
+ output[key] = array
50
+ end
51
+ # output.to_a.sort
52
+ else
53
+ output.collect{|p| [first_el_tryer(p, array_first_el), p.id]}
54
+ end
55
+ end
56
+ end
57
+
58
+ # Original method for one model looks like this
59
+ # def self.has_not_this_person(person_id)
60
+ # excluded_ids = ProfessionsPerson.where(person_id: person_id).collect(&:profession_id)
61
+ # self.where{id << excluded_ids}.order(:title).collect{|p| [p.title, p.id]}
62
+ # end
63
+ end
64
+
65
+ ActiveSupport.on_load :active_record do
66
+ extend ArIdeyabox
67
+ end
@@ -7,6 +7,7 @@ module Ideyabox
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
  argument :controller_path, :type => :string
9
9
  argument :child_controller_path, :type => :string
10
+ argument :join_controller_path, :type => :string, :default => nil, :required => false
10
11
  argument :model_name, :type => :string, :required => false
11
12
  argument :layout, :type => :string, :default => "application",
12
13
  :banner => "Specify application layout"
@@ -95,7 +96,9 @@ module Ideyabox
95
96
 
96
97
  #linking model
97
98
  def linking_model_name
98
- if ActiveRecord::Base.connection.table_exists? "#{child_name}_#{plural_resource_name}"
99
+ if join_controller_path
100
+ join_controller_path.singelarize.camelize
101
+ elsif ActiveRecord::Base.connection.table_exists? "#{child_name}_#{plural_resource_name}"
99
102
  "#{child_name}_#{plural_resource_name}".singularize.camelize
100
103
  elsif
101
104
  ActiveRecord::Base.connection.table_exists? "#{resource_name}_#{plural_child_name}"
@@ -1,9 +1,10 @@
1
- = form_for [:admin, <%=linking_model_name%>.new], :remote => true do |f|
2
- %table
3
- %tr
4
- %td= f.select :<%=child_name%>_id, <%=plural_child_name%>, {:include_blank => true, :prompt => "add <%=child_name%>" }, :class => "chosen_select"
5
- %td
1
+ - unless <%=plural_child_name%>.empty?
2
+ = form_for [:admin, <%=linking_model_name%>.new], :remote => true do |f|
3
+ %table
4
+ %tr
5
+ %td= f.select :<%=child_name%>_id, <%=plural_child_name%>, {:include_blank => true, :prompt => "add <%=child_name%>" }, :class => "chosen_select"
6
+ %td
6
7
 
7
- = f.hidden_field :<%=resource_name%>_id, :value => <%=resource_name%>.id
8
+ = f.hidden_field :<%=resource_name%>_id, :value => <%=resource_name%>.id
8
9
 
9
- = f.submit "Добавить", :class =>'black_button'
10
+ = f.submit "Добавить", :class =>'black_button'
@@ -2,4 +2,5 @@ require "ideyabox/version"
2
2
 
3
3
  module Ideyabox
4
4
  require 'ideyabox/engine'
5
+ require 'ar_ideyabox'
5
6
  end
@@ -1,3 +1,3 @@
1
1
  module Ideyabox
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ideyabox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-06 00:00:00.000000000 Z
13
+ date: 2013-04-07 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Write a gem description
16
16
  email:
@@ -59,6 +59,7 @@ files:
59
59
  - app/helpers/admin_helper.rb
60
60
  - app/tasks/reset_db.rake
61
61
  - ideyabox.gemspec
62
+ - lib/ar_ideyabox.rb
62
63
  - lib/generators/ideyabox/admin/admin_generator.rb
63
64
  - lib/generators/ideyabox/admin/templates/assets/admin.js
64
65
  - lib/generators/ideyabox/admin/templates/assets/admin.scss.erb