skozlov-netzke_basepack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGELOG +1 -0
  2. data/LICENSE +20 -0
  3. data/Manifest +64 -0
  4. data/README.mdown +18 -0
  5. data/Rakefile +11 -0
  6. data/generators/netzke_basepack/USAGE +8 -0
  7. data/generators/netzke_basepack/netzke_basepack_generator.rb +8 -0
  8. data/generators/netzke_basepack/netzke_grid_generator.rb +7 -0
  9. data/generators/netzke_basepack/templates/create_netzke_grid_columns.rb +21 -0
  10. data/init.rb +2 -0
  11. data/install.rb +1 -0
  12. data/javascripts/basepack.js +41 -0
  13. data/lib/app/models/netzke_grid_column.rb +23 -0
  14. data/lib/netzke/accordion.rb +11 -0
  15. data/lib/netzke/ar_ext.rb +163 -0
  16. data/lib/netzke/column.rb +43 -0
  17. data/lib/netzke/container.rb +81 -0
  18. data/lib/netzke/grid.rb +132 -0
  19. data/lib/netzke/grid_interface.rb +132 -0
  20. data/lib/netzke/grid_js_builder.rb +249 -0
  21. data/lib/netzke/preference_grid.rb +43 -0
  22. data/lib/netzke/properties_tool.rb +66 -0
  23. data/lib/netzke/property_grid.rb +60 -0
  24. data/lib/netzke_basepack.rb +14 -0
  25. data/netzke_basepack.gemspec +38 -0
  26. data/tasks/netzke_basepack_tasks.rake +4 -0
  27. data/test/app_root/app/controllers/application.rb +2 -0
  28. data/test/app_root/app/models/book.rb +9 -0
  29. data/test/app_root/app/models/category.rb +2 -0
  30. data/test/app_root/app/models/city.rb +3 -0
  31. data/test/app_root/app/models/continent.rb +2 -0
  32. data/test/app_root/app/models/country.rb +3 -0
  33. data/test/app_root/app/models/genre.rb +3 -0
  34. data/test/app_root/config/boot.rb +114 -0
  35. data/test/app_root/config/database.yml +21 -0
  36. data/test/app_root/config/environment.rb +13 -0
  37. data/test/app_root/config/environments/in_memory.rb +0 -0
  38. data/test/app_root/config/environments/mysql.rb +0 -0
  39. data/test/app_root/config/environments/postgresql.rb +0 -0
  40. data/test/app_root/config/environments/sqlite.rb +0 -0
  41. data/test/app_root/config/environments/sqlite3.rb +0 -0
  42. data/test/app_root/config/routes.rb +4 -0
  43. data/test/app_root/db/migrate/20081222033343_create_books.rb +15 -0
  44. data/test/app_root/db/migrate/20081222033440_create_genres.rb +14 -0
  45. data/test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb +18 -0
  46. data/test/app_root/db/migrate/20081223024935_create_categories.rb +13 -0
  47. data/test/app_root/db/migrate/20081223025635_create_countries.rb +14 -0
  48. data/test/app_root/db/migrate/20081223025653_create_continents.rb +13 -0
  49. data/test/app_root/db/migrate/20081223025732_create_cities.rb +15 -0
  50. data/test/app_root/script/console +7 -0
  51. data/test/ar_ext_test.rb +39 -0
  52. data/test/column_test.rb +27 -0
  53. data/test/console_with_fixtures.rb +4 -0
  54. data/test/fixtures/books.yml +9 -0
  55. data/test/fixtures/categories.yml +7 -0
  56. data/test/fixtures/cities.yml +21 -0
  57. data/test/fixtures/continents.yml +7 -0
  58. data/test/fixtures/countries.yml +9 -0
  59. data/test/fixtures/genres.yml +9 -0
  60. data/test/grid_test.rb +43 -0
  61. data/test/netzke_basepack_test.rb +8 -0
  62. data/test/schema.rb +10 -0
  63. data/test/test_helper.rb +20 -0
  64. data/uninstall.rb +1 -0
  65. metadata +159 -0
