optimacms 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/optimacms/admin/pages_controller.rb +2 -4
- data/lib/optimacms/filters/form_filter.rb +0 -228
- data/lib/optimacms/version.rb +1 -1
- data/lib/simple_filter/controller.rb +14 -0
- data/lib/simple_filter/filter.rb +223 -0
- metadata +4 -4
- data/test/dummy/tmp/pids/server.pid +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5c71915c85fc8f8b2c3b927bc7fc5b7c44f91ac
|
4
|
+
data.tar.gz: 2ff1155e854f1b56f6407ec212bcf585c8128a6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86d108c522d1c97bd753052ae6e9988e17285d7f286385647dc233647e2a5ca6bbd15750252468647a32f572b831ce48ee4f0dc3c91b82406ef47402c33bd758
|
7
|
+
data.tar.gz: e3af7c37bd671c11116fe67c6b7e4abdf0c87dfa83c2e1c7ac2f154f02e415ce76b572b263e5244b36772fc5e6402427c4a220c373d2e97a802307c090a531c3
|
@@ -138,10 +138,8 @@ module Optimacms
|
|
138
138
|
|
139
139
|
|
140
140
|
# filter
|
141
|
+
include SimpleFilters::Controller
|
141
142
|
|
142
|
-
def filter_prefix
|
143
|
-
'admin_pages'
|
144
|
-
end
|
145
143
|
|
146
144
|
def init_tabledata
|
147
145
|
init_filter
|
@@ -152,7 +150,7 @@ module Optimacms
|
|
152
150
|
@pg = params[:pg].to_i || 1
|
153
151
|
|
154
152
|
#
|
155
|
-
@filter = Filters::FormFilter.new(session,
|
153
|
+
@filter = Filters::FormFilter.new(session, 'admin_pages')
|
156
154
|
|
157
155
|
# set filter fields
|
158
156
|
@filter.add_fields_from_array(
|
@@ -1,228 +0,0 @@
|
|
1
|
-
module Optimacms
|
2
|
-
|
3
|
-
|
4
|
-
module Filters
|
5
|
-
class FormFilter
|
6
|
-
|
7
|
-
FIELD_TYPE_TEXT = 'text'
|
8
|
-
FIELD_TYPE_HIDDEN = 'hidden'
|
9
|
-
FIELD_TYPE_SELECT_AUTO = 'select_auto' # text with autocomplete
|
10
|
-
|
11
|
-
DBTYPE_STRING = 'string'
|
12
|
-
DBTYPE_INT = 'int'
|
13
|
-
DBTYPE_DATE = 'date'
|
14
|
-
|
15
|
-
#
|
16
|
-
attr_accessor :prefix # session prefix
|
17
|
-
attr_accessor :fields
|
18
|
-
attr_accessor :data
|
19
|
-
#attr_accessor :order # [ ["order_column", "asc|desc"], ..]
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def initialize(_session, _prefix)
|
24
|
-
@prefix = _prefix
|
25
|
-
@session = _session
|
26
|
-
|
27
|
-
@fields ||={}
|
28
|
-
|
29
|
-
# init data
|
30
|
-
data()
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
############
|
35
|
-
# fields
|
36
|
-
############
|
37
|
-
|
38
|
-
def add_field(f)
|
39
|
-
@fields[f[:name]] = f
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_fields_from_array(a)
|
44
|
-
a.each do |fa|
|
45
|
-
add_field fa
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
def field_def_value(name)
|
52
|
-
if (@fields.has_key? name) && (@fields[name].has_key? :def)
|
53
|
-
return @fields[name][:def]
|
54
|
-
end
|
55
|
-
nil
|
56
|
-
end
|
57
|
-
|
58
|
-
############
|
59
|
-
# sessions
|
60
|
-
############
|
61
|
-
|
62
|
-
def session_get(name, def_value)
|
63
|
-
@session[prefix+name] || def_value
|
64
|
-
end
|
65
|
-
|
66
|
-
def session_save(name, v)
|
67
|
-
@session[prefix+name] = v
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
############
|
72
|
-
# data
|
73
|
-
############
|
74
|
-
|
75
|
-
|
76
|
-
def data
|
77
|
-
return @data unless @data.nil?
|
78
|
-
|
79
|
-
# from session
|
80
|
-
@data_sess = session_get 'data', nil
|
81
|
-
unless @data_sess.nil?
|
82
|
-
@data = @data_sess
|
83
|
-
else
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
#
|
88
|
-
@data ||= {}
|
89
|
-
|
90
|
-
session_save('data', @data)
|
91
|
-
|
92
|
-
#
|
93
|
-
@data
|
94
|
-
end
|
95
|
-
|
96
|
-
def v(name, v_def=nil)
|
97
|
-
if (data.has_key? name) && (!data[name].nil?)
|
98
|
-
return data[name]
|
99
|
-
end
|
100
|
-
|
101
|
-
field_def_value(name) || v_def
|
102
|
-
end
|
103
|
-
|
104
|
-
def v_empty?(name)
|
105
|
-
if (data.has_key? name) && (!data[name].nil?)
|
106
|
-
return true
|
107
|
-
end
|
108
|
-
|
109
|
-
# if v == default value
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
def set(field_name,v)
|
114
|
-
data[field_name] = v
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
def clear_data
|
119
|
-
session_save 'data', {}
|
120
|
-
end
|
121
|
-
|
122
|
-
def set_data_from_form(params)
|
123
|
-
# search for fields like filter[XXX]
|
124
|
-
params.each do |name, v|
|
125
|
-
#if f =~ /^filter\[([^\]]+)\]$/
|
126
|
-
#name = Regexp.last_match(1)
|
127
|
-
|
128
|
-
next unless @fields.has_key? name
|
129
|
-
|
130
|
-
if @fields[name][:dbtype]==DBTYPE_INT
|
131
|
-
data[name] = (v.to_i rescue 0)
|
132
|
-
else
|
133
|
-
data[name] = v
|
134
|
-
end
|
135
|
-
|
136
|
-
#end
|
137
|
-
end
|
138
|
-
|
139
|
-
# default values from fields
|
140
|
-
@fields.each do |name, f|
|
141
|
-
next if @data.has_key? name
|
142
|
-
|
143
|
-
@data[name] = field_def_value name
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
####
|
151
|
-
# order
|
152
|
-
####
|
153
|
-
|
154
|
-
def order
|
155
|
-
return @order unless @order.nil?
|
156
|
-
|
157
|
-
# from session
|
158
|
-
@v_sess = session_get 'order', nil
|
159
|
-
@order = @v_sess unless @v_sess.nil?
|
160
|
-
|
161
|
-
#
|
162
|
-
@order ||= []
|
163
|
-
|
164
|
-
session_save 'order', @order
|
165
|
-
|
166
|
-
#
|
167
|
-
@order
|
168
|
-
end
|
169
|
-
|
170
|
-
def order= (value)
|
171
|
-
@order = value
|
172
|
-
|
173
|
-
session_save 'order', @order
|
174
|
-
end
|
175
|
-
|
176
|
-
def set_order_default(order_by, order_dir)
|
177
|
-
return false if !order.nil? && !order.empty?
|
178
|
-
|
179
|
-
set_order(order_by, order_dir)
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
|
184
|
-
def set_order(order_by, order_dir)
|
185
|
-
self.order = [[order_by, order_dir]]
|
186
|
-
end
|
187
|
-
|
188
|
-
def get_order
|
189
|
-
order[0] if order.count>0
|
190
|
-
order[0]
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
def get_opposite_order_dir_for_column(name)
|
195
|
-
return 'asc' if order.empty?
|
196
|
-
|
197
|
-
|
198
|
-
if order[0][0] == name
|
199
|
-
return opposite_order_dir(order[0][1])
|
200
|
-
end
|
201
|
-
|
202
|
-
return 'asc'
|
203
|
-
end
|
204
|
-
|
205
|
-
def opposite_order_dir(order_dir)
|
206
|
-
return 'asc' if order_dir=='desc'
|
207
|
-
return 'desc' if order_dir=='asc'
|
208
|
-
'asc'
|
209
|
-
end
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
#helper methods
|
214
|
-
|
215
|
-
def html_style(name)
|
216
|
-
return '' unless @fields[name].has_key?(:opt)
|
217
|
-
|
218
|
-
s = ''
|
219
|
-
opt = @fields[name][:opt]
|
220
|
-
unless opt[:width].nil?
|
221
|
-
s << "width: #{opt[:width]}px; "
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
data/lib/optimacms/version.rb
CHANGED
@@ -0,0 +1,223 @@
|
|
1
|
+
module SimpleFilter
|
2
|
+
class Filter
|
3
|
+
|
4
|
+
FIELD_TYPE_TEXT = 'text'
|
5
|
+
FIELD_TYPE_HIDDEN = 'hidden'
|
6
|
+
FIELD_TYPE_SELECT_AUTO = 'select_auto' # text with autocomplete
|
7
|
+
|
8
|
+
DBTYPE_STRING = 'string'
|
9
|
+
DBTYPE_INT = 'int'
|
10
|
+
DBTYPE_DATE = 'date'
|
11
|
+
|
12
|
+
#
|
13
|
+
attr_accessor :prefix # session prefix
|
14
|
+
attr_accessor :fields
|
15
|
+
attr_accessor :data
|
16
|
+
#attr_accessor :order # [ ["order_column", "asc|desc"], ..]
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
def initialize(_session, _prefix)
|
21
|
+
@prefix = _prefix
|
22
|
+
@session = _session
|
23
|
+
|
24
|
+
@fields ||={}
|
25
|
+
|
26
|
+
# init data
|
27
|
+
data()
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
############
|
32
|
+
# fields
|
33
|
+
############
|
34
|
+
|
35
|
+
def add_field(f)
|
36
|
+
@fields[f[:name]] = f
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_fields_from_array(a)
|
41
|
+
a.each do |fa|
|
42
|
+
add_field fa
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def field_def_value(name)
|
49
|
+
if (@fields.has_key? name) && (@fields[name].has_key? :def)
|
50
|
+
return @fields[name][:def]
|
51
|
+
end
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
############
|
56
|
+
# sessions
|
57
|
+
############
|
58
|
+
|
59
|
+
def session_get(name, def_value)
|
60
|
+
@session[prefix+name] || def_value
|
61
|
+
end
|
62
|
+
|
63
|
+
def session_save(name, v)
|
64
|
+
@session[prefix+name] = v
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
############
|
69
|
+
# data
|
70
|
+
############
|
71
|
+
|
72
|
+
|
73
|
+
def data
|
74
|
+
return @data unless @data.nil?
|
75
|
+
|
76
|
+
# from session
|
77
|
+
@data_sess = session_get 'data', nil
|
78
|
+
unless @data_sess.nil?
|
79
|
+
@data = @data_sess
|
80
|
+
else
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
@data ||= {}
|
86
|
+
|
87
|
+
session_save('data', @data)
|
88
|
+
|
89
|
+
#
|
90
|
+
@data
|
91
|
+
end
|
92
|
+
|
93
|
+
def v(name, v_def=nil)
|
94
|
+
if (data.has_key? name) && (!data[name].nil?)
|
95
|
+
return data[name]
|
96
|
+
end
|
97
|
+
|
98
|
+
field_def_value(name) || v_def
|
99
|
+
end
|
100
|
+
|
101
|
+
def v_empty?(name)
|
102
|
+
if (data.has_key? name) && (!data[name].nil?)
|
103
|
+
return true
|
104
|
+
end
|
105
|
+
|
106
|
+
# if v == default value
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def set(field_name,v)
|
111
|
+
data[field_name] = v
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def clear_data
|
116
|
+
session_save 'data', {}
|
117
|
+
end
|
118
|
+
|
119
|
+
def set_data_from_form(params)
|
120
|
+
# search for fields like filter[XXX]
|
121
|
+
params.each do |name, v|
|
122
|
+
#if f =~ /^filter\[([^\]]+)\]$/
|
123
|
+
#name = Regexp.last_match(1)
|
124
|
+
|
125
|
+
next unless @fields.has_key? name
|
126
|
+
|
127
|
+
if @fields[name][:dbtype]==DBTYPE_INT
|
128
|
+
data[name] = (v.to_i rescue 0)
|
129
|
+
else
|
130
|
+
data[name] = v
|
131
|
+
end
|
132
|
+
|
133
|
+
#end
|
134
|
+
end
|
135
|
+
|
136
|
+
# default values from fields
|
137
|
+
@fields.each do |name, f|
|
138
|
+
next if @data.has_key? name
|
139
|
+
|
140
|
+
@data[name] = field_def_value name
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
####
|
148
|
+
# order
|
149
|
+
####
|
150
|
+
|
151
|
+
def order
|
152
|
+
return @order unless @order.nil?
|
153
|
+
|
154
|
+
# from session
|
155
|
+
@v_sess = session_get 'order', nil
|
156
|
+
@order = @v_sess unless @v_sess.nil?
|
157
|
+
|
158
|
+
#
|
159
|
+
@order ||= []
|
160
|
+
|
161
|
+
session_save 'order', @order
|
162
|
+
|
163
|
+
#
|
164
|
+
@order
|
165
|
+
end
|
166
|
+
|
167
|
+
def order= (value)
|
168
|
+
@order = value
|
169
|
+
|
170
|
+
session_save 'order', @order
|
171
|
+
end
|
172
|
+
|
173
|
+
def set_order_default(order_by, order_dir)
|
174
|
+
return false if !order.nil? && !order.empty?
|
175
|
+
|
176
|
+
set_order(order_by, order_dir)
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def set_order(order_by, order_dir)
|
182
|
+
self.order = [[order_by, order_dir]]
|
183
|
+
end
|
184
|
+
|
185
|
+
def get_order
|
186
|
+
order[0] if order.count>0
|
187
|
+
order[0]
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
def get_opposite_order_dir_for_column(name)
|
192
|
+
return 'asc' if order.empty?
|
193
|
+
|
194
|
+
|
195
|
+
if order[0][0] == name
|
196
|
+
return opposite_order_dir(order[0][1])
|
197
|
+
end
|
198
|
+
|
199
|
+
return 'asc'
|
200
|
+
end
|
201
|
+
|
202
|
+
def opposite_order_dir(order_dir)
|
203
|
+
return 'asc' if order_dir=='desc'
|
204
|
+
return 'desc' if order_dir=='asc'
|
205
|
+
'asc'
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
#helper methods
|
211
|
+
|
212
|
+
def html_style(name)
|
213
|
+
return '' unless @fields[name].has_key?(:opt)
|
214
|
+
|
215
|
+
s = ''
|
216
|
+
opt = @fields[name][:opt]
|
217
|
+
unless opt[:width].nil?
|
218
|
+
s << "width: #{opt[:width]}px; "
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimacms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Ivak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -306,6 +306,8 @@ files:
|
|
306
306
|
- lib/optimacms/page_services/page_route_service.rb
|
307
307
|
- lib/optimacms/simple_form_extensions/button_components.rb
|
308
308
|
- lib/optimacms/version.rb
|
309
|
+
- lib/simple_filter/controller.rb
|
310
|
+
- lib/simple_filter/filter.rb
|
309
311
|
- lib/tasks/optimacms_tasks.rake
|
310
312
|
- test/controllers/optimacms/articles_controller_test.rb
|
311
313
|
- test/dummy/README.rdoc
|
@@ -2381,7 +2383,6 @@ files:
|
|
2381
2383
|
- test/dummy/tmp/cache/assets/development/sprockets/fedc8f629673405d3bbcd26e9e0b977d
|
2382
2384
|
- test/dummy/tmp/cache/assets/development/sprockets/ff9ed89418a3f78032b8f8184dd98e80
|
2383
2385
|
- test/dummy/tmp/cache/assets/development/sprockets/fff5cc1f57d172a75379719781f39cea
|
2384
|
-
- test/dummy/tmp/pids/server.pid
|
2385
2386
|
- test/fixtures/optimacms/articles.yml
|
2386
2387
|
- test/integration/navigation_test.rb
|
2387
2388
|
- test/models/optimacms/article_test.rb
|
@@ -4486,7 +4487,6 @@ test_files:
|
|
4486
4487
|
- test/dummy/tmp/cache/assets/development/sprockets/fedc8f629673405d3bbcd26e9e0b977d
|
4487
4488
|
- test/dummy/tmp/cache/assets/development/sprockets/ff9ed89418a3f78032b8f8184dd98e80
|
4488
4489
|
- test/dummy/tmp/cache/assets/development/sprockets/fff5cc1f57d172a75379719781f39cea
|
4489
|
-
- test/dummy/tmp/pids/server.pid
|
4490
4490
|
- test/fixtures/optimacms/articles.yml
|
4491
4491
|
- test/integration/navigation_test.rb
|
4492
4492
|
- test/models/optimacms/article_test.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
9372
|