bhf 0.10.14 → 0.10.15

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
  SHA1:
3
- metadata.gz: d52f22e8e17c8a3f1385b4322105b1f56d0df108
4
- data.tar.gz: 36bcbe73fbf572dbcbccd2da1fc0b9719d70fb14
3
+ metadata.gz: 73abb1591371e3997fe6b22fc5760e151d3907f6
4
+ data.tar.gz: eb7cb00592990c0462232f92931ad13f1ab9f635
5
5
  SHA512:
6
- metadata.gz: 76508689f724d0ce51b33898565fe61297ddf3ef2031456db5976dd64b7cc15d4c6eb6b76ea8711273fba2ce21107d35a37cdc8313b5b7c5ae44d3c5236e344d
7
- data.tar.gz: d7209cae58d7e66103978a2f5cfc26f66299906119607310c214ae869b70b622ad37f3a81dacba4bd03bceb80b1dedc94ed29fd60add2beeb690db81d3780ff9
6
+ metadata.gz: c076188d9fd8c68e5db03dd4acfe98774480f7d170443f30b895d92da8a5ba18de040380314bff892ec787ebe1866b311e3f1327a38e4a9f182df682b98bcd0f
7
+ data.tar.gz: 89b699f76a6a52f0b45ba45601e29719b86c10059ae18aed696001f5a60f1e8d8149b926e9d4c55ccfbb94219c4df441f8dbbfd3c75a548b31377f572e9dcfa1
data/README.md CHANGED
@@ -18,6 +18,8 @@ Also see [Getting Started](Getting_Started.md) document for additional info.
18
18
 
19
19
  * Adding unit tests and integration tests
20
20
  * Adding bulk edit for the table view (aka platform)
21
+ * Manage relations with help of autocomplete inputs
22
+ * Move from MooTools to jQuery
21
23
 
22
24
  ## Support
23
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.14
1
+ 0.10.15
@@ -327,6 +327,9 @@ Turbolinks.pagesCached(0);
327
327
  element.removeClass('dragged');
328
328
  new Request({
329
329
  method: 'put',
330
+ headers: {
331
+ 'X-CSRF-Token': rails && rails.csrf && rails.csrf.token
332
+ },
330
333
  url: sortableElems.get('data-sort-url')
331
334
  }).send({data: {order: this.serialize()}});
332
335
  }
@@ -29,7 +29,7 @@ class Bhf::EntriesController < Bhf::ApplicationController
29
29
  def create
30
30
  before_save
31
31
  if @object.save
32
- manage_many_to_many
32
+ manage_relations
33
33
  after_save
34
34
 
35
35
  if @quick_edit
@@ -54,7 +54,7 @@ class Bhf::EntriesController < Bhf::ApplicationController
54
54
 
55
55
  before_save
56
56
  if @object.update_attributes(@permited_params)
57
- manage_many_to_many
57
+ manage_relations
58
58
  after_save
59
59
 
60
60
  if @quick_edit
@@ -166,9 +166,8 @@ class Bhf::EntriesController < Bhf::ApplicationController
166
166
  def manage_many_to_many
167
167
  return unless params[:has_and_belongs_to_many]
168
168
  params[:has_and_belongs_to_many].each_pair do |relation, ids|
169
- reflection = @model.reflections[relation]
170
-
171
169
  next unless ids.any?
170
+ reflection = @model.reflections[relation]
172
171
  relation_array = @object.send(relation)
173
172
  reflection.klass.unscoped.find(ids.keys).each do |relation_obj|
174
173
  has_relation = relation_array.include?(relation_obj)
@@ -186,6 +185,55 @@ class Bhf::EntriesController < Bhf::ApplicationController
186
185
  end
187
186
  end
188
187
 
