drg_cms 0.6.0.8 → 0.6.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -10
- data/app/assets/javascripts/drg_cms/drg_cms.js +208 -81
- data/app/assets/stylesheets/drg_cms/drg_cms.css +298 -93
- data/app/assets/stylesheets/drg_cms/select-multiple.css +1 -1
- data/app/controllers/cmsedit_controller.rb +174 -167
- data/app/controllers/dc_application_controller.rb +230 -196
- data/app/controllers/dc_common_controller.rb +88 -50
- data/app/controls/dc_help_control.rb +138 -0
- data/app/controls/dc_report.rb +12 -16
- data/app/forms/all_options.yml +14 -5
- data/app/forms/cms_menu.yml +7 -1
- data/app/forms/dc_big_table.yml +0 -2
- data/app/forms/dc_big_table_value.yml +0 -2
- data/app/forms/dc_category.yml +2 -1
- data/app/forms/dc_design.yml +2 -2
- data/app/forms/dc_folder_permission.yml +0 -2
- data/app/forms/dc_help_1.yml +110 -0
- data/app/forms/dc_journal.yml +3 -1
- data/app/forms/dc_json_ld.yml +0 -3
- data/app/forms/dc_link.yml +1 -1
- data/app/forms/dc_menu.yml +8 -12
- data/app/forms/dc_menu_item.yml +2 -3
- data/app/forms/dc_page.yml +7 -2
- data/app/forms/dc_part.yml +1 -0
- data/app/forms/dc_piece.yml +1 -0
- data/app/forms/dc_policy.yml +2 -5
- data/app/forms/dc_poll.yml +13 -16
- data/app/forms/dc_seo.yml +1 -2
- data/app/forms/dc_simple_menu.yml +3 -2
- data/app/forms/dc_site.yml +5 -8
- data/app/forms/dc_user.yml +27 -11
- data/app/forms/dc_user_role.yml +3 -0
- data/app/helpers/cms_common_helper.rb +68 -4
- data/app/helpers/cms_edit_helper.rb +73 -55
- data/app/helpers/cms_helper.rb +70 -32
- data/app/helpers/cms_index_helper.rb +155 -102
- data/app/helpers/dc_application_helper.rb +132 -109
- data/app/models/concerns/dc_page_concern.rb +14 -4
- data/app/models/concerns/dc_piece_concern.rb +1 -1
- data/app/models/concerns/dc_policy_rule_concern.rb +20 -8
- data/app/models/concerns/dc_site_concern.rb +56 -44
- data/app/models/concerns/dc_user_concern.rb +58 -19
- data/app/models/dc_big_table.rb +2 -2
- data/app/models/dc_design.rb +29 -19
- data/app/models/dc_filter.rb +28 -22
- data/app/models/dc_key_value_store.rb +1 -0
- data/app/models/dc_permission.rb +19 -9
- data/app/models/dc_policy.rb +25 -14
- data/app/models/dc_policy_role.rb +22 -11
- data/app/models/dc_temp.rb +8 -1
- data/app/models/dc_user_role.rb +2 -2
- data/app/models/drgcms_form_fields/comment.rb +11 -2
- data/app/models/drgcms_form_fields/date_picker.rb +2 -0
- data/app/models/drgcms_form_fields/drgcms_field.rb +2 -1
- data/app/models/drgcms_form_fields/embedded.rb +9 -10
- data/app/models/drgcms_form_fields/file_field.rb +1 -1
- data/app/models/drgcms_form_fields/file_select.rb +2 -2
- data/app/models/drgcms_form_fields/hash_field.rb +11 -7
- data/app/models/drgcms_form_fields/link_to.rb +2 -2
- data/app/models/drgcms_form_fields/method.rb +5 -4
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +1 -1
- data/app/models/drgcms_form_fields/number_field.rb +4 -3
- data/app/models/drgcms_form_fields/readonly.rb +13 -17
- data/app/models/drgcms_form_fields/select.rb +24 -25
- data/app/models/drgcms_form_fields/text_autocomplete.rb +22 -14
- data/app/renderers/dc_page_renderer.rb +7 -6
- data/app/renderers/dc_poll_renderer.rb +16 -20
- data/app/views/cmsedit/_edit_stuff.html.erb +5 -2
- data/app/views/cmsedit/_form.html.erb +3 -2
- data/app/views/cmsedit/_result.html.erb +21 -18
- data/app/views/cmsedit/edit.html.erb +4 -1
- data/app/views/cmsedit/index.html.erb +3 -2
- data/app/views/cmsedit/new.html.erb +5 -2
- data/app/views/dc_common/_help.html.erb +17 -0
- data/app/views/layouts/models.html.erb +2 -1
- data/config/locales/drgcms_en.yml +17 -2
- data/config/locales/drgcms_sl.yml +20 -2
- data/config/locales/models_en.yml +7 -5
- data/config/locales/models_sl.yml +12 -9
- data/drg_cms.gemspec +16 -16
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +94 -2
- metadata +32 -30
- data/app/models/__dc_dummy.rb +0 -102
@@ -1,6 +1,5 @@
|
|
1
|
-
#coding: utf-8
|
2
1
|
#--
|
3
|
-
# Copyright (c) 2012
|
2
|
+
# Copyright (c) 2012+ Damjan Rems
|
4
3
|
#
|
5
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
6
5
|
# a copy of this software and associated documentation files (the
|
@@ -46,30 +45,36 @@ layout false
|
|
46
45
|
########################################################################
|
47
46
|
def autocomplete
|
48
47
|
# table parameter must be defined. If not, get it from search parameter
|
49
|
-
if params['table'].nil?
|
48
|
+
if params['table'].nil? && params['search'].match(/\./)
|
50
49
|
name = params['search'].split('.').first
|
51
50
|
params['table'] = name.underscore
|
52
51
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
table = params['table'].classify.constantize
|
57
|
-
id = [params['id']] || '_id'
|
58
|
-
# call method in class if search parameter has . This is for user defined searches
|
59
|
-
# result must be returned as array of [id, search_field_value]
|
60
|
-
a = if params['search'].match(/\./)
|
61
|
-
name, method = params['search'].split('.')
|
62
|
-
table.send(method, params['input']).inject([]) do |r,v|
|
63
|
-
r << { label: v[0], value: v[0], id: (v[1] || v[0]).to_s }
|
64
|
-
end
|
65
|
-
# simply search which will search and return field_name defined in params['search']
|
52
|
+
if params['table'].match('_control')
|
53
|
+
# it must be at least logged on
|
54
|
+
return render json: { label: t('drgcms.not_authorized') } unless dc_user_can(DcPermission::CAN_VIEW, 'dc_memory')
|
66
55
|
else
|
67
|
-
|
68
|
-
r << { label: v[params['search']], value: v[params['search']], id: v.id.to_s }
|
69
|
-
end
|
56
|
+
return render json: { label: t('drgcms.not_authorized') } unless dc_user_can(DcPermission::CAN_VIEW)
|
70
57
|
end
|
71
58
|
|
72
|
-
|
59
|
+
table = params['table'].classify.constantize
|
60
|
+
input = params['input'].gsub(/\(|\)|\[|\]|\{|\|\.|\,}/, '')
|
61
|
+
# call method in class if search parameter contains . This is for user defined searches
|
62
|
+
a = if params['search'].match(/\./)
|
63
|
+
#method, additional_params = params['search'].split('.')
|
64
|
+
#data = additional_params ? table.send(method, input, additional_params, self) : table.send(method, input)
|
65
|
+
name, method = params['search'].split('.')
|
66
|
+
data = table.send(method, input)
|
67
|
+
data.map do |v|
|
68
|
+
{ label: v[0], value: v[0], id: (v[1] || v[0]).to_s }
|
69
|
+
end
|
70
|
+
# will search and return field_name defined in params['search']
|
71
|
+
else
|
72
|
+
table.where(params['search'] => /#{input}/i).limit(20).map do |v|
|
73
|
+
{ label: v[params['search']], value: v[params['search']], id: v.id.to_s }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
render json: a
|
73
78
|
end
|
74
79
|
|
75
80
|
########################################################################
|
@@ -93,18 +98,19 @@ end
|
|
93
98
|
##########################################################################
|
94
99
|
def toggle_edit_mode
|
95
100
|
session[:edit_mode] ||= 0
|
96
|
-
# error when not logged in
|
97
|
-
return dc_render_404 if session[:edit_mode] < 1
|
98
|
-
|
99
|
-
#
|
101
|
+
# error when not logged in
|
102
|
+
return dc_render_404 if session[:edit_mode] < 1
|
103
|
+
|
104
|
+
# if return_to_ypos parameter is present it will forward it and thus scroll to
|
105
|
+
# aproximate position it was when toggle was clicked
|
100
106
|
session[:edit_mode] = (session[:edit_mode] == 1) ? 2 : 1
|
101
107
|
uri = Rack::Utils.parse_nested_query(request.url)
|
102
|
-
# it parses only on & so first (return_to) parameter also contains url
|
108
|
+
# it parses only on & so first (return_to) parameter also contains url
|
103
109
|
url = uri.first.last
|
104
110
|
if (i = url.index('return_to_ypos')).to_i > 0
|
105
|
-
url = url[0,i-1]
|
111
|
+
url = url[0, i-1]
|
106
112
|
end
|
107
|
-
# offset CMS menu
|
113
|
+
# offset CMS menu
|
108
114
|
if (ypos = uri['return_to_ypos'].to_i) > 0
|
109
115
|
ypos += session[:edit_mode] == 2 ? 250 : -250
|
110
116
|
end
|
@@ -117,14 +123,16 @@ end
|
|
117
123
|
# Default user login action.
|
118
124
|
####################################################################
|
119
125
|
def process_login
|
120
|
-
# Somebody is probably playing
|
121
|
-
return dc_render_404 unless ( params[:record]
|
126
|
+
# Somebody is probably playing
|
127
|
+
return dc_render_404 unless ( params[:record] && params[:record][:username] && params[:record][:password] )
|
122
128
|
|
123
129
|
unless params[:record][:password].blank? #password must not be empty
|
124
130
|
user = DcUser.find_by(username: params[:record][:username], active: true)
|
125
131
|
if user and user.authenticate(params[:record][:password])
|
126
132
|
fill_login_data(user, params[:record][:remember_me].to_i == 1)
|
127
133
|
return redirect_to params[:return_to] || '/'
|
134
|
+
else
|
135
|
+
clear_login_data # on the safe side
|
128
136
|
end
|
129
137
|
end
|
130
138
|
flash[:error] = t('drgcms.invalid_username')
|
@@ -149,12 +157,11 @@ def login
|
|
149
157
|
if user and user.active
|
150
158
|
fill_login_data(user, true)
|
151
159
|
return redirect_to params[:return_to]
|
152
|
-
|
153
160
|
else
|
154
161
|
clear_login_data # on the safe side
|
155
162
|
end
|
156
163
|
end
|
157
|
-
# Display login
|
164
|
+
# Display login
|
158
165
|
route = params[:route] || 'poll'
|
159
166
|
redirect_to "/#{route}?poll_id=login&return_to=#{params[:return_to]}"
|
160
167
|
end
|
@@ -163,23 +170,23 @@ end
|
|
163
170
|
# Action for restoring document data from journal document.
|
164
171
|
####################################################################
|
165
172
|
def restore_from_journal
|
166
|
-
# Only administrators can perform this operation
|
173
|
+
# Only administrators can perform this operation
|
167
174
|
unless dc_user_has_role('admin')
|
168
175
|
return render plain: { 'msg_info' => (t ('drgcms.not_authorized')) }.to_json
|
169
176
|
end
|
170
|
-
# selected fields to hash
|
177
|
+
# selected fields to hash
|
171
178
|
restore = {}
|
172
|
-
params[:select].each {|key,value| restore[key] = value if value == '1' }
|
179
|
+
params[:select].each { |key,value| restore[key] = value if value == '1' }
|
173
180
|
result = if restore.size == 0
|
174
181
|
{ 'msg_error' => (t ('drgcms.dc_journal.zero_selected')) }
|
175
182
|
else
|
176
183
|
journal_doc = DcJournal.find(params[:id])
|
177
|
-
# update hash with data to be restored
|
184
|
+
# update hash with data to be restored
|
178
185
|
JSON.parse(journal_doc.diff).each {|k,v| restore[k] = v.first if restore[k] }
|
179
|
-
# determine tables and document ids
|
186
|
+
# determine tables and document ids
|
180
187
|
tables = journal_doc.tables.split(';')
|
181
188
|
ids = (journal_doc.ids.blank? ? [] : journal_doc.ids.split(';') ) << journal_doc.doc_id
|
182
|
-
# find document
|
189
|
+
# find document
|
183
190
|
doc = nil
|
184
191
|
tables.each_index do |i|
|
185
192
|
doc = if doc.nil?
|
@@ -188,10 +195,10 @@ def restore_from_journal
|
|
188
195
|
doc.send(tables[i].pluralize).find(ids[i])
|
189
196
|
end
|
190
197
|
end
|
191
|
-
# restore and save values
|
198
|
+
# restore and save values
|
192
199
|
restore.each { |field,value| doc.send("#{field}=",value) }
|
193
200
|
doc.save
|
194
|
-
# TODO Error checking
|
201
|
+
# TODO Error checking
|
195
202
|
{ 'msg_info' => (t ('drgcms.dc_journal.restored')) }
|
196
203
|
end
|
197
204
|
render plain: result.to_json
|
@@ -202,10 +209,11 @@ end
|
|
202
209
|
# window with data formatted as json.
|
203
210
|
########################################################################
|
204
211
|
def copy_clipboard
|
205
|
-
# Only administrators can perform this operation
|
212
|
+
# Only administrators can perform this operation
|
206
213
|
return render(plain: t('drgcms.not_authorized') ) unless dc_user_can(DcPermission::CAN_ADMIN,'dc_site')
|
214
|
+
|
207
215
|
respond_to do |format|
|
208
|
-
# just open new window to same url and come back with html request
|
216
|
+
# just open new window to same url and come back with html request
|
209
217
|
format.json { dc_render_ajax(operation: 'window', url: request.url ) }
|
210
218
|
|
211
219
|
format.html do
|
@@ -213,7 +221,6 @@ def copy_clipboard
|
|
213
221
|
text = "<br><br>[#{params[:table]},#{params[:id]},#{params[:ids]}]<br>"
|
214
222
|
render plain: text + doc.as_document.to_json
|
215
223
|
end
|
216
|
-
|
217
224
|
end
|
218
225
|
end
|
219
226
|
|
@@ -223,17 +230,19 @@ end
|
|
223
230
|
# ajax call for processing data.
|
224
231
|
########################################################################
|
225
232
|
def paste_clipboard
|
226
|
-
# Only administrators can perform this operation
|
233
|
+
# Only administrators can perform this operation
|
227
234
|
return render(plain: t('drgcms.not_authorized') ) unless dc_user_can(DcPermission::CAN_ADMIN,'dc_site')
|
235
|
+
|
228
236
|
result = ''
|
229
237
|
respond_to do |format|
|
230
|
-
# just open new window to same url and come back with html request
|
238
|
+
# just open new window to same url and come back with html request
|
231
239
|
format.html { return render('paste_clipboard', layout: 'cms') }
|
232
240
|
format.json {
|
233
241
|
table, id, ids = nil
|
234
242
|
params[:data].split("\n").each do |line|
|
235
243
|
line.chomp!
|
236
244
|
next if line.size < 5 # empty line. Skip
|
245
|
+
|
237
246
|
begin
|
238
247
|
if line[0] == '[' # id(s)
|
239
248
|
result << "<br>#{line}"
|
@@ -260,7 +269,7 @@ def add_json_ld_schema
|
|
260
269
|
edited_document = DcJsonLd.find_document_by_ids(params[:table], params[:ids])
|
261
270
|
yaml = YAML.load_file( dc_find_form_file('json_ld_schema') )
|
262
271
|
schema_data = yaml[params[:schema]]
|
263
|
-
# Existing document
|
272
|
+
# Existing document
|
264
273
|
if edited_document.dc_json_lds.find_by(type: "@#{params[:schema]}")
|
265
274
|
return render json: {'msg_error' => t('helpers.help.dc_json_ld.add_error', schema: params[:schema] ) }
|
266
275
|
else
|
@@ -269,8 +278,37 @@ def add_json_ld_schema
|
|
269
278
|
render json: {'reload_' => 1}
|
270
279
|
end
|
271
280
|
|
281
|
+
########################################################################
|
282
|
+
# Will provide help data
|
283
|
+
########################################################################
|
284
|
+
def help
|
285
|
+
form_name = params[:form_name] || params[:table]
|
286
|
+
@form = form_name ? YAML.load_file(dc_find_form_file(form_name)) : {}
|
287
|
+
return render json: {} if @form.nil?
|
288
|
+
|
289
|
+
help_file_name = @form['help'] || @form['extend'] || params[:form_name] || params[:table]
|
290
|
+
help_file_name = find_help_file(help_file_name)
|
291
|
+
@help = YAML.load_file(help_file_name) if help_file_name
|
292
|
+
# no auto generated help on index action
|
293
|
+
return render json: {} if params[:type] == 'index' && @help.nil?
|
294
|
+
|
295
|
+
render json: { popup: render_to_string(partial: 'help') }
|
296
|
+
end
|
297
|
+
|
272
298
|
protected
|
273
299
|
|
300
|
+
########################################################################
|
301
|
+
# Will search for help file and return it's path if found
|
302
|
+
########################################################################
|
303
|
+
def find_help_file(help_file_name)
|
304
|
+
file_name = nil
|
305
|
+
DrgCms.paths(:forms).reverse.each do |path|
|
306
|
+
f = "#{path}/help/#{help_file_name}.#{I18n.locale}"
|
307
|
+
file_name = f and break if File.exist?(f)
|
308
|
+
end
|
309
|
+
file_name
|
310
|
+
end
|
311
|
+
|
274
312
|
########################################################################
|
275
313
|
# Subroutine of add_json_ld_schema for adding one element
|
276
314
|
########################################################################
|
@@ -308,7 +346,7 @@ def update_json(json, is_update=false) #:nodoc:
|
|
308
346
|
json.each do |k,v|
|
309
347
|
if v.class == Hash
|
310
348
|
result[k] = v['$oid'] unless is_update
|
311
|
-
#TODO Double check if unless works as expected
|
349
|
+
# TODO Double check if unless works as expected
|
312
350
|
elsif v.class == Array
|
313
351
|
result[k] = []
|
314
352
|
v.each {|e| result[k] << update_json(e, is_update)}
|
@@ -325,22 +363,22 @@ end
|
|
325
363
|
def process_document(line, table, id, ids)
|
326
364
|
if params[:do_update] == '1'
|
327
365
|
doc = dc_find_document(table, id, ids)
|
328
|
-
# document found. Update it and return
|
366
|
+
# document found. Update it and return
|
329
367
|
if doc
|
330
368
|
doc.update( update_json(ActiveSupport::JSON.decode(line), true) )
|
331
369
|
msg = dc_check_model(doc)
|
332
370
|
return (msg ? " ERROR! #{msg}" : " UPDATE. OK.")
|
333
371
|
end
|
334
372
|
end
|
335
|
-
# document will be added to collection
|
373
|
+
# document will be added to collection
|
336
374
|
if ids.to_s.size > 5
|
337
|
-
#TODO Add embedded document
|
375
|
+
#TODO Add embedded document
|
338
376
|
" NOT SUPPORTED YET!"
|
339
377
|
else
|
340
378
|
doc = table.classify.constantize.new( update_json(ActiveSupport::JSON.decode(line)) )
|
341
379
|
doc.save
|
342
380
|
end
|
343
|
-
msg =
|
381
|
+
msg = DrgCms.model_check(doc)
|
344
382
|
msg ? " ERROR! #{msg}" : " NEW. OK."
|
345
383
|
end
|
346
384
|
|
@@ -0,0 +1,138 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2021+ Damjan Rems
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
######################################################################
|
25
|
+
# Controls for creating help files
|
26
|
+
######################################################################
|
27
|
+
module DcHelpControl
|
28
|
+
|
29
|
+
######################################################################
|
30
|
+
# Will fill dc_temp with help documents found in a defined project directory.
|
31
|
+
######################################################################
|
32
|
+
def project_refresh
|
33
|
+
DcTemp.clear(temp_key)
|
34
|
+
if params[:record][:select_project].present?
|
35
|
+
# far less complicated if saved to session
|
36
|
+
session[:help_project] = params[:record][:select_project]
|
37
|
+
session[:help_lang] = params[:record][:lang_1]
|
38
|
+
help_dir_name = "#{session[:help_project]}/help/"
|
39
|
+
# create help directory if not yet exists
|
40
|
+
FileUtils.mkdir(help_dir_name) unless File.exist?(help_dir_name)
|
41
|
+
Dir["#{help_dir_name}*"].each do |file_name|
|
42
|
+
lang = File.extname(file_name).sub('.','')
|
43
|
+
next unless lang == session[:help_lang]
|
44
|
+
|
45
|
+
DcTemp.new(key: temp_key,
|
46
|
+
project: session[:help_project],
|
47
|
+
form_name: File.basename(file_name,'.*'),
|
48
|
+
lang: lang,
|
49
|
+
updated_at: File.mtime(file_name)).save
|
50
|
+
end
|
51
|
+
end
|
52
|
+
render json: { url: url_for(controller: :cmsedit, table: :dc_temp, form_name: :dc_help_1) }
|
53
|
+
end
|
54
|
+
|
55
|
+
######################################################################
|
56
|
+
# Will populate fields with default values
|
57
|
+
######################################################################
|
58
|
+
def dc_new_record
|
59
|
+
@record.project = session[:help_project]
|
60
|
+
@record.lang = session[:help_lang]
|
61
|
+
end
|
62
|
+
|
63
|
+
######################################################################
|
64
|
+
# Will read data from help file
|
65
|
+
######################################################################
|
66
|
+
def dc_before_edit
|
67
|
+
file_name = "#{session[:help_project]}/help/#{@record.form_name}.#{session[:help_lang]}"
|
68
|
+
data = YAML.load_file(file_name)
|
69
|
+
@record.index = data['index']
|
70
|
+
@record.form = data['form']
|
71
|
+
flash[:warning] = "Use only in development!" unless Rails.env.development?
|
72
|
+
end
|
73
|
+
|
74
|
+
######################################################################
|
75
|
+
# Will save data to help file
|
76
|
+
######################################################################
|
77
|
+
def dc_before_save
|
78
|
+
rec = params[:record]
|
79
|
+
file_name = "#{session[:help_project]}/help/#{@record.form_name}.#{@record.lang}"
|
80
|
+
data = { 'index' => @record.index, 'form' => @record.form }
|
81
|
+
File.write(file_name, data.to_yaml)
|
82
|
+
end
|
83
|
+
|
84
|
+
######################################################################
|
85
|
+
# Will return query to report data
|
86
|
+
######################################################################
|
87
|
+
def data_filter
|
88
|
+
DcTemp.where(key: temp_key).order_by(order: 1)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
######################################################################
|
94
|
+
# Will return choices for select project input field on a form
|
95
|
+
######################################################################
|
96
|
+
def self.choices_for_project
|
97
|
+
r = DrgCms.paths(:forms).map do |path|
|
98
|
+
path = path.to_s
|
99
|
+
a = path.split('/')
|
100
|
+
project = a[a.size - 3]
|
101
|
+
project = if project == 'app'
|
102
|
+
a[a.size - 4] + ' : ' + a.last(2).join('/')
|
103
|
+
else
|
104
|
+
project + ' : ' + a.last
|
105
|
+
end
|
106
|
+
[project, path]
|
107
|
+
end
|
108
|
+
[[I18n.t('drgcms.dc_help.project'), nil]] + r.sort
|
109
|
+
end
|
110
|
+
|
111
|
+
######################################################################
|
112
|
+
# Will return choices for selecting help file name, based on forms already
|
113
|
+
# present in forms directory.
|
114
|
+
######################################################################
|
115
|
+
def self.choices_for_form_name(session)
|
116
|
+
Dir["#{session[:help_project]}/*.yml"].map { |file_name| File.basename(file_name,'.*') }.sort
|
117
|
+
end
|
118
|
+
|
119
|
+
######################################################################
|
120
|
+
# Will return choices for language select on form. Choices can be either set by dc_locales document in dc_big_table
|
121
|
+
# or can be acquired from Rails default locale
|
122
|
+
######################################################################
|
123
|
+
def self.choices_for_locales
|
124
|
+
choices = DcBigTable.choices4('dc_locales')
|
125
|
+
return choices unless choices[0,0] == I18n.t('drgcms.error')
|
126
|
+
|
127
|
+
choices = [I18n.default_locale] + I18n.fallbacks.inject([]) { |r, e| r << e.first }
|
128
|
+
choices.map(&:to_s).uniq
|
129
|
+
end
|
130
|
+
|
131
|
+
######################################################################
|
132
|
+
# Will return temp key for data saved in dc_temp file
|
133
|
+
######################################################################
|
134
|
+
def temp_key
|
135
|
+
"dc-help-#{session[:user_id]}"
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
data/app/controls/dc_report.rb
CHANGED
@@ -36,14 +36,12 @@ def dc_new_record
|
|
36
36
|
end
|
37
37
|
|
38
38
|
######################################################################
|
39
|
-
#
|
40
|
-
# be used to display result.
|
39
|
+
# If exists, set report section as form, so it can be used to display result.
|
41
40
|
######################################################################
|
42
41
|
def dc_update_form
|
43
|
-
return unless @form && @form['report'] && params[:table]
|
42
|
+
return unless @form && @form['report'] && params[:table] == 'dc_temp'
|
44
43
|
|
45
|
-
|
46
|
-
@form['report'].each { |key, data| @form[key] = data }
|
44
|
+
@form = @form['report']
|
47
45
|
end
|
48
46
|
|
49
47
|
######################################################################
|
@@ -118,7 +116,7 @@ end
|
|
118
116
|
# Will write bulk data to dc_temp collection.
|
119
117
|
######################################################################
|
120
118
|
def bulk_write(doc, the_end = false)
|
121
|
-
if doc.class == TrueClass
|
119
|
+
if doc.nil? || doc.class == TrueClass
|
122
120
|
the_end = true
|
123
121
|
else
|
124
122
|
@bulk << doc
|
@@ -134,7 +132,7 @@ end
|
|
134
132
|
# Export data to Excel
|
135
133
|
######################################################################
|
136
134
|
def export_to_excel(report_id)
|
137
|
-
|
135
|
+
read_drg_form if @form.blank?
|
138
136
|
# use report options if present
|
139
137
|
columns = (@form['report'] ? @form['report'] : @form)['result_set']['columns'].sort
|
140
138
|
|
@@ -155,8 +153,9 @@ def export_to_excel(report_id)
|
|
155
153
|
excel[n, i] = value
|
156
154
|
end
|
157
155
|
end
|
158
|
-
|
159
|
-
|
156
|
+
file_name = "#{report_id}-#{Time.now.to_i}.xls"
|
157
|
+
workbook.write Rails.root.join('public', 'tmp', file_name)
|
158
|
+
dc_render_ajax(operation: :window, value: "/tmp/#{file_name}")
|
160
159
|
end
|
161
160
|
|
162
161
|
############################################################################
|
@@ -202,15 +201,12 @@ end
|
|
202
201
|
# @param [Object] txt : Text or object. Result of to_s method of the object is
|
203
202
|
# @param [Hash] opts
|
204
203
|
###############################################################################
|
205
|
-
def pdf_text(txt, opts={})
|
206
|
-
box_opts =
|
204
|
+
def pdf_text(txt, opts = {})
|
205
|
+
box_opts = opts.dup
|
207
206
|
ypos = @pdf.cursor
|
208
207
|
xpos = opts.delete(:atx) || 0
|
209
|
-
box_opts
|
210
|
-
box_opts
|
211
|
-
box_opts.merge!(width: opts[:width]) if opts[:width]
|
212
|
-
box_opts.merge!(align: opts[:align]) if opts[:align]
|
213
|
-
box_opts.merge!(inline_format: opts[:inline_format]) if opts[:inline_format]
|
208
|
+
box_opts[:single_line] ||= true
|
209
|
+
box_opts[:at] ||= [xpos, ypos]
|
214
210
|
|
215
211
|
@pdf.text_box(txt.to_s, box_opts)
|
216
212
|
end
|
data/app/forms/all_options.yml
CHANGED
@@ -17,9 +17,7 @@ javascript code
|
|
17
17
|
|
18
18
|
index:
|
19
19
|
filter: name, id as text_field
|
20
|
-
|
21
|
-
deny_fields: body,email
|
22
|
-
|
20
|
+
|
23
21
|
actions: standard
|
24
22
|
|
25
23
|
actions:
|
@@ -58,6 +56,8 @@ result_set:
|
|
58
56
|
footer: custom_footer
|
59
57
|
actions_width: 100
|
60
58
|
per_page: 10
|
59
|
+
select_fields: id,name
|
60
|
+
deny_fields: body,email
|
61
61
|
|
62
62
|
dblclick:
|
63
63
|
table: model_name
|
@@ -141,6 +141,7 @@ form:
|
|
141
141
|
caption: ajax_call
|
142
142
|
control: control_name.method_to_call
|
143
143
|
when_new: false
|
144
|
+
show: default always readonly
|
144
145
|
5:
|
145
146
|
type: window
|
146
147
|
controller: cmsedit
|
@@ -196,7 +197,13 @@ form:
|
|
196
197
|
eval: ModelName.choices4_site
|
197
198
|
eval: dc_big_table 'key-name'
|
198
199
|
html:
|
199
|
-
include_blank: true
|
200
|
+
include_blank: true
|
201
|
+
90:
|
202
|
+
name: kats
|
203
|
+
type: multitext_autocomplete
|
204
|
+
search: dc_category.name
|
205
|
+
with_new: model_name
|
206
|
+
size: 30
|
200
207
|
|
201
208
|
40:
|
202
209
|
name: operation
|
@@ -245,6 +252,7 @@ form:
|
|
245
252
|
type: embedded
|
246
253
|
load: default,delay,always
|
247
254
|
form_name: dc_poll_item
|
255
|
+
readonly: no
|
248
256
|
html:
|
249
257
|
height: 800
|
250
258
|
20:
|
@@ -258,7 +266,8 @@ form:
|
|
258
266
|
40:
|
259
267
|
name: customer_id
|
260
268
|
type: text_autocomplete
|
261
|
-
search:
|
269
|
+
search: model_name.method.additional_parameter
|
270
|
+
search:
|
262
271
|
table: customer
|
263
272
|
field: custumer_name
|
264
273
|
method: search
|
data/app/forms/cms_menu.yml
CHANGED
@@ -127,10 +127,16 @@ menu:
|
|
127
127
|
controller: cmsedit
|
128
128
|
icon: trash-o lg
|
129
129
|
table: dc_removed_url
|
130
|
+
400:
|
131
|
+
caption: drgcms.dc_help.title
|
132
|
+
controller: cmsedit
|
133
|
+
icon: question-circle lg
|
134
|
+
table: dc_temp
|
135
|
+
form_name: dc_help_1
|
130
136
|
500:
|
131
137
|
caption: helpers.label.dc_journal.tabletitle
|
132
138
|
controller: cmsedit
|
133
|
-
icon:
|
139
|
+
icon: history lg
|
134
140
|
table: dc_journal
|
135
141
|
|
136
142
|
600:
|
data/app/forms/dc_big_table.yml
CHANGED
data/app/forms/dc_category.yml
CHANGED
data/app/forms/dc_design.yml
CHANGED