record_collection 0.5.0 → 0.5.1

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 (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +88 -3
  3. data/lib/generators/collection_scaffold/collection_scaffold_generator.rb +94 -0
  4. data/lib/generators/collection_scaffold/templates/_form.html.haml +8 -0
  5. data/lib/generators/collection_scaffold/templates/_form.html.slim +8 -0
  6. data/lib/generators/collection_scaffold/templates/collection.rb +7 -0
  7. data/lib/generators/collection_scaffold/templates/collection_edit.html.haml +10 -0
  8. data/lib/generators/collection_scaffold/templates/collection_edit.html.slim +10 -0
  9. data/lib/generators/collection_scaffold/templates/controller.rb +83 -0
  10. data/lib/generators/collection_scaffold/templates/create_table_migration.rb +22 -0
  11. data/lib/generators/collection_scaffold/templates/edit.html.haml +7 -0
  12. data/lib/generators/collection_scaffold/templates/edit.html.slim +7 -0
  13. data/lib/generators/collection_scaffold/templates/index.html.haml +26 -0
  14. data/lib/generators/collection_scaffold/templates/index.html.slim +26 -0
  15. data/lib/generators/collection_scaffold/templates/model.rb +13 -0
  16. data/lib/generators/collection_scaffold/templates/new.html.haml +6 -0
  17. data/lib/generators/collection_scaffold/templates/new.html.slim +6 -0
  18. data/lib/generators/collection_scaffold/templates/show.html.haml +10 -0
  19. data/lib/generators/collection_scaffold/templates/show.html.slim +10 -0
  20. data/lib/record_collection/base.rb +4 -0
  21. data/lib/record_collection/rails/form_options_helper.rb +9 -0
  22. data/lib/record_collection/version.rb +1 -1
  23. data/record_collection.gemspec +1 -0
  24. data/spec/base/finding_records_spec.rb +7 -0
  25. data/spec/dummy/app/assets/javascripts/application.js.coffee +5 -1
  26. data/spec/dummy/app/views/employees/index.html.slim +5 -2
  27. data/spec/dummy/config/locales/record_collection.en.yml +17 -0
  28. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1dfc73354ba9b9a8f5c890106e92e7929f95b702
4
- data.tar.gz: 99cf631416ce9a8ec12b1959c785d29b3a1da010
3
+ metadata.gz: 97111669c3034b55d12ce281bb8131ad3e92b4e1
4
+ data.tar.gz: 47b7bf620af4113c183775031662e166645ec12f
5
5
  SHA512:
6
- metadata.gz: 0df9ecbe183b157a5cbba434d6303ff5b48367ca1fde5510e7cdbf7bd22f35c1bd00e195e70d8109b541c4af7f8fb0d3cba3f5bf466dad2859bbbfc4caa0bab6
7
- data.tar.gz: 011cc7ee0db03df40241cbf96a46a9a053b33f8cc340b0c64ccbd421fb8c14f48cbf8864d5ee23799a9bf9e64e4b51c2393631e9500993289eccf2479bd5ad0e
6
+ metadata.gz: 797dc853281125a3b7c5b35a26168d5f073d6c8b0a0f1d0625f1a4c06a4be17d9a0a6754e800768865ffb19e8c4aa83b3ed6aaf6a025f32ee1cadcf6d53c1fcf
7
+ data.tar.gz: 6beb6733aad0b2fcc1eedfc69ab1788f9bf6317898152c4a86ec5e82b047d210c0c6e9dec07f44e5403244665ff4deec5aa96a097027661550a7ac41e5738704
data/README.md CHANGED
@@ -107,6 +107,19 @@ class MyAwesomeCollection < RecordCollection::Base
107
107
  end
108
108
  ```
109
109
 
110
+ ### The `after_record_update` hook
111
+ The collection implements a general `update(attributes)` method that will
112
+ update all the attributes that are set in the collection on the records it contains.
113
+ If you want to trigger a conditional for example a state machine trigger, you can do it like:
114
+
115
+ ```ruby
116
+ class Project::Prince2::Collection < RecordCollection::Base
117
+ after_record_update do |record|
118
+ record.is_planned! if record.plan_date.present?
119
+ end
120
+ end
121
+ ```
122
+
110
123
  ## Defining your controllers
111
124
  If you already used the specification `collection_resources :employees` in
112
125
  your [config/routes.rb](spec/dummy/config/routes.rb) file you can add
@@ -202,7 +215,8 @@ table.with-selection
202
215
  Note that each row needs a json version of the record at least
203
216
  containing its id.<br>
204
217
  Implement the multiselect dependencies in your manifest files, typically
205
- being `app/assets/javascripts/application.js`:
218
+ being
219
+ [app/assets/javascripts/application.js](spec/dummy/app/assets/javascriptss/application.js.coffee):
206
220
  ```javascript
207
221
  //= require record_collection/multi_select
208
222
  // Or require record_collection/all for all components
@@ -232,7 +246,44 @@ $(function(){
232
246
  ```
233
247
 
234
248
  You can also apply it to dynamically loaded html replacing document for
235
- the html added to your page.
249
+ the html added to your page:
250
+ ```javascript
251
+ $.get('/ajax-page.html', function(response){
252
+ $('#ajax-container').html(response);
253
+ $('#ajax-container').multi_select();
254
+ });
255
+ ```
256
+ ### The selection action button
257
+ Selecting records from the tabble is the first step. Then going to the
258
+ edit page to edit the selection is another. At the moment there is not
259
+ yet a standardized solution in the `record_collection` gem, but with
260
+ your suggestions there will be one in the future. A current method can
261
+ be:
262
+ ```slim
263
+ table.with-selection
264
+ ...
265
+ tfoot
266
+ tr
267
+ td
268
+ button#selected-records-action Actions
269
+ ```
270
+ And in your [app/assets/javascripts/application.js.coffee](spec/dummy/app/assets/javascriptss/application.js.coffee)
271
+ ```coffeescript
272
+ $ ->
273
+ if selector = $(document).multi_select()
274
+ $('#selected-records-action').click ->
275
+ ids = selector.selected_ids()
276
+ return alert "No records selected" unless ids.length
277
+ window.location = "/employees/collection_edit?#{$.param(ids: ids)}"
278
+ ```
279
+ This indicates the controll you can implement on your collectoins.
280
+ Another way could be to use the less advicable way when the
281
+ [js-routes](https://github.com/railsware/js-routes) gem is added to just
282
+ have a button like:
283
+ ```html
284
+ <button onclick="window.location = Routes.collection_edit_employees_path({ids: MultiSelect.selected_ids()})">Actions</button>
285
+ ```
286
+ without any extra javascript.
236
287
 
237
288
  ## Optionals
238
289
  ![Screenshot](docs/screenshot-optionals-1.png?raw=true)
@@ -283,7 +334,41 @@ en:
283
334
  collection:
284
335
  create: "Update %{model}"
285
336
  ```
286
-
337
+
338
+ ## Generators
339
+ There is a scaffold generator available for collection resources. The
340
+ behaviour is very similar to the normal scaffold generator:
341
+ ```bash
342
+ rails g collection_scaffold Project name:string finished:boolean description:text
343
+ ```
344
+
345
+ This will generate the routes, model, migration, collection model and
346
+ views.
347
+
348
+ <b>NOTE:</b> At the moment only haml support for generated views.
349
+ Also note that the generators make an assumption about having the
350
+ following translations available:
351
+ ```yml
352
+ en:
353
+ action:
354
+ create:
355
+ successful: Successfully created %{model}
356
+ update:
357
+ successful: Successfully updated %{model}
358
+ collection_update:
359
+ successful: Successfully updated %{model} collection
360
+ destroy:
361
+ successful: Successfully destroyed %{model}
362
+ new:
363
+ link: New
364
+ index:
365
+ link: Back
366
+ edit:
367
+ link: Edit
368
+ show:
369
+ link: Show
370
+ ```
371
+
287
372
  ## Special thanks
288
373
 
289
374
  Special thanks for this project goes to:<br>
@@ -0,0 +1,94 @@
1
+ class CollectionScaffoldGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path("../templates", __FILE__)
3
+ include Rails::Generators::Migration
4
+ include Rails::Generators::ResourceHelpers
5
+
6
+ check_class_collision suffix: "Controller"
7
+
8
+ class_option :orm, banner: "NAME", type: :string, required: true,
9
+ desc: "ORM to generate the controller for"
10
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
11
+
12
+ def create_route
13
+ route "collection_resources :#{plural_name}"
14
+ end
15
+
16
+ def create_controller_files
17
+ template "controller.rb", File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
18
+ end
19
+
20
+ def create_model_file
21
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
22
+ end
23
+
24
+ def create_collection_file
25
+ template 'collection.rb', File.join('app/models', class_path, file_name, "collection.rb")
26
+ end
27
+
28
+ def create_root_folder
29
+ empty_directory File.join("app/views", controller_file_path)
30
+ end
31
+
32
+ def copy_view_files
33
+ available_views.each do |view|
34
+ formats.each do |format|
35
+ filename = filename_with_extensions(view, format)
36
+ template filename, File.join("app/views", controller_file_path, filename)
37
+ end
38
+ end
39
+ end
40
+
41
+ def create_migration_file
42
+ migration_template "create_table_migration.rb", "db/migrate/create_#{table_name}.rb"
43
+ end
44
+
45
+ class << self
46
+ # Implement the required interface for Rails::Generators::Migration.
47
+ # taken for record collection from: activerecord/lib/rails/generators/active_record/migration.rb
48
+ def next_migration_number(dirname)
49
+ next_migration_number = current_migration_number(dirname) + 1
50
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
51
+ end
52
+ end
53
+
54
+ protected
55
+
56
+ # taken from
57
+ # activerecord/lib/rails/generators/active_record/model/model_generator.rb
58
+ def attributes_with_index
59
+ attributes.select { |a| !a.reference? && a.has_index? }
60
+ end
61
+
62
+ # taken from
63
+ # activerecord/lib/rails/generators/active_record/model/model_generator.rb
64
+ def accessible_attributes
65
+ attributes.reject(&:reference?)
66
+ end
67
+
68
+ def collection_type_addition_for(attribute)
69
+ case attribute.type
70
+ when :boolean then ", type: Boolean"
71
+ else ''
72
+ end
73
+ end
74
+
75
+ def parent_class_name
76
+ options[:parent] || "ActiveRecord::Base"
77
+ end
78
+
79
+ def available_views
80
+ %w(index edit show new _form collection_edit)
81
+ end
82
+
83
+ def formats
84
+ [:html]
85
+ end
86
+
87
+ def handler
88
+ "Slim".safe_constantize ? :slim : :haml
89
+ end
90
+
91
+ def filename_with_extensions(view, format)
92
+ [view, format, handler].compact.join('.')
93
+ end
94
+ end
@@ -0,0 +1,8 @@
1
+ = form_for @<%= singular_table_name %> do |f|
2
+ / Error messages
3
+ <% for attribute in attributes -%>
4
+ .form-row
5
+ .form-label= f.label :<%= attribute.name %>
6
+ .form-field= f.<%= attribute.field_type %> :<%= attribute.name %>
7
+ <% end -%>
8
+ .form-actions= f.submit 'Save'
@@ -0,0 +1,8 @@
1
+ = form_for @<%= singular_table_name %> do |f|
2
+ / Error messages
3
+ <% for attribute in attributes -%>
4
+ .form-row
5
+ .form-label= f.label :<%= attribute.name %>
6
+ .form-field= f.<%= attribute.field_type %> :<%= attribute.name %>
7
+ <% end -%>
8
+ .form-actions= f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>::Collection < RecordCollection::Base
3
+ <% attributes.each do |attribute| -%>
4
+ attribute :<%= attribute.name %><%= collection_type_addition_for(attribute) %>
5
+ <% end -%>
6
+ end
7
+ <% end -%>
@@ -0,0 +1,10 @@
1
+ = form_for @collection, url: [:collection_update, @collection] do |f|
2
+ = f.collection_ids
3
+ / Error messages
4
+ <% for attribute in attributes -%>
5
+ .form-row= f.optional_<%= attribute.field_type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ .form-actions= f.submit 'Save'
8
+
9
+ .page-actions
10
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
@@ -0,0 +1,10 @@
1
+ = form_for @collection, url: [:collection_update, @collection] do |f|
2
+ = f.collection_ids
3
+ / Error messages
4
+ <% for attribute in attributes -%>
5
+ .form-row= f.optional_<%= attribute.field_type %> :<%= attribute.name %>
6
+ <% end -%>
7
+ .form-actions= f.submit 'Save'
8
+
9
+ .page-actions
10
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
@@ -0,0 +1,83 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
+
9
+ # GET <%= route_url %>
10
+ def index
11
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
12
+ end
13
+
14
+ # GET <%= route_url %>/1
15
+ def show
16
+ end
17
+
18
+ # GET <%= route_url %>/new
19
+ def new
20
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
21
+ end
22
+
23
+ # GET <%= route_url %>/1/edit
24
+ def edit
25
+ end
26
+
27
+ # POST <%= route_url %>
28
+ def create
29
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
30
+
31
+ if @<%= orm_instance.save %>
32
+ redirect_to @<%= singular_table_name %>, notice: t('action.create.successful', model: <%= class_name %>.model_name.human)
33
+ else
34
+ render :new
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT <%= route_url %>/1
39
+ def update
40
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
41
+ redirect_to @<%= singular_table_name %>, notice: t('action.update.successful', model: <%= class_name %>.model_name.human)
42
+ else
43
+ render :edit
44
+ end
45
+ end
46
+
47
+ # DELETE <%= route_url %>/1
48
+ def destroy
49
+ @<%= orm_instance.destroy %>
50
+ redirect_to <%= index_helper %>_url, notice: t('action.destroy.successful', model: <%= class_name %>.model_name.human)
51
+ end
52
+
53
+ # GET <%= route_url %>/collection_edit
54
+ def collection_edit
55
+ @collection = <%= class_name %>::Collection.find(params[:ids])
56
+ end
57
+
58
+ # GET <%= route_url %>/collection_edit
59
+ def collection_update
60
+ @collection = <%= class_name %>::Collection.find(params[:ids])
61
+ if @collection.update params[:collection]
62
+ redirect_to <%= index_helper %>_url, notice: t('action.collection_update.successful', model: <%= class_name %>.model_name.human)
63
+ else
64
+ render :collection_edit
65
+ end
66
+ end
67
+
68
+ private
69
+ # Use callbacks to share common setup or constraints between actions.
70
+ def set_<%= singular_table_name %>
71
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
72
+ end
73
+
74
+ # Only allow a trusted parameter "white list" through.
75
+ def <%= "#{singular_table_name}_params" %>
76
+ <%- if attributes_names.empty? -%>
77
+ params[:<%= singular_table_name %>]
78
+ <%- else -%>
79
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
80
+ <%- end -%>
81
+ end
82
+ end
83
+ <% end -%>
@@ -0,0 +1,22 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ <% if attribute.password_digest? -%>
6
+ t.string :password_digest<%= attribute.inject_options %>
7
+ <% else -%>
8
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
9
+ <% end -%>
10
+ <% end -%>
11
+ <% if options[:timestamps] %>
12
+ t.timestamps null: false
13
+ <% end -%>
14
+ end
15
+ <% attributes_with_index.each do |attribute| -%>
16
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
17
+ <% end -%>
18
+ <% attributes.select(&:reference?).reject(&:polymorphic?).each do |attribute| -%>
19
+ add_foreign_key :<%= table_name %>, :<%= attribute.name.pluralize %>
20
+ <% end -%>
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ -#= page_title :edit, <%= class_name %>
2
+
3
+ = render 'form'
4
+
5
+ .page-links
6
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
7
+ = link_to t('action.show.link', model: <%= class_name %>.model_name.human), @<%= singular_table_name %>, class: 'record-show-button'
@@ -0,0 +1,7 @@
1
+ -#= page_title :edit, <%= class_name %>
2
+
3
+ = render 'form'
4
+
5
+ .page-links
6
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
7
+ = link_to t('action.show.link', model: <%= class_name %>.model_name.human), @<%= singular_table_name %>, class: 'record-show-button'
@@ -0,0 +1,26 @@
1
+ -#= page_title :index, <%= class_name %>
2
+
3
+ %table.with-selection
4
+ %thead
5
+ %tr
6
+ <% for attribute in attributes -%>
7
+ %th= <%= class_name %>.human_attribute_name(:<%= attribute.name %>)
8
+ <% end -%>
9
+ %th.actions
10
+ %tbody
11
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
12
+ %tr{data: {record: {id: <%= singular_table_name %>.id}.to_json}}
13
+ <% for attribute in attributes[0...1] -%>
14
+ %td= link_to <%= singular_table_name %>.<%= attribute.name %>, <%= singular_table_name %>
15
+ <% end -%>
16
+ <% for attribute in attributes[1..-1] -%>
17
+ %td= <%= singular_table_name %>.<%= attribute.name %>
18
+ <% end -%>
19
+ %td.actions
20
+ = link_to content_tag(:span, '', class: 'icon'), <%= singular_table_name %>, class: 'table-new-button'
21
+ = link_to content_tag(:span, '', class: 'icon'), edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'table-edit-button'
22
+ = link_to content_tag(:span, '', class: 'icon'), <%= singular_table_name %>, method: :delete, class: 'table-destroy-button', data: { confirm: 'Are you sure?' }
23
+
24
+ .page-links
25
+ %button.actions-button onclick="window.location = $(this).data('url') + '?' + $.param({ids: MultiSelect.selected_ids()})" data-url=collection_edit_<%= plural_table_name %>_path Actions
26
+ = link_to t('action.new.link', model: <%= class_name %>.model_name.human), new_<%= singular_table_name %>_path, class: 'record-new-button'
@@ -0,0 +1,26 @@
1
+ -#= page_title :index, <%= class_name %>
2
+
3
+ table.with-selection
4
+ thead
5
+ tr
6
+ <% for attribute in attributes -%>
7
+ th= <%= class_name %>.human_attribute_name(:<%= attribute.name %>)
8
+ <% end -%>
9
+ th.actions
10
+ tbody
11
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
12
+ tr data-record={id: <%= singular_table_name %>.id}.to_json
13
+ <% for attribute in attributes[0...1] -%>
14
+ td= link_to <%= singular_table_name %>.<%= attribute.name %>, <%= singular_table_name %>
15
+ <% end -%>
16
+ <% for attribute in attributes[1..-1] -%>
17
+ td= <%= singular_table_name %>.<%= attribute.name %>
18
+ <% end -%>
19
+ td.actions
20
+ = link_to content_tag(:span, '', class: 'icon'), <%= singular_table_name %>, class: 'table-new-button'
21
+ = link_to content_tag(:span, '', class: 'icon'), edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: 'table-edit-button'
22
+ = link_to content_tag(:span, '', class: 'icon'), <%= singular_table_name %>, method: :delete, class: 'table-destroy-button', data: { confirm: 'Are you sure?' }
23
+
24
+ .page-links
25
+ button.actions-button onclick="window.location = $(this).data('url') + '?' + $.param({ids: MultiSelect.selected_ids()})" data-url=collection_edit_<%= plural_table_name %>_path Actions
26
+ = link_to t('action.new.link', model: <%= class_name %>.model_name.human), new_<%= singular_table_name %>_path, class: 'record-new-button'
@@ -0,0 +1,13 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %> < <%= parent_class_name.classify %>
3
+ <% attributes.each do |attribute| -%>
4
+ # property <%= attribute.name %>, type: :<%= attribute.type %>
5
+ <% end -%>
6
+ <% attributes.select(&:reference?).each do |attribute| -%>
7
+ belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
8
+ <% end -%>
9
+ <% if attributes.any?(&:password_digest?) -%>
10
+ has_secure_password
11
+ <% end -%>
12
+ end
13
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ -#= page_title :new, <%= class_name %>
2
+
3
+ = render 'form'
4
+
5
+ .page-links
6
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
@@ -0,0 +1,6 @@
1
+ -#= page_title :new, <%= class_name %>
2
+
3
+ = render 'form'
4
+
5
+ .page-links
6
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
@@ -0,0 +1,10 @@
1
+ -#= page_title :show, <%= class_name %>
2
+ <% for attribute in attributes -%>
3
+ .display-row
4
+ .display-label= <%= class_name %>.human_attribute_name(:<%= attribute.name %>)
5
+ .display-field= @<%= singular_table_name %>.<%= attribute.name %>
6
+ <% end -%>
7
+
8
+ .page-links
9
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
10
+ = link_to t('action.edit.link', model: <%= class_name %>.model_name.human), edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: 'record-edit-button'
@@ -0,0 +1,10 @@
1
+ -#= page_title :show, <%= class_name %>
2
+ <% for attribute in attributes -%>
3
+ .display-row
4
+ .display-label= <%= class_name %>.human_attribute_name(:<%= attribute.name %>)
5
+ .display-field= @<%= singular_table_name %>.<%= attribute.name %>
6
+ <% end -%>
7
+
8
+ .page-links
9
+ = link_to t('action.index.link', model: <%= class_name %>.model_name.human), <%= index_helper %>_path, class: 'to-index-button'
10
+ = link_to t('action.edit.link', model: <%= class_name %>.model_name.human), edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: 'record-edit-button'
@@ -51,6 +51,10 @@ module RecordCollection
51
51
  def where(*args)
52
52
  new record_class.where(*args)
53
53
  end
54
+
55
+ def all
56
+ new record_class.all
57
+ end
54
58
  end
55
59
 
56
60
  def initialize(collection = [], params = {})
@@ -22,6 +22,10 @@ class ActionView::Helpers::FormBuilder
22
22
  add_collection_ids @template.content_tag(:div, label_tag + check_box_tag , class: classes, data: { attribute: attr })
23
23
  end
24
24
 
25
+ def optional_check_box(attr)
26
+ optional_boolean(attr)
27
+ end
28
+
25
29
  def optional_input(attr, options = {})
26
30
  classes = get_optional_classes(attr, base_class: 'optional-input')
27
31
  add_collection_ids @template.content_tag(:div, input(attr, options), class: classes, data: { attribute: attr })
@@ -32,6 +36,11 @@ class ActionView::Helpers::FormBuilder
32
36
  add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + text_field(attr, options), class: classes, data: { attribute: attr })
33
37
  end
34
38
 
39
+ def optional_text_area(attr, options={})
40
+ classes = get_optional_classes(attr, base_class: 'optional-text-area')
41
+ add_collection_ids @template.content_tag(:div, label(attr, options[:label]) + text_area(attr, options), class: classes, data: { attribute: attr })
42
+ end
43
+
35
44
  def get_optional_classes(attr, options = {})
36
45
  active = false
37
46
  if object.respond_to?(:uniform_collection_attribute)
@@ -1,3 +1,3 @@
1
1
  module RecordCollection
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "poltergeist"
36
36
  spec.add_development_dependency "launchy"
37
37
  spec.add_development_dependency "database_cleaner"
38
+ spec.add_development_dependency "spring"
38
39
 
39
40
 
40
41
  spec.add_runtime_dependency 'active_attr', '~> 0.8'
@@ -33,4 +33,11 @@ RSpec.describe Employee::Collection do
33
33
  described_class.where(admin: false).ids.should eq [employee2.id]
34
34
  end
35
35
  end
36
+
37
+ describe '.all' do
38
+ it 'finds all record and makes it part of the collection' do
39
+ employee = Employee.create name: 'E1', section: 'ABC', admin: true, vegan: false
40
+ described_class.all.collection.should eq [employee]
41
+ end
42
+ end
36
43
  end
@@ -6,6 +6,10 @@
6
6
  #= require_tree .
7
7
  #= require_self
8
8
  $ ->
9
- $(document).multi_select()
10
9
  $(document).optionals()
11
10
  $(document).foundation()
11
+ if selector = $(document).multi_select()
12
+ $('#selected-records-action').click ->
13
+ ids = selector.selected_ids()
14
+ return alert "No records selected" unless ids.length
15
+ window.location = "/employees/collection_edit?#{$.param(ids: ids)}"
@@ -1,4 +1,3 @@
1
-
2
1
  h1 Listing Employees
3
2
  table.with-selection
4
3
  thead
@@ -7,7 +6,7 @@ table.with-selection
7
6
  th Section
8
7
  th Admin?
9
8
  th Vegan?
10
- th colspan="3"
9
+ th colspan=3
11
10
  tbody
12
11
  - @employees.each do |employee|
13
12
  tr data-record=employee.attributes.to_json
@@ -18,6 +17,10 @@ table.with-selection
18
17
  td= link_to 'Show', employee
19
18
  td= link_to 'Edit', edit_employee_path(employee)
20
19
  td= link_to 'Destroy', employee, method: :delete, data: {confirm: 'Are you sure?' }
20
+ tfoot
21
+ tr
22
+ td colspan=8
23
+ button#selected-records-action Actions
21
24
  br
22
25
  .page-actions
23
26
  button.actions-button.button.warning onclick="window.location = Routes.collection_edit_employees_path({ids: MultiSelect.selected_ids()})" Actions
@@ -9,3 +9,20 @@ en:
9
9
  submit:
10
10
  collection:
11
11
  create: "Update %{model}"
12
+ action:
13
+ create:
14
+ successful: Successfully created %{model}
15
+ update:
16
+ successful: Successfully updated %{model}
17
+ collection_update:
18
+ successful: Successfully updated %{model} collection
19
+ destroy:
20
+ successful: Successfully destroyed %{model}
21
+ new:
22
+ link: New
23
+ index:
24
+ link: Back
25
+ edit:
26
+ link: Edit
27
+ show:
28
+ link: Show
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin ter Kuile
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-11 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: spring
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
237
251
  - !ruby/object:Gem::Dependency
238
252
  name: active_attr
239
253
  requirement: !ruby/object:Gem::Requirement
@@ -300,6 +314,23 @@ files:
300
314
  - app/controllers/record_collection/application_controller.rb
301
315
  - app/helpers/record_collection/application_helper.rb
302
316
  - app/views/layouts/record_collection/application.html.erb
317
+ - lib/generators/collection_scaffold/collection_scaffold_generator.rb
318
+ - lib/generators/collection_scaffold/templates/_form.html.haml
319
+ - lib/generators/collection_scaffold/templates/_form.html.slim
320
+ - lib/generators/collection_scaffold/templates/collection.rb
321
+ - lib/generators/collection_scaffold/templates/collection_edit.html.haml
322
+ - lib/generators/collection_scaffold/templates/collection_edit.html.slim
323
+ - lib/generators/collection_scaffold/templates/controller.rb
324
+ - lib/generators/collection_scaffold/templates/create_table_migration.rb
325
+ - lib/generators/collection_scaffold/templates/edit.html.haml
326
+ - lib/generators/collection_scaffold/templates/edit.html.slim
327
+ - lib/generators/collection_scaffold/templates/index.html.haml
328
+ - lib/generators/collection_scaffold/templates/index.html.slim
329
+ - lib/generators/collection_scaffold/templates/model.rb
330
+ - lib/generators/collection_scaffold/templates/new.html.haml
331
+ - lib/generators/collection_scaffold/templates/new.html.slim
332
+ - lib/generators/collection_scaffold/templates/show.html.haml
333
+ - lib/generators/collection_scaffold/templates/show.html.slim
303
334
  - lib/record_collection.rb
304
335
  - lib/record_collection/base.rb
305
336
  - lib/record_collection/engine.rb