tb_core 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -2
  3. data/app/assets/javascripts/admin/core/dashboard.js +19 -16
  4. data/app/assets/libs/sortable/sortable.js +1481 -0
  5. data/app/controllers/admin/application_controller.rb +2 -1
  6. data/app/controllers/admin/users_controller.rb +5 -1
  7. data/app/controllers/concerns/tb_core/error_handling.rb +49 -0
  8. data/app/controllers/concerns/tb_core/redirection.rb +23 -0
  9. data/app/controllers/concerns/tb_core/sortable_params.rb +80 -0
  10. data/app/controllers/concerns/tb_core/user_authentication.rb +57 -0
  11. data/app/controllers/spud/application_controller.rb +8 -136
  12. data/app/controllers/tb_core/application_controller.rb +16 -0
  13. data/app/helpers/admin/application_helper.rb +3 -1
  14. data/app/helpers/tb_core/application_helper.rb +32 -0
  15. data/app/views/admin/users/index.html.erb +6 -6
  16. data/config/locales/en.yml +1 -0
  17. data/config/routes.rb +1 -1
  18. data/lib/generators/spud/templates/application_controller.rb +1 -1
  19. data/lib/spud_core/engine.rb +1 -1
  20. data/lib/spud_core/version.rb +1 -1
  21. data/lib/tb_core/form_builder.rb +1 -1
  22. data/lib/tb_core/table_header.rb +92 -0
  23. data/spec/controllers/admin/application_controller_spec.rb +1 -1
  24. data/spec/controllers/{spud → tb_core}/application_controller_spec.rb +1 -1
  25. data/spec/controllers/tb_core/sortable_params_spec.rb +64 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  27. data/spec/helpers/tb_core/application_helper_spec.rb +39 -0
  28. data/spec/rails_helper.rb +3 -4
  29. data/spec/spec_helper.rb +2 -0
  30. metadata +18 -11
  31. data/app/assets/javascripts/admin/core/jquery_ui.js +0 -22
  32. data/app/assets/stylesheets/admin/core/jquery_ui.scss +0 -19
  33. data/app/controllers/spud/admin/application_controller.rb +0 -12
  34. data/app/helpers/spud/application_helper.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9b6cb6c8e20c8f5e050ff4194eecd52873a8ee8
4
- data.tar.gz: 6f0923c173310c948501ab42f63fd9cdc4117577
3
+ metadata.gz: 5d4b115f542bdd9445a2a32b9d1d0ea8a664c6ae
4
+ data.tar.gz: c77ab9bab3976d0c567ea557111991b1b45a8388
5
5
  SHA512:
6
- metadata.gz: 75f1dcb89bd05dad030e06f21955d670c3cd8cb7af2541807de9588840aa1202205699cbd53bb95ecce5d6337ae456fe53b529f01b35e57fcca6c8f83c0ffac0
7
- data.tar.gz: e8fbe677701e25eafca66574b35ed73bd0689bddf9af713c896da23d21b28d013a4166f7b7645f450c7bf35917b258e9fb9da0fa149fa0b0649e64c6b0af99ab
6
+ metadata.gz: e6b8e1f29af8d51135fb1a724eecceacb31f3bf9d43ec9ca3e2496bdb93c4aecb21027d81ecbd9b4a3e5be3c140b137f2257a799b4cd142cdca5e090c098a3bb
7
+ data.tar.gz: 13e3206f5b3327ad0473cce81d1869552227c227772fe41cefddd72afe685867ca2e120111e8bf17b89a4864130f55a4a1ef1ae72721657f04fb30c46f4631de
data/README.md CHANGED
@@ -32,7 +32,7 @@ Setup Tasks
32
32
 
33
33
  The `spud:setup` generator takes care of a few tasks for you. If you missed that step or would like to complete them manually, they are listed below:
34
34
 
35
- 1. Your base `ApplicationController` should extend from `Spud::ApplicationController`.
35
+ 1. Your base `ApplicationController` should extend from `TbCore::ApplicationController`.
36
36
  2. Your base `application.html.erb` should include a few special head tags (see generator template for example).
37
37
  3. You should copy in the base migrations with `rake railties:install:migrations`.
38
38
 
