skozlov-netzke-basepack 0.1.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.1.1
2
+ Cleaner exception handling while loading data to grid
3
+ Column resize & move functionality enabled by default
4
+ Column filters added
5
+
1
6
  v0.1.0.1 Meta work: replacing underscore with dash in the name
2
7
 
3
8
  v0.1.0 Initial release
data/Manifest CHANGED
@@ -6,6 +6,7 @@ generators/netzke_basepack/USAGE
6
6
  init.rb
7
7
  install.rb
8
8
  javascripts/basepack.js
9
+ javascripts/filters.js
9
10
  lib/app/models/netzke_grid_column.rb
10
11
  lib/netzke/accordion.rb
11
12
  lib/netzke/ar_ext.rb
@@ -33,9 +33,20 @@ Ext.netzke.editors = {
33
33
  })
34
34
  },
35
35
 
36
+ // TODO: it's simply a text field for now
36
37
  datetime: function(c, config){
37
38
  return new Ext.form.TextField({
38
39
  selectOnFocus:true
39
40
  })
40
41
  }
42
+ };
43
+
44
+ // Mapping of showsAs field to grid filters
45
+ Ext.netzke.filterMap = {
46
+ number_field:'Numeric',
47
+ text_field:'String',
48
+ datetime:'String',
49
+ checkbox:'Boolean',
50
+ combo_box:'String',
51
+ date:'Date'
41
52
  }
@@ -0,0 +1,7 @@
1
+ Ext.menu.RangeMenu.prototype.icons = {
2
+ gt: '/extjs/examples/grid-filtering/img/greater_then.png',
3
+ lt: '/extjs/examples/grid-filtering/img/less_then.png',
4
+ eq: '/extjs/examples/grid-filtering/img/equals.png'
5
+ };
6
+
7
+ Ext.grid.filter.StringFilter.prototype.icon = '/extjs/examples/grid-filtering/img/find.png';
@@ -11,4 +11,18 @@ require 'netzke/ar_ext'
11
11
  ActiveSupport::Dependencies.load_once_paths.delete(path)
12
12
  end
13
13
 
14
- Netzke::Base.config[:javascripts] << "#{File.dirname(__FILE__)}/../javascripts/basepack.js"
14
+ # Include the javascript
15
+ Netzke::Base.config[:javascripts] << "#{File.dirname(__FILE__)}/../javascripts/basepack.js"
16
+
17
+ # TODO: implement configurable loading of JS, to spare the traffic at the initial loading
18
+ extjs_dir = "#{File.dirname(RAILS_ROOT)}/netzke_tutorial/public/extjs"
19
+ Netzke::Base.config[:javascripts] << "#{extjs_dir}/examples/grid-filtering/menu/EditableItem.js"
20
+ Netzke::Base.config[:javascripts] << "#{extjs_dir}/examples/grid-filtering/menu/RangeMenu.js"
21
+ Netzke::Base.config[:javascripts] << "#{extjs_dir}/examples/grid-filtering/grid/GridFilters.js"
22
+ %w{Boolean Date List Numeric String}.unshift("").each do |f|
23
+ Netzke::Base.config[:javascripts] << "#{extjs_dir}/examples/grid-filtering/grid/filter/#{f}Filter.js"
24
+ end
25
+ Netzke::Base.config[:javascripts] << "#{File.dirname(__FILE__)}/../javascripts/filters.js"
26
+
27
+ # Make this plugin reloadable for easier development
28
+ ActiveSupport::Dependencies.load_once_paths.delete(File.join(File.dirname(__FILE__)))
data/lib/netzke/grid.rb CHANGED
@@ -18,8 +18,10 @@ module Netzke
18
18
 
19
19
  def initial_config
20
20
  {
21
- :ext_config => {:properties => true},
22
- :layout_manager => "NetzkeLayout"
21
+ :ext_config => {:properties => true, :column_filters => true},
22
+ :layout_manager => "NetzkeLayout",
23
+ :column_resize => true,
24
+ :column_move => true
23
25
  }
24
26
  end
25
27
 
