beautiful_scaffold 1.0.0.pre → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +9 -0
  3. data/Gemfile +1 -9
  4. data/README.rdoc +1 -1
  5. data/beautiful_scaffold.gemspec +1 -1
  6. data/lib/generators/beautiful_locale_generator.rb +24 -3
  7. data/lib/generators/beautiful_scaffold_common_methods.rb +47 -10
  8. data/lib/generators/beautiful_scaffold_generator.rb +61 -40
  9. data/lib/generators/templates/app/assets/javascripts/application-bs.js +3 -2
  10. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +37 -1
  11. data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +23 -44
  12. data/lib/generators/templates/app/assets/stylesheets/application-bs.css +1 -2
  13. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +25 -1
  14. data/lib/generators/templates/app/controllers/base.rb +17 -7
  15. data/lib/generators/templates/app/controllers/master_base.rb +39 -25
  16. data/lib/generators/templates/app/helpers/beautiful_helper.rb +23 -9
  17. data/lib/generators/templates/app/helpers/model_helper.rb +14 -3
  18. data/lib/generators/templates/app/initializers/ransack.rb +16 -0
  19. data/lib/generators/templates/app/views/_mass_inserting.html.erb +3 -2
  20. data/lib/generators/templates/app/views/_modal_columns.html.erb +2 -2
  21. data/lib/generators/templates/app/views/index.html.erb +25 -3
  22. data/lib/generators/templates/app/views/layout.html.erb +0 -11
  23. data/lib/generators/templates/app/views/partials/_index_search.html.erb +1 -1
  24. data/lib/generators/templates/app/views/partials/_index_search_default_fields.html.erb +1 -1
  25. data/lib/generators/templates/app/views/treeview.html.erb +4 -4
  26. metadata +5 -6
  27. data/lib/generators/templates/app/assets/javascripts/bootstrap-datepicker.js +0 -834
  28. data/lib/generators/templates/app/assets/javascripts/bootstrap-timepicker.js +0 -797
@@ -3,53 +3,67 @@ class BeautifulController < ApplicationController
3
3
 
4
4
  layout "beautiful_layout"
5
5
 
6
+ # That clear cookie to avoid cookie overflow
7
+ # if you want to keep all in memory and you use ARCookieStore, just comment next line
8
+ before_action :delete_session_for_others_models_scaffold
9
+
6
10
  def dashboard
7
11
  render :layout => "beautiful_layout"
8
12
  end
9
13
 
14
+ def delete_session_for_others_models_scaffold
15
+ current_model = params[:controller].split('/').last.singularize
16
+
17
+ ['fields','sorting','search','scope','paginate'].each{ |k|
18
+ session[k] = session[k].delete_if {|key, v| key != current_model } if not session[k].blank?
19
+ }
20
+ end
21
+
10
22
  # Call in AJAX
11
23
  def select_fields
12
24
  model_sym = params[:model_sym]
13
25
 
14
- do_select_fields(model_sym)
26
+ do_select_fields(model_sym.to_s) #TODO vérifier si nécessaire
15
27
 
16
28
  render :nothing => true
17
29
  end
18
30
 
19
- def do_select_fields(model_sym)
31
+ # TODO session use key string because json serializer don't know the type of key.
32
+
33
+ def do_select_fields(model_str)
20
34
  # Fields
21
- session[:fields] ||= {}
22
- session[:fields][model_sym] ||= nil
23
- params[:fields] ||= session[:fields][model_sym]
24
- session[:fields][model_sym] = params[:fields]
35
+ session['fields'] ||= {}
36
+ session['fields'][model_str] ||= nil
37
+ params[:fields] ||= session['fields'][model_str]
38
+ session['fields'][model_str] = params[:fields]
25
39
  end
26
40
 
27
- def do_sort_and_paginate(model_sym)
41
+ def do_sort_and_paginate(model_str)
28
42
  # Sort
