dynamic_query 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -4
- data/app/helpers/dynamic_query.erb +39 -0
- data/app/helpers/dynamic_query_helper.rb +9 -0
- data/lib/dynamic_query/version.rb +1 -1
- data/lib/dynamic_query.rb +1 -0
- data/lib/generators/helper_generator.rb +15 -0
- metadata +6 -3
data/README.md
CHANGED
@@ -1,8 +1,45 @@
|
|
1
|
-
|
1
|
+
# dynamic_query
|
2
2
|
|
3
|
-
|
3
|
+
dynamic_query is a dynamic generated query gui for ActiveRecord.
|
4
4
|
|
5
|
-
|
5
|
+
Installation:
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
## Gemfile for Rails 3
|
9
|
+
gem 'dynamic_query'
|
10
|
+
|
11
|
+
## rails generator
|
12
|
+
rails g dynamic_query
|
13
|
+
|
14
|
+
## you may skip this step unless you want to customize your own helper
|
15
|
+
rails g dynamic_query:helper
|
16
|
+
```
|
17
|
+
|
18
|
+
## Basic usage of dynamic_query
|
19
|
+
|
20
|
+
``` ruby
|
21
|
+
## controller of Rails 3
|
22
|
+
dq = dynamic_query(:list, :entry) # list models you wish to be queried. e.g. List => :list, AbcDef => :abc_def
|
23
|
+
@panel = dq.panel(params[:query])
|
24
|
+
@lists = List.includes(:entries).where(dq.statement(params[:query]))
|
25
|
+
|
26
|
+
## render query panel in the view:
|
27
|
+
<%= dynamic_query @panel %>
|
28
|
+
```
|
29
|
+
|
30
|
+
## Advanced usage of dynamic_query
|
31
|
+
|
32
|
+
``` ruby
|
33
|
+
# columns with name 'id' or name ended with '_id' are hided by default
|
34
|
+
# :reveal_keys => true reveals those columns in the query panel
|
35
|
+
dq = dynamic_query(:list, :entry, :reveal_keys => true)
|
36
|
+
|
37
|
+
# a white list or a black list can be defined by following options
|
38
|
+
dq = dynamic_query(:list, :entry, :accept => { :list => [:name], :entry => [:title, :priority] }, :reject => { :entry => [:title] })
|
39
|
+
# only lists.name and entries.priority can be seen on the query panel because the white list gets higher precedence than the black list
|
40
|
+
```
|
41
|
+
|
42
|
+
# Contributing to dynamic_query
|
6
43
|
|
7
44
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
45
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
@@ -12,7 +49,7 @@ Description goes here.
|
|
12
49
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
50
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
51
|
|
15
|
-
|
52
|
+
# Copyright
|
16
53
|
|
17
54
|
Copyright (c) 2012 Wei-Ming Wu. See LICENSE.txt for
|
18
55
|
further details.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<%= form_tag(request.url, opt.merge(:style => 'text-align: center;')) %>
|
2
|
+
<% if panel %>
|
3
|
+
<table style="margin-left: auto; margin-right: auto;">
|
4
|
+
<% panel.select { |k, _| k =~ /^or_\d+$/ }.each_with_index do |(or_key, or_val), idx1| %>
|
5
|
+
<% or_val.each_with_index do |(and_key, and_val), idx2| %>
|
6
|
+
<tr>
|
7
|
+
<td>
|
8
|
+
<%= submit_tag '∇', :name => "query[add_or]", :style => 'color: purple;' if idx1 == 0 && idx2 == 0 %>
|
9
|
+
<%= submit_tag '-', :name => "query[remove_#{or_key}]", :style => 'color: red;' if idx1 != 0 && idx2 == 0 %>
|
10
|
+
</td>
|
11
|
+
<td><%= select_tag "query[#{or_key}][#{and_key}][column]", options_for_select(panel[:columns].keys, and_val[:column]) %></td>
|
12
|
+
<td><%= select_tag "query[#{or_key}][#{and_key}][operator]", options_for_select(DynamicQuery::OPERATOR, and_val[:operator]), :class => 'query_op' %></td>
|
13
|
+
<td>
|
14
|
+
<% if ['IS NULL', 'IS NOT NULL'].include? and_val[:operator] %>
|
15
|
+
<%= text_field_tag "query[#{or_key}][#{and_key}][value1]", '', :style => 'display: none;' %>
|
16
|
+
<% else %>
|
17
|
+
<%= text_field_tag "query[#{or_key}][#{and_key}][value1]", and_val[:value1] %>
|
18
|
+
<% end %>
|
19
|
+
</td>
|
20
|
+
<td>
|
21
|
+
<% if ['BETWEEN', 'NOT BETWEEN'].include? and_val[:operator] %>
|
22
|
+
<%= text_field_tag "query[#{or_key}][#{and_key}][value2]", and_val[:value2] %>
|
23
|
+
<% else %>
|
24
|
+
<%= text_field_tag "query[#{or_key}][#{and_key}][value2]", '', :style => 'display: none;' %>
|
25
|
+
<% end %>
|
26
|
+
</td>
|
27
|
+
<td>
|
28
|
+
<%= submit_tag '+', :name => "query[#{or_key}-and]", :style => 'color: blue;' if idx2 == 0 %>
|
29
|
+
<%= submit_tag 'x', :name => "query[#{or_key}-#{and_key}]", :style => 'color: green;' if idx2 != 0 %>
|
30
|
+
</td>
|
31
|
+
</tr>
|
32
|
+
<% end %>
|
33
|
+
<tr style="height: 10px;"></tr>
|
34
|
+
<% end %>
|
35
|
+
<% end %>
|
36
|
+
</table>
|
37
|
+
<br />
|
38
|
+
<%= submit_tag 'Query', :style => 'width: 150px;'%>
|
39
|
+
</form>
|
data/lib/dynamic_query.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module DynamicQuery
|
4
|
+
|
5
|
+
class HelperGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../../", __FILE__)
|
7
|
+
|
8
|
+
def manifest
|
9
|
+
copy_file "app/helpers/dynamic_query_helper.rb", "app/helpers/dynamic_query_helper.rb"
|
10
|
+
copy_file "app/helpers/dynamic_query.erb", "app/helpers/dynamic_query.erb"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -119,12 +119,15 @@ files:
|
|
119
119
|
- README.md
|
120
120
|
- Rakefile
|
121
121
|
- app/assets/javascripts/dynamic_query.js
|
122
|
+
- app/helpers/dynamic_query.erb
|
123
|
+
- app/helpers/dynamic_query_helper.rb
|
122
124
|
- lib/dynamic_query.rb
|
123
125
|
- lib/dynamic_query/dynamic_query.erb
|
124
126
|
- lib/dynamic_query/helper.rb
|
125
127
|
- lib/dynamic_query/railtie.rb
|
126
128
|
- lib/dynamic_query/version.rb
|
127
129
|
- lib/generators/dynamic_query_generator.rb
|
130
|
+
- lib/generators/helper_generator.rb
|
128
131
|
homepage: http://github.com/wnameless/dynamic_query
|
129
132
|
licenses:
|
130
133
|
- Apache License, Version 2.0
|
@@ -140,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
143
|
version: '0'
|
141
144
|
segments:
|
142
145
|
- 0
|
143
|
-
hash: -
|
146
|
+
hash: -2211947115688522246
|
144
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
148
|
none: false
|
146
149
|
requirements:
|
@@ -152,5 +155,5 @@ rubyforge_project:
|
|
152
155
|
rubygems_version: 1.8.24
|
153
156
|
signing_key:
|
154
157
|
specification_version: 3
|
155
|
-
summary: dynamic_query-0.1.
|
158
|
+
summary: dynamic_query-0.1.1
|
156
159
|
test_files: []
|