constructor-pages 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7c99ad910ed090f671a97bb20daac6d2c794705
|
4
|
+
data.tar.gz: 738a7f27c0dfaa1c1cb5bdb8684b42cc640599ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21cd621106d968f6458280fbf8046f1e51dc92352311a986ddfef188d91a718beb2ea0d157ca7069cca17a3977c7a2e89d50ce2d73a24151211f423a250f097e
|
7
|
+
data.tar.gz: 072ac7bd7b8a4975c62181809f41faf45477d4b5af133d3d5ff24fc0af3502d759dcd36d10ee7ceaca96371e9e5612af7bdffdadcb937897cdebb6a04d4e9793
|
@@ -33,20 +33,6 @@ module ConstructorPages
|
|
33
33
|
render template: "templates/#{_code_name}"
|
34
34
|
end
|
35
35
|
|
36
|
-
def search
|
37
|
-
@page = Page.find_by_request_or_first("/#{params[:all]}")
|
38
|
-
|
39
|
-
_params = request.query_parameters
|
40
|
-
_params.each_pair {|k,v| v || (_params.delete(k); next)
|
41
|
-
_params[k] = v.numeric? ? v.to_f : (v.to_boolean if v.boolean?)}
|
42
|
-
|
43
|
-
@pages = Page.in(@page).by(_params).search(params[:what_search])
|
44
|
-
|
45
|
-
@page.template.code_name.tap {|c| [c.pluralize, c.singularize].each {|name|
|
46
|
-
instance_variable_set('@'+name, @pages)}
|
47
|
-
render template: "templates/#{c}_search"}
|
48
|
-
end
|
49
|
-
|
50
36
|
def edit
|
51
37
|
@page = Page.find(params[:id])
|
52
38
|
@parent_id, @template_id = @page.parent.try(:id), @page.template.id
|
@@ -47,13 +47,19 @@ module ConstructorPages
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def search(what_search = nil)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
hash_search, array_search = {}, []
|
51
|
+
|
52
|
+
@where_search = Page.find_by(full_url: @where_search) if @where_search.is_a?(String)
|
53
|
+
array_search = ['lft > ? and rgt < ?', @where_search.lft, @where_search.rgt] if @where_search
|
54
|
+
|
55
|
+
what_search && what_search = what_search.to_s.singularize.downcase
|
56
|
+
hash_search[:template_id] = ConstructorPages::Template.find_by(code_name: what_search).try(:id) if what_search
|
57
|
+
|
58
|
+
hash_search[:id] = ids_by_params(@params_search) if @params_search
|
59
|
+
|
55
60
|
@where_search = @params_search = nil
|
56
|
-
|
61
|
+
|
62
|
+
hash_search.empty? && array_search.empty? ? [] : Page.where(hash_search).where(array_search).to_a
|
57
63
|
end
|
58
64
|
|
59
65
|
def in(where_search = nil); tap {@where_search = where_search} end
|
@@ -61,6 +67,45 @@ module ConstructorPages
|
|
61
67
|
|
62
68
|
def search_in(where_search = nil); self.in(where_search).search end
|
63
69
|
def search_by(params_search = nil); self.by(params_search).search end
|
70
|
+
|
71
|
+
|
72
|
+
def ids_by_params(params)
|
73
|
+
_hash = {}
|
74
|
+
|
75
|
+
params.each_pair do |key, value|
|
76
|
+
next if key == 'utf8'
|
77
|
+
|
78
|
+
key = key.to_s
|
79
|
+
_key, _value = key.gsub(/>|</, ''), value
|
80
|
+
|
81
|
+
if _value.is_a?(String)
|
82
|
+
next if _value.strip.empty?
|
83
|
+
_value = _value.gsub(/>|</, '')
|
84
|
+
_value = _value.numeric? ? _value.to_f : (_value.to_boolean if _value.boolean?)
|
85
|
+
end
|
86
|
+
|
87
|
+
sign = '='
|
88
|
+
|
89
|
+
if key =~ />$/ || value =~ /^>/
|
90
|
+
sign = '>'
|
91
|
+
elsif key =~ /<$/ || value =~ /^</
|
92
|
+
sign = '<'
|
93
|
+
end
|
94
|
+
|
95
|
+
_fields = ConstructorPages::Field.where(code_name: _key)
|
96
|
+
|
97
|
+
_ids = []
|
98
|
+
|
99
|
+
_fields.each do |_field|
|
100
|
+
_hash[:field_id] = _field.id
|
101
|
+
_ids << _field.type_class.where("value #{sign} #{_value}").where(_hash).map(&:page_id)
|
102
|
+
end
|
103
|
+
|
104
|
+
_hash[:page_id] = _ids.flatten.uniq
|
105
|
+
end
|
106
|
+
|
107
|
+
return _hash[:page_id] || []
|
108
|
+
end
|
64
109
|
end
|
65
110
|
|
66
111
|
def search(what_search = nil); Page.in(self).search(what_search) end
|
data/config/routes.rb
CHANGED
@@ -70,7 +70,7 @@ module ConstructorPages
|
|
70
70
|
@content_field = Field.create name: 'Content', code_name: 'content', template: @brand_template, type_value: 'text'
|
71
71
|
@check_field = Field.create name: 'Check', code_name: 'check', template: @brand_template, type_value: 'boolean'
|
72
72
|
@brand_price_field = Field.create name: 'Price', code_name: 'price', template: @brand_template, type_value: 'float'
|
73
|
-
@brand_area_field = Field.create name: 'Area', code_name: '
|
73
|
+
@brand_area_field = Field.create name: 'Area', code_name: 'brand_area', template: @brand_template, type_value: 'integer'
|
74
74
|
|
75
75
|
@page = Page.create name: 'Fresco', template: @template
|
76
76
|
@page.price = 15000
|
@@ -82,21 +82,23 @@ module ConstructorPages
|
|
82
82
|
|
83
83
|
@first_brand_page = Page.create name: 'Midea', template: @brand_template, parent: @page
|
84
84
|
@first_brand_page.price = 20000
|
85
|
-
@first_brand_page.
|
85
|
+
@first_brand_page.brand_area = 25
|
86
86
|
@first_brand_page.content = 'This is first brand page'
|
87
87
|
@first_brand_page.check = true
|
88
88
|
|
89
89
|
@second_brand_page = Page.create name: 'Dantex', template: @brand_template, parent: @page
|
90
90
|
@second_brand_page.price = 30000
|
91
|
-
@second_brand_page.
|
91
|
+
@second_brand_page.brand_area = 55
|
92
92
|
@second_brand_page.content = 'This is second brand page'
|
93
93
|
@second_brand_page.check = false
|
94
|
+
@second_brand_page.reload
|
94
95
|
|
95
96
|
@third_brand_page = Page.create name: 'LG', template: @brand_template, parent: @second_page
|
96
97
|
@third_brand_page.price = 10000
|
97
|
-
@third_brand_page.
|
98
|
+
@third_brand_page.brand_area = 38
|
98
99
|
@third_brand_page.content = 'This is third brand page'
|
99
100
|
@third_brand_page.check = true
|
101
|
+
@third_brand_page.reload
|
100
102
|
|
101
103
|
@page.reload
|
102
104
|
@second_page.reload
|
@@ -104,7 +106,6 @@ module ConstructorPages
|
|
104
106
|
|
105
107
|
context 'search in all pages' do
|
106
108
|
it 'should search with what search' do
|
107
|
-
Page.search.should == [@page, @first_brand_page, @second_brand_page, @second_page, @third_brand_page]
|
108
109
|
Page.search(:hello).should == []
|
109
110
|
Page.search(:brand).should == [@first_brand_page, @second_brand_page, @third_brand_page]
|
110
111
|
Page.search(:brands).should == [@first_brand_page, @second_brand_page, @third_brand_page]
|
@@ -121,22 +122,23 @@ module ConstructorPages
|
|
121
122
|
Page.in(@second_page).search('brand').should == [@third_brand_page]
|
122
123
|
end
|
123
124
|
|
124
|
-
it '
|
125
|
-
|
125
|
+
it 'should search with by params' do
|
126
|
+
@page.reload
|
127
|
+
Page.in(@page).search_by(brand_area: 25).should == [@first_brand_page]
|
126
128
|
Page.search_by(area: 10).should == [@second_page]
|
127
129
|
Page.search_by(price: 15000).should == [@page]
|
128
|
-
Page.in(@page).by(
|
129
|
-
Page.in(@second_page).by(
|
130
|
-
Page.in(@second_page).by(
|
131
|
-
Page.in('/world').search_by(
|
130
|
+
Page.in(@page).by(brand_area: 25).search(:brand).should == [@first_brand_page]
|
131
|
+
Page.in(@second_page).by(brand_area: 38).search(:brand).should == [@third_brand_page]
|
132
|
+
Page.in(@second_page).by(brand_area: 40).search(:brand).should == []
|
133
|
+
Page.in('/world').search_by(brand_area: 10).should == []
|
132
134
|
end
|
133
135
|
|
134
136
|
it 'should search with less' do
|
135
|
-
|
137
|
+
Page.search_by('price<' => '20000').should == [@page, @second_page, @third_brand_page]
|
136
138
|
end
|
137
139
|
|
138
140
|
it 'should search with more' do
|
139
|
-
|
141
|
+
Page.search_by('price>' => 20000).should == [@second_brand_page]
|
140
142
|
end
|
141
143
|
end
|
142
144
|
|
@@ -149,7 +151,7 @@ module ConstructorPages
|
|
149
151
|
end
|
150
152
|
|
151
153
|
it 'it should search with by params' do
|
152
|
-
@page.search_by(
|
154
|
+
@page.search_by(brand_area: 25).should == [@first_brand_page]
|
153
155
|
@page.search_by(price: 30000).should == [@second_brand_page]
|
154
156
|
@page.by(price: 30000).search.should == [@second_brand_page]
|
155
157
|
@page.search_by(area: 10).should == []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constructor-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Zotov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: constructor-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.
|
19
|
+
version: 0.8.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.
|
26
|
+
version: 0.8.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dragonfly
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|