188
+ def manage_has_one
189
+ return unless params[:has_one]
190
+ object_id = @object.send(@model.bhf_primary_key)
191
+ params[:has_one].each_pair do |relation, id|
192
+ reflection = @model.reflections[relation]
193
+ reflection.klass.where(reflection.foreign_key, object_id).each do |ref_object|
194
+ next if ref_object.send(reflection.klass.bhf_primary_key) == id
195
+ ref_object.update_attribute(reflection.foreign_key, nil)
196
+ end
197
+ unless id.blank?
198
+ ref_object = reflection.klass.find(id)
199
+ next if ref_object.send(reflection.foreign_key) == object_id
200
+ ref_object.update_attribute(reflection.foreign_key, object_id)
201
+ end
202
+ end
203
+ end
204
+
205
+ def manage_has_many
206
+ return unless params[:has_many]
207
+ object_id = @object.send(@model.bhf_primary_key)
208
+ params[:has_many].each_pair do |relation, ids|
209
+ next unless ids.any?
210
+ reflection = @model.reflections[relation]
211
+ preset_ids = @object.send(relation).collect do |object|
212
+ object.send(object.class.bhf_primary_key).to_s
213
+ end
214
+ @object.send(relation).klass.find(ids.keys).each do |relation_obj|
215
+ fk = relation_obj.class.reflections[reflection.inverse_of.name.to_s].foreign_key
216
+ relation_obj_id_as_string = relation_obj.send(relation_obj.class.bhf_primary_key).to_s
217
+
218
+ if ids[relation_obj_id_as_string].blank?
219
+ if preset_ids.include?(relation_obj_id_as_string)
220
+ relation_obj.update_attribute(fk, nil)
221
+ end
222
+ else
223
+ if ! preset_ids.include?(relation_obj_id_as_string)
224
+ relation_obj.update_attribute(fk, object_id)
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
230
+
231
+ def manage_relations
232
+ manage_many_to_many
233
+ manage_has_many
234
+ manage_has_one
235
+ end
236
+
189
237
  def after_load
190
238
  @object.send(@platform.hooks(:after_load)) if @platform.hooks(:after_load)
191
239
  end
@@ -1,10 +1,11 @@
1
1
  - data_source ||= field.link ? field.link.get_objects : field.reflection.klass.all
2
+ - check_box_type ||= :many_to_many_check_box
2
3
  = reflection_node f, field do
3
4
  .quick_edit_block
4
5
  %ul.relation.quick_edit_inject
5
6
  - data_source.each do |ref_object|
6
7
  %li.quick_edit_entry
7
- = f.many_to_many_check_box(ref_object, field.reflection.name, params, field.link && ! field.link.hide_edit)
8
+ = f.send(check_box_type, ref_object, field.reflection.name, params, field.link && ! field.link.hide_edit)
8
9
  - if field.link && ! field.link.hide_edit
9
10
  = link_to ref_object.to_bhf_s, edit_entry_path(field.link.name, ref_object), class: 'js_edit_field qe_button quick_edit'
10
11
  - if field.link && ! field.link.hide_delete
@@ -12,7 +13,7 @@
12
13
 
13
14
  .quick_edit_template{type: 'text/template'}
14
15
  %li.quick_edit_entry
15
- = f.many_to_many_check_box(OpenStruct.new(to_bhf_s: '{to_bhf_s}'), field.reflection.name, params, field.link && ! field.link.hide_edit, true, "{object_id}", {class: 'js_remove_disabled', disabled: true}).gsub('_object_id_', '{object_id}').html_safe # fix for id attr
16
+ = f.send(check_box_type, OpenStruct.new(to_bhf_s: '{to_bhf_s}'), field.reflection.name, params, field.link && ! field.link.hide_edit, true, "{object_id}", {class: 'js_remove_disabled', disabled: true}).gsub('_object_id_', '{object_id}').html_safe # fix for id attr
16
17
  - if field.link && ! field.link.hide_edit
17
18
  = link_to '{to_bhf_s}', edit_entry_path(field.link.name, '{object_id}'), class: 'js_edit_field qe_button quick_edit'
18
19
  - if field.link && ! field.link.hide_delete
@@ -0,0 +1 @@
1
+ = render partial: "bhf/form/has_and_belongs_to_many/check_box", locals: {f: f, field: field, check_box_type: :has_many_check_box}
@@ -0,0 +1,23 @@
1
+ - data_source ||= field.link ? field.link.get_objects : field.reflection.klass.all
2
+ - fk = field.reflection.name
3
+ - ref_obj = f.object.send(fk)
4
+ - ref_obj_id = ref_obj ? ref_obj.send(field.reflection.klass.bhf_primary_key) : nil
5
+ .node
6
+ .label= f.label fk, reflection_title(f, field, 1)
7
+ .input.select_input.quick_edit_block
8
+ - if field.link
9
+ .quick_edit_template{type: 'text/template'}
10
+ = options_for_select([['{to_bhf_s}', '{object_id}', {data: {edit: edit_entry_path(field.link.name, '{object_id}'), delete: entry_path(field.link.name, '{object_id}')}}]])
11
+ - select_options ||= options_from_collection_for_select_with_html_attrs(data_source, :id, :to_bhf_s, ref_obj_id, Proc.new {|obj| {data: {edit: edit_entry_path(field.link.name, obj), delete: entry_path(field.link.name, obj)}}})
12
+ - else
13
+ - select_options ||= options_from_collection_for_select(data_source, :id, :to_bhf_s, ref_obj_id)
14
+
15
+ = select :has_one, fk, select_options, {include_blank: true}, {class: ('quick_edit_inject quick_edit_select' if field.link)}
16
+ = render partial: 'bhf/helper/field_errors', locals: {f: f, field: fk}
17
+
18
+ - if field.link && ! field.link.hide_edit
19
+ = link_to edit_t(field.link), '', class: 'js_edit_field icon edit quick_edit'
20
+ - if field.link && ! field.link.hide_delete
21
+ = link_to '&times;'.html_safe, '', method: :delete, class: 'qe_delete js_delete', remote: true, data: {confirm: t('bhf.helpers.promts.confirm', platform_title: field.link.title_singular)}
22
+ - if field.link && ! field.link.hide_create
23
+ = link_to '+', new_entry_path(field.link.name), class: 'js_add_field plus_button qe_button quick_edit'
data/bhf.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bhf 0.10.14 ruby lib
5
+ # stub: bhf 0.10.15 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bhf"
9
- s.version = "0.10.14"
9
+ s.version = "0.10.15"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Anton Pawlik"]
14
- s.date = "2015-11-01"
14
+ s.date = "2016-03-08"
15
15
  s.description = "A simple to use Rails-Engine-Gem that offers an admin interface for trusted user. Easy integratable and highly configurable and agnostic. Works with ActiveRecord and Mongoid."
