Skip to content

Commit

Permalink
first version for Rails 3.0 with basic functionality working
Browse files Browse the repository at this point in the history
  • Loading branch information
leikind committed Nov 11, 2010
1 parent ed4df3b commit 9000c56
Show file tree
Hide file tree
Showing 38 changed files with 180 additions and 162 deletions.
17 changes: 16 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= WiceGrid

Version:: 0.5.6
Version:: 3.0.0.pre1
Author:: Yuri Leikind
Contributor:: Xavier Defrang
Homepage:: http://leikind.org/pages/wicegrid
Expand All @@ -10,6 +10,21 @@ Email:: "Yuri Leikind" <yuri.leikind at gmail dot com>

== Intro


THIS IS AN EARLY ALPHA VERSION OF THE PLUGIN FOR RAILS 3.0.
BASIC STUFF WORKS, BUT A LOT OF FUNCTIONALITIES ARE BROKEN.
THE DOCUMENTATION BELOW CAN BE OUTDATED.

FOR RAILS 3.0 IT ONLY WORKS AS A GEM.
AT THE SAME TIME NO OFFICIAL IS GEM YET RELEASED, SO IF YOU WANT TO TRY IT, CLONE THE REPOSITORY, PUT IT INTO vendor/wice_grid AND ADD THIS TO YOUR GEMFILE:

gem "wice_grid", '3.0.0.pre1', :path => 'vendor/wice_grid'


OR BUILD THE GEM.

=========================

WiceGrid is a Rails grid plugin.

One of the goals of this plugin was to allow the programmer to define the contents of the cell by himself, just like one does when rendering a collection via a simple table (and this is what differentiates WiceGrid from various scaffolding solutions), but automate implementation of filters, ordering, paginations, CSV export, and so on. Ruby blocks provide an elegant means for this.
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ begin
gem.email = "yuri.leikind@gmail.com"
gem.homepage = "http://github.com/lekind/wice_grid"
gem.authors = ["Yuri Leikind"]
gem.add_development_dependency "will_paginate", ">= 2.3.2"
gem.add_development_dependency "will_paginate", ">= 3.0.pre2"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.6
3.0.0.pre1
6 changes: 0 additions & 6 deletions generators/wice_grid_assets_jquery/templates/USAGE

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions generators/wice_grid_assets_prototype/USAGE

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion init.rb

This file was deleted.

1 change: 0 additions & 1 deletion install.rb

This file was deleted.

32 changes: 32 additions & 0 deletions lib/generators/wice_grid/wice_grid_assets_jquery_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module WiceGrid
module Generators
class WiceGridAssetsJqueryGenerator < Rails::Generators::Base

desc "Copy WiceGrid assets for JQuery based apps"
source_root File.expand_path('../templates', __FILE__)

def active_js_framework
'jquery'
end
def inactive_js_framework
'prototype'
end


def copy_stuff
template 'wice_grid_config.rb', 'config/initializers/wice_grid_config.rb'

copy_file 'wice_grid.yml', 'config/locales/wice_grid.yml'

copy_file 'wice_grid_jquery.js', 'public/javascripts/wice_grid.js'
copy_file 'wice_grid.css', 'public/stylesheets/wice_grid.css'

%w(arrow_down.gif calendar_view_month.png expand.png page_white_find.png table_refresh.png
arrow_up.gif delete.png page_white_excel.png table.png tick_all.png untick_all.png ).each do |f|
copy_file "icons/#{f}", "public/images/icons/grid/#{f}"
end
end

end
end
end
34 changes: 34 additions & 0 deletions lib/generators/wice_grid/wice_grid_assets_prototype_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module WiceGrid
module Generators
class WiceGridAssetsPrototypeGenerator < Rails::Generators::Base

desc "Copy WiceGrid assets for Prototype based apps"
source_root File.expand_path('../templates', __FILE__)


def active_js_framework
'prototype'
end
def inactive_js_framework
'jquery'
end

def copy_stuff
template 'wice_grid_config.rb', 'config/initializers/wice_grid_config.rb'

copy_file 'wice_grid.yml', 'config/locales/wice_grid.yml'

copy_file 'wice_grid_prototype.js', 'public/javascripts/wice_grid.js'
copy_file 'calendarview.js', 'public/javascripts/calendarview.js'
copy_file 'wice_grid.css', 'public/stylesheets/wice_grid.css'
copy_file 'calendarview.css', 'public/stylesheets/calendarview.css'

%w(arrow_down.gif calendar_view_month.png expand.png page_white_find.png table_refresh.png
arrow_up.gif delete.png page_white_excel.png table.png tick_all.png untick_all.png ).each do |f|
copy_file "icons/#{f}", "public/images/icons/grid/#{f}"
end
end

end
end
end
1 change: 0 additions & 1 deletion lib/grid_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class GridRenderer
include ActionView::Helpers::TextHelper
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::JavaScriptHelper
include ::WillPaginate::ViewHelpers

attr_reader :page_parameter_name
attr_reader :after_row_handler
Expand Down
5 changes: 0 additions & 5 deletions lib/helpers/js_calendar_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module Wice
module JsCalendarHelpers