29
- session[:sorting] ||= {}
30
- session[:sorting][model_sym] ||= { :attribute => "id", :sorting => "DESC" }
31
- params[:sorting] ||= session[:sorting][model_sym]
32
- session[:sorting][model_sym] = params[:sorting]
33
-
43
+ session['sorting'] ||= {}
44
+ session['sorting'][model_str] ||= { 'attribute' => "id", 'sorting' => "DESC" }
45
+ params[:sorting] ||= session['sorting'][model_str]
46
+ session['sorting'][model_str] = params[:sorting]
47
+
34
48
  # Search and Filter
35
- session[:search] ||= {}
36
- session[:search][model_sym] = nil if not params[:nosearch].blank?
49
+ session['search'] ||= {}
50
+ session['search'][model_str] = nil if not params[:nosearch].blank?
37
51
  params[:page] = 1 if not params[:q].nil?
38
- params[:q] ||= session[:search][model_sym]
39
- session[:search][model_sym] = params[:q] if params[:skip_save_search].blank?
40
-
52
+ params[:q] ||= session['search'][model_str]
53
+ session['search'][model_str] = params[:q] if params[:skip_save_search].blank?
54
+
41
55
  # Scope
42
- session[:scope] ||= {}
43
- session[:scope][model_sym] ||= nil
56
+ session['scope'] ||= {}
57
+ session['scope'][model_str] ||= nil
44
58
  params[:page] = 1 if not params[:scope].nil?
45
- params[:scope] ||= session[:scope][model_sym]
46
- session[:scope][model_sym] = params[:scope]
59
+ params[:scope] ||= session['scope'][model_str]
60
+ session['scope'][model_str] = params[:scope]
47
61
 
48
62
  # Paginate
49
- session[:paginate] ||= {}
50
- session[:paginate][model_sym] ||= nil
51
- params[:page] ||= session[:paginate][model_sym]
52
- session[:paginate][model_sym] = params[:page]
63
+ session['paginate'] ||= {}
64
+ session['paginate'][model_str] ||= nil
65
+ params[:page] ||= session['paginate'][model_str]
66
+ session['paginate'][model_str] = params[:page]
53
67
  end
54
68
 
55
69
  def boolean(string)
@@ -1,8 +1,18 @@
1
1
  # encoding : utf-8
2
+ <%
3
+ if !engine_name.blank?
4
+ b_module = "module #{engine_camel}"
5
+ e_module = "end"
6
+ else
7
+ b_module = ""
8
+ e_module = ""
9
+ end
10
+ %>
11
+ <%= b_module %>
2
12
  module BeautifulHelper
3
13
 
4
14
  def visible_column(model_name, field_name, display_default = 'table-cell', other_css = "")
5
- return ('style="display:' + ((session[:fields][model_name].to_a.include?(field_name)) ? display_default : 'none') + ';' + other_css + '"').html_safe
15
+ return ('style="display:' + ((session['fields'][model_name].to_a.include?(field_name)) ? display_default : 'none') + ';' + other_css + '"').html_safe
6
16
  end
7
17
 
8
18
  def dropdown_submenu(link_caption, &block)
@@ -54,13 +64,13 @@ module BeautifulHelper
54
64
  ).html_safe
55
65
  end
56
66
 
57
- def ransack_field(path_of_model, attribute_name, f, caption = nil)
67
+ def ransack_field(path_of_model, attribute_name, f, caption = nil, engine = nil)
58
68
  model_path = path_of_model.split("/")
59
69
  model_name = model_path.last
60
70
  model_path.delete(model_path.first)
61
71
  model_name_for_ransack = model_path.join("_")
62
72
 
63
- ar_model = model_name.camelize.constantize
73
+ ar_model = (engine.blank? ? model_name.camelize.constantize : "#{engine.camelize}::#{model_name.camelize}".constantize)
64
74
 
65
75
  default_caption = caption
66
76
  if default_caption.blank? then
@@ -158,14 +168,16 @@ module BeautifulHelper
158
168
  response += f.label name_field + "_eq_false", raw(f.radio_button((name_field + "_eq").to_sym, false)) + " " + h(t(:no, :default => "No")), :class => "checkbox inline"