@@ -54,20 +56,6 @@ module Netzke
54
56
  w.interface_load_source(params)
55
57
  end
56
58
 
57
- # we pass column config at the time of instantiating the JS class
58
- def js_config
59
- res = super
60
- res.merge!(:columns => get_columns || config[:columns]) # first try to get columns from DB, then from config
61
- res.merge!(:data_class_name => config[:data_class_name])
62
- res
63
- end
64
-
65
- def js_listeners
66
- super.merge({
67
- :columnresize => (config[:column_resize] ? {:fn => "this.onColumnResize".l, :scope => this} : nil),
68
- :columnmove => (config[:column_move] ? {:fn => "this.onColumnMove".l, :scope => this} : nil)
69
- })
70
- end
71
59
 
72
60
 
73
61
  protected
@@ -95,9 +95,9 @@ module Netzke::GridInterface
95
95
 
96
96
  # get records
97
97
  def get_records(params)
98
- conditions = normalize_params(params)
98
+ search_params = normalize_params(params)
99
99
  raise ArgumentError, "No data_class_name specified for widget '#{config[:name]}'" if !config[:data_class_name]
100
- records = config[:data_class_name].constantize.all(conditions)
100
+ records = config[:data_class_name].constantize.all(search_params.clone) # clone needed as searchlogic removes :conditions key from the hash
101
101
  output_array = []
102
102
  records.each do |r|
103
103
  r_array = []
@@ -111,14 +111,39 @@ module Netzke::GridInterface
111
111
  class << output_array
112
112
  attr :total_records, true
113
113
  end
114
- total_records_count = config[:data_class_name].constantize.count(conditions)
114
+ total_records_count = config[:data_class_name].constantize.count(search_params)
115
115
  output_array.total_records = total_records_count
116
116
 
117
117
  output_array
118
118
  end
119
119
 
120
+ def convert_filters(column_filter)
121
+ res = {}
122
+ column_filter.each_pair do |k,v|
123
+ field = v["field"]
124
+ case v["data"]["type"]
125
+ when "string"
126
+ field << "_contains"
127
+ when "numeric"
128
+ field << "_#{v["data"]["comparison"]}"
129
+ end
130
+ value = v["data"]["value"]
131
+ res.merge!({field => value})
132
+ end
133
+ res
134
+ end
135
+
120
136
  # make params understandable to searchlogic
121
137
  def normalize_params(params)
138
+ # filters
139
+ conditions = params[:filter] && convert_filters(params[:filter])
140
+
141
+ normalized_conditions = {}
142
+ conditions && conditions.each_pair do |k, v|
143
+ assoc, method = k.split('__')
144
+ normalized_conditions.merge!(method.nil? ? {assoc => v} : {assoc => {method => v}})
145
+ end
146
+
122
147
  # sorting
123
148
  order_by = if params[:sort]
124
149
  assoc, method = params[:sort].split('__')
@@ -126,6 +151,6 @@ module Netzke::GridInterface
126
151
  end
127
152
 
128
153
  page = params[:start].to_i/params[:limit].to_i + 1 if params[:limit]
129
- {:per_page => params[:limit], :page => page, :order_by => order_by, :order_as => params[:dir]}
154
+ {:per_page => params[:limit], :page => page, :order_by => order_by, :order_as => params[:dir], :conditions => normalized_conditions}
130
155
  end
131
156
  end
@@ -23,6 +23,7 @@ module Netzke::GridJsBuilder
23
23
  :track_mouse_over => true,
24
24
  # :bbar => "config.actions".l,
25
25
  :bbar => js_bbar,
26
+ :plugins => "plugins".l,
26
27
 
27
28
  #custom configs
28
29
  :auto_load_data => true
@@ -31,20 +32,22 @@ module Netzke::GridJsBuilder
31
32
 
32
33
  def js_before_constructor
33
34
  <<-JS
35
+ var plugins = [];
36
+ if (!config.columns) this.feedback('No columns defined for grid '+config.id);
34
37
  this.recordConfig = [];
