Skip to content

Commit

Permalink
Added yard.
Browse files Browse the repository at this point in the history
Some fixes.
  • Loading branch information
ryanfox1985 committed Jul 14, 2015
1 parent 3c7975a commit 9fa3452
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 65 deletions.
44 changes: 22 additions & 22 deletions CHANGELOG → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
3.4.10
# 3.4.10

bug fixes
better support for :group

3.4.9
# 3.4.9

better support for Asset Pipeline

bugfixes

dropped support for Ruby 1.8

3.4.8
# 3.4.8

a friendlier exception message when a constant is missing in wice_grid_config.rb

bugfixes

3.4.6
# 3.4.6

Better support for Turbolinks

Better support for ActiveRelation #references

variable Wice::Defaults::PAGE_METHOD_NAME

3.4.5
# 3.4.5

Support for ActiveRelation #references

bugfixes

3.4.4
# 3.4.4

bugfixes

3.4.3
# 3.4.3

bugfixes

3.4.2
# 3.4.2

External columns processors

Operators '<','>','<=','>=','=' in the integer column

Bugfixes

3.4.1
# 3.4.1

Support for Bootstrap 3

3.4.0
# 3.4.0

Support for Rails 4

3.3.0
# 3.3.0

The with_paginated_resultset callback receives an ActiveRelation object, not a lambda

Expand All @@ -76,7 +76,7 @@ Bug fixed: extra_request_parameters not propagating to the pagination panel

Documentation improvements

3.2.2
# 3.2.2

improvement of the javascript calendar control: if the FROM field is set to a value after TO, TO is set to the value of FROM.
Vice versa: if the TO field is set to a value before FROM, FROM is set to the value of TO
Expand All @@ -93,7 +93,7 @@ helpers filter_and_order_state_as_hash(grid) and filter_state_as_hash(grid)

the with_paginated_resultset callback receives an ActiveRelation object, not a lambda

3.2.1
# 3.2.1

action_column can now also take a block. If the block returns a falsy value, no checkbox will be rendered.

Expand All @@ -105,7 +105,7 @@ The default filter for numeric columns has been replaced by a simple one field f
New column parameter :filter_type allows to load custom alternative filters.
The old numeric range filter can still be used by specifying filter_type: :range. See lib/columns/column_processor_index.rb for the list of available filters.

3.2.0
# 3.2.0

Fixes:
https://github.com/leikind/wice_grid/issues/83
Expand All @@ -122,24 +122,24 @@ New column parameter :filter_type allows to load custom alternative filters. The
See lib/columns/column_processor_index.rb</tt> for the list of available filters.


3.0.4
# 3.0.4

bugfixes

3.0.3
# 3.0.3

bugxixes

3.0.2
# 3.0.2

bugxixes

3.0.1
# 3.0.1

Fixed the "Cannot modify SafeBuffer in place" problem and thus Rails 3.0.8 and 3.0.9
Fixed the "Cannot modify SafeBuffer in place" problem and thus Rails # 3.0.8 and # 3.0.9
Support for ActiveRecord::Relation

3.0.0
# 3.0.0

Rails 3 support

Expand Down Expand Up @@ -175,7 +175,7 @@ the selected records.
using merge_conditions to merge conditions :)

WiceGrid is now compatible with the new Rails XSS behavior which
will be the default in Rails 3.0 and can be used in Rails 2.3.5
will be the default in Rails # 3.0 and can be used in Rails 2.3.5
using the rails_xss plugin.
Read http://github.com/nzkoz/rails_xss for more

