record_collection 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +217 -0
- data/Rakefile +16 -0
- data/app/assets/images/record_collection/.keep +0 -0
- data/app/assets/javascripts/record_collection/application.js.coffee +1 -0
- data/app/assets/javascripts/record_collection/multi_select.js.coffee +66 -0
- data/app/assets/javascripts/record_collection/optionals.js.coffee +101 -0
- data/app/assets/stylesheets/record_collection/application.css +15 -0
- data/app/assets/stylesheets/record_collection/multi_select.css.sass +20 -0
- data/app/assets/stylesheets/record_collection/optionals.css.sass +48 -0
- data/app/controllers/record_collection/application_controller.rb +4 -0
- data/app/helpers/record_collection/application_helper.rb +4 -0
- data/app/views/layouts/record_collection/application.html.erb +14 -0
- data/lib/record_collection.rb +12 -0
- data/lib/record_collection/base.rb +98 -0
- data/lib/record_collection/engine.rb +5 -0
- data/lib/record_collection/name.rb +7 -0
- data/lib/record_collection/rails/form_options_helper.rb +48 -0
- data/lib/record_collection/rails/routes.rb +21 -0
- data/lib/record_collection/version.rb +3 -0
- data/record_collection.gemspec +43 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js.coffee +10 -0
- data/spec/dummy/app/assets/stylesheets/application.css.sass +4 -0
- data/spec/dummy/app/assets/stylesheets/components/_forms.css.sass +0 -0
- data/spec/dummy/app/assets/stylesheets/components/_structure.css.sass +0 -0
- data/spec/dummy/app/assets/stylesheets/scaffolds.scss +69 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/employees_controller.rb +75 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/employee.rb +2 -0
- data/spec/dummy/app/models/employee/collection.rb +6 -0
- data/spec/dummy/app/models/project.rb +2 -0
- data/spec/dummy/app/views/application/_form_errors.html.slim +8 -0
- data/spec/dummy/app/views/employees/_form.html.erb +25 -0
- data/spec/dummy/app/views/employees/batch_actions.html.slim +13 -0
- data/spec/dummy/app/views/employees/edit.html.erb +6 -0
- data/spec/dummy/app/views/employees/index.html.slim +25 -0
- data/spec/dummy/app/views/employees/new.html.erb +5 -0
- data/spec/dummy/app/views/employees/show.html.erb +14 -0
- data/spec/dummy/app/views/layouts/application.html.slim +10 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/locales/models.en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20150203124634_create_employees.rb +10 -0
- data/spec/dummy/db/migrate/20150204103712_add_vegan_to_employees.rb +5 -0
- data/spec/dummy/db/migrate/20150204103925_add_admin_to_employees.rb +5 -0
- data/spec/dummy/db/migrate/20150204125014_create_projects.rb +11 -0
- data/spec/dummy/db/schema.rb +33 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/features/multi_select_spec.rb +23 -0
- data/spec/fixtures/collections.rb +0 -0
- data/spec/record_selection/base_spec.rb +113 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/validations_spec.rb +19 -0
- metadata +482 -0
File without changes
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class EmployeesController < ApplicationController
|
2
|
+
before_action :set_employee, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /employees
|
5
|
+
def index
|
6
|
+
@employees = Employee.all
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /employees/1
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /employees/new
|
14
|
+
def new
|
15
|
+
@employee = Employee.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /employees/1/edit
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /employees
|
23
|
+
def create
|
24
|
+
@employee = Employee.new(employee_params)
|
25
|
+
|
26
|
+
if @employee.save
|
27
|
+
redirect_to @employee, notice: 'Employee was successfully created.'
|
28
|
+
else
|
29
|
+
render :new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# PATCH/PUT /employees/1
|
34
|
+
def update
|
35
|
+
if @employee.update(employee_params)
|
36
|
+
redirect_to @employee, notice: 'Employee was successfully updated.'
|
37
|
+
else
|
38
|
+
render :edit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# DELETE /employees/1
|
43
|
+
def destroy
|
44
|
+
@employee.destroy
|
45
|
+
redirect_to employees_url, notice: 'Employee was successfully destroyed.'
|
46
|
+
end
|
47
|
+
|
48
|
+
def batch_actions
|
49
|
+
@employees = Employee.find(Array.wrap(params[:ids]))
|
50
|
+
@collection = Employee::Collection.new(@employees)
|
51
|
+
redirect_to employees_path, alert: 'No employees selected' if @collection.empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
def process_batch
|
55
|
+
@employees = Employee.find(Array.wrap(params[:ids]))
|
56
|
+
@collection = Employee::Collection.new(@employees, params[:collection])
|
57
|
+
if @collection.save
|
58
|
+
redirect_to employees_path, notice: 'Collection is updated'
|
59
|
+
else
|
60
|
+
render 'batch_actions'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# Use callbacks to share common setup or constraints between actions.
|
67
|
+
def set_employee
|
68
|
+
@employee = Employee.find(params[:id])
|
69
|
+
end
|
70
|
+
|
71
|
+
# Only allow a trusted parameter "white list" through.
|
72
|
+
def employee_params
|
73
|
+
params.require(:employee).permit(:name, :section)
|
74
|
+
end
|
75
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%= form_for(@employee) do |f| %>
|
2
|
+
<% if @employee.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@employee.errors.count, "error") %> prohibited this employee from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @employee.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :name %><br>
|
16
|
+
<%= f.text_field :name %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :section %><br>
|
20
|
+
<%= f.text_field :section %>
|
21
|
+
</div>
|
22
|
+
<div class="actions">
|
23
|
+
<%= f.submit %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
h1 Edit multiple employees
|
2
|
+
= form_for @collection, url: [:process_batch, @collection.record_class] do |f|
|
3
|
+
= render 'form_errors', target: @collection
|
4
|
+
.form-inputs= f.optional_text_field :section
|
5
|
+
.form-inputs= f.optional_boolean :admin
|
6
|
+
.form-inputs= f.optional_boolean :vegan
|
7
|
+
/.form-inputs= f.check_box :admin
|
8
|
+
/.form-inputs= f.check_box :vegan
|
9
|
+
.form-actions= f.submit
|
10
|
+
.page-actions
|
11
|
+
= link_to 'Back', employees_path
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
h1 Listing Employees
|
3
|
+
|
4
|
+
table.with-selection
|
5
|
+
thead
|
6
|
+
tr
|
7
|
+
th Name
|
8
|
+
th Section
|
9
|
+
th Admin?
|
10
|
+
th Vegan?
|
11
|
+
th colspan="3"
|
12
|
+
tbody
|
13
|
+
- @employees.each do |employee|
|
14
|
+
tr data-record=employee.attributes.to_json
|
15
|
+
td= employee.name
|
16
|
+
td= employee.section
|
17
|
+
td.admin= employee.admin ? 'yes' : 'no'
|
18
|
+
td.vegan= employee.vegan ? 'yes' : 'no'
|
19
|
+
td= link_to 'Show', employee
|
20
|
+
td= link_to 'Edit', edit_employee_path(employee)
|
21
|
+
td= link_to 'Destroy', employee, method: :delete, data: {confirm: 'Are you sure?' }
|
22
|
+
br
|
23
|
+
button.actions-button onclick="window.location = Routes.batch_actions_employees_path({ids: MultiSelect.selected_ids()})" Actions
|
24
|
+
|
25
|
+
= link_to 'New Employee', new_employee_path
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Name:</strong>
|
5
|
+
<%= @employee.name %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Section:</strong>
|
10
|
+
<%= @employee.section %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<%= link_to 'Edit', edit_employee_path(@employee) %> |
|
14
|
+
<%= link_to 'Back', employees_path %>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups(development: ['development', 'test']))
|
6
|
+
require "record_collection"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
|
22
|
+
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
+
config.active_record.raise_in_transactional_callbacks = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
#
|
7
|
+
default: &default
|
8
|
+
adapter: sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: db/development.sqlite3
|
15
|
+
|
16
|
+
# Warning: The database defined as "test" will be erased and
|
17
|
+
# re-generated from your development database when you run "rake".
|
18
|
+
# Do not set this db to the same as development or production.
|
19
|
+
test:
|
20
|
+
<<: *default
|
21
|
+
database: db/test.sqlite3
|
22
|
+
|
23
|
+
production:
|
24
|
+
<<: *default
|
25
|
+
database: db/production.sqlite3
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raise an error on page load if there are pending migrations.
|
23
|
+
config.active_record.migration_error = :page_load
|
24
|
+
|
25
|
+
# Debug mode disables concatenation and preprocessing of assets.
|
26
|
+
# This option may cause significant delays in view rendering with a large
|
27
|
+
# number of complex assets.
|
28
|
+
config.assets.debug = true
|
29
|
+
|
30
|
+
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
31
|
+
# yet still be able to expire them through the digest params.
|
32
|
+
config.assets.digest = true
|
33
|
+
|
34
|
+
# Adds additional error checking when serving assets at runtime.
|
35
|
+
# Checks for improperly declared sprockets dependencies.
|
36
|
+
# Raises helpful error messages.
|
37
|
+
config.assets.raise_runtime_errors = true
|
38
|
+
|
39
|
+
# Raises error for missing translations
|
40
|
+
# config.action_view.raise_on_missing_translations = true
|
41
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# Code is not reloaded between requests.
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Eager load code on boot. This eager loads most of Rails and
|
8
|
+
# your application in memory, allowing both threaded web servers
|
9
|
+
# and those relying on copy on write to perform better.
|
10
|
+
# Rake tasks automatically ignore this option for performance.
|
11
|
+
config.eager_load = true
|
12
|
+
|
13
|
+
# Full error reports are disabled and caching is turned on.
|
14
|
+
config.consider_all_requests_local = false
|
15
|
+
config.action_controller.perform_caching = true
|
16
|
+
|
17
|
+
# Enable Rack::Cache to put a simple HTTP cache in front of your application
|
18
|
+
# Add `rack-cache` to your Gemfile before enabling this.
|
19
|
+
# For large-scale production use, consider using a caching reverse proxy like
|
20
|
+
# NGINX, varnish or squid.
|
21
|
+
# config.action_dispatch.rack_cache = true
|
22
|
+
|
23
|
+
# Disable serving static files from the `/public` folder by default since
|
24
|
+
# Apache or NGINX already handles this.
|
25
|
+
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
26
|
+
|
27
|
+
# Compress JavaScripts and CSS.
|
28
|
+
config.assets.js_compressor = :uglifier
|
29
|
+
# config.assets.css_compressor = :sass
|
30
|
+
|
31
|
+
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
32
|
+
config.assets.compile = false
|
33
|
+
|
34
|
+
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
35
|
+
# yet still be able to expire them through the digest params.
|
36
|
+
config.assets.digest = true
|
37
|
+
|
38
|
+
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
39
|
+
|
40
|
+
# Specifies the header that your server uses for sending files.
|
41
|
+
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
42
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
43
|
+
|
44
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
45
|
+
# config.force_ssl = true
|
46
|
+
|
47
|
+
# Use the lowest log level to ensure availability of diagnostic information
|
48
|
+
# when problems arise.
|
49
|
+
config.log_level = :debug
|
50
|
+
|
51
|
+
# Prepend all log lines with the following tags.
|
52
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
53
|
+
|
54
|
+
# Use a different logger for distributed setups.
|
55
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
56
|
+
|
57
|
+
# Use a different cache store in production.
|
58
|
+
# config.cache_store = :mem_cache_store
|
59
|
+
|
60
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
61
|
+
# config.action_controller.asset_host = 'http://assets.example.com'
|
62
|
+
|
63
|
+
# Ignore bad email addresses and do not raise email delivery errors.
|
64
|
+
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
65
|
+
# config.action_mailer.raise_delivery_errors = false
|
66
|
+
|
67
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
68
|
+
# the I18n.default_locale when a translation cannot be found).
|
69
|
+
config.i18n.fallbacks = true
|
70
|
+
|
71
|
+
# Send deprecation notices to registered listeners.
|
72
|
+
config.active_support.deprecation = :notify
|
73
|
+
|
74
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
75
|
+
config.log_formatter = ::Logger::Formatter.new
|
76
|
+
|
77
|
+
# Do not dump schema after migrations.
|
78
|
+
config.active_record.dump_schema_after_migration = false
|
79
|
+
end
|