drg_cms 0.6.1.11 → 0.7.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +260 -0
- data/MIT-LICENSE +1 -1
- data/README.md +9 -5
- data/app/assets/javascripts/drg_cms/drg_cms.js +95 -34
- data/app/assets/javascripts/drg_cms/jquery.bpopup.js +372 -0
- data/app/assets/javascripts/drg_cms_application.js +1 -3
- data/app/assets/javascripts/drg_cms_cms.js +3 -4
- data/app/assets/stylesheets/drg_cms/drg_cms.css +37 -5
- data/app/assets/stylesheets/drg_cms/jstree.css +32 -27
- data/app/assets/stylesheets/drg_cms/select-multiple.css +6 -4
- data/app/controllers/cmsedit_controller.rb +22 -24
- data/app/controllers/dc_application_controller.rb +10 -9
- data/app/controllers/dc_common_controller.rb +14 -11
- data/app/controllers/dc_main_controller.rb +0 -1
- data/app/controls/dc_gallery_control.rb +46 -0
- data/app/controls/dc_image_control.rb +180 -0
- data/app/controls/dc_page_control.rb +3 -3
- data/app/controls/dc_poll_result_control.rb +7 -8
- data/app/controls/dc_report.rb +9 -4
- data/app/controls/design_element_settings_control.rb +88 -37
- data/app/forms/all_options.yml +18 -7
- data/app/forms/cms_menu.yml +10 -4
- data/app/forms/dc_category.yml +17 -8
- data/app/forms/dc_category_as_tree.yml +31 -0
- data/app/forms/dc_gallery.yml +1 -1
- data/app/forms/dc_image.yml +122 -0
- data/app/forms/dc_image_search.yml +72 -0
- data/app/forms/dc_page.yml +11 -8
- data/app/forms/dc_steps_template.yml +2 -1
- data/app/forms/help/dc_category_as_tree.en +4 -0
- data/app/forms/help/dc_category_as_tree.sl +5 -0
- data/app/helpers/cms_common_helper.rb +24 -16
- data/app/helpers/cms_edit_helper.rb +28 -35
- data/app/helpers/cms_helper.rb +21 -5
- data/app/helpers/cms_index_helper.rb +53 -38
- data/app/helpers/dc_application_helper.rb +95 -121
- data/app/helpers/dc_category_helper.rb +129 -0
- data/app/helpers/dc_image_helper.rb +127 -0
- data/app/models/concerns/dc_policy_rule_concern.rb +1 -1
- data/app/models/concerns/dc_user_concern.rb +12 -4
- data/app/models/dc_category.rb +62 -24
- data/app/models/dc_design.rb +5 -4
- data/app/models/dc_filter.rb +19 -18
- data/app/models/dc_image.rb +237 -0
- data/app/models/dc_internals.rb +5 -9
- data/app/models/dc_policy_role.rb +8 -8
- data/app/models/drgcms_form_fields/date_picker.rb +10 -12
- data/app/models/drgcms_form_fields/datetime_picker.rb +10 -11
- data/app/models/drgcms_form_fields/drgcms_field.rb +55 -30
- data/app/models/drgcms_form_fields/embedded.rb +11 -8
- data/app/models/drgcms_form_fields/journal_diff.rb +2 -2
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +51 -47
- data/app/models/drgcms_form_fields/select.rb +20 -14
- data/app/models/drgcms_form_fields/text_with_select.rb +5 -9
- data/app/models/drgcms_form_fields/tree_select.rb +20 -19
- data/app/renderers/dc_gallery_renderer.rb +10 -4
- data/app/renderers/dc_page_renderer.rb +7 -7
- data/app/renderers/dc_poll_renderer.rb +13 -12
- data/app/views/cmsedit/_edit_stuff.html.erb +1 -1
- data/app/views/cmsedit/edit.html.erb +1 -1
- data/app/views/cmsedit/index.html.erb +1 -1
- data/app/views/cmsedit/new.html.erb +1 -0
- data/app/views/layouts/content.html.erb +1 -1
- data/config/locales/drgcms_en.yml +16 -2
- data/config/locales/drgcms_sl.yml +15 -2
- data/config/locales/models_en.yml +33 -0
- data/config/locales/models_sl.yml +44 -1
- data/drg_cms.gemspec +3 -3
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +19 -5
- data/lib/generators/convert_to_ar/USAGE +8 -0
- data/lib/generators/convert_to_ar/convert_to_ar_generator.rb +158 -0
- data/lib/tasks/dc_cleanup.rake +20 -42
- metadata +25 -14
- data/History.log +0 -109
- data/app/assets/javascripts/drg_cms/jquery.bpopup.min.js +0 -7
- data/app/views/layouts/__cmsedit.html.erb +0 -16
@@ -113,7 +113,8 @@ def show
|
|
113
113
|
ret = call_callback_method(m)
|
114
114
|
if ret.class == FalseClass
|
115
115
|
@form['readonly'] = nil # must be
|
116
|
-
|
116
|
+
flash[:error] ||= t('drgcms.not_authorized')
|
117
|
+
return index
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
@@ -271,7 +272,7 @@ def create
|
|
271
272
|
# Prevent double form submit
|
272
273
|
params[:form_time_stamp] = params[:form_time_stamp].to_i
|
273
274
|
session[:form_time_stamp] ||= 0
|
274
|
-
return index if params[:form_time_stamp] <= session[:form_time_stamp]
|
275
|
+
return index if params[:form_time_stamp] <= session[:form_time_stamp] && !Rails.env.test?
|
275
276
|
|
276
277
|
session[:form_time_stamp] = params[:form_time_stamp]
|
277
278
|
create_new_empty_record
|
@@ -385,7 +386,7 @@ def destroy
|
|
385
386
|
save_journal(:delete)
|
386
387
|
flash[:info] = t('drgcms.record_deleted')
|
387
388
|
# after_delete callback
|
388
|
-
if (m = callback_method('after_delete') )
|
389
|
+
if (m = callback_method('after_delete') )
|
389
390
|
call_callback_method(m)
|
390
391
|
elsif params['after-delete'].to_s.match('return_to')
|
391
392
|
params[:return_to] = params['after-delete']
|
@@ -613,7 +614,7 @@ def save_journal(operation, changes = {})
|
|
613
614
|
|
614
615
|
if (operation != :update) || changes.size > 0
|
615
616
|
# determine site_id
|
616
|
-
site_id = @record.site_id if @record.respond_to?('site_id')
|
617
|
+
site_id = @record.site_id if @record && @record.respond_to?('site_id')
|
617
618
|
site_id = dc_get_site._id if site_id.nil? && dc_get_site
|
618
619
|
|
619
620
|
DcJournal.create(site_id: site_id,
|
@@ -637,8 +638,9 @@ def callback_method(key) #:nodoc:
|
|
637
638
|
callback = case
|
638
639
|
when params['data'] && params['data'][data_key] then params['data'][data_key]
|
639
640
|
# dc_ + key method is present then call it automatically
|
640
|
-
when @form.dig('
|
641
|
+
when @form.dig('permissions', key) then @form['permissions'][key]
|
641
642
|
when respond_to?('dc_' + key) then 'dc_' + key
|
643
|
+
when respond_to?(key) then key
|
642
644
|
when params[data_key] then params[data_key]
|
643
645
|
else nil
|
644
646
|
end
|
@@ -843,24 +845,20 @@ def process_collections #:nodoc
|
|
843
845
|
check_sort_options()
|
844
846
|
end
|
845
847
|
# result set is defined by filter method in control object
|
846
|
-
form_filter = @form['result_set']['filter']
|
847
|
-
if form_filter
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
@records = @records.page(params[:page]).per(per_page) if per_page > 0
|
861
|
-
end
|
862
|
-
elsif form_filter != 'dc_filter'
|
863
|
-
Rails.logger.error "Error: result_set:filter: #{@form['result_set']['filter']} not found in controls!"
|
848
|
+
form_filter = @form['result_set']['filter'] || 'default_filter'
|
849
|
+
if respond_to?(form_filter)
|
850
|
+
@records = send(form_filter)
|
851
|
+
# something went wrong. flash[] should have explanation.
|
852
|
+
if @records.class == FalseClass
|
853
|
+
@records = []
|
854
|
+
render(action: :index)
|
855
|
+
return true
|
856
|
+
end
|
857
|
+
process_select_and_deny_fields
|
858
|
+
# pagination but only if not already set
|
859
|
+
unless (@form['table'] == 'dc_memory' || (@records.respond_to?(:options) && @records.options[:limit]))
|
860
|
+
per_page = (@form['result_set']['per_page'] || 25).to_i
|
861
|
+
@records = @records.page(params[:page]).per(per_page) if per_page > 0
|
864
862
|
end
|
865
863
|
else
|
866
864
|
if @tables.size > 1
|
@@ -871,7 +869,7 @@ def process_collections #:nodoc
|
|
871
869
|
@records = rec.send(embedded_field_name) # current embedded set
|
872
870
|
# sort by order if order field is present in model
|
873
871
|
if @tables.last[1].classify.constantize.respond_to?(:order)
|
874
|
-
@records = @records.order_by(
|
872
|
+
@records = @records.order_by(order: 1)
|
875
873
|
end
|
876
874
|
end
|
877
875
|
end
|
@@ -27,7 +27,6 @@
|
|
27
27
|
##########################################################################
|
28
28
|
class DcApplicationController < ActionController::Base
|
29
29
|
protect_from_forgery with: :null_session, only: Proc.new { |c| c.request.format.json? }
|
30
|
-
before_action :dc_reload_patches if Rails.env.development?
|
31
30
|
before_action :dc_set_locale
|
32
31
|
|
33
32
|
########################################################################
|
@@ -91,7 +90,7 @@ def dc_get_site
|
|
91
90
|
|
92
91
|
@site = DcSite.find_by(name: uri.host)
|
93
92
|
# Site can be aliased
|
94
|
-
if @site
|
93
|
+
if @site&.alias_for.present?
|
95
94
|
@site = DcSite.find_by(name: @site.alias_for)
|
96
95
|
end
|
97
96
|
# Development environment. Check if site with name test exists and use
|
@@ -162,14 +161,15 @@ protected
|
|
162
161
|
############################################################################
|
163
162
|
def dc_user_can(permission, table = params[:table])
|
164
163
|
table = table.underscore
|
165
|
-
cache_key = ['dc_permission', table,
|
166
|
-
permissions =
|
164
|
+
cache_key = ['dc_permission', table, dc_get_site.id]
|
165
|
+
permissions = DrgCms.cache_read(cache_key)
|
167
166
|
if permissions.nil?
|
168
167
|
permissions = DcPermission.permissions_for_table(table)
|
169
|
-
|
168
|
+
DrgCms.cache_write(cache_key, permissions)
|
170
169
|
end
|
171
|
-
|
172
|
-
|
170
|
+
return false if session[:user_roles].nil?
|
171
|
+
|
172
|
+
session[:user_roles].inject(false) { |r, rule| break true if permissions[rule] && permissions[rule] >= permission }
|
173
173
|
end
|
174
174
|
|
175
175
|
####################################################################
|
@@ -424,7 +424,7 @@ end
|
|
424
424
|
# decamelize_type(ModelName) # 'ModelName' => 'model_name'
|
425
425
|
########################################################################
|
426
426
|
def decamelize_type(model_string)
|
427
|
-
model_string ? model_string.underscore : nil
|
427
|
+
model_string ? model_string.to_s.underscore : nil
|
428
428
|
end
|
429
429
|
|
430
430
|
####################################################################
|
@@ -439,7 +439,8 @@ def dc_error_messages_for(document)
|
|
439
439
|
|
440
440
|
msg = ''
|
441
441
|
document.errors.each do |error|
|
442
|
-
label = t("helpers.label.#{decamelize_type(document.class)}.#{error.attribute}"
|
442
|
+
label = t("helpers.label.#{decamelize_type(document.class)}.#{error.attribute}")
|
443
|
+
label = error.attribute if label.match(/translation missing/i)
|
443
444
|
msg << "<li>#{label} : #{error.message}</li>"
|
444
445
|
end
|
445
446
|
|
@@ -116,7 +116,7 @@ def toggle_edit_mode
|
|
116
116
|
end
|
117
117
|
url << (url.match(/\?/) ? '&' : '?')
|
118
118
|
url << "return_to_ypos=#{ypos}"
|
119
|
-
redirect_to
|
119
|
+
redirect_to(url, allow_other_host: true)
|
120
120
|
end
|
121
121
|
|
122
122
|
####################################################################
|
@@ -124,19 +124,20 @@ end
|
|
124
124
|
####################################################################
|
125
125
|
def process_login
|
126
126
|
# Somebody is probably playing
|
127
|
-
return dc_render_404 unless ( params
|
127
|
+
return dc_render_404 unless ( params.dig(:record, :username) && params.dig(:record, :password) )
|
128
128
|
|
129
|
-
|
129
|
+
return_to = request.env['HTTP_REFERER'] || '/'
|
130
|
+
if params[:record][:password].present? #password must not be empty
|
130
131
|
user = DcUser.find_by(username: params[:record][:username], active: true)
|
131
|
-
if user
|
132
|
+
if user && user.authenticate(params[:record][:password])
|
132
133
|
fill_login_data(user, params[:record][:remember_me].to_i == 1)
|
133
|
-
return redirect_to
|
134
|
+
return redirect_to(params[:return_to] || return_to, allow_other_host: true)
|
134
135
|
else
|
135
136
|
clear_login_data # on the safe side
|
136
137
|
end
|
137
138
|
end
|
138
139
|
flash[:error] = t('drgcms.invalid_username')
|
139
|
-
redirect_to
|
140
|
+
redirect_to return_to
|
140
141
|
end
|
141
142
|
|
142
143
|
####################################################################
|
@@ -144,7 +145,7 @@ end
|
|
144
145
|
####################################################################
|
145
146
|
def logout
|
146
147
|
clear_login_data
|
147
|
-
redirect_to
|
148
|
+
redirect_to(params[:return_to] || '/', allow_other_host: true)
|
148
149
|
end
|
149
150
|
|
150
151
|
####################################################################
|
@@ -156,14 +157,14 @@ def login
|
|
156
157
|
user = DcUser.find(cookies.signed[:remember_me])
|
157
158
|
if user and user.active
|
158
159
|
fill_login_data(user, true)
|
159
|
-
return
|
160
|
+
return(redirect_to params[:return_to], allow_other_host: true)
|
160
161
|
else
|
161
162
|
clear_login_data # on the safe side
|
162
163
|
end
|
163
164
|
end
|
164
165
|
# Display login
|
165
166
|
route = params[:route] || 'poll'
|
166
|
-
redirect_to
|
167
|
+
redirect_to("/#{route}?poll_id=login&return_to=#{params[:return_to]}", allow_other_host: true)
|
167
168
|
end
|
168
169
|
|
169
170
|
####################################################################
|
@@ -219,8 +220,10 @@ def copy_clipboard
|
|
219
220
|
format.html do
|
220
221
|
table = CmsHelper.table_param(params)
|
221
222
|
doc = dc_find_document(table, params[:id], params[:ids])
|
222
|
-
text =
|
223
|
-
|
223
|
+
text = '<style>body {font-family: monospace;}</style><pre>'
|
224
|
+
text << "JSON:<br>[#{table},#{params[:id]},#{params[:ids]}]<br>#{doc.as_document.to_json}<br><br>"
|
225
|
+
text << "YAML:<br>#{doc.as_document.to_hash.to_yaml.gsub("\n", '<br>')}</pre>"
|
226
|
+
render plain: text
|
224
227
|
end
|
225
228
|
end
|
226
229
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2022+ 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
|
+
# DRG CMS controls for DcGallery collection
|
26
|
+
######################################################################
|
27
|
+
module DcGalleryControl
|
28
|
+
|
29
|
+
######################################################################
|
30
|
+
# Remove picture from gallery.
|
31
|
+
######################################################################
|
32
|
+
def picture_remove
|
33
|
+
unless dc_user_can(DcPermission::CAN_DELETE, 'dc_gallery')
|
34
|
+
return render json: { alert: t('drgcms.not_authorized') }
|
35
|
+
end
|
36
|
+
|
37
|
+
doc = DcGallery.find(params[:id])
|
38
|
+
pic = Rails.root.join('public', doc.picture.delete_prefix('/'))
|
39
|
+
File.delete(pic) if File.exist?(pic)
|
40
|
+
pic = Rails.root.join('public', doc.thumbnail.delete_prefix('/'))
|
41
|
+
File.delete(pic) if File.exist?(pic)
|
42
|
+
doc.delete
|
43
|
+
render json: { reload: true }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2022+ 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
|
+
# DrgcmsControls for DcImage data entry.
|
26
|
+
######################################################################
|
27
|
+
module DcImageControl
|
28
|
+
|
29
|
+
######################################################################
|
30
|
+
#
|
31
|
+
######################################################################
|
32
|
+
def search_filter
|
33
|
+
flash[:record] ||= {}
|
34
|
+
|
35
|
+
created_by = flash[:record][:created_by]
|
36
|
+
qry = created_by.present? ? DcImage.where(created_by: created_by) : DcImage.all
|
37
|
+
|
38
|
+
short_name = flash[:record][:short]
|
39
|
+
qry = qry.and(short: /#{short_name}/i) if short_name.present?
|
40
|
+
|
41
|
+
category = flash[:record][:categories]
|
42
|
+
qry = qry.and(categories: category) if category.present?
|
43
|
+
qry.limit(30).order_by(created_at: -1)
|
44
|
+
end
|
45
|
+
|
46
|
+
######################################################################
|
47
|
+
# Invoke images search. Just forward parameters and reload form. Filter parameters will
|
48
|
+
# be taken into account on reload.
|
49
|
+
######################################################################
|
50
|
+
def images_search
|
51
|
+
flash[:record] = {}
|
52
|
+
flash[:record][:short] = params[:record][:short]
|
53
|
+
flash[:record][:created_by] = params[:record][:created_by]
|
54
|
+
flash[:record][:categories] = params[:record][:categories]
|
55
|
+
|
56
|
+
url = url_for(controller: :cmsedit, table: :dc_image, form_name: :dc_image_search, field_name: params[:field_name])
|
57
|
+
render json: { url: url }
|
58
|
+
end
|
59
|
+
|
60
|
+
######################################################################
|
61
|
+
# Set some default values when new record
|
62
|
+
######################################################################
|
63
|
+
def dc_new_record
|
64
|
+
default_sizes = dc_get_site.params.dig('dc_image', 'sizes').to_s.split(',')
|
65
|
+
@record.size_ls = default_sizes.shift
|
66
|
+
@record.size_ms = default_sizes.shift
|
67
|
+
@record.size_ss = default_sizes.shift
|
68
|
+
end
|
69
|
+
|
70
|
+
######################################################################
|
71
|
+
# Save uploaded file if selected and extract properties data
|
72
|
+
######################################################################
|
73
|
+
def dc_before_save
|
74
|
+
return if @record.size_o.present? || !params[:upload_file]
|
75
|
+
|
76
|
+
input_file_name = params[:upload_file].original_filename
|
77
|
+
type = File.extname(input_file_name).to_s.downcase.gsub('.', '').strip
|
78
|
+
unless %w(jpg jpeg png gif svg webp).include?(type)
|
79
|
+
flash[:error] = t 'drgcms.dc_image.wrong_type'
|
80
|
+
return false
|
81
|
+
end
|
82
|
+
name = File.basename(input_file_name)
|
83
|
+
path = File.dirname(params[:upload_file].tempfile)
|
84
|
+
|
85
|
+
@record.img_type = dc_get_site.params.dig('dc_image', 'img_type') || type
|
86
|
+
@record.short = File.basename(input_file_name, '.*') if @record.short.blank?
|
87
|
+
@record.name = File.join(path, name)
|
88
|
+
FileUtils.mv(params[:upload_file].tempfile, @record.name, force: nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
######################################################################
|
92
|
+
# Prepare additional images
|
93
|
+
######################################################################
|
94
|
+
def dc_after_save
|
95
|
+
%w[l m s o].each { |size| image_convert(size) }
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
######################################################################
|
101
|
+
#
|
102
|
+
######################################################################
|
103
|
+
def image_convert(which)
|
104
|
+
new_file_name = "#{@record.id}-#{which}.#{@record.img_type}"
|
105
|
+
new_file_name = Rails.root.join('public', images_location, new_file_name)
|
106
|
+
new_size = @record["size_#{which}"]
|
107
|
+
# remove file if not needed
|
108
|
+
if new_size.blank?
|
109
|
+
FileUtils.rm(new_file_name) if File.exist?(new_file_name)
|
110
|
+
return
|
111
|
+
end
|
112
|
+
|
113
|
+
original_file_name = Rails.root.join('public', images_location, "#{@record.id}-o.#{@record.img_type}")
|
114
|
+
@record.name = original_file_name unless @record.name.present? && File.exist?(@record.name)
|
115
|
+
if !File.exist?(@record.name)
|
116
|
+
flash[:warning] = t 'drgcms.dc_image.no_file'
|
117
|
+
return
|
118
|
+
end
|
119
|
+
|
120
|
+
image_magick_do(new_size, new_file_name)
|
121
|
+
end
|
122
|
+
|
123
|
+
######################################################################
|
124
|
+
# Crop and resize image
|
125
|
+
#
|
126
|
+
# @new_size [String] new_size widthxheight+offsetx+offsety 300x200+1000+0
|
127
|
+
# @file_name [String] Image file name
|
128
|
+
######################################################################
|
129
|
+
def image_magick_do(new_size, file_name)
|
130
|
+
image = MiniMagick::Image.open(@record.name)
|
131
|
+
|
132
|
+
a = new_size.split(/x|\+/).map(&:to_i)
|
133
|
+
a += [0, 0] if a.size < 4
|
134
|
+
image_offset(image, a[2, 2]) if a[2, 2] != [0, 0]
|
135
|
+
|
136
|
+
img_w, img_h = image.width, image.height
|
137
|
+
new_w, new_h = a[0, 2]
|
138
|
+
img_ratio = img_w.to_f / img_h
|
139
|
+
new_ratio = new_w.to_f / new_h
|
140
|
+
formula = if new_ratio > img_ratio
|
141
|
+
"#{img_w}x#{img_w/new_ratio}+0+0"
|
142
|
+
else
|
143
|
+
"#{img_h*new_ratio}x#{img_h}+0+0"
|
144
|
+
end
|
145
|
+
image.crop(formula)
|
146
|
+
|
147
|
+
image.resize("#{new_w}x#{new_h}")
|
148
|
+
image.write(file_name)
|
149
|
+
image_reduce(file_name)
|
150
|
+
end
|
151
|
+
|
152
|
+
######################################################################
|
153
|
+
# Reduce image quality of image
|
154
|
+
######################################################################
|
155
|
+
def image_reduce(file_name)
|
156
|
+
if (quality = dc_get_site.params.dig('dc_image', 'quality').to_i) > 0
|
157
|
+
convert = MiniMagick::Tool::Convert.new
|
158
|
+
convert << file_name
|
159
|
+
convert.quality(quality)
|
160
|
+
convert << file_name
|
161
|
+
convert.call
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
######################################################################
|
166
|
+
# Offset image if requested
|
167
|
+
######################################################################
|
168
|
+
def image_offset(image, offset)
|
169
|
+
img_w, img_h = image.width - offset[0], image.height - offset[1]
|
170
|
+
image.crop("#{img_w}x#{img_h}+#{offset[0]}+#{offset[1]}")
|
171
|
+
end
|
172
|
+
|
173
|
+
######################################################################
|
174
|
+
# Returns location of images files relative to public directory
|
175
|
+
######################################################################
|
176
|
+
def images_location
|
177
|
+
dc_get_site.params.dig('dc_image', 'location') || 'images'
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
@@ -22,14 +22,14 @@
|
|
22
22
|
#++
|
23
23
|
|
24
24
|
######################################################################
|
25
|
-
#
|
25
|
+
# DRG Controls for DcPage model.
|
26
26
|
######################################################################
|
27
27
|
module DcPageControl
|
28
28
|
|
29
29
|
######################################################################
|
30
30
|
# Called when new empty record is created
|
31
31
|
######################################################################
|
32
|
-
def dc_new_record
|
32
|
+
def dc_new_record
|
33
33
|
# Called from menu. Fill in values, that could be obtained from menu
|
34
34
|
if params[:from_menu]
|
35
35
|
# find menu and submenu. Menu class is defined in Site.
|
@@ -59,7 +59,7 @@ end
|
|
59
59
|
######################################################################
|
60
60
|
# Called just after record is saved to DB.
|
61
61
|
######################################################################
|
62
|
-
def dc_after_save
|
62
|
+
def dc_after_save
|
63
63
|
if params.dig(:_record,:_update_menu).to_s == '1'
|
64
64
|
dc_get_site.menu_klass.update_menu_item_link(@record)
|
65
65
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#encoding: utf-8
|
2
1
|
#--
|
3
2
|
# Copyright (c) 2014+ Damjan Rems
|
4
3
|
#
|
@@ -23,14 +22,14 @@
|
|
23
22
|
#++
|
24
23
|
|
25
24
|
######################################################################
|
26
|
-
#
|
25
|
+
# DRG Controls for DcPage model.
|
27
26
|
######################################################################
|
28
27
|
module DcPollResultControl
|
29
28
|
|
30
29
|
######################################################################
|
31
30
|
# Filter result data when filter is set
|
32
31
|
######################################################################
|
33
|
-
def poll_filter
|
32
|
+
def poll_filter
|
34
33
|
get_query
|
35
34
|
end
|
36
35
|
|
@@ -55,15 +54,15 @@ def do_export
|
|
55
54
|
# ensure, that fields are always in same order
|
56
55
|
data = YAML.load(doc.data)
|
57
56
|
if c.blank?
|
58
|
-
data.each {|k,v| keys << k}
|
57
|
+
data.each { |k, v| keys << k }
|
59
58
|
c << I18n.t('helpers.label.dc_poll_result.created_at') + "\t"
|
60
59
|
c << keys.join("\t") + "\n"
|
61
60
|
end
|
62
61
|
c << doc.created_at.strftime(I18n.t('date.formats.default') ) + "\t"
|
63
|
-
keys.each {|k| c << data[k] + "\t"}
|
62
|
+
keys.each { |k| c << data[k] + "\t" }
|
64
63
|
c << "\n"
|
65
64
|
end
|
66
|
-
File.write(Rails.root.join('public','export.csv'), c)
|
65
|
+
File.write(Rails.root.join('public', 'export.csv'), c)
|
67
66
|
dc_render_ajax(operation: :window, value: 'export.csv')
|
68
67
|
end
|
69
68
|
|
@@ -71,8 +70,8 @@ private
|
|
71
70
|
######################################################################
|
72
71
|
# Creates query for Poll results
|
73
72
|
######################################################################
|
74
|
-
def get_query
|
75
|
-
if params.dig(:record
|
73
|
+
def get_query
|
74
|
+
if params.dig(:record, :dc_poll_id).nil?
|
76
75
|
qry = DcPollResult.all
|
77
76
|
else
|
78
77
|
qry = DcPollResult.where(dc_poll_id: params[:record][:dc_poll_id])
|
data/app/controls/dc_report.rb
CHANGED
@@ -55,7 +55,7 @@ def print
|
|
55
55
|
render json: { msg_error: t('drgcms.runtime_error') } and return
|
56
56
|
end
|
57
57
|
|
58
|
-
pdf_file = "tmp/
|
58
|
+
pdf_file = "tmp/document-#{Time.now.to_i}.pdf"
|
59
59
|
@pdf.render_file Rails.root.join('public', pdf_file)
|
60
60
|
|
61
61
|
render json: print_response(pdf_file)
|
@@ -142,14 +142,19 @@ def export_to_excel(report_id)
|
|
142
142
|
columns.each_with_index do |column, i|
|
143
143
|
caption = column.last['caption'] || column.last['label']
|
144
144
|
label = t(caption)
|
145
|
-
excel[n, i] = label.match(
|
145
|
+
excel[n, i] = label.match(/translation missing/i) ? caption : label
|
146
146
|
end
|
147
147
|
|
148
148
|
data_filter.each do |doc|
|
149
149
|
n += 1
|
150
150
|
columns.each_with_index do |column, i|
|
151
|
-
value = doc[column.last['name']]
|
152
|
-
value = value.
|
151
|
+
value = doc[column.last['name']]
|
152
|
+
value = case value.class.to_s
|
153
|
+
when /Integer|Float/ then value
|
154
|
+
when /Decimal/ then value.to_s.to_f
|
155
|
+
else
|
156
|
+
value.to_s.gsub('<br>', ";").gsub(/\<\/strong\>|\<strong\>|\<\/b\>|\<b\>/, '')
|
157
|
+
end
|
153
158
|
excel[n, i] = value
|
154
159
|
end
|
155
160
|
end
|