include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::FormTagHelper

# Jquery

def date_calendar_jquery(initial_date, view, opts = {}, html_opts = {}) #:nodoc:
Expand Down
1 change: 0 additions & 1 deletion lib/helpers/wice_grid_view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ def pagination_panel_content(grid, extra_request_parameters, allow_showing_all_r
html, js = pagination_info(grid, allow_showing_all_records)

[will_paginate(grid.resultset,
:renderer => 'Wice::LinkRenderer',
:previous_label => WiceGridNlMessageProvider.get_message(:PREVIOUS_LABEL),
:next_label => WiceGridNlMessageProvider.get_message(:NEXT_LABEL),
:param_name => "#{grid.name}[page]",
Expand Down
16 changes: 0 additions & 16 deletions lib/helpers/will_paginate_link_renderer.rb

This file was deleted.

File renamed without changes.
12 changes: 12 additions & 0 deletions lib/view_columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ def yield_javascript #:nodoc:
end
end


def config
@view.config
end

def controller
@view.controller
end


def render_filter(view) #:nodoc:
# TO DO: this has to be initialized in the initializer
@view = view
params = @grid.filter_params(self)
res = render_filter_internal(params, view)
return (res.is_a?(Array)) ? res : [res, nil]
Expand Down
70 changes: 56 additions & 14 deletions lib/wice_grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'wice_grid_core_ext.rb'
require 'grid_renderer.rb'
require 'table_column_matrix.rb'
require 'helpers/will_paginate_link_renderer.rb'
require 'helpers/wice_grid_view_helpers.rb'
require 'helpers/wice_grid_misc_view_helpers.rb'
require 'helpers/wice_grid_serialized_queries_view_helpers.rb'
Expand All @@ -19,12 +18,66 @@
require 'js_adaptors/prototype_adaptor.rb'
require 'view_columns.rb'

ActionView::Base.class_eval { include Wice::GridViewHelper }
ActionController::Base.send(:include, Wice::Controller)


ActionController::Base.send(:helper_method, :wice_grid_custom_filter_params)

module Wice

module Foo
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def merge_conditions(*conditions)
segments = []

conditions.each do |condition|
unless condition.blank?
sql = sanitize_sql(condition)
segments << sql unless sql.blank?
end
end

"(#{segments.join(') AND (')})" unless segments.empty?
end
end
end

class WiceGridRailtie < Rails::Railtie

initializer "wice_grid_railtie.configure_rails_initialization" do |app|

ActionController::Base.send(:include, Wice::Controller)

ActiveRecord::ConnectionAdapters::Column.send(:include, ::Wice::WiceGridExtentionToActiveRecordColumn)

Wice::GridRenderer.send(:include, ::WillPaginate::ViewHelpers)

::ActionView::Base.class_eval { include Wice::GridViewHelper }

ActiveRecord::Base.send(:include, ::Wice::Foo)

[ActionView::Helpers::AssetTagHelper,
ActionView::Helpers::TagHelper,
ActionView::Helpers::JavaScriptHelper,
ActionView::Helpers::FormTagHelper].each do |m|
JsCalendarHelpers.send(:include, m)
end


# ActiveSupport::Notifications.subscribe do |*args|
# event = ActiveSupport::Notifications::Event.new(*args)
# puts "Got notification: #{event.inspect}"
# end
end

rake_tasks do
load 'tasks/wice_grid_tasks.rake'
end
end

class WiceGrid

attr_reader :klass, :name, :resultset, :custom_order, :query_store_model
Expand All @@ -37,20 +90,11 @@ class WiceGrid
def initialize(klass, controller, opts = {}) #:nodoc:
@controller = controller

# check for will_paginate
# raise WiceGridException.new("Plugin will_paginate not found! wice_grid requires will_paginate.")
unless klass.respond_to?(:paginate)
raise Wice::WiceGridException.new('will_paginate not found, WiceGrid cannot proceed. Please install gem mislav-will_paginate. ' +
'You might need to add github.com as the gem source before you install the gem: ' +
'gem sources -a http://gems.github.com')
end

unless klass.kind_of?(Class) && klass.ancestors.index(ActiveRecord::Base)
raise WiceGridArgumentError.new("ActiveRecord model class (second argument) must be a Class derived from ActiveRecord::Base")
end

Wice.deprecated_call(:after, :with_resultset, opts)

# validate :with_resultset & :with_paginated_resultset
[:with_resultset, :with_paginated_resultset].each do |callback_symbol|
unless [NilClass, Symbol, Proc].index(opts[callback_symbol].class)
Expand Down Expand Up @@ -806,5 +850,3 @@ def generate_conditions(table_alias, opts) #:nodoc:
end

end

ActiveRecord::ConnectionAdapters::Column.send(:include, ::Wice::WiceGridExtentionToActiveRecordColumn)
1 change: 0 additions & 1 deletion uninstall.rb

This file was deleted.

Loading

0 comments on commit 9000c56

Please sign in to comment.