Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 3 simple form rails 5 2 #1

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3e1bbc3
support for parent objects
Sep 23, 2013
1e85d85
more wip on parent objects
Sep 24, 2013
ce8e6d9
show_path and edit_path
Sep 26, 2013
178157c
use multiple parameters instead of array for crud_actions and parent_…
Sep 26, 2013
f2df39d
set parent object id on a new object in a new action
Sep 27, 2013
48e022a
localize time and date values in datatables
Sep 28, 2013
485495b
underscore instead of downcase
Oct 1, 2013
92af967
partial for index actions
Oct 2, 2013
189390d
allow all options, like joins etc.
Oct 3, 2013
70708b9
authorize instead of unauthorize
Oct 15, 2013
c06e6ee
implement edit action
Oct 15, 2013
26ac296
show checkboxes for boolean values
Oct 18, 2013
bf2011d
load_resource
Oct 22, 2013
7d7a2d5
support for namespaces
Jan 12, 2014
15aaacf
fix namespacing
Jan 12, 2014
cac3eb4
remove namespace when looking for ActiveRecord model name, don't show…
Jan 13, 2014
be12588
fix sql options for count
Jan 13, 2014
690b185
remove namespace from the model class name
Jan 17, 2014
c601e59
remove offset from count options
Jan 17, 2014
d51ebf6
actions are determined individually
Sep 17, 2014
fd816ea
underscore instead of downcase
Sep 27, 2014
c27246b
fix controller namespaces
Oct 15, 2014
d904299
better translations
Dec 20, 2014
036171e
upgrade to the new datatables version
Dec 27, 2014
134b4aa
support for polymorphic parents
Dec 29, 2014
ddc8266
fix
anikolskiy Jan 6, 2015
7e90a48
simple_form
anikolskiy Aug 1, 2015
ed6cf58
fixed for rails 4.2.3
anikolskiy Aug 15, 2015
dee961b
add global filter
anikolskiy Aug 19, 2015
5d44d74
get values from 'permitted_params' method
anikolskiy Aug 21, 2015
29b79dc
default notifications
anikolskiy Dec 28, 2016
691a351
rails5
anikolskiy Dec 29, 2018
47c8c2c
fix for rails 5.2
anikolskiy Feb 7, 2020
c482d40
don't crash if order param is missing
anikolskiy Feb 14, 2020
0567a13
DEPRECATION WARNING: `Module#parent` has been renamed to `module_pare…
stereosupersonic Mar 29, 2021
fe1a95f
change for miceplace roils 6.1
amin19948 Jul 27, 2021
ca06625
rails 7 upgrade
ahmedm10 Aug 31, 2022
075f389
rails 7 upgrade
ahmedm10 Aug 31, 2022
d990f02
fix
ahmedm10 Sep 6, 2022
230e015
fix
ahmedm10 Sep 6, 2022
73f9048
fix
ahmedm10 Sep 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions lib/datatables_crud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ def current_path
File.dirname(__FILE__)
end

def include_file(filename)
filename = filename.sub(current_path, '')
require File.join(current_path, File.dirname(filename), File.basename(filename, '.rb'))
end

autoload_dirs = %w{datatables helpers support}

autoload_dirs.each do |dir|
Dir.glob(File.join(current_path, 'datatables_crud', dir, '**/*.rb')).sort.each do |file|
include_file file
end
end

# load localizations
Dir.glob(File.join(current_path, 'datatables_crud', 'config', 'locales', '**/*.yml')).each do |locale_file|
I18n.load_path << locale_file
Expand All @@ -27,9 +14,9 @@ def include_file(filename)
module DatatablesCRUD

class Railtie < ::Rails::Railtie
initializer 'datatables_crud.init' do |app|
Dir.glob(File.join(current_path, 'datatables_crud', 'controllers', '**/*.rb')).sort.each do |file|
include_file file
configure do
%w(controllers datatables support).each do |d|
ActiveSupport::Dependencies.autoload_paths << "#{__dir__}/datatables_crud/#{d}"
end
end
end
Expand Down
58 changes: 0 additions & 58 deletions lib/datatables_crud/datatables/active_record_datatable.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ def initialize(view, options = nil)
@view = view

@options = (options || {}).merge(
:limit => params[:iDisplayLength] || 10,
:offset => params[:iDisplayStart] || 0,
:limit => params[:length] || 10,
:offset => params[:start] || 0,
:order => sort_options
)
end

def as_json(options = {})
{
sEcho: params[:sEcho].to_i,
iTotalRecords: count,
iTotalDisplayRecords: count,
aaData: data
draw: params[:draw].to_i,
recordsTotal: total_count,
recordsFiltered: count,
data: data
}
end

Expand All @@ -38,11 +38,11 @@ def columns
end

def page
params[:iDisplayStart].to_i / per_page + 1
params[:start].to_i / per_page + 1
end

def per_page
params[:iDisplayLength].to_i > 0 ? params[:iDisplayLength].to_i : 10
params[:length].to_i > 0 ? params[:length].to_i : 10
end

def sort_columns
Expand All @@ -51,14 +51,9 @@ def sort_columns

def sort_options
{}.tap do |opts|
columns.size.times.each do |i|
iSortColSym = "iSortCol_#{i}".to_sym
break unless params[iSortColSym]

sSortDirSym = "sSortDir_#{i}".to_sym

sort_col = sort_columns[(params[iSortColSym].to_i rescue 0)]
opts[sort_col] = params[sSortDirSym]
(params[:order] || []).each do |k, order|
sort_col = sort_columns[order[:column].to_i]
opts[sort_col] = order[:dir]
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module DatatablesCRUD
class ActiveRecordDatatable < AbstractDatatable
def self.search_columns(columns = nil)
@search_columns = columns.map(&:to_s) unless columns.nil?
@search_columns
end

def self.search_column(column)
@search_columns ||= []
@search_columns << column.to_s unless @search_columns.include?(column.to_s)
end

def initialize(view, options = nil, clazz = nil)
super(view, options)
@clazz = clazz || self.class.name.gsub(/.*\:\:/, '').gsub("Datatable", "").singularize.constantize
end

private

def prepared_clazz
@options[:conditions] ? @clazz.where(@options[:conditions]) : @clazz
end

def search_columns
self.class.search_columns
end

def sort_options
super.map { |k, v| "#{k} #{v == 'desc' ? 'desc' : 'asc'}" }.join(", ")
end

def count_options
(@options || {}).reject { |k, v| %w(limit offset).include? k.to_s }
end

def count
if params[:search].try(:[], :value).present? and search_columns.present?
@count ||= begin
c = prepared_clazz.where(search_columns.map { |v| "#{v} like :search" }.join(' OR '), search: "%#{params[:search][:value]}%")
c = c.where(count_options[:conditions]) if count_options[:conditions].present?
c.count
end
else
total_count
end
end

def total_count
@total_count ||= count_options[:conditions].present? ? prepared_clazz.where(count_options[:conditions]).count : prepared_clazz.count
end

def apply_options
return unless @records
@records = @records.limit(@options[:limit]) if @options.try(:[], :limit)
@records = @records.offset(@options[:offset]) if @options.try(:[], :offset)
@records = @records.order(@options[:order]) if @options.try(:[], :order)
@records
end

def records
if params[:search].try(:[], :value).present? and search_columns.present?
@records ||= prepared_clazz.where(search_columns.map { |v| "#{v} like :search" }.join(' OR '), search: "%#{params[:search][:value]}%")
else
@records ||= prepared_clazz
end

apply_options
end

def column_value(object, column)
if column == 'actions'
object_action_links(object)
else
object.send(column) rescue nil
end
end

def column_data(object, column, value)
if value.is_a?(Time) or value.is_a?(Date)
I18n.l value
elsif !!value == value
"<input type=\"checkbox\" #{'checked' if value} onclick=\"checked = !checked\"/>".html_safe
else
value
end
end

# column_data can be re-defined in the subclass for custom results
end
end
90 changes: 0 additions & 90 deletions lib/datatables_crud/support/datatables_crud.rb

This file was deleted.

Loading