bhf 0.8.0 → 0.8.2

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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +1 -1
  4. data/VERSION +1 -1
  5. data/app/assets/images/bhf/pictos.png +0 -0
  6. data/app/assets/images/bhf/pictos_2x.png +0 -0
  7. data/app/assets/javascripts/bhf/application.js +153 -116
  8. data/app/assets/javascripts/bhf/classes/ArrayFields.js +1 -1
  9. data/app/assets/javascripts/bhf/classes/MultipleFields.js +2 -2
  10. data/app/assets/javascripts/bhf/classes/PlatformHelper.js +6 -11
  11. data/app/assets/javascripts/bhf/classes/{AjaxEdit.js → QuickEdit.js} +9 -9
  12. data/app/assets/javascripts/bhf/classes/{AjaxEditStack.js → QuickEditStack.js} +4 -20
  13. data/app/assets/javascripts/bhf/mootools-core-1.5.0-full-compat.js +1 -0
  14. data/app/assets/javascripts/bhf/mootools_ujs.js +11 -11
  15. data/app/assets/stylesheets/bhf/application.css.sass +86 -48
  16. data/app/controllers/bhf/application_controller.rb +8 -4
  17. data/app/controllers/bhf/embed_entries_controller.rb +2 -6
  18. data/app/controllers/bhf/entries_controller.rb +13 -16
  19. data/app/controllers/bhf/pages_controller.rb +14 -13
  20. data/app/helpers/bhf/application_helper.rb +6 -6
  21. data/app/helpers/bhf/entries_helper.rb +4 -2
  22. data/app/helpers/bhf/pages_helper.rb +0 -4
  23. data/app/views/bhf/entries/_form.haml +7 -4
  24. data/app/views/bhf/entries/show.haml +3 -4
  25. data/app/views/bhf/form/belongs_to/_radio.haml +28 -0
  26. data/app/views/bhf/form/belongs_to/_select.haml +21 -0
  27. data/app/views/bhf/form/belongs_to/_static.haml +1 -0
  28. data/app/views/bhf/{entries/form → form}/column/_array.haml +0 -0
  29. data/app/views/bhf/{entries/form → form}/column/_boolean.haml +0 -0
  30. data/app/views/bhf/{entries/form → form}/column/_date.haml +0 -0
  31. data/app/views/bhf/{entries/form → form}/column/_hash.haml +0 -0
  32. data/app/views/bhf/{entries/form → form}/column/_mappin.haml +0 -0
  33. data/app/views/bhf/{entries/form → form}/column/_markdown.haml +0 -0
  34. data/app/views/bhf/{entries/form → form}/column/_multiple_fields.haml +0 -0
  35. data/app/views/bhf/{entries/form → form}/column/_number.haml +0 -0
  36. data/app/views/bhf/{entries/form → form}/column/_paperclip.haml +0 -0
  37. data/app/views/bhf/{entries/form → form}/column/_password.haml +0 -0
  38. data/app/views/bhf/{entries/form → form}/column/_static.haml +0 -0
  39. data/app/views/bhf/{entries/form → form}/column/_string.haml +0 -0
  40. data/app/views/bhf/{entries/form → form}/column/_text.haml +0 -0
  41. data/app/views/bhf/{entries/form → form}/column/_wysiwyg.haml +0 -0
  42. data/app/views/bhf/form/embeds_many/_static.haml +26 -0
  43. data/app/views/bhf/form/embeds_one/_static.haml +2 -0
  44. data/app/views/bhf/form/has_and_belongs_to_many/_check_box.haml +22 -0
  45. data/app/views/bhf/form/has_and_belongs_to_many/_static.haml +1 -0
  46. data/app/views/bhf/form/has_many/_static.haml +26 -0
  47. data/app/views/bhf/form/has_one/_static.haml +2 -0
  48. data/app/views/bhf/helper/_definition_item.haml +1 -1
  49. data/app/views/bhf/helper/_frontend_edit.haml +1 -1
  50. data/app/views/bhf/pages/_platform.haml +39 -16
  51. data/app/views/bhf/{pages/macro → table}/belongs_to/_default.haml +1 -1
  52. data/app/views/bhf/table/column/_array.haml +1 -0
  53. data/app/views/bhf/table/column/_boolean.haml +1 -0
  54. data/app/views/bhf/table/column/_date.haml +1 -0
  55. data/app/views/bhf/table/column/_extern_link.haml +2 -0
  56. data/app/views/bhf/table/column/_file.haml +1 -0
  57. data/app/views/bhf/table/column/_hash.haml +1 -0
  58. data/app/views/bhf/table/column/_image.haml +1 -0
  59. data/app/views/bhf/table/column/_number.haml +1 -0
  60. data/app/views/bhf/table/column/_paperclip.haml +5 -0
  61. data/app/views/bhf/table/column/_primary_key.haml +1 -0
  62. data/app/views/bhf/table/column/_string.haml +1 -0
  63. data/app/views/bhf/table/column/_text.haml +1 -0
  64. data/app/views/bhf/table/embeds_many/_default.haml +1 -0
  65. data/app/views/bhf/table/embeds_one/_default.haml +1 -0
  66. data/app/views/bhf/table/has_and_belongs_to_many/_default.haml +1 -0
  67. data/app/views/bhf/table/has_many/_default.haml +2 -0
  68. data/app/views/bhf/{pages/macro → table}/has_one/_default.haml +1 -1
  69. data/bhf.gemspec +60 -59
  70. data/config/locales/de.yml +8 -8
  71. data/config/locales/en.yml +7 -7
  72. data/lib/bhf.rb +26 -21
  73. data/lib/bhf/action_view/form_builder.rb +36 -0
  74. data/lib/bhf/action_view/form_options.rb +30 -0
  75. data/lib/bhf/active_record/base.rb +58 -0
  76. data/lib/bhf/mongoid/document.rb +135 -137
  77. data/lib/bhf/platform/attribute/abstract.rb +52 -0
  78. data/lib/bhf/platform/attribute/column.rb +78 -0
  79. data/lib/bhf/platform/attribute/reflection.rb +68 -0
  80. data/lib/bhf/platform/base.rb +333 -0
  81. data/lib/bhf/{pagination.rb → platform/pagination.rb} +1 -1
  82. data/lib/bhf/{settings.rb → settings/base.rb} +14 -11
  83. data/lib/bhf/settings/platform.rb +20 -0
  84. data/lib/bhf/settings/yaml_parser.rb +84 -0
  85. data/lib/rails/generators/bhf/templates/initializer.rb +1 -1
  86. metadata +58 -57
  87. data/app/views/bhf/entries/form/belongs_to/_account_scope.haml +0 -2
  88. data/app/views/bhf/entries/form/belongs_to/_radio.haml +0 -8
  89. data/app/views/bhf/entries/form/belongs_to/_select.haml +0 -7
  90. data/app/views/bhf/entries/form/belongs_to/_static.haml +0 -1
  91. data/app/views/bhf/entries/form/embeds_many/_static.haml +0 -12
  92. data/app/views/bhf/entries/form/embeds_one/_static.haml +0 -12
  93. data/app/views/bhf/entries/form/has_and_belongs_to_many/_account_scope.haml +0 -2
  94. data/app/views/bhf/entries/form/has_and_belongs_to_many/_check_box.haml +0 -5
  95. data/app/views/bhf/entries/form/has_and_belongs_to_many/_static.haml +0 -1
  96. data/app/views/bhf/entries/form/has_many/_static.haml +0 -12
  97. data/app/views/bhf/entries/form/has_one/_account_scope.haml +0 -2
  98. data/app/views/bhf/entries/form/has_one/_static.haml +0 -9
  99. data/app/views/bhf/pages/macro/column/_array.haml +0 -1
  100. data/app/views/bhf/pages/macro/column/_boolean.haml +0 -1
  101. data/app/views/bhf/pages/macro/column/_date.haml +0 -1
  102. data/app/views/bhf/pages/macro/column/_extern_link.haml +0 -2
  103. data/app/views/bhf/pages/macro/column/_file.haml +0 -1
  104. data/app/views/bhf/pages/macro/column/_hash.haml +0 -1
  105. data/app/views/bhf/pages/macro/column/_image.haml +0 -2
  106. data/app/views/bhf/pages/macro/column/_number.haml +0 -1
  107. data/app/views/bhf/pages/macro/column/_paperclip.haml +0 -6
  108. data/app/views/bhf/pages/macro/column/_primary_key.haml +0 -1
  109. data/app/views/bhf/pages/macro/column/_string.haml +0 -1
  110. data/app/views/bhf/pages/macro/column/_text.haml +0 -1
  111. data/app/views/bhf/pages/macro/embeds_many/_default.haml +0 -1
  112. data/app/views/bhf/pages/macro/embeds_one/_default.haml +0 -1
  113. data/app/views/bhf/pages/macro/has_and_belongs_to_many/_default.haml +0 -1
  114. data/app/views/bhf/pages/macro/has_many/_default.haml +0 -2
  115. data/lib/bhf/active_record/active_record.rb +0 -59
  116. data/lib/bhf/data.rb +0 -169
  117. data/lib/bhf/form.rb +0 -36
  118. data/lib/bhf/platform.rb +0 -308
  119. data/lib/bhf/settings_parser.rb +0 -84