16
16
  s.email = "anton.pawlik@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -101,7 +101,9 @@ Gem::Specification.new do |s|
101
101
  "app/views/bhf/form/embeds_one/_static.html.haml",
102
102
  "app/views/bhf/form/has_and_belongs_to_many/_check_box.html.haml",
103
103
  "app/views/bhf/form/has_and_belongs_to_many/_static.html.haml",
104
+ "app/views/bhf/form/has_many/_check_box.html.haml",
104
105
  "app/views/bhf/form/has_many/_static.html.haml",
106
+ "app/views/bhf/form/has_one/_select.html.haml",
105
107
  "app/views/bhf/form/has_one/_static.html.haml",
106
108
  "app/views/bhf/helper/_definition_item.html.haml",
107
109
  "app/views/bhf/helper/_field_errors.html.haml",
@@ -14,8 +14,7 @@ module Bhf::ActionView
14
14
  field_errors(field).any?
15
15
  end
16
16
 
17
- def many_to_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
18
- mm = :has_and_belongs_to_many
17
+ def many_to_many_or_has_many_check_box(mm, obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
19
18
  bhf_primary_key ||= obj.send(obj.class.bhf_primary_key).to_s
20
19
  unless checked
21
20
  checked = if params[mm] && params[mm][ref_name]
@@ -32,5 +31,13 @@ module Bhf::ActionView
32
31
  html
33
32
  end
34
33
 
34
+ def many_to_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
35
+ many_to_many_or_has_many_check_box(:has_and_belongs_to_many, obj, ref_name, params, hide_label, checked, bhf_primary_key, extra_html_attrs)
36
+ end
37
+
38
+ def has_many_check_box(obj, ref_name, params, hide_label = false, checked = false, bhf_primary_key = nil, extra_html_attrs = {})
39
+ many_to_many_or_has_many_check_box(:has_many, obj, ref_name, params, hide_label, checked, bhf_primary_key, extra_html_attrs)
40
+ end
41
+
35
42
  end
36
43
  end
@@ -42,9 +42,9 @@ module Bhf::Platform::Attribute
42
42
  def type
43
43
  return @options_form_type if @options_form_type
44
44
 
45
- if macro == :has_and_belongs_to_many
45
+ if macro == :has_and_belongs_to_many or macro == :has_many
46
46
  :check_box
47
- elsif macro == :belongs_to
47
+ elsif macro == :belongs_to or macro == :has_one
48
48
  :select
49
49
  else
50
50
  :static
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bhf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.14
4
+ version: 0.10.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Pawlik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-01 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -242,7 +242,9 @@ files:
242
242
  - app/views/bhf/form/embeds_one/_static.html.haml
243
243
  - app/views/bhf/form/has_and_belongs_to_many/_check_box.html.haml
244
244
  - app/views/bhf/form/has_and_belongs_to_many/_static.html.haml
245
+ - app/views/bhf/form/has_many/_check_box.html.haml
245
246
  - app/views/bhf/form/has_many/_static.html.haml
247
+ - app/views/bhf/form/has_one/_select.html.haml
246
248
  - app/views/bhf/form/has_one/_static.html.haml
247
249
  - app/views/bhf/helper/_definition_item.html.haml
248
250
  - app/views/bhf/helper/_field_errors.html.haml