drg_cms 0.6.1.4 → 0.6.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +203 -24
- data/app/assets/fonts/ibm-plex-sans-300.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-400.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-500.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-600.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-700.woff2 +0 -0
- data/app/assets/fonts/ibm-plex-sans-italic.woff2 +0 -0
- data/app/assets/javascripts/drg_cms/drg_cms.js +229 -95
- data/app/assets/stylesheets/drg_cms/drg_cms.css +608 -542
- data/app/assets/stylesheets/drg_cms_application.css +1 -1
- data/app/assets/stylesheets/drg_cms_cms.css +1 -4
- data/app/controllers/cmsedit_controller.rb +54 -127
- data/app/controllers/dc_application_controller.rb +17 -2
- data/app/controllers/dc_common_controller.rb +13 -7
- data/app/controls/browse_models_control.rb +15 -26
- data/app/controls/cmsedit_control.rb +125 -0
- data/app/controls/dc_help_control.rb +13 -1
- data/app/controls/dc_page_control.rb +0 -1
- data/app/controls/dc_poll_result_control.rb +1 -1
- data/app/controls/dc_report.rb +1 -1
- data/app/controls/design_element_settings_control.rb +1 -1
- data/app/forms/all_options.yml +23 -7
- data/app/forms/cms_menu.yml +24 -24
- data/app/forms/dc_big_table.yml +0 -2
- data/app/forms/dc_big_table_value.yml +0 -2
- data/app/forms/dc_browse_fields.yml +13 -9
- data/app/forms/dc_design.yml +1 -2
- data/app/forms/dc_folder_permission.yml +0 -2
- data/app/forms/dc_help_1.yml +2 -1
- data/app/forms/dc_json_ld.yml +0 -3
- data/app/forms/dc_menu.yml +6 -12
- data/app/forms/dc_menu_item.yml +1 -3
- data/app/forms/dc_page.yml +1 -2
- data/app/forms/dc_policy.yml +2 -5
- data/app/forms/dc_poll.yml +10 -16
- data/app/forms/dc_poll_result_export.yml +1 -1
- data/app/forms/dc_seo.yml +1 -2
- data/app/forms/dc_simple_menu.yml +1 -2
- data/app/forms/dc_site.yml +5 -7
- data/app/helpers/cms_common_helper.rb +8 -6
- data/app/helpers/cms_edit_helper.rb +61 -53
- data/app/helpers/cms_helper.rb +78 -42
- data/app/helpers/cms_index_helper.rb +198 -137
- data/app/helpers/dc_application_helper.rb +65 -43
- data/app/models/concerns/dc_page_concern.rb +1 -1
- data/app/models/concerns/dc_site_concern.rb +9 -3
- data/app/models/dc_big_table.rb +2 -2
- data/app/models/dc_filter.rb +45 -37
- data/app/models/dc_json_ld.rb +1 -1
- data/app/models/dc_part.rb +19 -9
- data/app/models/dc_site.rb +0 -1
- data/app/models/dc_temp.rb +7 -0
- data/app/models/drgcms_form_fields/comment.rb +11 -2
- data/app/models/drgcms_form_fields/drgcms_field.rb +10 -4
- data/app/models/drgcms_form_fields/link_to.rb +1 -1
- data/app/models/drgcms_form_fields/multitext_autocomplete.rb +5 -5
- data/app/models/drgcms_form_fields/readonly.rb +3 -0
- data/app/models/drgcms_form_fields/select.rb +14 -14
- data/app/models/drgcms_form_fields/text_autocomplete.rb +19 -11
- data/app/renderers/dc_part_renderer.rb +1 -1
- data/app/renderers/dc_poll_renderer.rb +1 -1
- data/app/views/cmsedit/_edit_stuff.html.erb +12 -12
- data/app/views/cmsedit/_form.html.erb +3 -2
- data/app/views/cmsedit/_result.html.erb +21 -18
- data/app/views/cmsedit/login.html.erb +1 -1
- data/app/views/dc_common/paste_clipboard.html.erb +1 -1
- data/app/views/layouts/cms.html.erb +3 -5
- data/config/locales/drgcms_en.yml +5 -3
- data/config/locales/drgcms_sl.yml +5 -3
- data/config/locales/kaminari.yml +1 -1
- data/config/locales/models_sl.yml +1 -0
- data/drg_cms.gemspec +1 -1
- data/lib/drg_cms/version.rb +1 -1
- data/lib/drg_cms.rb +6 -12
- metadata +10 -5
- data/app/views/cmsedit/__remove_edit_stuff.js.erb +0 -6
- data/app/views/cmsedit/__show.html.erb +0 -21
@@ -41,9 +41,10 @@
|
|
41
41
|
# its control's would be found in model_embedded_controls.rb. By convention module names
|
42
42
|
# are declared in camel case, so our dc_page_controls.rb declares DrgcmsControls::DcPageControls module.
|
43
43
|
#
|
44
|
-
# Controls (among other) may contain
|
44
|
+
# Controls (among other) may contain 7 callback methods.
|
45
45
|
# These methods are:
|
46
46
|
# * dc_new_record
|
47
|
+
# * dc_dup_record
|
47
48
|
# * dc_before_edit
|
48
49
|
# * dc_before_save
|
49
50
|
# * dc_after_save
|
@@ -67,7 +68,7 @@
|
|
67
68
|
# if dc_user_can(DcPermission::CAN_READ)
|
68
69
|
# dc_page.where(created_by: session[:user_id])
|
69
70
|
# else
|
70
|
-
# flash[:error] = '
|
71
|
+
# flash[:error] = 'User can not perform this operation!'
|
71
72
|
# nil
|
72
73
|
# end
|
73
74
|
# end
|
@@ -76,7 +77,6 @@
|
|
76
77
|
########################################################################
|
77
78
|
class CmseditController < DcApplicationController
|
78
79
|
before_action :check_authorization, :except => [:login, :logout, :test, :run]
|
79
|
-
before_action :dc_reload_patches if Rails.env.development?
|
80
80
|
protect_from_forgery with: :null_session, only: Proc.new { |c| c.request.format.json? }
|
81
81
|
|
82
82
|
layout 'cms'
|
@@ -99,7 +99,7 @@ end
|
|
99
99
|
########################################################################
|
100
100
|
# Filter action.
|
101
101
|
########################################################################
|
102
|
-
def
|
102
|
+
def _filter
|
103
103
|
index
|
104
104
|
end
|
105
105
|
|
@@ -128,12 +128,10 @@ end
|
|
128
128
|
# Login can be called directly with url http://site.com/cmsedit/login
|
129
129
|
########################################################################
|
130
130
|
def login
|
131
|
-
if
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
render action: 'login', layout: 'cms'
|
136
|
-
end
|
131
|
+
return set_test_site if params[:id] == 'test'
|
132
|
+
|
133
|
+
session[:edit_mode] = 0 if !params[:ok]
|
134
|
+
render action: 'login', layout: 'cms'
|
137
135
|
end
|
138
136
|
|
139
137
|
########################################################################
|
@@ -234,6 +232,7 @@ end
|
|
234
232
|
# duplicating document and is subroutine of create action.
|
235
233
|
########################################################################
|
236
234
|
def duplicate_document(source)
|
235
|
+
params['dup_fields'] += ',' if params['dup_fields'] # for easier field matching
|
237
236
|
dest = {}
|
238
237
|
source.attribute_names.each do |attribute_name|
|
239
238
|
next if attribute_name == '_id' # don't duplicate _id
|
@@ -258,12 +257,9 @@ def duplicate_document(source)
|
|
258
257
|
end
|
259
258
|
|
260
259
|
########################################################################
|
261
|
-
# Create (or duplicate) action.
|
260
|
+
# Create (or duplicate) action.
|
262
261
|
########################################################################
|
263
262
|
def create
|
264
|
-
# abusing create for turning filter on
|
265
|
-
return index if params[:filter].to_s == 'on'
|
266
|
-
|
267
263
|
# not authorized
|
268
264
|
unless dc_user_can(DcPermission::CAN_CREATE)
|
269
265
|
flash[:error] = t('drgcms.not_authorized')
|
@@ -294,12 +290,11 @@ def create
|
|
294
290
|
end
|
295
291
|
else # duplicate record
|
296
292
|
find_record
|
297
|
-
params['dup_fields'] += ',' if params['dup_fields'] # for easier field matching
|
298
293
|
new_doc = duplicate_document(@record)
|
299
294
|
create_new_empty_record(new_doc)
|
300
|
-
|
295
|
+
if (m = callback_method('dup_record')) then call_callback_method(m) end
|
296
|
+
update_standards
|
301
297
|
@record.save!
|
302
|
-
|
303
298
|
index
|
304
299
|
end
|
305
300
|
end
|
@@ -331,10 +326,8 @@ def update
|
|
331
326
|
end
|
332
327
|
end
|
333
328
|
|
334
|
-
if dc_user_can(DcPermission::CAN_EDIT_ALL)
|
335
|
-
(
|
336
|
-
@record.created_by == session[:user_id] and
|
337
|
-
dc_user_can(DcPermission::CAN_EDIT) )
|
329
|
+
if dc_user_can(DcPermission::CAN_EDIT_ALL) ||
|
330
|
+
(@record.respond_to?('created_by') && @record.created_by == session[:user_id] && dc_user_can(DcPermission::CAN_EDIT))
|
338
331
|
|
339
332
|
if save_data
|
340
333
|
params[:return_to] = 'index' if params[:commit] == t('drgcms.save&back') # save & back
|
@@ -441,7 +434,7 @@ def run
|
|
441
434
|
control_name, method_name = params[:control].split('.')
|
442
435
|
if method_name.nil?
|
443
436
|
method_name = control_name
|
444
|
-
control_name = params
|
437
|
+
control_name = CmsHelper.table_param(params)
|
445
438
|
end
|
446
439
|
# extend with control methods
|
447
440
|
extend_with_control_module(control_name)
|
@@ -478,7 +471,7 @@ def can_process_run
|
|
478
471
|
response = send(:dc_can_process)
|
479
472
|
return response unless response.class == Array
|
480
473
|
else
|
481
|
-
response = [DcPermission::CAN_VIEW, params
|
474
|
+
response = [DcPermission::CAN_VIEW, CmsHelper.table_param(params) || 'dc_memory']
|
482
475
|
end
|
483
476
|
dc_user_can *response
|
484
477
|
end
|
@@ -571,19 +564,19 @@ end
|
|
571
564
|
# Read DRG form into @form object. Subroutine of check_authorization.
|
572
565
|
########################################################################
|
573
566
|
def read_drg_form
|
574
|
-
table_name = decamelize_type(params
|
575
|
-
@tables = table_name.split(';').inject([]) { |r,v| r << [(v.classify.constantize rescue nil), v] }
|
567
|
+
table_name = decamelize_type(CmsHelper.table_param(params).strip)
|
568
|
+
@tables = table_name.split(';').inject([]) { |r, v| r << [(v.classify.constantize rescue nil), v] }
|
576
569
|
|
577
570
|
# split ids passed when embedded document
|
578
571
|
ids = params[:ids].to_s.strip.downcase
|
579
572
|
@ids = ids.split(';').inject([]) { |r,v| r << v }
|
580
573
|
|
581
574
|
# form_name defaults to last table specified
|
582
|
-
form_name = params
|
575
|
+
form_name = CmsHelper.form_param(params) || @tables.last[1]
|
583
576
|
@form_js = ''
|
584
577
|
|
585
578
|
# dynamically generated form
|
586
|
-
@form = if params
|
579
|
+
@form = if CmsHelper.form_param(params) == 'method'
|
587
580
|
dc_eval_class_method(params[:form_method], params)
|
588
581
|
else
|
589
582
|
form_file_name = dc_find_form_file(form_name)
|
@@ -623,7 +616,7 @@ end
|
|
623
616
|
############################################################################
|
624
617
|
def extend_with_control_module(control_name = @form['controls'] || @form['control'])
|
625
618
|
# May include embedded forms so ; => _
|
626
|
-
control_name ||= params
|
619
|
+
control_name ||= CmsHelper.table_param(params).gsub(';','_')
|
627
620
|
control_name += '_control' unless control_name.match(/control$|report$/i)
|
628
621
|
# p '************', control_name
|
629
622
|
controls = load_controls_module(control_name)
|
@@ -644,9 +637,10 @@ end
|
|
644
637
|
# load DRG form.
|
645
638
|
############################################################################
|
646
639
|
def check_authorization
|
647
|
-
params[:table] ||= params[:
|
640
|
+
params[:table] ||= params[:t] || CmsHelper.form_param(params)
|
648
641
|
# Only show menu
|
649
642
|
return login if params[:id].in?(%w(login logout test))
|
643
|
+
|
650
644
|
table = params[:table].to_s.strip.downcase
|
651
645
|
set_default_guest_user_role if session[:user_roles].nil?
|
652
646
|
# request shouldn't pass
|
@@ -688,7 +682,7 @@ def create_new_empty_record(initial_data = nil) #:nodoc:
|
|
688
682
|
@record = @tables.first[0].new(initial_data)
|
689
683
|
else
|
690
684
|
rec = @tables.first[0].find(@ids.first) # top most record
|
691
|
-
1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) } # find embedded
|
685
|
+
1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) } # find embedded children by ids
|
692
686
|
@record = rec.send(@tables.last[1].pluralize).new(initial_data) # new record
|
693
687
|
end
|
694
688
|
end
|
@@ -715,8 +709,9 @@ end
|
|
715
709
|
########################################################################
|
716
710
|
def save_journal(operation, changes = {})
|
717
711
|
if operation == :delete
|
718
|
-
@record.attributes.each {|k,v| changes[k] = v}
|
712
|
+
@record.attributes.each { |k, v| changes[k] = v }
|
719
713
|
end
|
714
|
+
changes.except!('created_at', 'updated_at', 'created_by', 'updated_by')
|
720
715
|
|
721
716
|
if (operation != :update) || changes.size > 0
|
722
717
|
# determine site_id
|
@@ -740,7 +735,7 @@ end
|
|
740
735
|
# Returns callback method name or nil if not defined.
|
741
736
|
########################################################################
|
742
737
|
def callback_method(key) #:nodoc:
|
743
|
-
data_key = key.gsub('_','-') # convert _ to -
|
738
|
+
data_key = key.gsub('_', '-') # convert _ to -
|
744
739
|
callback = case
|
745
740
|
when params['data'] && params['data'][data_key] then params['data'][data_key]
|
746
741
|
# dc_ + key method is present then call it automatically
|
@@ -784,9 +779,10 @@ end
|
|
784
779
|
def process_return_to(return_to)
|
785
780
|
script = case
|
786
781
|
when return_to == 'index' then return index
|
782
|
+
when return_to.match(/eval=/i) then return_to.sub('eval=', '')
|
787
783
|
when return_to.match(/parent\.reload/i) then 'parent.location.href=parent.location.href;'
|
788
784
|
when return_to.match(/reload/i) then 'location.href=location.href;'
|
789
|
-
when return_to.match(/close/i) then 'window.close();'
|
785
|
+
when return_to.match(/window.close/i) then 'window.close();'
|
790
786
|
when return_to.match(/none/i) then return
|
791
787
|
else "location.href='#{return_to}'"
|
792
788
|
end
|
@@ -830,6 +826,7 @@ def save_data
|
|
830
826
|
value = DrgcmsFormFields.const_get(v['type'].camelize).get_data(params, v['name'])
|
831
827
|
@record.send("#{v['name']}=", value)
|
832
828
|
end
|
829
|
+
|
833
830
|
# before_save callback
|
834
831
|
if (m = callback_method('before_save') )
|
835
832
|
ret = call_callback_method(m)
|
@@ -842,7 +839,7 @@ def save_data
|
|
842
839
|
update_standards() if changes.size > 0 # update only if there has been some changes
|
843
840
|
if (saved = @record.save)
|
844
841
|
operation = @record.new_record? ? :new : :update
|
845
|
-
save_journal(operation,
|
842
|
+
save_journal(operation, @record.previous_changes)
|
846
843
|
# after_save callback
|
847
844
|
if (m = callback_method('after_save') ) then call_callback_method(m) end
|
848
845
|
end
|
@@ -871,23 +868,12 @@ end
|
|
871
868
|
########################################################################
|
872
869
|
# Will check and set sorting options for current result set. Subroutine of index method.
|
873
870
|
########################################################################
|
874
|
-
def check_sort_options
|
871
|
+
def check_sort_options #:nodoc:
|
875
872
|
table_name = @tables.first[1]
|
876
|
-
|
877
|
-
sort, direction = old_sort.split(' ')
|
873
|
+
return if session[table_name][:sort].nil? || @records.class != Mongoid::Criteria
|
878
874
|
|
879
|
-
|
880
|
-
|
881
|
-
if params['sort'] == sort
|
882
|
-
direction = (direction == '1') ? '-1' : '1'
|
883
|
-
end
|
884
|
-
direction ||= '1'
|
885
|
-
sort = params[:sort]
|
886
|
-
session[table_name][:sort] = "#{params['sort']} #{direction}"
|
887
|
-
session[table_name][:page] = 1
|
888
|
-
end
|
889
|
-
@records.sort( sort => direction.to_i ) if session[table_name][:sort] && @records.class == Mongoid::Criteria
|
890
|
-
params['sort'] = nil # otherwise there is problem with other links
|
875
|
+
sort, direction = session[table_name][:sort].split(' ')
|
876
|
+
@records = @records.order_by( sort => direction.to_i )
|
891
877
|
end
|
892
878
|
|
893
879
|
########################################################################
|
@@ -913,82 +899,20 @@ def user_sort_options(model) #:nodoc:
|
|
913
899
|
{ field.to_sym => direction.to_i }
|
914
900
|
end
|
915
901
|
|
916
|
-
########################################################################
|
917
|
-
# Will set session[table_name][:filter] and save last filter settings to session.
|
918
|
-
# subroutine of check_filter_options.
|
919
|
-
########################################################################
|
920
|
-
def set_session_filter(table_name)
|
921
|
-
# models that can not be filtered (for now)
|
922
|
-
return if %w(dc_temp dc_memory).include?(params[:table])
|
923
|
-
# clear filter
|
924
|
-
if params[:filter] == 'off'
|
925
|
-
session[table_name][:filter] = nil
|
926
|
-
return
|
927
|
-
end
|
928
|
-
# field_name should exist on set filter condition
|
929
|
-
return if params[:filter_oper] && params[:filter_field].blank?
|
930
|
-
|
931
|
-
filter_value = if params[:filter_value].nil?
|
932
|
-
#NIL indicates that no filtering is needed
|
933
|
-
'#NIL'
|
934
|
-
else
|
935
|
-
if params[:filter_value].class == String and params[:filter_value][0] == '@'
|
936
|
-
# Internal value. Remove leading @ and evaluate expression
|
937
|
-
expression = DcInternals.get(params[:filter_value])
|
938
|
-
eval(expression) rescue nil
|
939
|
-
else
|
940
|
-
# No filter when empty
|
941
|
-
params[:filter_value] == '' ? '#NIL' : params[:filter_value]
|
942
|
-
end
|
943
|
-
end
|
944
|
-
# if filter field parameter is omitted then just set filter value
|
945
|
-
session[table_name][:filter] =
|
946
|
-
if params[:filter_field].nil?
|
947
|
-
saved = YAML.load(session[table_name][:filter])
|
948
|
-
saved['value'] = filter_value
|
949
|
-
saved.to_yaml
|
950
|
-
else
|
951
|
-
# as field defined. Split name and alternative input field
|
952
|
-
field = if params[:filter_field].match(' as ')
|
953
|
-
params[:filter_input] = params[:filter_field].split(' as ').last.strip
|
954
|
-
params[:filter_field].split(' as ').first.strip
|
955
|
-
else
|
956
|
-
params[:filter_field]
|
957
|
-
end
|
958
|
-
|
959
|
-
{'field' => field,
|
960
|
-
'operation' => params[:filter_oper],
|
961
|
-
'value' => filter_value,
|
962
|
-
'input' => params[:filter_input],
|
963
|
-
'table' => table_name }.to_yaml
|
964
|
-
end
|
965
|
-
# must be. Otherwise kaminari includes parames on paging links
|
966
|
-
params[:filter] = nil
|
967
|
-
params[:filter_id] = nil
|
968
|
-
params[:filter_oper] = nil
|
969
|
-
params[:filter_input] = nil
|
970
|
-
params[:filter_field] = nil
|
971
|
-
end
|
972
|
-
|
973
902
|
########################################################################
|
974
903
|
# Will check and set current filter options for result set. Subroutine of index method.
|
975
904
|
########################################################################
|
976
|
-
def check_filter_options
|
977
|
-
table_name =
|
978
|
-
model =
|
905
|
+
def check_filter_options #:nodoc:
|
906
|
+
table_name = CmsHelper.table_param(params).strip.split(';').first.underscore
|
907
|
+
model = table_name.classify.constantize
|
979
908
|
session[table_name] ||= {}
|
980
909
|
# page is set
|
981
910
|
session[table_name][:page] = params[:page] if params[:page]
|
982
|
-
# new filter is applied
|
983
|
-
if params[:filter]
|
984
|
-
set_session_filter(table_name)
|
985
|
-
session[table_name][:page] = 1
|
986
|
-
end
|
987
911
|
# if data model has field dc_site_id ensure that only documents which belong to the site are selected.
|
988
912
|
site_id = dc_get_site._id if dc_get_site
|
989
913
|
|
990
914
|
# don't filter site if no dc_site_id field or user is ADMIN
|
991
|
-
site_id = nil if !model.method_defined?('dc_site_id')
|
915
|
+
site_id = nil if !model.method_defined?('dc_site_id') || dc_user_can(DcPermission::CAN_ADMIN)
|
992
916
|
site_id = nil if session[table_name][:filter].to_s.match('dc_site_id')
|
993
917
|
|
994
918
|
if @records = DcFilter.get_filter(session[table_name][:filter])
|
@@ -998,7 +922,7 @@ def check_filter_options() #:nodoc:
|
|
998
922
|
end
|
999
923
|
process_select_and_deny_fields
|
1000
924
|
# pagination if required
|
1001
|
-
per_page = (@form['result_set']['per_page'] ||
|
925
|
+
per_page = (@form['result_set']['per_page'] || 25).to_i
|
1002
926
|
@records = @records.page(session[table_name][:page]).per(per_page) if per_page > 0
|
1003
927
|
end
|
1004
928
|
|
@@ -1006,31 +930,35 @@ end
|
|
1006
930
|
# Process index action for normal collections.
|
1007
931
|
########################################################################
|
1008
932
|
def process_collections #:nodoc
|
1009
|
-
# If result_set is not defined on form, then it will fail. :return_to should know where to go
|
933
|
+
# If result_set is not defined on form, then it will fail. :return_to should know where to go
|
1010
934
|
if @form['result_set'].nil?
|
1011
|
-
process_return_to(params[:return_to] || 'reload')
|
935
|
+
process_return_to(params[:return_to] || 'reload')
|
1012
936
|
return true
|
1013
937
|
end
|
1014
|
-
#
|
938
|
+
# when result set is evaluated as Rails helper
|
939
|
+
@form['result_set']['type'] ||= 'default'
|
940
|
+
return unless @form['result_set']['type'] == 'default'
|
941
|
+
|
942
|
+
# for now enable only filtering of top level documents
|
1015
943
|
if @tables.size == 1
|
1016
944
|
check_filter_options()
|
1017
945
|
check_sort_options()
|
1018
946
|
end
|
1019
|
-
# result set is defined by filter method in control object
|
947
|
+
# result set is defined by filter method in control object
|
1020
948
|
form_filter = @form['result_set']['filter']
|
1021
949
|
if form_filter
|
1022
950
|
if respond_to?(form_filter)
|
1023
951
|
@records = send(form_filter)
|
1024
|
-
# something went wrong. flash[] should have explanation.
|
952
|
+
# something went wrong. flash[] should have explanation.
|
1025
953
|
if @records.class == FalseClass
|
1026
954
|
@records = []
|
1027
955
|
render(action: :index)
|
1028
956
|
return true
|
1029
957
|
end
|
1030
958
|
process_select_and_deny_fields
|
1031
|
-
# pagination but only if not already set
|
1032
|
-
unless (@form['table'] == 'dc_memory'
|
1033
|
-
per_page = (@form['result_set']['per_page'] ||
|
959
|
+
# pagination but only if not already set
|
960
|
+
unless (@form['table'] == 'dc_memory' || @records.options[:limit])
|
961
|
+
per_page = (@form['result_set']['per_page'] || 25).to_i
|
1034
962
|
@records = @records.page(params[:page]).per(per_page) if per_page > 0
|
1035
963
|
end
|
1036
964
|
elsif form_filter != 'dc_filter'
|
@@ -1040,10 +968,10 @@ def process_collections #:nodoc
|
|
1040
968
|
if @tables.size > 1
|
1041
969
|
rec = @tables.first[0].find(@ids.first) # top most document.id
|
1042
970
|
1.upto(@tables.size - 2) { |i| rec = rec.send(@tables[i][1].pluralize).find(@ids[i]) } # find embedded childrens by ids
|
1043
|
-
# TO DO. When field name is different then pluralized class name. Not working yet.
|
971
|
+
# TO DO. When field name is different then pluralized class name. Not working yet.
|
1044
972
|
embedded_field_name = @tables.last[0] ? @tables.last[1].pluralize : @tables.last[1]
|
1045
973
|
@records = rec.send(embedded_field_name) # current embedded set
|
1046
|
-
# sort by order if order field is present in model
|
974
|
+
# sort by order if order field is present in model
|
1047
975
|
if @tables.last[1].classify.constantize.respond_to?(:order)
|
1048
976
|
@records = @records.order_by('order asc')
|
1049
977
|
end
|
@@ -1074,5 +1002,4 @@ def process_in_memory #:nodoc
|
|
1074
1002
|
false
|
1075
1003
|
end
|
1076
1004
|
|
1077
|
-
|
1078
1005
|
end
|
@@ -28,7 +28,8 @@
|
|
28
28
|
class DcApplicationController < ActionController::Base
|
29
29
|
protect_from_forgery with: :null_session, only: Proc.new { |c| c.request.format.json? }
|
30
30
|
before_action :dc_reload_patches if Rails.env.development?
|
31
|
-
|
31
|
+
before_action :dc_set_locale
|
32
|
+
|
32
33
|
########################################################################
|
33
34
|
# Writes anything passed as parameter to logger file.
|
34
35
|
# Very useful for debuging strange errors.
|
@@ -256,7 +257,7 @@ def dc_set_options(parameters)
|
|
256
257
|
return if parameters.to_s.size < 3
|
257
258
|
# parameters are set as YAML. This should be default in future.
|
258
259
|
parms = YAML.load(parameters) rescue {}
|
259
|
-
@options.
|
260
|
+
@options = @options.deep_merge(parms)
|
260
261
|
end
|
261
262
|
|
262
263
|
##########################################################################
|
@@ -578,6 +579,20 @@ def dc_reload_patches
|
|
578
579
|
end
|
579
580
|
end
|
580
581
|
|
582
|
+
########################################################################
|
583
|
+
# Will set new default locale for application
|
584
|
+
#
|
585
|
+
# @param [String] new_locale : New locale value. If omitted it will be provided from params[:locale].
|
586
|
+
# if new_locale value is 00, application's default_locale will be used.
|
587
|
+
########################################################################
|
588
|
+
def dc_set_locale(new_locale = nil)
|
589
|
+
new_locale ||= params[:locale]
|
590
|
+
if new_locale && new_locale != session[:locale]
|
591
|
+
session[:locale] = new_locale == '00' ? nil : new_locale.to_sym
|
592
|
+
end
|
593
|
+
I18n.locale = session[:locale] ? session[:locale] : I18n.default_locale
|
594
|
+
end
|
595
|
+
|
581
596
|
############################################################################
|
582
597
|
# Writes out deprication msg. It also adds site_name to message, so it is easier to
|
583
598
|
# find where the message is comming from.
|
@@ -49,7 +49,12 @@ def autocomplete
|
|
49
49
|
name = params['search'].split('.').first
|
50
50
|
params['table'] = name.underscore
|
51
51
|
end
|
52
|
-
|
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')
|
55
|
+
else
|
56
|
+
return render json: { label: t('drgcms.not_authorized') } unless dc_user_can(DcPermission::CAN_VIEW)
|
57
|
+
end
|
53
58
|
|
54
59
|
table = params['table'].classify.constantize
|
55
60
|
input = params['input'].gsub(/\(|\)|\[|\]|\{|\|\.|\,}/, '')
|
@@ -69,7 +74,7 @@ def autocomplete
|
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
|
-
render
|
77
|
+
render json: a
|
73
78
|
end
|
74
79
|
|
75
80
|
########################################################################
|
@@ -212,8 +217,9 @@ def copy_clipboard
|
|
212
217
|
format.json { dc_render_ajax(operation: 'window', url: request.url ) }
|
213
218
|
|
214
219
|
format.html do
|
215
|
-
|
216
|
-
|
220
|
+
table = CmsHelper.table_param(params)
|
221
|
+
doc = dc_find_document(table, params[:id], params[:ids])
|
222
|
+
text = "<br><br>[#{table},#{params[:id]},#{params[:ids]}]<br>"
|
217
223
|
render plain: text + doc.as_document.to_json
|
218
224
|
end
|
219
225
|
end
|
@@ -261,7 +267,7 @@ end
|
|
261
267
|
# document.
|
262
268
|
########################################################################
|
263
269
|
def add_json_ld_schema
|
264
|
-
edited_document = DcJsonLd.find_document_by_ids(params
|
270
|
+
edited_document = DcJsonLd.find_document_by_ids(CmsHelper.table_param(params), params[:ids])
|
265
271
|
yaml = YAML.load_file( dc_find_form_file('json_ld_schema') )
|
266
272
|
schema_data = yaml[params[:schema]]
|
267
273
|
# Existing document
|
@@ -277,11 +283,11 @@ end
|
|
277
283
|
# Will provide help data
|
278
284
|
########################################################################
|
279
285
|
def help
|
280
|
-
form_name = params
|
286
|
+
form_name = CmsHelper.form_param(params) || CmsHelper.table_param(params)
|
281
287
|
@form = form_name ? YAML.load_file(dc_find_form_file(form_name)) : {}
|
282
288
|
return render json: {} if @form.nil?
|
283
289
|
|
284
|
-
help_file_name = @form['help'] || @form['extend'] ||
|
290
|
+
help_file_name = @form['help'] || @form['extend'] || form_name
|
285
291
|
help_file_name = find_help_file(help_file_name)
|
286
292
|
@help = YAML.load_file(help_file_name) if help_file_name
|
287
293
|
# no auto generated help on index action
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#encoding: utf-8
|
2
1
|
#--
|
3
2
|
# Copyright (c) 2014+ Damjan Rems
|
4
3
|
#
|
@@ -26,31 +25,19 @@
|
|
26
25
|
#
|
27
26
|
######################################################################
|
28
27
|
module BrowseModelsControl
|
29
|
-
include DcApplicationHelper
|
30
|
-
|
31
|
-
#########################################################################
|
32
|
-
# Determine model class from filename.
|
33
|
-
#########################################################################
|
34
|
-
def determine_model(path)
|
35
|
-
path =~ /(.*)\/(.*).rb/
|
36
|
-
begin
|
37
|
-
$2.camelize.constantize
|
38
|
-
$2
|
39
|
-
rescue Exception # it happends
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
end
|
43
28
|
|
44
29
|
#########################################################################
|
45
30
|
# Return array of all models found in application.
|
46
31
|
#########################################################################
|
47
|
-
def all_collections
|
32
|
+
def all_collections
|
48
33
|
collections = []
|
49
34
|
DrgCms.paths(:forms).each do |path|
|
50
35
|
models_dir = File.expand_path("../models", path)
|
51
|
-
Dir["#{models_dir}/*.rb"].each do |model_file|
|
52
|
-
|
53
|
-
|
36
|
+
Dir["#{models_dir}/*.rb"].each do |model_file|
|
37
|
+
model_file =~ /(.*)\/(.*).rb/
|
38
|
+
# check if model exists
|
39
|
+
collection = $2.camelize.constantize.new rescue nil
|
40
|
+
collections << collection.class.to_s.underscore if collection&.respond_to?(:_id)
|
54
41
|
end
|
55
42
|
end
|
56
43
|
collections.sort
|
@@ -59,10 +46,10 @@ end
|
|
59
46
|
######################################################################
|
60
47
|
# List all collections
|
61
48
|
######################################################################
|
62
|
-
def collections
|
49
|
+
def collections
|
63
50
|
@records = []
|
64
51
|
all_collections.each do |collection|
|
65
|
-
@records << {'id' => collection, 'description' => t("helpers.label.#{collection}.tabletitle") }
|
52
|
+
@records << DcMemory.new({'id' => collection, 'description' => t("helpers.label.#{collection}.tabletitle") })
|
66
53
|
end
|
67
54
|
@records
|
68
55
|
end
|
@@ -70,7 +57,7 @@ end
|
|
70
57
|
######################################################################
|
71
58
|
# List field definition for single model
|
72
59
|
######################################################################
|
73
|
-
def all_fields
|
60
|
+
def all_fields
|
74
61
|
@records = []
|
75
62
|
model = params[:id].classify.constantize
|
76
63
|
document = model.new
|
@@ -80,12 +67,13 @@ def all_fields()
|
|
80
67
|
description = I18n.t("helpers.label.#{params[:id]}.#{attribute_name}") if description.match('missing:')
|
81
68
|
description = attribute_name if description.match('missing:')
|
82
69
|
|
83
|
-
@records << {
|
70
|
+
@records << DcMemory.new({id: attribute_name,
|
71
|
+
'collection' => params[:id],
|
84
72
|
'field' => attribute_name,
|
85
73
|
'type' => options[:type],
|
86
74
|
'description' => description,
|
87
75
|
'_default' => options[:default]
|
88
|
-
}
|
76
|
+
})
|
89
77
|
end
|
90
78
|
# embedded documents
|
91
79
|
document.embedded_relations.each do |a_embedded|
|
@@ -94,11 +82,12 @@ def all_fields()
|
|
94
82
|
description = I18n.t("helpers.label.#{params[:id]}.#{embedded.key}") if description.match('missing:')
|
95
83
|
description = embedded.key if description.match('missing:')
|
96
84
|
|
97
|
-
@records << {
|
85
|
+
@records << DcMemory.new({ id: embedded.key,
|
86
|
+
'collection' => params[:id],
|
98
87
|
'field' => embedded.key,
|
99
88
|
'type' => 'Embedded:' + embedded.class_name,
|
100
89
|
'description' => description
|
101
|
-
}
|
90
|
+
})
|
102
91
|
end
|
103
92
|
|
104
93
|
@records
|