@@ -0,0 +1,78 @@
1
+ module Bhf::Platform::Attribute
2
+ class Column
3
+
4
+ attr_reader :name, :title, :info, :type
5
+
6
+ def initialize(props, options = {})
7
+ @name = props.name
8
+ @title = options[:title]
9
+ @info = options[:info]
10
+ @type = props.type
11
+
12
+ @options_form_type = options[:form_type].to_sym if options[:form_type]
13
+ @options_display_type = options[:display_type].to_sym if options[:display_type]
14
+ @options_show_type = options[:show_type].to_sym if options[:show_type]
15
+
16
+ @pk = options[:primary_key]
17
+ end
18
+
19
+ def macro
20
+ :column
21
+ end
22
+
23
+ def form_type
24
+ return @options_form_type if @options_form_type
25
+
26
+ if name == @pk || name == 'updated_at' || name == 'created_at'
27
+ :static
28
+ else
29
+ supported_types(@type)
30
+ end
31
+ end
32
+
33
+ def display_type
34
+ return @options_display_type if @options_display_type
35
+
36
+ if name == @pk
37
+ :primary_key
38
+ else
39
+ supported_types(@type)
40
+ end
41
+ end
42
+
43
+ def show_type
44
+ @options_show_type || display_type
45
+ end
46
+
47
+ def reflection
48
+ false
49
+ end
50
+
51
+ def db_name
52
+ name
53
+ end
54
+
55
+ def reorderble
56
+ true
57
+ end
58
+
59
+ private
60
+
61
+ def supported_types(check_type)
62
+ if [:boolean, :text, :array, :hash].include?(check_type)
63
+ check_type
64
+ elsif type_sym = group_types(check_type)
65
+ type_sym
66
+ else
67
+ :string
68
+ end
69
+ end
70
+
71
+ def group_types(type_sym)
72
+ return :date if [:date, :datetime, :timestamp, :time, :year].include?(type_sym)
73
+ return :number if [:integer, :float].include?(type_sym)
74
+ return :file if type_sym == :file
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,68 @@
1
+ module Bhf::Platform::Attribute
2
+ class Reflection
3
+
4
+ attr_reader :name, :title, :info
5
+
6
+ def initialize(reflection, options = {})
7
+ @name = reflection.name.to_s
8
+ @title = options[:title]
9
+ @info = options[:info]
10
+ @reflection = reflection
11
+
12
+ @options_form_type = options[:form_type].to_sym if options[:form_type]
13
+ @options_display_type = options[:display_type].to_sym if options[:display_type]
14
+ @options_show_type = options[:show_type].to_sym if options[:show_type]
15
+
16
+ @link_platform_settings = options[:link] unless options[:link].blank?
17
+
18
+ @reorderble = options[:reorderble]
19
+ end
20
+
21
+ def macro
22
+ return :has_and_belongs_to_many if @reflection.macro == :has_many && @reflection.options[:through]
23
+ @reflection.macro
24
+ end
25
+
26
+ def form_type
27
+ type
28
+ end
29
+
30
+ def display_type
31
+ @options_display_type || :default
32
+ end
33
+
34
+ def show_type
35
+ @options_show_type || display_type
36
+ end
37
+
38
+ def type
39
+ return @options_form_type if @options_form_type
40
+
41
+ if macro == :has_and_belongs_to_many
42
+ :check_box
43
+ elsif macro == :belongs_to
44
+ :select
45
+ else
46
+ :static
47
+ end
48
+ end
49
+
50
+ def reflection
51
+ @reflection
52
+ end
53
+
54
+ def db_name
55
+ @reflection.foreign_key
56
+ end
57
+
58
+ def reorderble
59
+ @reorderble
60
+ end
61
+
62
+ def link
63
+ return unless @link_platform_settings
64
+ @link ||= Bhf::Platform::Base.new(@link_platform_settings)
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,333 @@
1
+ module Bhf::Platform
2
+ class Base
3
+ attr_reader :name, :objects, :page_name, :title, :title_zero, :title_singular
4
+
5
+ def initialize(options)
6
+ @objects = []
7
+
8
+ @name = options.name
9
+ @data = options.hash
10
+ @settings = options.settings_base
11
+ @user = @settings.user
12
+
13
+ t_model_path = "activerecord.models.#{model.model_name.to_s.downcase}"
14
+ model_name = I18n.t(t_model_path, count: 2, default: @name.pluralize.capitalize)
15
+ @title = I18n.t("bhf.platforms.#{@name}.title", count: 2, default: model_name)
16
+ model_name = I18n.t(t_model_path, count: 1, default: @name.singularize.capitalize)
17
+ @title_singular = I18n.t("bhf.platforms.#{@name}.title", count: 1, default: model_name)
18
+ model_name = I18n.t(t_model_path, count: 0, default: @name.singularize.capitalize)
19
+ @title_zero = I18n.t("bhf.platforms.#{@name}.title", count: 0, default: model_name)
20
+
21
+ @page_name = options.page_name
22
+ end
23
+
24
+
25
+ def pagination
26
+ @pagination ||= Bhf::Platform::Pagination.new(entries_per_page)
27
+ end
28
+
29
+ def get_objects(options = {}, paginate_options = nil)
30
+ if user_scope? and @user
31
+ chain = @user.send(table_value(:user_scope).to_sym)
32
+ else
33
+ chain = model
34
+ chain = chain.send data_source if data_source
35
+ end
36
+
37
+ unless options[:order].blank?
38
+ chain = chain.reorder("#{options[:order]} #{options[:direction]}")
39
+ end
40
+
41
+ if search? && options[:search].present?
42
+ chain = do_search(chain, options[:search])
43
+ end
44
+
45
+
46
+ if paginate_options && !sortable
47
+ chain = chain.page(paginate_options[:page]).per(paginate_options[:per_page])
48
+ elsif chain == model
49
+ chain = chain.all
50
+ end
51
+
52
+ @objects = chain
53
+ end
54
+
55
+ def model
56
+ @model ||= if @data['model']
57
+ @data['model'].constantize
58
+ else
59
+ @name.singularize.camelize.constantize
60
+ end
61
+ end
62
+
63
+ def model_name
64
+ ActiveModel::Naming.singular(model)
65
+ end
66
+
67
+ def table_hide?
68
+ table_value(:hide) == true || model.bhf_embedded?
69
+ end
70
+
71
+ def remove_excludes(attrs, excludes)
72
+ return attrs unless excludes
73
+ attrs.each_with_object([]) do |attribute, obj|
74
+ next if excludes.include?(attribute.name.to_s)
75
+ obj << attribute
76
+ end
77
+ end
78
+
79
+ def fields
80
+ @fields ||= remove_excludes(default_attrs(form_value(:display), attributes), form_value(:exclude))
81
+ end
82
+
83
+ def columns
84
+ return @columns if @columns
85
+
86
+ tmp = default_attrs(table_columns, attributes[0..5], true)
87
+ @columns = remove_excludes(tmp, table_value(:exclude))
88
+ end
89
+
90
+ def definitions
91
+ return @definitions if @definitions
92
+
93
+ tmp = default_attrs(show_value(:display) || show_value(:definitions), attributes)
94
+ @definitions = remove_excludes(tmp, show_value(:exclude))
95
+ end
96
+
97
+ def has_file_upload?
98
+ return true if form_value(:multipart) == true
99
+
100
+ fields.each do |field|
101
+ return true if field.form_type == :file
102
+ end
103
+ false
104
+ end
105
+
106
+
107
+
108
+
109
+
110
+
111
+ def search?
112
+ table_value(:search) != false
113
+ end
114
+
115
+ def search_field?
116
+ table_value(:search_field) != false
117
+ end
118
+
119
+ def custom_search
120
+ table_value(:custom_search)
121
+ end
122
+
123
+ def table_columns
124
+ table_value(:display) || table_value(:columns)
125
+ end
126
+
127
+ def custom_columns?
128
+ table_columns.is_a?(Array)
129
+ end
130
+
131
+ def user_scope?
132
+ @user && table_value(:user_scope)
133
+ end
134
+
135
+ def table
136
+ @data['table']
137
+ end
138
+
139
+ def show
140
+ @data['show']
141
+ end
142
+
143
+ def form
144
+ @data['form']
145
+ end
146
+
147
+ def hooks(method)
148
+ if @data['hooks'] && @data['hooks'][method.to_s]
149
+ @data['hooks'][method.to_s].to_sym
150
+ end
151
+ end
152
+
153
+ def sortable
154
+ table_value 'sortable'
155
+ end
156
+
157
+ def sortable_property
158
+ (@data['sortable_property'] || :position).to_sym
159
+ end
160
+
161
+ def columns_count
162
+ columns.count + (sortable ? 2 : 1)
163
+ end
164
+
165
+ def hide_edit
166
+ table_value 'hide_edit'
167
+ end
168
+
169
+ def hide_create
170
+ table_value('hide_create') || table_value('hide_new') || table_value('hide_add')
171
+ end
172
+
173
+ def show_duplicate
174
+ table_value 'show_duplicate'
175
+ end
176
+
177
+ def hide_delete
178
+ table_value('hide_delete') || table_value('hide_destroy')
179
+ end
180
+
181
+ def custom_link
182
+ table_value 'custom_link'
183
+ end
184
+
185
+ def custom_partial
186
+ table_value 'partial'
187
+ end
188
+
189
+ def data_source
190
+ table_value(:source) || table_value(:scope)
191
+ end
192
+
193
+ def show_extra_fields
194
+ show_value(:extra_fields)
195
+ end
196
+
197
+ def entries_per_page
198
+ table_value(:per_page)
199
+ end
200
+
201
+
202
+
203
+
204
+ private
205
+
206
+ def do_search(chain, search_params)
207
+ if table_value(:search)
208
+ chain.send table_value(:search), search_params
209
+ else
210
+ chain.bhf_default_search(search_params)
211
+ end
212
+ end
213
+
214
+ def find_platform_settings_for_link(link_name)
215
+ if form_value(:links, link_name) != false
216
+ if form_value(:links, link_name)
217
+ @settings.find_platform_settings(form_value(:links, link_name))
218
+ else
219
+ @settings.find_platform_settings(link_name.to_s.pluralize) || @settings.find_platform_settings(link_name.to_s.singularize)
220
+ end
221
+ end
222
+ end
223
+
224
+ def default_attrs(attrs, d_attrs, warning = false)
225
+ return d_attrs unless attrs
226
+
227
+ model_respond_to?(attrs) if warning
228
+ attrs.each_with_object([]) do |name, obj|
229
+ obj << (
230
+ attributes.select{ |field| name == field.name }[0] ||
231
+ Bhf::Platform::Attribute::Abstract.new(default_attribute_options(name).merge({
232
+ name: name,
233
+ link: find_platform_settings_for_link(name)
234
+ }))
235
+ )
236
+ end
237
+ end
238
+
239
+ def attributes
240
+ return @attributes if @attributes
241
+
242
+ all = {}
243
+
244
+ model.columns_hash.each_pair do |name, props|
245
+ next if sortable && name == sortable_property
246
+ all[name] = Bhf::Platform::Attribute::Column.new(props, default_attribute_options(name).merge({
247
+ primary_key: model.bhf_primary_key
248
+ }))
249
+ end
250
+
251
+ model.reflections.each_pair do |name, props|
252
+ fk = props.foreign_key
253
+ all[name.to_s] = Bhf::Platform::Attribute::Reflection.new(props, default_attribute_options(name).merge({
254
+ link: find_platform_settings_for_link(name),
255
+ reorderble: model.bhf_attribute_method?(fk)
256
+ }))
257
+
258
+ if all.has_key?(fk) and fk != name.to_s
259
+ all.delete(fk)
260
+ end
261
+ end
262
+
263
+ @attributes = default_sort(all)
264
+ end
265
+
266
+ def default_sort(attrs)
267
+ id = []
268
+ headlines = []
269
+ static_dates = []
270
+ output = []
271
+
272
+ attrs.each_pair do |key, value|
273
+ if key == model.bhf_primary_key
274
+ id << value
275
+ elsif key == 'title' || key == 'name' || key == 'headline'
276
+ headlines << value
277
+ elsif key == 'created_at' || key == 'updated_at'
278
+ static_dates << value
279
+ else
280
+ output << value
281
+ end
282
+ end
283
+
284
+ id + headlines + output.sort_by(&:name) + static_dates
285
+ end
286
+
287
+ def model_respond_to?(attrs)
288
+ new_obj = model.new
289
+ attrs.each do |attribute|
290
+ unless new_obj.respond_to?(attribute)
291
+ raise Exception.new("Model '#{model}' does not respond to '#{attribute}'")
292
+ return false
293
+ end
294
+ end
295
+ true
296
+ end
297
+
298
+ def default_attribute_options(name)
299
+ {
300
+ title: model.human_attribute_name(name),
301
+ form_type: form_value(:types, name),
302
+ display_type: table_value(:types, name),
303
+ show_type: show_value(:types, name),
304
+ info: I18n.t("bhf.platforms.#{@name}.infos.#{name}", default: '')
305
+ }
306
+ end
307
+
308
+
309
+
310
+ def form_value(key, attribute = nil)
311
+ lookup_value form, key, attribute
312
+ end
313
+
314
+ def table_value(key, attribute = nil)
315
+ lookup_value table, key, attribute
316
+ end
317
+
318
+ def show_value(key, attribute = nil)
319
+ lookup_value show, key, attribute
320
+ end
321
+
322
+ def lookup_value(main_key, key, attribute = nil)
323
+ if main_key
324
+ if attribute == nil
325
+ main_key[key.to_s]
326
+ elsif main_key[key.to_s]
327
+ main_key[key.to_s][attribute.to_s]
328
+ end
329
+ end
330
+ end
331
+
332
+ end
333
+ end