Expand Down Expand Up @@ -551,4 +551,4 @@ In this case +attribute_name+ will be used as the method name to send to the Act
* New parameter +grid+ parameter: <tt>:extra_request_parameters</tt>.
(Read http://redmine.wice.eu/api/wice_grid/classes/Wice/GridViewHelper.html#M000002)

=== 0
=== 0
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
gemspec
source 'https://rubygems.org'

gem 'yard'
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Version](http://img.shields.io/gem/v/wice_grid.svg)](https://rubygems.org/gems/wice_grid)
[![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)

# WiceGrid

Expand Down Expand Up @@ -1342,4 +1343,10 @@ Icons used by the plugin are courtesy of Mark James, the creator of [the SILK ic
## Bug reports

The author of the plugins welcomes any contribution.
Please follow [these guidelines]{https://github.com/leikind/wice_grid/wiki/How-to-submit-a-bug-report-or-a-question} when submitting a bug report.
Please follow [these guidelines](https://github.com/leikind/wice_grid/wiki/How-to-submit-a-bug-report-or-a-question) when submitting a bug report.

## Changelog
{file:CHANGELOG.md}

## License
{file:MIT-LICENSE}
20 changes: 10 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require 'rdoc/task'
require 'yard'
require 'yard/rake/yardoc_task'

task default: :rdoc
task default: :doc

desc 'Generate documentation for the wice_grid plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'WiceGrid'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('SAVED_QUERIES_HOWTO.rdoc')
rdoc.rdoc_files.include('CHANGELOG')
rdoc.rdoc_files.include('lib/**/*.rb')
YARD::Rake::YardocTask.new(:doc) do |t|
OTHER_PATHS = %w()

t.files = ['lib/**/*.rb', OTHER_PATHS]
t.options = %w(--main=README.md --file CHANGELOG.md,SAVED_QUERIES_HOWTO.md,MIT-LICENSE)
t.stats_options = ['--list-undoc']
end
65 changes: 34 additions & 31 deletions SAVED_QUERIES_HOWTO.rdoc → SAVED_QUERIES_HOWTO.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
== Saving Queries How-To
## Saving Queries How-To

WiceGrid allows to save the state of filters as a custom query and later restore it from the list of saved queries.

=== Step 1: Create the database table to store queries
### Step 1: Create the database table to store queries

To get started create the database table to store queries. Run the following generator:

rails g wice_grid:add_migration_for_serialized_queries

```
rails g wice_grid:add_migration_for_serialized_queries
```
This add a migration file with the definition of the table. Run the migrate task:

```
bundle 'rake db:migrate'

=== Step 2: Create the controller to handle AJAX queries.
```
### Step 2: Create the controller to handle AJAX queries.

Creation and deletion of queries is implemented as AJAX calls, and a controller is needed to handle these calls. Create an empty controller
with any name and add method +save_wice_grid_queries+ to it:

```
class QueriesController < ApplicationController
save_wice_grid_queries
end

```
This is it. The controller now has the required action methods.

=== Step 3: Add routes

If the name of the query controller is QueriesController, add the following to <tt>routes.rb</tt>:
### Step 3: Add routes

If the name of the query controller is QueriesController, add the following to `routes.rb`:
```
Wice::define_routes(self, 'queries')

=== Step 4: Add the saved query panel to the view.
```
### Step 4: Add the saved query panel to the view.

To show the list of saved queries and the form to create new queries in a view, add the following helper to the view:

```
<%= saved_queries_panel(@grid_object) %>

```
Voila!

Just like WiceGrid itself, the query panel contains no forms and is thus form-friendly.

*Important*: Saved queries of all grids in the application are stored in one table and differentiated by the name of the grid, thus, for all forms
with saved queries it is important to define different names! (use parameter <tt>:name</tt> in +initialize_grid+)
with saved queries it is important to define different names! (use parameter `:name` in +initialize_grid+)

It is also possible to initialize a grid with an initial saved query providing the id of the query record or the ActiveRecord
itself to parameter <tt>saved_query</tt>:

itself to parameter `saved_query`:
```
@products_grid = initialize_grid(Product,
:name => 'prod_grid',
:saved_query => SavedQuery.find_by_id_and_grid_name(12, 'prod_grid') )
```


== Adding Application Specific Logic to Saving/Restoring Queries
## Adding Application Specific Logic to Saving/Restoring Queries

WiceGrid allows to add application specific logic to saving and restoring queries by substituting the default ActiveRecord model provided by WiceGrid with a custom model.

Copy <tt>lib/wice_grid_serialized_query.rb</tt> from the gem to <tt>app/models/</tt>, rename the file and the class to your liking.
Copy `lib/wice_grid_serialized_query.rb` from the gem to `app/models/`, rename the file and the class to your liking.

After renaming the model to SavedQuery it looks like this:

```
class SavedQuery < ActiveRecord::Base #:nodoc:
serialize :query
Expand All @@ -71,11 +71,12 @@ After renaming the model to SavedQuery it looks like this:
self.find(:all, :conditions => conditions)
end
end
```

It is required that the model provides class method +list+ which accepts two parameters: the name of the WiceGrid instance and the controller
object, and returns a list of queries. The controller object is needed to provide the application context. For instance, if it is needed to
store queries for each user, we could add +user_id+ to the table and modify the code so it looks like the following:

```
class SavedQuery < ActiveRecord::Base
serialize :query
Expand All @@ -94,17 +95,19 @@ store queries for each user, we could add +user_id+ to the table and modify the
self.find(:all, :conditions => conditions)
end
end
```

The following step is to make sure that a new query is saved with the correct +user_id+. To do so, change the helper
<tt>saved_queries_panel(@grid_object)</tt> to the following:

`saved_queries_panel(@grid_object)` to the following:

```
<%= saved_queries_panel(@identities_grid, :extra_parameters => {:user_id => @current_user.id}) %>

```
For every key in has :extra_parameters there must exist a field in the model - this hash will be used as a parameter to
<tt>attributes=</tt> method of the query object.
`attributes=` method of the query object.

Finally, let WiceGrid know which model to use for saving queries by changing constant +QUERY_STORE_MODEL+
in <tt>lib/wice_grid_config.rb</tt> to the name of the custom model (as a string), in the above example this would look like the following:

in `lib/wice_grid_config.rb` to the name of the custom model (as a string), in the above example this would look like the following:
```
QUERY_STORE_MODEL = 'SavedQuery'
```

0 comments on commit 9fa3452

Please sign in to comment.