159
169
  response += f.label name_field + "_eq", raw(f.radio_button((name_field + "_eq").to_sym, nil)) + " " + h(t(:all, :default => "All")), :class => "checkbox inline"
160
170
 
161
- infostr = (begin session[:search][model_name.to_sym][(name_field + "_eq").to_sym] == "on" ? "" : "info" rescue "" end)
171
+ infostr = (begin session['search'][model_name][(name_field + "_eq").to_sym] == "on" ? "" : "info" rescue "" end)
162
172
  when :string then
163
173
  response += f.text_field((name_field + "_cont").to_sym, :class => "filter col-md-12 form-control")
164
174
 
165
175
  infostr = info_input(model_name, (name_field + "_cont").to_sym)
166
176
  when :integer, :float, :decimal then
167
177
  if is_belongs_to_column?(name_field_bk) then
168
- btmodel = get_belongs_to_model(name_field_bk).camelize.constantize
178
+ bt_model_name = get_belongs_to_model(name_field_bk).camelize
179
+ bt_model_name = "#{engine.camelize}::#{bt_model_name}" if !engine.blank?
180
+ btmodel = bt_model_name.constantize
169
181
  response += f.collection_select((name_field + "_eq").to_sym, btmodel.all, :id, :caption, { :include_blank => t(:all, :default => "All") }, { :class => "col-md-12 form-control" })
170
182
 
171
183
  infostr = info_input(model_name, (name_field + "_eq").to_sym)
@@ -199,13 +211,13 @@ module BeautifulHelper
199
211
  end
200
212
 
201
213
  def info_input(modname, attr)
202
- model_name = modname.to_sym
214
+ model_name = modname
203
215
  rep = false
204
- if not session[:search].blank? and not session[:search][model_name].blank? then
216
+ if not session['search'].blank? and not session['search'][model_name].blank? then
205
217
  if attr.kind_of?(Array) then
206
- rep = (attr.any? { |elt| (not session[:search][model_name][elt].blank?) })
218
+ rep = (attr.any? { |elt| (not session['search'][model_name][elt].blank?) })
207
219
  else
208
- rep = (not session[:search][model_name][attr].blank?)
220
+ rep = (not session['search'][model_name][attr].blank?)
209
221
  end
210
222
  end
211
223
  return (rep ? "info" : "")
@@ -264,6 +276,7 @@ module BeautifulHelper
264
276
  def clean_params
265
277
  params.delete :q
266
278
  params.delete :fields
279
+ params.delete :scope
267
280
  end
268
281
 
269
282
  def i18n_translate_path(model, attr)
@@ -278,3 +291,4 @@ module BeautifulHelper
278
291
  "app.models.#{model}.bs_caption_plural"
279
292
  end
280
293
  end
294
+ <%= e_module %>
@@ -1,4 +1,15 @@
1
1
  # encoding : utf-8