@@ -0,0 +1,15 @@
1
+ class CreateBooks < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :books do |t|
4
+ t.string :title
5
+ t.integer :amount
6
+ t.integer :genre_id
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :books
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ class CreateGenres < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :genres do |t|
4
+ t.string :name
5
+ t.integer :category_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :genres
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ class CreateNetzkePreferences < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :netzke_preferences do |t|
4
+ t.string :name
5
+ t.string :pref_type
6
+ t.string :value
7
+ t.integer :user_id
8
+ t.integer :role_id
9
+ t.string :custom_field
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+
15
+ def self.down
16
+ drop_table :netzke_preferences
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCategories < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :categories do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :categories
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ class CreateCountries < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :countries do |t|
4
+ t.string :name
5
+ t.integer :continent_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :countries
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class CreateContinents < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :continents do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :continents
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class CreateCities < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :cities do |t|
4
+ t.string :name
5
+ t.integer :population
6
+ t.integer :country_id
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :cities
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
2
+ libs = " -r irb/completion"
3
+ libs << " -r test/test_helper"
4
+ libs << " -r test/console_with_fixtures"
5
+ libs << " -r console_app"
6
+ libs << " -r console_with_helpers"
7
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ require 'netzke/ar_ext'
4
+
5
+ class ArExtTest < ActiveSupport::TestCase
6
+ fixtures :cities, :countries, :continents
7
+
8
+ test "default column config" do
9
+ cc = Book.default_column_config(:title)
10
+
11
+ assert_equal("Title", cc[:label])
12
+ assert_equal(:text_field, cc[:shows_as])
13
+
14
+ cc = Book.default_column_config({:name => :amount, :label => 'AMOUNT'})
15
+
16
+ assert_equal("AMOUNT", cc[:label])
17
+ assert_equal(:number_field, cc[:shows_as])
18
+ end
19
+
20
+ test "choices for column" do
21
+ # TODO: test virtual columns, too
22
+ cities = City.choices_for("name")
23
+ assert_equal(3, cities.size)
24
+ assert(cities.include?('Cordoba') && cities.include?('Buenos Aires'))
25
+
26
+ countries = City.choices_for("country__name")
27
+ assert_equal(2, countries.size)
28
+ assert(countries.include?('Spain') && countries.include?('Argentina'))
29
+
30
+ continents = City.choices_for("country__continent__name")
31
+ assert_equal(2, continents.size)
32
+ assert(continents.include?('Europe') && continents.include?('South America'))
33
+
34
+ cities = City.choices_for("name", "Co")
35
+ assert_equal(2, cities.size)
36
+ assert(cities.include?('Cordoba') && cities.include?('Concordia'))
37
+ end
38
+ end
39
+
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ require 'netzke/ar_ext'
4
+
5
+ ActiveRecord::Base.class_eval do
6
+ include Netzke::ActiveRecordExtensions
7
+ end
8
+
9
+ require 'netzke/column'
10
+
11
+ class ColumnTest < ActiveSupport::TestCase
12
+ test "default columns" do
13
+ stub_widget = Object.new
14
+ def stub_widget.config
15
+ {:name => 'widget', :data_class_name => 'Book', :columns => [:title, {:name => :amount, :read_only => true}, :recent]}
16
+ end
17
+
18
+ columns = Netzke::Column.default_columns_for_widget(stub_widget)
19
+
20
+ assert_equal(false, columns[0][:read_only])
21
+ assert_equal(true, columns[1][:read_only])
22
+ assert_equal("Amount", columns[1][:label])
23
+ assert_equal("Recent", columns[2][:label])
24
+ assert_equal(true, columns[2][:read_only]) # read_only specified in the model itself
25
+ # puts "!!! columns: #{columns.inspect}"
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ # Loads fixtures into the database when running the test app via the console
2
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Rails.root, '../fixtures/*.{yml,csv}'))).each do |fixture_file|
3
+ Fixtures.create_fixtures(File.join(Rails.root, '../fixtures'), File.basename(fixture_file, '.*'))
4
+ end
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ title: Separate Reality
5
+ genre_id: 1
6
+
7
+ two:
8
+ title: The Journey to Ixtlan
9
+ genre_id: 1
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: Bestseller
5
+
6
+ two:
7
+ name: Misc
@@ -0,0 +1,21 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: Cordoba
5
+ population: 323_600
6
+ country_id: 1
7
+
8
+ two:
9
+ name: Buenos Aires
10
+ population: 10000000
11
+ country_id: 2
12
+
13
+ three:
14
+ name: Cordoba
15
+ population: 1_315_500
16
+ country_id: 2
17
+
18
+ four:
19
+ name: Concordia
20
+ population: 148_000
21
+ country_id: 2
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: Europe
5
+
6
+ two:
7
+ name: South America
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: Spain
5
+ continent_id: 1
6
+
7
+ two:
8
+ name: Argentina
9
+ continent_id: 2
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: MyString
5
+ category_id: 1
6
+
7
+ two:
8
+ name: MyString
9
+ category_id: 2
data/test/grid_test.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+ require 'netzke_core'
3
+
4
+ require 'netzke/properties_tool'
5
+ require 'netzke/container'
6
+ require 'netzke/accordion'
7
+
8
+ require 'netzke/grid_interface'
9
+ require 'netzke/grid_js_builder'
10
+ require 'netzke/grid'
11
+
12
+ require 'netzke/ar_ext'
13
+ require 'netzke/column'
14
+
15
+ class GridTest < ActiveSupport::TestCase
16
+
17
+ test "interface" do
18
+ grid = Netzke::Grid.new(:name => 'grid', :data_class_name => 'Book', :layout_manager => false, :columns => [:id, :title, :recent])
19
+
20
+ # post
21
+ grid.post_data(:created_records => [{:title => 'Lord of the Rings'}].to_json)
22
+ assert_equal('Lord of the Rings', Book.first.title)
23
+
24
+ grid.post_data(:updated_records => [{:id => Book.first.id, :title => 'Lolita'}].to_json)
25
+ assert_equal('Lolita', Book.first.title)
26
+
27
+ grid.post_data(:created_records => [{:title => 'Upanishad'}].to_json)
28
+
29
+ # get
30
+ data = grid.get_data
31
+ assert_equal('Lolita', data[:data][0][1]) # title of the first book
32
+ assert_equal('Yes', data[:data][1][2]) # "recent" virtual column in the second book
33
+
34
+ # delete
35
+ res = grid.delete_data(:records => [1,2].to_json)
36
+ assert_equal(true, res[:success])
37
+ assert_equal(nil, Book.first)
38
+
39
+ end
40
+
41
+ # TODO: add tests with association columns
42
+
43
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class NetzkeBasepackTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :books, :force => true do |t|
3
+ t.string :name
4
+ t.integer :amount
5
+ t.integer :genre_id
6
+ end
7
+ create_table :genres, :force => true do |t|
8
+ t.string :name
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ # Set the default environment to sqlite3's in_memory database
2
+ ENV['RAILS_ENV'] ||= 'in_memory'
3
+
4
+ # Load the Rails environment and testing framework
5
+ require "#{File.dirname(__FILE__)}/app_root/config/environment"
6
+ require 'test_help'
7
+ require 'action_view/test_case' # Load additional test classes not done automatically by < Rails 2.2.2
8
+
9
+ # Undo changes to RAILS_ENV
10
+ silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
11
+
12
+ # Run the migrations
13
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
14
+
15
+ # Set default fixture loading properties
16
+ Test::Unit::TestCase.class_eval do
17
+ self.use_transactional_fixtures = true
18
+ self.use_instantiated_fixtures = false
19
+ self.fixture_path = "#{File.dirname(__FILE__)}/fixtures"
20
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skozlov-netzke_basepack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergei Kozlov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-27 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: searchlogic
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.2
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: netzke_core
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.1.0
35
+ version:
36
+ description: Base Netzke widgets - grid, form, tree, and more
37
+ email: sergei@writelesscode.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - CHANGELOG
44
+ - lib/app/models/netzke_grid_column.rb
45
+ - lib/netzke/accordion.rb
46
+ - lib/netzke/ar_ext.rb
47
+ - lib/netzke/column.rb
48
+ - lib/netzke/container.rb
49
+ - lib/netzke/grid.rb
50
+ - lib/netzke/grid_interface.rb
51
+ - lib/netzke/grid_js_builder.rb
52
+ - lib/netzke/preference_grid.rb
53
+ - lib/netzke/properties_tool.rb
54
+ - lib/netzke/property_grid.rb
55
+ - lib/netzke_basepack.rb
56
+ - LICENSE
57
+ - README.mdown
58
+ - tasks/netzke_basepack_tasks.rake
59
+ files:
60
+ - CHANGELOG
61
+ - generators/netzke_basepack/netzke_basepack_generator.rb
62
+ - generators/netzke_basepack/netzke_grid_generator.rb
63
+ - generators/netzke_basepack/templates/create_netzke_grid_columns.rb
64
+ - generators/netzke_basepack/USAGE
65
+ - init.rb
66
+ - install.rb
67
+ - javascripts/basepack.js
68
+ - lib/app/models/netzke_grid_column.rb
69
+ - lib/netzke/accordion.rb
70
+ - lib/netzke/ar_ext.rb
71
+ - lib/netzke/column.rb
72
+ - lib/netzke/container.rb
73
+ - lib/netzke/grid.rb
74
+ - lib/netzke/grid_interface.rb
75
+ - lib/netzke/grid_js_builder.rb
76
+ - lib/netzke/preference_grid.rb
77
+ - lib/netzke/properties_tool.rb
78
+ - lib/netzke/property_grid.rb
79
+ - lib/netzke_basepack.rb
80
+ - LICENSE
81
+ - Manifest
82
+ - netzke_basepack.gemspec
83
+ - Rakefile
84
+ - README.mdown
85
+ - tasks/netzke_basepack_tasks.rake
86
+ - test/app_root/app/controllers/application.rb
87
+ - test/app_root/app/models/book.rb
88
+ - test/app_root/app/models/category.rb
89
+ - test/app_root/app/models/city.rb
90
+ - test/app_root/app/models/continent.rb
91
+ - test/app_root/app/models/country.rb
92
+ - test/app_root/app/models/genre.rb
93
+ - test/app_root/config/boot.rb
94
+ - test/app_root/config/database.yml
95
+ - test/app_root/config/environment.rb
96
+ - test/app_root/config/environments/in_memory.rb
97
+ - test/app_root/config/environments/mysql.rb
98
+ - test/app_root/config/environments/postgresql.rb
99
+ - test/app_root/config/environments/sqlite.rb
100
+ - test/app_root/config/environments/sqlite3.rb
101
+ - test/app_root/config/routes.rb
102
+ - test/app_root/db/migrate/20081222033343_create_books.rb
103
+ - test/app_root/db/migrate/20081222033440_create_genres.rb
104
+ - test/app_root/db/migrate/20081222035855_create_netzke_preferences.rb
105
+ - test/app_root/db/migrate/20081223024935_create_categories.rb
106
+ - test/app_root/db/migrate/20081223025635_create_countries.rb
107
+ - test/app_root/db/migrate/20081223025653_create_continents.rb
108
+ - test/app_root/db/migrate/20081223025732_create_cities.rb
109
+ - test/app_root/script/console
110
+ - test/ar_ext_test.rb
111
+ - test/column_test.rb
112
+ - test/console_with_fixtures.rb
113
+ - test/fixtures/books.yml
114
+ - test/fixtures/categories.yml
115
+ - test/fixtures/cities.yml
116
+ - test/fixtures/continents.yml
117
+ - test/fixtures/countries.yml
118
+ - test/fixtures/genres.yml
119
+ - test/grid_test.rb
120
+ - test/netzke_basepack_test.rb
121
+ - test/schema.rb
122
+ - test/test_helper.rb
123
+ - uninstall.rb
124
+ has_rdoc: true
125
+ homepage: http://writelesscode.com
126
+ post_install_message:
127
+ rdoc_options:
128
+ - --line-numbers
129
+ - --inline-source
130
+ - --title
131
+ - Netzke_basepack
132
+ - --main
133
+ - README.mdown
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: "0"
141
+ version:
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: "1.2"
147
+ version:
148
+ requirements: []
149
+
150
+ rubyforge_project: netzke_basepack
151
+ rubygems_version: 1.2.0
152
+ signing_key:
153
+ specification_version: 2
154
+ summary: Base Netzke widgets - grid, form, tree, and more
155
+ test_files:
156
+ - test/ar_ext_test.rb
157
+ - test/column_test.rb
158
+ - test/grid_test.rb
159
+ - test/netzke_basepack_test.rb