@@ -121,7 +121,7 @@ Create a file in your app at `app/views/admin/users/_show_additions.html.erb`.
121
121
  Error Handling
122
122
  ------------
123
123
 
124
- The base `Spud::ApplicationController` will automatically rescue from any `Spud::NotFoundError` and `Spud::AccessDeniedError` errors by rendering out the `layouts/error_page.html` template. If you ran the `spud:setup` generator, a template of that name will have been created for you automatically.
124
+ The base `TbCore::ApplicationController` will automatically rescue from any `Spud::NotFoundError` and `Spud::AccessDeniedError` errors by rendering out the `layouts/error_page.html` template. If you ran the `spud:setup` generator, a template of that name will have been created for you automatically.
125
125
 
126
126
  When building your own apps you may raise a `Spud::NotFoundError` or `Spud::AccessDeniedError` error at any time to halt further execution and cause the error page to render. For example:
127
127
 
@@ -175,6 +175,38 @@ A common case is to have a model in your app that `belongs_to :spud_user`. The `
175
175
  <%= f.tb_save_buttons('Widget', widgets_path) %>
176
176
  <% end %>
177
177
 
178
+ Table Sorting
179
+ -------------
180
+
181
+ We provide a few tools to assist with sorting tables of data backed by ActiveRecord queries. In your view, the `tb_table_header` helper method will generate a `<thead>` element with header tags.
182
+
183
+ ### Example
184
+
185
+ ```erb
186
+ <%= tb_table_header :users_path do |t| %>
187
+ <%= t.sortable :full_name %>
188
+ <%= t.sortable :email %>
189
+ <%= t.sortable :birth_date %>
190
+ <%= t.header :favorite_color %> # Header without sorting
191
+ <th>Plain HTML is fine too</th>
192
+ <% end %>
193
+ ```
194
+
195
+ On the controller side, you can choose to deal with the `:dir` and `:sort` params using your own custom logic, or you can use the `SortableParams` module.
196
+
197
+ ```ruby
198
+ include TbCore::SortableParams
199
+
200
+ sortable_by :email, # A basic sort
201
+ full_name: [:last_name, :first_name], # This will sort on two columns
202
+ birth_date: 'birth_dates.date :dir', # This will sort on a joined table
203
+ default: :email # The sort to use when none is passed
204
+
205
+ def index
206
+ MyModel.where(...).order(sortable_query)
207
+ end
208
+ ```
209
+
178
210
  Remote Forms
179
211
  --------------
180
212
 
@@ -1,3 +1,5 @@
1
+ //= require sortable/sortable
2
+
1
3
  (function(){
2
4
 
3
5
  var badgeInterval;
@@ -46,27 +48,28 @@ var updateBadge = function(badge_id, count) {
46
48
  };
47
49
 
48
50
  var sortableIcons = function(){
49
- $(".sortable").sortable({
50
- update : function(e, ui) {
51
+ var element = document.querySelector('.sortable');
52
+ var sortable = Sortable.create(element, {
53
+ onUpdate: function() {
51
54
  var sortArr = [];
52
55
  var index = 0;
53
- $(".sortable > div > a").each(function() {
54
- sortArr.push($(this).attr('href'));
55
- });
56
- //save the order to userSettings
57
- $.ajax('/admin/change_sort', {
58
- method: 'PUT',
59
- data: {order:sortArr},
60
- dataType: "json",
61
- success: function(data, status, jqXHR) {
62
-
63
- },
64
- error: function(XMLHttpRequest, textStatus, errorThrown) {
65
- alert("Status: " + textStatus); alert("Error: " + errorThrown);
66
- }
56
+ document.querySelectorAll('.sortable > div > a').forEach(function(element){
57
+ sortArr.push(element.getAttribute('href'));
67
58
  });
59
+ saveOrder(sortArr);
68
60
  }
69
61
  });
70
62
  };
71
63
 
64
+ function saveOrder(sortArray) {
65
+ $.ajax('/admin/change_sort', {
66
+ method: 'PUT',
67
+ data: { order: sortArray },
68
+ dataType: "json",
69
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
70
+ console.error('Saving sort order failed:', arguments);
71
+ }
72
+ });
73
+ }
74
+
72
75
  })();