2
- require "beautiful_helper"
3
- module <%= namespace_for_class %><%= model_pluralize.camelize %>Helper
4
- end
2
+ require "<%= engine_name %>beautiful_helper"
3
+ <%
4
+ if engine_name.blank?
5
+ b_module = e_module = space_indent = ""
6
+ else
7
+ b_module = "module #{engine_camel}"
8
+ e_module = "end"
9
+ space_indent = " "
10
+ end
11
+ %>
12
+ <%= b_module %>
13
+ <%= space_indent %>module <%= namespace_for_class %><%= model_pluralize.camelize %>Helper
14
+ <%= space_indent %>end
15
+ <%= e_module %>
@@ -0,0 +1,16 @@
1
+ Ransack.configure do |config|
2
+
3
+ # Change default search parameter key name.
4
+ # Default key name is :q
5
+ config.search_key = :q
6
+
7
+ # Raise errors if a query contains an unknown predicate or attribute.
8
+ # Default is true (do not raise error on unknown conditions).
9
+ config.ignore_unknown_conditions = false
10
+
11
+ # Globally display sort links without the order indicator arrow.
12
+ # Default is false (sort order indicators are displayed).
13
+ # This can also be configured individually in each sort link (see the README).
14
+ config.hide_sort_order_indicators = true
15
+
16
+ end
@@ -1,14 +1,15 @@
1
+ <% model = ("#{(engine.blank? ? '' : "#{engine.camelize}::")}#{model_name.camelize}").constantize %>
1
2
  <% formparams = [] %>
2
3
  <% if not namespace.blank? then %>
3
4
  <% formparams << namespace %>
4
5
  <% end %>
5
- <% formparams << model_name.camelize.constantize.new %>
6
+ <% formparams << model.new %>
6
7
  <%= form_for formparams, :method => :post, :html => { :class => "well well-small form-inline mass-inserting #{(params[:mass_inserting] ? 'setfocus' : '')}" } do |f| %>
7
8
  <%= hidden_field_tag :mass_inserting, true %>
8
9
  <% for col in model_columns %>
9
10
  <div <%= visible_column(model_name, col, 'inline') %> class="col-<%= col %>">
10
11
  <%=
11
- ar = model_name.camelize.constantize.columns_hash[col]
12
+ ar = model.columns_hash[col]
12
13
  if not ar.nil? then
13
14
  case ar.type
14
15
  when :integer then
@@ -8,12 +8,12 @@
8
8
  <div class="modal-body">
9
9
  <% for field in model_columns %>
10
10
  <label class="checkbox">
11
- <input type="checkbox" name="field[]" value="<%= field %>" <%= "checked" if session[:fields][model_name].include?(field) %>> <%= t("app.models.#{model_name}.bs_attributes.#{field}", :default => field.capitalize) %>
11
+ <input type="checkbox" name="field[]" value="<%= field %>" <%= "checked" if session['fields'][model_name.to_s].include?(field) %>> <%= t("app.models.#{model_name}.bs_attributes.#{field}", :default => field.capitalize) %>
12
12
  </label><br />
13
13
  <% end %>
14
14
  </div>
15
15
  <div class="modal-footer">
16
- <button type="button" class="btn btn-primary" id="filter-columns" data-url="/<%= model_name %>/select_fields">Ok</button>
16
+ <button type="button" class="btn btn-primary" id="filter-columns" data-url="/<%= engine_name %><%= model_name %>/select_fields">Ok</button>
17
17
  <button type="button" class="btn btn-default" id="cancel-filter-columns"><%= t(:cancel, :default => "Cancel") %></button>
18
18
  </div>
19
19
  </div>
@@ -2,12 +2,12 @@
2
2
 
3
3
  <p>
4
4
  <%%= link_to '<i class="fa fa-plus"></i> '.html_safe + t(:new, :default => "New") + ' ' + <%= i18n_t_m(model) %>, new_<%= namespace_for_route %><%= singular_table_name %>_path, :class => "btn btn-default" %>
5
- <%% if <%= model_camelize %>.columns.map(&:name).include?("<%= model %>_id") then %>
5
+ <%% if <%= model_with_engine_camelize %>.columns.map(&:name).include?("<%= model %>_id") then %>
6
6
  <%%= link_to '<i class="fa fa-folder-close"></i> '.html_safe + t(:treeview, :default => "Treeview") + ' ' + <%= i18n_t_m(model) %>, treeview_<%= namespace_for_route %><%= model_pluralize %>_path, :class => "btn btn-default" %>
7
7
  <%% end %>
8
8
  </p>
9
9
 
10
- <%%= render :partial => "layouts/mass_inserting", :locals => { :namespace => '<%= namespace_alone %>', :model_name => '<%= model %>', :model_columns => [<%= attributes.map{ |e| "'#{e.name}'" }.join(',') %>] } %>
10
+ <%%= render :partial => "layouts/mass_inserting", :locals => { :engine => '<%= engine_opt %>', :namespace => '<%= namespace_alone %>', :model_name => '<%= model %>', :model_columns => [<%= attributes.map{ |e| "'#{e.name}'" }.join(',') %>] } %>
11
11
 
12
12
  <%%# Set your scopes below (string in array) %>
13
13
  <%% scopes = [] %>
@@ -22,6 +22,28 @@
22
22
  </div>
23
23
  <%% end %>
24
24
 
25
+ <div class="row">
26
+ <div class="col-md-12">
27
+ <a class="btn btn-xs btn-default" id="hide-menu-btn">
28
+ <i class="fa fa-caret-left"></i>
29
+ <i class="fa fa-caret-left"></i>
30
+ </a>
31
+ <a class="btn btn-xs btn-default" id="show-menu-btn">
32
+ <i class="fa fa-caret-right"></i>
33
+ <i class="fa fa-caret-right"></i>
34
+ </a>
35
+
36
+ <a class="btn btn-xs btn-default pull-right" id="hide-search-btn">
37
+ <i class="fa fa-caret-right"></i>
38
+ <i class="fa fa-caret-right"></i>
39
+ </a>
40
+ <a class="btn btn-xs btn-default pull-right" id="show-search-btn">
41
+ <i class="fa fa-caret-left"></i>
42
+ <i class="fa fa-caret-left"></i>
43
+ </a>
44
+ </div>
45
+ </div>
46
+
25
47
  <div class="row">
26
48
  <div class="col-md-9">
27
49
  <%%= form_tag batch_<%= namespace_for_route %><%= plural_table_name %>_path, :class => "form-inline" do %>
@@ -36,7 +58,7 @@
36
58
  <button class="btn btn-default" type="submit"><i class="fa fa-ok"></i> <%%= t(:process, :default => "Process") %></button>
37
59
  </div>
38
60
 
39
- <%%= render :partial => "layouts/modal_columns", :locals => { :model_name => "<%= singular_table_name %>", :model_columns => [<%= (attributes.map{ |e| "'#{e.name}'" }.to_a + ["'created_at'", "'updated_at'"]).join(',') %>] } %>
61
+ <%%= render :partial => "layouts/modal_columns", :locals => { :engine_name => '<%= engine_opt %>', :model_name => "<%= singular_table_name %>", :model_columns => [<%= (attributes.map{ |e| "'#{e.name}'" }.to_a + ["'created_at'", "'updated_at'"]).join(',') %>] } %>
40
62
 
41
63
  <table class="table table-striped table-bordered table-condensed">
42
64
  <thead>
@@ -80,16 +80,5 @@
80
80
  $('<%%= @opened_modal %>').modal('show');
81
81
  <%% end %>
82
82
  </script>
83
- <script type="text/javascript">
84
- ;(function($){
85
- $.fn.datepicker.dates['<%%= I18n.locale.to_s %>'] = {
86
- days: <%%= (t("date.day_names") + [t("date.day_names").first]).map(&:capitalize).to_s.html_safe %>,
87
- daysShort: <%%= (t("date.abbr_day_names") + [t("date.abbr_day_names").first]).map(&:capitalize).to_s.html_safe %>,
88
- daysMin: <%%= (t("date.abbr_day_names") + [t("date.abbr_day_names").first]).map{ |d| d.capitalize[0..2] }.to_s.html_safe %>,
89
- months: <%%= t("date.month_names")[1..12].map(&:capitalize).to_s.html_safe %>,
90
- monthsShort: <%%= t("date.abbr_month_names")[1..12].map(&:capitalize).to_s.html_safe %>
91
- };
92
- }(jQuery));
93
- </script>
94
83
  </body>
95
84
  </html>
@@ -5,5 +5,5 @@
5
5
  <%- if @beautiful_attributes.include?(a.name + ':references') then -%>
6
6
  <%- attribute = "_id" -%>
7
7
  <%- end -%>
8
- <%%= ransack_field("<%= singular_table_name %>", "<%= a.name %><%= attribute %>", f, "<%= caption %>") %>
8
+ <%%= ransack_field("<%= singular_table_name %>", "<%= a.name %><%= attribute %>", f, "<%= caption %>"<%= (engine_name.blank? ? '' : ", \"#{engine_opt}\"") %>) %>
9
9
  <%- end -%>
@@ -1,3 +1,3 @@
1
1
  <%- { :created_at => "Created At", :updated_at => "Updated At", :id => "Id" }.each{ |k,v| -%>
2
- <%%= ransack_field("<%= singular_table_name %>", "<%= k.to_s %>", f, "<%= v %>") %>
2
+ <%%= ransack_field("<%= singular_table_name %>", "<%= k.to_s %>", f, "<%= v %>"<%= (engine_name.blank? ? '' : ", \"#{engine_opt}\"") %>) %>
3
3
  <%- } -%>
@@ -4,14 +4,14 @@
4
4
  namespace_for_url = "<%= namespace_for_url %>"
5
5
  plural_model_name = "<%= model_pluralize %>"
6
6
  model_name = "<%= singular_table_name %>"
7
- opened_node = <%= model_camelize %>.select(:id).all.map{ |g| "'treeelt_" + g.id.to_s + "'" }.join(',').html_safe
7
+ opened_node = <%= model_with_engine_camelize %>.select(:id).all.map{ |g| "'treeelt_" + g.id.to_s + "'" }.join(',').html_safe
8
8
  %>
9
9
 
10
10
  <div id="treeview" data-model="<%%= model_name %>" data-url="/<%%= namespace_for_url %><%%= plural_model_name %>/" data-opened="[<%%= opened_node %>]">
11
11
  <ul>
12
- <%% <%= model_camelize %>.transaction do %>
13
- <%% ar = <%= model_camelize %>.where(:<%= model %>_id => nil) %>
14
- <%% ar = ar.order("position") if <%= model_camelize %>.column_names.include?("position") %>
12
+ <%% <%= model_with_engine_camelize %>.transaction do %>
13
+ <%% ar = <%= model_with_engine_camelize %>.where(:<%= model %>_id => nil) %>
14
+ <%% ar = ar.order("position") if <%= model_with_engine_camelize %>.column_names.include?("position") %>
15
15
  <%% for g in ar.all %>
16
16
  <%%= build_treeview(g, '<%= model_pluralize %>') %>
17
17
  <%% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beautiful_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Claudel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Beautiful Scaffold generate a complete scaffold (sort, export, paginate
14
14
  and filter data) http://www.beautiful-scaffold.com
@@ -39,9 +39,7 @@ files:
39
39
  - lib/generators/templates/app/assets/javascripts/application-bs.js
40
40
  - lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js
41
41
  - lib/generators/templates/app/assets/javascripts/bootstrap-colorpicker.js
42
- - lib/generators/templates/app/assets/javascripts/bootstrap-datepicker.js
43
42
  - lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js
44
- - lib/generators/templates/app/assets/javascripts/bootstrap-timepicker.js
45
43
  - lib/generators/templates/app/assets/javascripts/bootstrap-wysihtml5.js
46
44
  - lib/generators/templates/app/assets/javascripts/fixed_menu.js
47
45
  - lib/generators/templates/app/assets/javascripts/jquery-barcode.js
@@ -67,6 +65,7 @@ files:
67
65
  - lib/generators/templates/app/helpers/beautiful_helper.rb
68
66
  - lib/generators/templates/app/helpers/model_helper.rb
69
67
  - lib/generators/templates/app/initializers/link_renderer.rb
68
+ - lib/generators/templates/app/initializers/ransack.rb
70
69
  - lib/generators/templates/app/locales/beautiful_scaffold.en.yml
71
70
  - lib/generators/templates/app/locales/beautiful_scaffold.fr.yml
72
71
  - lib/generators/templates/app/locales/beautiful_scaffold.ja.yml
@@ -114,9 +113,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
113
  version: '0'
115
114
  required_rubygems_version: !ruby/object:Gem::Requirement
116
115
  requirements:
117
- - - ">"
116
+ - - ">="
118
117
  - !ruby/object:Gem::Version
119
- version: 1.3.1
118
+ version: '0'
120
119
  requirements: []
121
120
  rubyforge_project: beautiful_scaffold
122
121
  rubygems_version: 2.5.2