Class: KirguduBase::DynamicPagesController
Instance Attribute Summary
#kirgudu_controller_options
Instance Method Summary
collapse
-
#before_entry_create(entry, filter_params, options) ⇒ Object
Transaction Injection Methods ########################################.
-
#before_entry_update(entry, filter_params, options) ⇒ Object
-
#class_strong_filters(list, options = {}) ⇒ Object
Strong Parameters Filters Methods ########################################.
-
#create ⇒ Object
-
#dashboard ⇒ Object
-
#destroy ⇒ Object
-
#edit ⇒ Object
-
#edit_inplace ⇒ Object
-
#export ⇒ Object
-
#fill_obligatory_db_query_params(db_query_params, options = {}) ⇒ Object
-
#fill_parents_for_local_data(local_data, db_query_params, options = {}) ⇒ Object
-
#import ⇒ Object
-
#index ⇒ Object
-
#kb_db_render_entry_not_found_page ⇒ Object
-
#kb_dp_breadcrumbs_build(local_data, is_index_page) ⇒ Object
-
#kb_dp_init_controller_action ⇒ Object
-
#kb_dp_render_page_404 ⇒ Object
-
#load_data_for_entry_controls(form, entry, options = {}) ⇒ Object
Data For Form Controls ########################################.
-
#load_data_for_filters_controls(list, values_source, options = {}) ⇒ Object
-
#manage_items ⇒ Object
-
#manage_items_add ⇒ Object
-
#manage_items_remove ⇒ Object
-
#new ⇒ Object
-
#show ⇒ Object
-
#sort_items ⇒ Object
-
#sort_items_process ⇒ Object
-
#update ⇒ Object
#add_new_breadcrumb, #authenticate_user, #breadcrumbs_length, #check_locale_parameter, #class_strong_params, #current_user, #current_user=, #current_user_clear_info, #current_user_query_db, #current_user_set_info, #current_user_symbol, #entry_class, #fake_counter_iterate, #get_best_locale, get_class_hierarchy, #get_class_hierarchy, #get_class_variable, #get_filters_for_list, #get_kirgudu_base_authentication_controller_setting, #get_layout_path, get_method_latest_result, #get_template_path, #get_url_for_login, #get_url_for_logout, #get_url_for_restore_password_code, #get_url_to_redirect_for_authentication, #get_view_default_path, #get_view_path, #initialize_global_variables, #kb_breadcrumbs, #page_for_default_redirection_after_login, #prepare_applications_data, #prepare_breadcrumbs, #process_transaction_injections, #render, #render_breadcrumbs, #render_page_e404, #set_content_type, #set_i18n_locale_from_params, #string_logger, #string_logger=, #system_logging_init, #system_logging_write_event, #to_i18n, to_i18n, #to_route_path, to_route_path, to_url_for, #to_url_for, #update_url_with_ajax_referer_url
#get_kb_entry_class, #get_kb_home_controller, #get_kb_home_path, #get_kb_menu, #get_kb_option, #get_kb_page, #get_kb_parent_controller_data, #get_kb_template, #get_kb_view_path, #kb_entry_class, #kb_home_controller, #kb_home_path, #kb_management_settings, #kb_menu, #kb_page, #kb_parent_controller, #kb_template_path, #kb_views_paths_404_page, #kb_views_paths_dashboard, #kb_views_paths_delete, #kb_views_paths_edit, #kb_views_paths_entry_not_found, #kb_views_paths_index, #kb_views_paths_layout, #kb_views_paths_management, #kb_views_paths_new, #kb_views_paths_show, #kb_views_paths_sorting
#get_kb_transaction_injections, #kb_transaction_injection
#get_kb_obligatory_filters, #kb_obligatory_filter
assign_portal_to_all_models, assign_portal_to_models_of_class, #build_query_string_params, #get_flash_message, #kb_auth_form_for, #kb_dynamic_form_for, #kirgudu_form_for, #print_flash_message, #print_flash_notice, #print_property, #render_html, #render_html1, #render_json, #render_json_access_denied, #render_json_error, #render_json_need_authentication, #render_json_not_found, #render_json_ok, #render_json_page_404, #render_liquid, #render_redirect, #russian_month_labels, #security_login, #security_logout, #web_chu_form_for
included
Methods included from UrlHelper
#url_for, #with_subdomain
Instance Method Details
#before_entry_create(entry, filter_params, options) ⇒ Object
Transaction Injection Methods ########################################
1195
1196
1197
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 1195
def before_entry_create(entry, filter_params, options)
end
|
#before_entry_update(entry, filter_params, options) ⇒ Object
1199
1200
1201
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 1199
def before_entry_update(entry, filter_params, options)
end
|
#class_strong_filters(list, options = {}) ⇒ Object
Strong Parameters Filters Methods ########################################
1182
1183
1184
1185
1186
1187
1188
1189
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 1182
def class_strong_filters(list, options = {})
strong_filters = {}
list.filters.each do |filter|
strong_filters[filter.name] = params[filter.name] if params[filter.name]
end if list && list.filters
strong_filters
end
|
#create ⇒ Object
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 193
def create
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
strong_params = {}.merge(self.class_strong_params(@local_data[:page].forms[:changes]))
self.fill_obligatory_db_query_params(strong_params)
strong_params.merge!(@local_data[:parent_ids])
@local_data[:entry] = self.entry_class.new(strong_params)
self.process_transaction_injections(@local_data[:entry], :create, :before_transaction, strong_params)
transaction_is_ok = true
ActiveRecord::Base.transaction do
unless self.process_transaction_injections(@local_data[:entry], :create, :before_save, strong_params)
transaction_is_ok = false
raise ActiveRecord::Rollback
end
if @local_data[:entry].save
unless process_transaction_injections(@local_data[:entry], :create, :after_save, strong_params)
transaction_is_ok = false
raise ActiveRecord::Rollback
end
else
transaction_is_ok = false
raise ActiveRecord::Rollback
end
end
self.process_transaction_injections(@local_data[:entry], :create, :after_transaction, strong_params)
respond_to do |format|
if transaction_is_ok
@local_data[:messages] << I18n.t("#{self.to_i18n}.messages.entry_created", entry_name: @local_data[:entry].to_s)
format.html { render_redirect self.to_url_for(:show, @local_data[:parent_ids].merge(id: @local_data[:entry].id)) }
format.json { render_json_ok @local_data[:entry], message: @local_data[:messages] }
else
@local_data[:controls_data] = self.load_data_for_entry_controls(@local_data[:page].forms[:changes], @local_data[:entry])
@local_data[:errors] << I18n.t("#{self.to_i18n}.messages.create_error")
self.kb_dp_breadcrumbs_build(@local_data, false)
format.html { render_html1 self.get_view_path(:new), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_error @local_data[:entry], message: @local_data[:errors] }
end
end
end
|
#dashboard ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 81
def dashboard
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
self.kb_dp_breadcrumbs_build(@local_data, true)
respond_to do |format|
format.html { render_html1 self.get_view_path(:dashboard), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_ok(nil) }
end
end
|
#destroy ⇒ Object
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 358
def destroy
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
db_query_params = {}
self.fill_obligatory_db_query_params(db_query_params)
db_query_params.merge!(@local_data[:parent_ids])
@local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], db_query_params, {logger: string_logger})
self.kb_db_render_entry_not_found_page and return unless @local_data[:entry]
if @local_data[:entry].destroy
respond_to do |format|
format.html { render_redirect(self.to_url_for(:index, @local_data[:parent_ids])) }
format.json { render_json_ok(@local_data[:entry], message: "Record Deleted") }
end
else
@local_data[:errors] << I18n.t("#{self.to_i18n}.messages.delete_error")
respond_to do |format|
format.html { render_html1 self.get_view_path(:delete), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_error(message: @local_data[:errors]) }
end
end
end
|
#edit ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 255
def edit
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
db_query_params = {}
self.fill_obligatory_db_query_params(db_query_params)
db_query_params.merge!(@local_data[:parent_ids])
@local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], db_query_params, @options)
self.kb_db_render_entry_not_found_page and return unless @local_data[:entry]
@local_data[:controls_data] = self.load_data_for_entry_controls(@local_data[:page].forms[:changes], @local_data[:entry])
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
self.kb_dp_breadcrumbs_build(@local_data, false)
respond_to do |format|
format.html { render_html1 self.get_view_path(:edit), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_ok @local_data[:entry] }
end
end
|
#edit_inplace ⇒ Object
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 801
def edit_inplace
@local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], nil, {logger: string_logger})
if @local_data[:entry]
result_string = ''
begin
unless @local_data[:entry][params[:field_name]] == params[:value]
@local_data[:entry][params[:field_name]] = params[:value]
@local_data[:entry].updated_at = Time.now
@local_data[:entry].updater = self.current_user
unless @local_data[:entry].save
result_string = '<span style = "color: red;"><b>FAILED TO SAVE!!!</b></span>'
end
end
rescue
result_string = '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
end
if result_string.blank?
begin
result_string = @local_data[:entry].send(params[:field_name])
rescue
result_string = '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
end
end
render text: result_string
else
render text: '<span style = "color: red;"><b>NOT FOUND!!!</b></span>'
end
end
|
#export ⇒ Object
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 394
def export
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
db_query_params = {}
self.fill_obligatory_db_query_params(db_query_params)
db_query_params.merge!(@local_data[:parent_ids])
@local_data[:entries] = self.entry_class.get_entries(nil, db_query_params, @options)
export_type = params[:type]
unless export_type
end
export_options = {}
self.entry_class.export_types_set.each do |exp|
if exp[:name] == export_type
end
end
if params[:type]
case params[:type]
when "json"
when "xml"
render text: @local_data[:entries_list].to_xml
end
else
respond_to do |format|
format.json { render json: @local_data[:entries] }
format.json { render xml: @local_data[:entries] }
end
end
end
|
#fill_obligatory_db_query_params(db_query_params, options = {}) ⇒ Object
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 975
def fill_obligatory_db_query_params(db_query_params, options = {})
options ||= {}
classes_to_process = self.get_class_hierarchy
classes_to_process.each do |kontroller_klass|
kontroller_klass.get_kb_obligatory_filters.each do |filter|
execute_flag = true
if filter.only && filter.only.length > 0
execute_flag = false
filter.only.each do |item|
if item == self.action.to_sym
execute_flag = true
end
end
end
if filter.skip && filter.skip.length > 0
filter.skip.each do |item|
if item == self.action.to_sym
execute_flag = false
end
end
end
db_query_params[filter.name] = self.send(filter.source_method) if execute_flag
end if kontroller_klass.respond_to?(:get_kb_obligatory_filters)
end
end
|
#fill_parents_for_local_data(local_data, db_query_params, options = {}) ⇒ Object
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 1140
def fill_parents_for_local_data(local_data, db_query_params, options = {})
options ||= {}
if local_data && local_data.is_a?(Hash)
local_data[:parents] = []
local_data[:parent_elements] = {}
local_data[:parent_ids] = {}
ktrlr = self.class
while true do
parent_ktrlr_data = ktrlr.get_kb_parent_controller_data
break unless parent_ktrlr_data
parent_entry = parent_ktrlr_data[:controller].get_kb_entry_class.get_entry_by_id(params[parent_ktrlr_data[:id]], db_query_params, options)
parent_hash = {
controller: parent_ktrlr_data[:controller],
entry: parent_entry,
id_param: parent_ktrlr_data[:id],
id_value: parent_entry.id
}
local_data[:parents] << parent_hash
local_data[:parent_elements][parent_ktrlr_data[:id]] = parent_entry
local_data[:parent_ids][parent_ktrlr_data[:id]] = parent_entry.id
ktrlr = parent_ktrlr_data[:controller]
end
end
end
|
#import ⇒ Object
437
438
439
440
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 437
def import
import_type = params[:type]
end
|
#index ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 33
def index
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
db_query_params = self.get_filters_for_list(@local_data[:page].lists[:entries_list], params)
self.fill_obligatory_db_query_params(db_query_params)
db_query_params.merge!(@local_data[:parent_ids])
db_query_params[:per_page] = 30 unless db_query_params[:per_page]
db_query_params[:per_page] ||= 30
@local_data[:filters_data] = self.load_data_for_filters_controls(@local_data[:page].lists[:entries_list], params)
@local_data[:entries] = self.entry_class.get_entries(nil, db_query_params, @options)
filters_for_current_url = self.get_filters_for_list(@local_data[:page].lists[:entries_list], params)
filters_for_current_url.merge!(@local_data[:parent_ids])
@local_data[:current_url] = self.to_url_for(:index, filters_for_current_url)
self.kb_dp_breadcrumbs_build(@local_data, true)
respond_to do |format|
format.html { render_html1 self.get_view_path(:index), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_ok(@local_data[:entries]) }
end
end
|
#kb_db_render_entry_not_found_page ⇒ Object
845
846
847
848
849
850
851
852
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 845
def kb_db_render_entry_not_found_page
@local_data[:errors] << I18n.t("#{self.to_i18n}.messages.entry_not_found", entry_id: params[:id])
respond_to do |format|
format.html { render_html1 self.get_view_path(:entry_not_found), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_not_found message: @local_data[:errors] }
end
end
|
#kb_dp_breadcrumbs_build(local_data, is_index_page) ⇒ Object
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 855
def kb_dp_breadcrumbs_build(local_data, is_index_page)
local_home_path = self.class.get_method_latest_result(:get_kb_home_path)
if local_home_path
local_home_controller = eval(local_home_path[:controller])
local_home_url = local_home_controller.to_url_for(local_home_path[:action], local_home_path[:params])
if is_index_page
if self.class == local_home_path[:controller]
self.add_new_breadcrumb(I18n.t("#{local_home_controller.to_i18n}.#{local_home_path[:action]}.title"))
else
self.add_new_breadcrumb(I18n.t("#{local_home_controller.to_i18n}.#{local_home_path[:action]}.title"), local_home_url)
end
else
self.add_new_breadcrumb(I18n.t("#{local_home_controller.to_i18n}.#{local_home_path[:action]}.title"), local_home_url)
end
end
parent_ids = {}
@local_data[:parents].reverse.each do |parent|
add_new_breadcrumb(I18n.t("#{parent[:controller].to_i18n}.index.title"), parent[:controller].to_url_for(:index, parent_ids))
parent_entry_name = nil
parent_entry_name = parent[:entry].name_for_breadcrumbs if parent[:entry].respond_to?(:name_for_breadcrumbs)
parent_entry_name = parent[:entry].id unless parent_entry_name
self.add_new_breadcrumb(parent_entry_name, parent[:controller].to_url_for(:show, parent_ids.merge(id: parent[:entry].id)))
parent_ids[parent[:id_param]] = parent[:id_value]
end if @local_data[:parents]
self.add_new_breadcrumb(I18n.t("#{self.to_i18n}.index.title"), self.to_url_for(:index, @local_data[:parent_ids]))
unless is_index_page
entry_name = nil
entry_name = @local_data[:entry].name_for_breadcrumbs if @local_data[:entry].respond_to?(:name_for_breadcrumbs)
page_name = @local_data[:page].name
if page_name == :edit
self.add_new_breadcrumb(@local_data[:entry].id)
elsif page_name == :show || page_name == :delete
self.add_new_breadcrumb(entry_name || @local_data[:entry].id)
elsif page_name == :new
self.add_new_breadcrumb(I18n.t("#{self.to_i18n}.new.title"))
elsif page_name == :management
self.add_new_breadcrumb(I18n.t("#{self.to_i18n}.management.title"))
elsif page_name == :sorting
self.add_new_breadcrumb(I18n.t("#{self.to_i18n}.sorting.title"))
end
end
end
|
#kb_dp_init_controller_action ⇒ Object
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 912
def kb_dp_init_controller_action
raise "Method :get_kb_page must be implemented for controller '#{self.class}'" unless self.class.respond_to?(:get_kb_page)
page_name = case self.action_name
when 'index' then
:index
when 'dashboard' then
:dashboard
when 'new', 'create' then
:new
when 'edit', 'update', 'edit_inplace' then
:edit
when 'delete', 'destroy' then
:delete
when 'sort_items', 'sort_items_process' then
:sorting
when 'manage_items', 'manage_items_add', 'manage_items_remove' then
:management
when 'show' then
:show
else
nil
end
@local_data = {
errors: [],
messages: [],
page: nil,
menus: {}
}
@local_data[:page] = self.class.get_kb_page(page_name) if page_name
self.kb_dp_render_page_404 unless @local_data[:page] if page_name
@local_data[:allow_create] = self.class.get_kb_page(:new) != nil
@local_data[:allow_update] = self.class.get_kb_page(:edit) != nil
@local_data[:allow_delete] = self.class.get_kb_page(:delete) != nil
@options = {
logger: self.string_logger
}
@local_data[:menus][:left_menu] = self.class.get_method_latest_result(:get_kb_menu, :left_menu)
end
|
#kb_dp_render_page_404 ⇒ Object
837
838
839
840
841
842
843
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 837
def kb_dp_render_page_404
respond_to do |format|
format.html { render_html1 self.get_view_path(:page_404), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_page_404 }
end
end
|
#load_data_for_entry_controls(form, entry, options = {}) ⇒ Object
Data For Form Controls ########################################
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 1009
def load_data_for_entry_controls(form, entry, options = {})
controls_data = {}
form.properties.values.select { |p| !p.data_source.nil? }.each do |property|
if property.data_source
controls_data[property.name] = if property.data_source.type == :db || property.data_source.type == :jquery_db
db_query_params = {}
parent_value = nil
if property.parent
parent_value = entry[property.parent]
db_query_params[property.parent] = parent_value
end
self.fill_obligatory_db_query_params(db_query_params, options)
db_query_params.merge!({
per_page: 9999999,
page: 1
})
property.data_source.model.get_entries(nil, db_query_params, options).map { |u| [u.send(property.data_source.label_property), u.send(property.data_source.value_property)] } if property.parent.nil? || parent_value
elsif property.data_source.type == :i18n
elsif property.data_source.type == :enum
property.data_source.model.to_select
elsif property.data_source.type == :array
property.data_source.model.map { |i| i.is_a?(Array) ? [i[0], i[0]] : [i, i] }
end
end
end if form && form.properties
controls_data
end
|
#load_data_for_filters_controls(list, values_source, options = {}) ⇒ Object
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 1041
def load_data_for_filters_controls(list, values_source, options = {})
controls_data = {}
list.filters.select { |f| !f.data_source.nil? }.each do |filter|
controls_data[filter.name] = if filter.data_source.type == :db || filter.data_source.type == :jquery_db
db_query_params = {}
if filter.parent
parent_value = values_source[filter.parent]
db_query_params[filter.parent] = values_source[filter.parent] if parent_value
end
fill_obligatory_db_query_params(db_query_params, options)
db_query_params.merge!({
per_page: 9999999,
page: 1
})
filter.data_source.model.get_entries(nil, db_query_params, options).map { |u| [u.send(filter.data_source.label_property), u.send(filter.data_source.value_property)] }
elsif filter.data_source.type == :i18n
elsif filter.data_source.type == :enum
filter.data_source.model.to_select
elsif filter.data_source.type == :array
filter.data_source.model
end
end if list && list.filters
controls_data
end
|
#manage_items ⇒ Object
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 442
def manage_items
@local_data[:management_settings] = @local_data[:page].managements[:manage] if @local_data[:page].managements
self.kb_dp_render_page_404 and return unless @local_data[:management_settings]
local_container_class = @local_data[:management_settings].container_class
local_container_id_property = @local_data[:management_settings].container_id_property
local_item_class = @local_data[:management_settings].item_class
local_entry_id_property = @local_data[:management_settings].entry_id_property
local_entry_class = @local_data[:management_settings].entry_class
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
filters_4_container = {}
self.fill_obligatory_db_query_params(filters_4_container)
filters_4_container.merge!(@local_data[:parent_ids])
@local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, @options)
filters_4_items = {}
self.fill_obligatory_db_query_params(filters_4_items)
filters_4_items.merge!(@local_data[:parent_ids])
filters_4_items[local_container_id_property] = params[local_container_id_property]
@local_data[:items] = local_item_class.get_entries(nil, filters_4_items, @options)
filters_4_entries = {}
self.fill_obligatory_db_query_params(filters_4_entries)
filters_4_entries[local_entry_id_property] = params[local_entry_id_property]
local_entries_initial_query = local_entry_class.where { -(id.in local_item_class.get_entries(nil, filters_4_items, @options).select(local_entry_id_property)) }
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
local_entries = local_entry_class.get_entries(local_entries_initial_query, filters_4_entries, @options)
@local_data[:entries] = local_entries
self.kb_dp_breadcrumbs_build(@local_data, false)
respond_to do |format|
format.html { render_html1 self.get_view_path(:management), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render json: @local_data }
end
end
|
#manage_items_add ⇒ Object
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 510
def manage_items_add
@local_data[:management_settings] = @local_data[:page].managements[:manage] if @local_data[:page].managements
self.kb_dp_render_page_404 and return unless @local_data[:management_settings]
local_container_class = @local_data[:management_settings].container_class
local_container_id_property = @local_data[:management_settings].container_id_property
local_item_class = @local_data[:management_settings].item_class
local_entry_id_property = @local_data[:management_settings].entry_id_property
local_entry_class = @local_data[:management_settings].entry_class
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
filters_4_container = {}
self.fill_obligatory_db_query_params(filters_4_container)
@local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, @options)
unless @local_data[:container]
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('set_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.set_not_found", id: params[local_container_id_property])}
return
end
filters_4_entries = {}
self.fill_obligatory_db_query_params(filters_4_entries)
@local_data[:entry] = local_entry_class.get_entry_by_id(params[:entry_id], filters_4_entries, @options)
self.kb_db_render_entry_not_found_page and return unless @local_data[:entry]
filters_4_item = {}
self.fill_obligatory_db_query_params(filters_4_item)
filters_4_item[local_container_id_property] = params[local_container_id_property]
filters_4_item[local_entry_id_property] = params[:entry_id]
@local_data[:item] = local_item_class.get_entries(nil, filters_4_item, @options).first
unless @local_data[:item]
@local_data[:item] = local_item_class.new
@local_data[:item][local_container_id_property] = @local_data[:container].id
@local_data[:item][local_entry_id_property] = @local_data[:entry].id
if @local_data[:item].respond_to?(:sort_position)
filters_4_items_max = {}
self.fill_obligatory_db_query_params(filters_4_items_max)
filters_4_items_max[local_container_id_property] = params[local_container_id_property]
max_sort_position = local_item_class.get_entries(nil, filters_4_items_max, @options).maximum(:sort_position)
@local_data[:item].sort_position = max_sort_position ? max_sort_position + 1 : 1
end
self.process_transaction_injections(@local_data[:item], :create, :before_transaction, nil)
transaction_is_ok = true
ActiveRecord::Base.transaction do
unless self.process_transaction_injections(@local_data[:item], :create, :before_save, nil)
transaction_is_ok = false
raise ActiveRecord::Rollback
end
if @local_data[:item].save
unless self.process_transaction_injections(@local_data[:item], :create, :after_save, nil)
transaction_is_ok = false
raise ActiveRecord::Rollback
end
else
transaction_is_ok = false
raise ActiveRecord::Rollback
end
end
self.process_transaction_injections(@local_data[:item], :create, :after_transaction, nil)
if transaction_is_ok
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('ok'), message: I18n.t("#{self.to_i18n}.management.messages.add_management_ok")}
else
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('error'), message: I18n.t("#{self.to_i18n}.management.messages.add_management_error")}
end
else
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('entry_already_in_set'), message: I18n.t("#{self.to_i18n}.management.messages.entry_already_in_set")}
end
end
|
#manage_items_remove ⇒ Object
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 612
def manage_items_remove
@local_data[:management_settings] = @local_data[:page].managements[:manage] if @local_data[:page].managements
self.kb_dp_render_page_404 and return unless @local_data[:management_settings]
local_container_class = @local_data[:management_settings].container_class
local_container_id_property = @local_data[:management_settings].container_id_property
local_item_class = @local_data[:management_settings].item_class
local_entry_id_property = @local_data[:management_settings].entry_id_property
local_entry_class = @local_data[:management_settings].entry_class
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
filters_4_container = {}
self.fill_obligatory_db_query_params(filters_4_container)
@local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, @options)
unless @local_data[:container]
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('set_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.set_not_found", id: params[local_container_id_property])}
return
end
filters_4_item = {}
self.fill_obligatory_db_query_params(filters_4_item)
filters_4_item[local_container_id_property] = params[local_container_id_property]
filters_4_item[local_entry_id_property] = params[:entry_id]
@local_data[:item] = local_item_class.get_entries(nil, filters_4_item, @options).first
unless @local_data[:item]
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('item_not_found'), message: I18n.t("#{self.to_i18n}.management.messages.item_not_found", entry_id: params[:entry_id])}
return
end
if @local_data[:item].destroy
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('ok'), message: I18n.t("#{self.to_i18n}.management.messages.remove_management_ok")}
else
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('error'), message: I18n.t("#{self.to_i18n}.management.messages.remove_management_error")}
end
end
|
#new ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 166
def new
db_query_params = {}
self.fill_obligatory_db_query_params(db_query_params)
@local_data[:entry] = entry_class.new
@local_data[:controls_data] = self.load_data_for_entry_controls(@local_data[:page].forms[:changes], @local_data[:entry])
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
self.kb_dp_breadcrumbs_build(@local_data, false)
respond_to do |format|
format.html { render_html1 self.get_view_path(:new), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_ok @local_data[:entry] }
end
end
|
#show ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 111
def show
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
db_query_params = {}
self.fill_obligatory_db_query_params(db_query_params)
db_query_params.merge!(@local_data[:parent_ids])
@local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], db_query_params, @options)
self.kb_db_render_entry_not_found_page and return unless @local_data[:entry]
@local_data[:page].lists.each_pair do |key, list|
if list.relation
filters_for_list = {}
self.fill_obligatory_db_query_params(filters_for_list)
reflection = self.entry_class.reflections[list.relation.name]
list_per_page = list.relation.per_page_param
list_page = list.relation.page_param
filters_for_list[:per_page] = params[list_per_page].to_i rescue 30
filters_for_list[:per_page] ||= 30
filters_for_list[:per_page] = 30 if filters_for_list[:per_page] == 0
filters_for_list[:page] = params[list_page].to_i rescue 1
filters_for_list[reflection.foreign_key] = @local_data[:entry].id
@local_data[:"list_entries_#{list.name}"] = eval(reflection.class_name).get_entries(nil, filters_for_list, @options)
end
end if @local_data[:page].lists
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
self.kb_dp_breadcrumbs_build(@local_data, false)
respond_to do |format|
format.html { render_html1 self.get_view_path(:show), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render_json_ok @local_data[:entry] }
end
end
|
#sort_items ⇒ Object
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 666
def sort_items
@local_data[:sorting_settings] = @local_data[:page].sortings[:sort] if @local_data[:page].sortings
self.kb_dp_render_page_404 and return unless @local_data[:sorting_settings]
local_container_class = @local_data[:sorting_settings].container_class
local_container_id_property = @local_data[:sorting_settings].container_id_property
local_item_class = @local_data[:sorting_settings].item_class
local_entry_id_property = @local_data[:sorting_settings].entry_id_property
local_entry_class = @local_data[:sorting_settings].entry_class
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
filters_4_container = {}
self.fill_obligatory_db_query_params(filters_4_container)
filters_4_container.merge!(@local_data[:parent_ids])
@local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, @options)
filters_4_items = {}
self.fill_obligatory_db_query_params(filters_4_items)
filters_4_items.merge!(@local_data[:parent_ids])
filters_4_items[local_container_id_property] = params[local_container_id_property]
filters_4_items[:order] = ::Core::Store::CollectionProduct.for_sql_order_by(:sort_position, :asc)
@local_data[:items] = local_item_class.get_entries(nil, filters_4_items, @options)
self.kb_dp_breadcrumbs_build(@local_data, false)
respond_to do |format|
format.html { render_html1 "#{self.class.get_method_latest_result(:get_kb_template)}/#{self.class.get_method_latest_result(:get_kb_view_path, :sorting)}", locals: {data: @local_data} }
format.json { render_json_ok @local_data }
end
end
|
#sort_items_process ⇒ Object
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 715
def sort_items_process
@local_data[:sorting_settings] = @local_data[:page].sortings[:sort] if @local_data[:page].sortings
self.kb_dp_render_page_404 and return unless @local_data[:sorting_settings]
local_container_class = @local_data[:sorting_settings].container_class
local_container_id_property = @local_data[:sorting_settings].container_id_property
local_item_class = @local_data[:sorting_settings].item_class
local_entry_id_property = @local_data[:sorting_settings].entry_id_property
local_entry_class = @local_data[:sorting_settings].entry_class
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
filters_4_container = {}
self.fill_obligatory_db_query_params(filters_4_container)
@local_data[:container] = local_container_class.get_entry_by_id(params[local_container_id_property], filters_4_container, @options)
unless @local_data[:container]
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('set_not_found'), message: I18n.t("#{self.to_i18n}.sorting.messages.set_not_found", id: params[local_container_id_property])}
return
end
filters_4_item = {}
self.fill_obligatory_db_query_params(filters_4_item)
filters_4_item[local_container_id_property] = params[local_container_id_property]
result_is_ok = false
if params[:items]
begin
ActiveRecord::Base.transaction do
params[:items].each_with_index do |id, index|
logger.info("ITEMID: #{id}")
logger.info "ITEM FILTERS: #{filters_4_item.to_json}"
item = local_item_class.get_entry_by_id(id, filters_4_item, @options)
if item
item.sort_position = index + 1
item.save
end
end
result_is_ok = true
end
end
end
if result_is_ok == true
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('ok'), message: I18n.t("#{self.to_i18n}.sorting.messages.sorting_ok")}
else
render json: {status: ::ChupakabraTools::ApiStatus.id_by_tag('error'), message: I18n.t("#{self.to_i18n}.sorting.messages.sorting_error")}
end
end
|
#update ⇒ Object
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
# File 'app/controllers/kirgudu_base/dynamic_pages_controller.rb', line 292
def update
filters_for_parents = {}
self.fill_obligatory_db_query_params(filters_for_parents)
self.fill_parents_for_local_data(@local_data, filters_for_parents)
db_query_params = {}
self.fill_obligatory_db_query_params(db_query_params)
db_query_params.merge!(@local_data[:parent_ids])
@local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], db_query_params, {logger: string_logger})
self.kb_db_render_entry_not_found_page and return unless @local_data[:entry]
strong_params = {}.merge(self.class_strong_params(@local_data[:page].forms[:changes]))
self.fill_obligatory_db_query_params(strong_params)
self.process_transaction_injections(@local_data[:entry], :update, :before_transaction, strong_params)
transaction_is_ok = true
ActiveRecord::Base.transaction do
unless self.process_transaction_injections(@local_data[:entry], :update, :before_save, strong_params)
transaction_is_ok = false
raise ActiveRecord::Rollback
end
if @local_data[:entry].update(strong_params)
unless process_transaction_injections(@local_data[:entry], :update, :after_save, strong_params)
transaction_is_ok = false
raise ActiveRecord::Rollback
end
else
transaction_is_ok = false
raise ActiveRecord::Rollback
end
end
self.process_transaction_injections(@local_data[:entry], :update, :after_transaction, strong_params)
respond_to do |format|
flash[:success] = I18n.t("#{self.to_i18n}.messages.manufacturer_updated", entry_name: @local_data[:entry].to_s)
if transaction_is_ok
format.html { render_redirect url_for(action: :show, id: @local_data[:entry]) }
format.json { head :no_content }
else
@local_data[:controls_data] = self.load_data_for_entry_controls(@local_data[:page].forms[:changes], @local_data[:entry])
@local_data[:entry].errors[:form] << I18n.t("#{self.to_i18n}.messages.update_error")
self.kb_dp_breadcrumbs_build(@local_data, false)
format.html { render_html1 self.get_view_path(:edit), layout: self.get_view_path(:layout), locals: {data: @local_data} }
format.json { render json: @local_data[:entry].errors, status: :unprocessable_entity }
end
end
end
|