35
-
36
- if (!config.columns) {
37
- this.feedback('No columns defined for grid '+config.id);
38
- }
39
-
40
38
  Ext.each(config.columns, function(column){this.recordConfig.push({name:column.name})}, this);
41
39
  this.Row = Ext.data.Record.create(this.recordConfig);
40
+
42
41
  var ds = new Ext.data.Store({
43
42
  proxy: this.proxy = new Ext.data.HttpProxy({url:config.interface.getData}),
44
43
  reader: new Ext.data.ArrayReader({root: "data", totalProperty: "total", successProperty: "succes", id:0}, this.Row),
45
- remoteSort: true
44
+ remoteSort: true,
45
+ listeners:{'loadexception':{
46
+ fn:this.loadExceptionHandler,
47
+ scope:this
48
+ }}
46
49
  });
47
-
50
+
48
51
  this.cmConfig = [];
49
52
  Ext.each(config.columns, function(c){
50
53
  var editor = c.readOnly ? null : Ext.netzke.editors[c.showsAs](c, config);
@@ -62,41 +65,62 @@ module Netzke::GridJsBuilder
62
65
  var cm = new Ext.grid.ColumnModel(this.cmConfig);
63
66
 
64
67
  this.addEvents("refresh");
65
-
68
+
69
+ // Filters
70
+ if (config.columnFilters) {
71
+ var filters = []
72
+ Ext.each(config.columns, function(c){
73
+ filters.push({type:Ext.netzke.filterMap[c.showsAs], dataIndex:c.name})
74
+ })
75
+ var gridFilters = new Ext.grid.GridFilters({filters:filters});
76
+ plugins.push(gridFilters);
77
+ }
78
+
66
79
  JS
67
80
  end
68
81
 
82
+ def js_config
83
+ res = super
84
+ # we pass column config at the time of instantiating the JS class
85
+ res.merge!(:columns => get_columns || config[:columns]) # first try to get columns from DB, then from config
86
+ res.merge!(:data_class_name => config[:data_class_name])
87
+ res
88
+ end
89
+
90
+ def js_listeners
91
+ super.merge({
92
+ :columnresize => (config[:column_resize] ? {:fn => "this.onColumnResize".l, :scope => this} : nil),
93
+ :columnmove => (config[:column_move] ? {:fn => "this.onColumnMove".l, :scope => this} : nil)
94
+ })
95
+ end
96
+
97
+
69
98
  def js_extend_properties
70
99
  {
71
100
  :on_widget_load => <<-JS.l,
72
101
  function(){
102
+ // auto-load
73
103
  if (this.initialConfig.autoLoadData) {
74
- this.loadWithFeedback({start:0, limit: this.initialConfig.rowsPerPage})
104
+ // if we have a paging toolbar, load the first page, otherwise
105
+ if (this.getBottomToolbar().changePage) this.getBottomToolbar().changePage(0); else this.store.load();
75
106
  }
76
107
  }
77
108
  JS
78
-
79
- :load_with_feedback => <<-JS.l,
80
- function(params){
81
- if (!params) params = {};
82
- var exceptionHandler = function(proxy, options, response, error){
83
- if (response.status == 200 && (responseObject = Ext.decode(response.responseText)) && responseObject.flash){
84
- this.feedback(responseObject.flash)
85
- } else {
86
- if (error){
87
- this.feedback(error.message);
88
- } else {
89
- this.feedback(response.statusText)
90
- }
91
- }
92
- }.createDelegate(this);
93
- this.store.proxy.on('loadexception', exceptionHandler);
94
- this.store.load({callback:function(r, options, success){
95
- this.store.proxy.un('loadexception', exceptionHandler);
96
- }, params: params, scope:this});
97
- }
98
- JS
99
109
 
110
+ :load_exception_handler => <<-JS.l,
111
+ function(proxy, options, response, error){
112
+ if (response.status == 200 && (responseObject = Ext.decode(response.responseText)) && responseObject.flash){
113
+ this.feedback(responseObject.flash)
114
+ } else {
115
+ if (error){
116
+ this.feedback(error.message);
117
+ } else {
118
+ this.feedback(response.statusText)
119
+ }
120
+ }
121
+ }
122
+ JS
123
+
100
124
  :add => <<-JS.l,
101
125
  function(){
102
126
  var rowConfig = {};
@@ -153,7 +177,8 @@ module Netzke::GridJsBuilder
153
177
  params: {records: Ext.encode(records)},
154
178
  success:function(r){
155
179
  var m = Ext.decode(r.responseText);
156
- this.loadWithFeedback();
180
+ this.store.reload();
181
+ // this.loadWithFeedback();
157
182
  this.feedback(m.flash);
158
183
  },
159
184
  scope:this
@@ -195,7 +220,8 @@ module Netzke::GridJsBuilder
195
220
  success:function(response){
196
221
  var m = Ext.decode(response.responseText);
197
222
  if (m.success) {
198
- this.loadWithFeedback();
223
+ this.store.reload();
224
+ // this.loadWithFeedback();
199
225
  this.store.commitChanges();
200
226
  this.feedback(m.flash);
201
227
  } else {
@@ -215,7 +241,8 @@ module Netzke::GridJsBuilder
215
241
  :refresh_click => <<-JS.l,
216
242
  function() {
217
243
  // console.info(this);
218
- if (this.fireEvent('refresh', this) !== false) this.loadWithFeedback();
244
+ // if (this.fireEvent('refresh', this) !== false) this.loadWithFeedback();
245
+ if (this.fireEvent('refresh', this) !== false) this.store.reload();
219
246
  }
220
247
  JS
221
248
 
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{netzke-basepack}
5
- s.version = "0.1.0.1"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sergei Kozlov"]
9
- s.date = %q{2008-12-27}
9
+ s.date = %q{2008-12-28}
10
10
  s.description = %q{Base Netzke widgets - grid, form, tree, and more}
11
11
  s.email = %q{sergei@writelesscode.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "lib/app/models/netzke_grid_column.rb", "lib/netzke/accordion.rb", "lib/netzke/ar_ext.rb", "lib/netzke/column.rb", "lib/netzke/container.rb", "lib/netzke/grid.rb", "lib/netzke/grid_interface.rb", "lib/netzke/grid_js_builder.rb", "lib/netzke/preference_grid.rb", "lib/netzke/properties_tool.rb", "lib/netzke/property_grid.rb", "lib/netzke-basepack.rb", "LICENSE", "README.mdown", "tasks/netzke_basepack_tasks.rake"]
13
- s.files = ["CHANGELOG", "generators/netzke_basepack/netzke_basepack_generator.rb", "generators/netzke_basepack/netzke_grid_generator.rb", "generators/netzke_basepack/templates/create_netzke_grid_columns.rb", "generators/netzke_basepack/USAGE", "init.rb", "install.rb", "javascripts/basepack.js", "lib/app/models/netzke_grid_column.rb", "lib/netzke/accordion.rb", "lib/netzke/ar_ext.rb", "lib/netzke/column.rb", "lib/netzke/container.rb", "lib/netzke/grid.rb", "lib/netzke/grid_interface.rb", "lib/netzke/grid_js_builder.rb", "lib/netzke/preference_grid.rb", "lib/netzke/properties_tool.rb", "lib/netzke/property_grid.rb", "lib/netzke-basepack.rb", "LICENSE", "Manifest", "netzke-basepack.gemspec", "Rakefile", "README.mdown", "tasks/netzke_basepack_tasks.rake", "test/app_root/app/controllers/application.rb", "test/app_root/app/models/book.rb", "test/app_root/app/models/category.rb", "test/app_root/app/models/city.rb", "test/app_root/app/models/continent.rb", "test/app_root/app/models/country.rb", "test/app_root/app/models/genre.rb", "test/app_root/config/boot.rb", "test/app_root/config/database.yml", "test/app_root/config/environment.rb", "test/app_root/config/environments/in_memory.rb", "test/app_root/config/environments/mysql.rb", "test/app_root/config/environments/postgresql.rb", "test/app_root/config/environments/sqlite.rb", "test/app_root/config/environments/sqlite3.rb", "test/app_root/config/routes.rb", "test/app_root/db/migrate/20081222033343_create_books.rb", "test/app_root/db/migrate/20081222033440_create_genres.rb", "test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb", "test/app_root/db/migrate/20081223024935_create_categories.rb", "test/app_root/db/migrate/20081223025635_create_countries.rb", "test/app_root/db/migrate/20081223025653_create_continents.rb", "test/app_root/db/migrate/20081223025732_create_cities.rb", "test/app_root/script/console", "test/ar_ext_test.rb", "test/column_test.rb", "test/console_with_fixtures.rb", "test/fixtures/books.yml", "test/fixtures/categories.yml", "test/fixtures/cities.yml", "test/fixtures/continents.yml", "test/fixtures/countries.yml", "test/fixtures/genres.yml", "test/grid_test.rb", "test/netzke_basepack_test.rb", "test/schema.rb", "test/test_helper.rb", "uninstall.rb"]
13
+ s.files = ["CHANGELOG", "generators/netzke_basepack/netzke_basepack_generator.rb", "generators/netzke_basepack/netzke_grid_generator.rb", "generators/netzke_basepack/templates/create_netzke_grid_columns.rb", "generators/netzke_basepack/USAGE", "init.rb", "install.rb", "javascripts/basepack.js", "javascripts/filters.js", "lib/app/models/netzke_grid_column.rb", "lib/netzke/accordion.rb", "lib/netzke/ar_ext.rb", "lib/netzke/column.rb", "lib/netzke/container.rb", "lib/netzke/grid.rb", "lib/netzke/grid_interface.rb", "lib/netzke/grid_js_builder.rb", "lib/netzke/preference_grid.rb", "lib/netzke/properties_tool.rb", "lib/netzke/property_grid.rb", "lib/netzke-basepack.rb", "LICENSE", "Manifest", "netzke-basepack.gemspec", "Rakefile", "README.mdown", "tasks/netzke_basepack_tasks.rake", "test/app_root/app/controllers/application.rb", "test/app_root/app/models/book.rb", "test/app_root/app/models/category.rb", "test/app_root/app/models/city.rb", "test/app_root/app/models/continent.rb", "test/app_root/app/models/country.rb", "test/app_root/app/models/genre.rb", "test/app_root/config/boot.rb", "test/app_root/config/database.yml", "test/app_root/config/environment.rb", "test/app_root/config/environments/in_memory.rb", "test/app_root/config/environments/mysql.rb", "test/app_root/config/environments/postgresql.rb", "test/app_root/config/environments/sqlite.rb", "test/app_root/config/environments/sqlite3.rb", "test/app_root/config/routes.rb", "test/app_root/db/migrate/20081222033343_create_books.rb", "test/app_root/db/migrate/20081222033440_create_genres.rb", "test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb", "test/app_root/db/migrate/20081223024935_create_categories.rb", "test/app_root/db/migrate/20081223025635_create_countries.rb", "test/app_root/db/migrate/20081223025653_create_continents.rb", "test/app_root/db/migrate/20081223025732_create_cities.rb", "test/app_root/script/console", "test/ar_ext_test.rb", "test/column_test.rb", "test/console_with_fixtures.rb", "test/fixtures/books.yml", "test/fixtures/categories.yml", "test/fixtures/cities.yml", "test/fixtures/continents.yml", "test/fixtures/countries.yml", "test/fixtures/genres.yml", "test/grid_test.rb", "test/netzke_basepack_test.rb", "test/schema.rb", "test/test_helper.rb", "uninstall.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://writelesscode.com}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Netzke-basepack", "--main", "README.mdown"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skozlov-netzke-basepack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Kozlov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-27 00:00:00 -08:00
12
+ date: 2008-12-28 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -77,6 +77,7 @@ files:
77
77
  - init.rb
78
78
  - install.rb
79
79
  - javascripts/basepack.js
80
+ - javascripts/filters.js
80
81
  - lib/app/models/netzke_grid_column.rb
81
82
  - lib/netzke/accordion.rb
82
83
  - lib/netzke/ar_ext.rb