netzke-basepack 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +11 -0
- data/CHANGELOG.rdoc +10 -0
- data/README.md +36 -2
- data/Rakefile +1 -3
- data/config/ci/before-travis.sh +28 -0
- data/lib/netzke/active_record.rb +10 -8
- data/lib/netzke/active_record/attributes.rb +28 -17
- data/lib/netzke/active_record/relation_extensions.rb +3 -1
- data/lib/netzke/basepack.rb +10 -2
- data/lib/netzke/basepack/action_column.rb +6 -8
- data/lib/netzke/basepack/data_accessor.rb +11 -174
- data/lib/netzke/basepack/data_adapters/abstract_adapter.rb +164 -0
- data/lib/netzke/basepack/data_adapters/active_record_adapter.rb +279 -0
- data/lib/netzke/basepack/data_adapters/data_mapper_adapter.rb +264 -0
- data/lib/netzke/basepack/data_adapters/sequel_adapter.rb +260 -0
- data/lib/netzke/basepack/form_panel.rb +3 -3
- data/lib/netzke/basepack/form_panel/fields.rb +6 -10
- data/lib/netzke/basepack/form_panel/javascripts/form_panel.js +1 -0
- data/lib/netzke/basepack/form_panel/services.rb +15 -16
- data/lib/netzke/basepack/grid_panel.rb +16 -10
- data/lib/netzke/basepack/grid_panel/columns.rb +6 -7
- data/lib/netzke/basepack/grid_panel/javascripts/event_handling.js +29 -27
- data/lib/netzke/basepack/grid_panel/services.rb +13 -90
- data/lib/netzke/basepack/paging_form_panel.rb +3 -3
- data/lib/netzke/basepack/query_builder.rb +2 -0
- data/lib/netzke/basepack/query_builder/javascripts/query_builder.js +29 -19
- data/lib/netzke/basepack/search_panel.rb +6 -3
- data/lib/netzke/basepack/search_panel/javascripts/search_panel.js +2 -1
- data/lib/netzke/basepack/search_window.rb +2 -1
- data/lib/netzke/basepack/version.rb +1 -1
- data/lib/netzke/data_mapper.rb +18 -0
- data/lib/netzke/data_mapper/attributes.rb +273 -0
- data/lib/netzke/data_mapper/combobox_options.rb +11 -0
- data/lib/netzke/data_mapper/relation_extensions.rb +38 -0
- data/lib/netzke/sequel.rb +18 -0
- data/lib/netzke/sequel/attributes.rb +274 -0
- data/lib/netzke/sequel/combobox_options.rb +10 -0
- data/lib/netzke/sequel/relation_extensions.rb +40 -0
- data/netzke-basepack.gemspec +24 -13
- data/test/basepack_test_app/Gemfile +33 -8
- data/test/basepack_test_app/Gemfile.lock +98 -79
- data/test/basepack_test_app/Guardfile +46 -0
- data/test/basepack_test_app/app/components/book_grid_with_persistence.rb +3 -0
- data/test/basepack_test_app/app/components/extras/book_presentation.rb +10 -3
- data/test/basepack_test_app/app/models/address.rb +27 -1
- data/test/basepack_test_app/app/models/author.rb +28 -0
- data/test/basepack_test_app/app/models/book.rb +43 -0
- data/test/basepack_test_app/app/models/book_with_custom_primary_key.rb +22 -0
- data/test/basepack_test_app/app/models/role.rb +21 -0
- data/test/basepack_test_app/app/models/user.rb +24 -0
- data/test/basepack_test_app/config/database.yml.sample +11 -10
- data/test/basepack_test_app/config/database.yml.travis +15 -0
- data/test/basepack_test_app/config/initializers/data_mapper_logging.rb +3 -0
- data/test/basepack_test_app/config/initializers/sequel.rb +26 -0
- data/test/basepack_test_app/db/schema.rb +0 -3
- data/test/basepack_test_app/features/grid_panel.feature +28 -8
- data/test/basepack_test_app/features/grid_sorting.feature +6 -6
- data/test/basepack_test_app/features/paging_form_panel.feature +13 -13
- data/test/basepack_test_app/features/search_in_grid.feature +31 -31
- data/test/basepack_test_app/features/step_definitions/generic_steps.rb +3 -1
- data/test/basepack_test_app/features/support/env.rb +17 -4
- data/test/basepack_test_app/lib/tasks/travis.rake +7 -0
- data/test/basepack_test_app/spec/components/form_panel_spec.rb +2 -2
- data/test/basepack_test_app/spec/data_adapter/adapter_spec.rb +68 -0
- data/test/basepack_test_app/spec/{active_record → data_adapter}/attributes_spec.rb +12 -4
- data/test/basepack_test_app/spec/data_adapter/relation_extensions_spec.rb +125 -0
- data/test/basepack_test_app/spec/spec_helper.rb +9 -0
- data/test/unit/active_record_basepack_test.rb +1 -1
- data/test/unit/grid_panel_test.rb +1 -1
- metadata +26 -31
- data/app/models/netzke_field_list.rb +0 -261
- data/app/models/netzke_model_attr_list.rb +0 -21
- data/app/models/netzke_persistent_array_auto_model.rb +0 -57
- data/test/basepack_test_app/spec/active_record/relation_extensions_spec.rb +0 -44
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'acts_as_list'
|
2
|
-
class NetzkePersistentArrayAutoModel < ActiveRecord::Base
|
3
|
-
set_table_name "netzke_temp_table"
|
4
|
-
connection.create_table(table_name){} if !connection.table_exists?(table_name)
|
5
|
-
|
6
|
-
acts_as_list
|
7
|
-
default_scope :order => "position"
|
8
|
-
|
9
|
-
cattr_accessor :config
|
10
|
-
|
11
|
-
def self.all_columns
|
12
|
-
self.all.map{ |c| c.attributes.reject{ |k,v| k == 'id' || k == 'position' } }
|
13
|
-
end
|
14
|
-
|
15
|
-
# Configuration
|
16
|
-
def self.configure(config)
|
17
|
-
self.config = config
|
18
|
-
if NetzkePreference.first(:conditions => {:name => "netzke_persistent_array_refresh_token"}).try(:value) != refresh_token || !connection.table_exists?(table_name)
|
19
|
-
rebuild_table#(:columns => config[:columns], :initial_data => config[:initial_data])
|
20
|
-
end
|
21
|
-
NetzkePreference.find_or_create_by_name("netzke_persistent_array_refresh_token").update_attribute(:value, refresh_token)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.rebuild_table#(config)
|
25
|
-
connection.drop_table(table_name) if connection.table_exists?(table_name)
|
26
|
-
# create the table with the fields
|
27
|
-
self.connection.create_table(table_name) do |t|
|
28
|
-
config[:columns].each do |c|
|
29
|
-
c = c.dup # to make next line shorter
|
30
|
-
t.column c.delete(:name), c.delete(:type), c
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
self.reset_column_information
|
35
|
-
|
36
|
-
# self.create config[:initial_data]
|
37
|
-
self.replace_data(config[:initial_data])
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.replace_data(data)
|
41
|
-
# only select those attributes that were provided to us as columns. The rest is ignored.
|
42
|
-
column_names = config[:columns].map{ |c| c[:name] }
|
43
|
-
clean_data = data.collect{ |c| c.reject{ |k,v| !column_names.include?(k.to_s) } }
|
44
|
-
self.delete_all
|
45
|
-
self.create(clean_data)
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def self.refresh_token
|
51
|
-
@@refresh_token ||= begin
|
52
|
-
session = Netzke::Base.session
|
53
|
-
config[:owner] + (session[:masq_user] || session[:masq_role] || session[:masq_world] || session[:netzke_user_id]).to_s
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Netzke::ActiveRecord::RelationExtensions do
|
4
|
-
it "should accept different options in extend_with" do
|
5
|
-
# Preparations
|
6
|
-
10.times do |i|
|
7
|
-
Factory(:user, :first_name => "First Name #{i}", :role_id => i)
|
8
|
-
end
|
9
|
-
|
10
|
-
User.scope(:role_id_gt_7, User.where(["role_id > ?", 7]))
|
11
|
-
User.scope(:role_id_gt, lambda{ |param| User.where(["role_id > ?", param]) })
|
12
|
-
|
13
|
-
# Tests
|
14
|
-
User.where({}).extend_with(["role_id >= ?", 5]).count.should == 5
|
15
|
-
|
16
|
-
User.where({}).extend_with(:role_id_gt_7).count.should == 2
|
17
|
-
|
18
|
-
User.where({}).extend_with(:role_id_gt, 2).count.should == 7
|
19
|
-
|
20
|
-
User.where({}).extend_with([:role_id_gt, 3]).count.should == 6
|
21
|
-
|
22
|
-
User.where({}).extend_with(:role_id => 5).first.first_name.should == "First Name 5"
|
23
|
-
|
24
|
-
User.where(["role_id < ?", 7]).extend_with(lambda{ |relation| relation.where(["role_id > ?", 4]) }).count.should == 2
|
25
|
-
|
26
|
-
# User.where({}).extend_with("select * from users where role_id > 6").all.size.should == 3
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should be extendable with extend_with_netzke_conditions" do
|
31
|
-
# Preparations
|
32
|
-
roles = [Factory(:role, :name => "admin"), Factory(:role, :name => "user"), Factory(:role, :name => "superadmin")]
|
33
|
-
|
34
|
-
# 3 users of each role
|
35
|
-
9.times do |i|
|
36
|
-
Factory(:user, :role_id => roles[i%3].id)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Tests
|
40
|
-
User.where({}).extend_with_netzke_conditions(:role_id__eq => roles.last.id).count.should == 3
|
41
|
-
User.where({}).extend_with_netzke_conditions(:role__name__eq => "admin").count.should == 3
|
42
|
-
User.where({}).extend_with_netzke_conditions(:role__name__like => "%admin%").count.should == 6
|
43
|
-
end
|
44
|
-
end
|