Class: KirguduBase::ApplicationController
Instance Attribute Summary
#kirgudu_controller_options
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_new_breadcrumb(label, path = nil) ⇒ Object
-
#authenticate_user ⇒ Object
-
#breadcrumbs_length ⇒ Object
-
#check_locale_parameter ⇒ Object
def default_url_options I18n.locale end.
-
#class_strong_params(form) ⇒ Object
-
#current_user ⇒ Object
-
#current_user=(value) ⇒ Object
-
#current_user_clear_info ⇒ Object
-
#current_user_query_db(user_id) ⇒ Object
-
#current_user_set_info(user, remember_me = nil) ⇒ Object
-
#current_user_symbol ⇒ Object
-
#entry_class ⇒ Object
-
#fake_counter_iterate(counter_name) ⇒ Object
-
#get_best_locale ⇒ Object
-
#get_class_hierarchy ⇒ Object
Class Hierarchy Methods ########################################.
-
#get_class_variable(name) ⇒ Object
-
#get_filters_for_list(list, source) ⇒ Object
Filters #########################################.
-
#get_kirgudu_base_authentication_controller_setting ⇒ Object
-
#get_layout_path(include_template = true) ⇒ Object
-
#get_template_path ⇒ Object
Views Paths #######################################.
-
#get_url_for_login(options = {}) ⇒ Object
-
#get_url_for_logout(options = {}) ⇒ Object
-
#get_url_for_restore_password_code(options = {}) ⇒ Object
-
#get_url_to_redirect_for_authentication ⇒ Object
-
#get_view_default_path(view_name) ⇒ Object
-
#get_view_path(view_name, include_template = true) ⇒ Object
-
#initialize_global_variables ⇒ Object
called in before_action in ::KirguduBase::ApplicationController.
-
#kb_breadcrumbs ⇒ Object
-
#page_for_default_redirection_after_login ⇒ Object
-
#prepare_applications_data ⇒ Object
-
#prepare_breadcrumbs ⇒ Object
-
#process_transaction_injections(entry, action, flow_position, filter_params, options = {}) ⇒ Object
Dynamic Transactions #########################################.
-
#render(*args) ⇒ Object
-
#render_breadcrumbs ⇒ Object
-
#render_page_e404 ⇒ Object
-
#set_content_type ⇒ Object
-
#set_i18n_locale_from_params ⇒ Object
-
#string_logger ⇒ Object
#######################################.
-
#string_logger=(value) ⇒ Object
-
#system_logging_init ⇒ Object
-
#system_logging_write_event(source, level_id, message) ⇒ Object
-
#to_i18n ⇒ Object
-
#to_route_path ⇒ Object
-
#to_url_for(action = nil, options = {}) ⇒ Object
-
#update_url_with_ajax_referer_url ⇒ Object
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
Class Method Details
.get_class_hierarchy ⇒ Object
231
232
233
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 231
def self.get_class_hierarchy
::ChupakabraTools::ClassHelper.get_controller_hierarchy(self)
end
|
.get_method_latest_result(method_name, *method_args) ⇒ Object
239
240
241
242
243
244
245
246
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 239
def self.get_method_latest_result(method_name, *method_args)
method_result = nil
self.get_class_hierarchy.each do |controller_class|
method_result = controller_class.send(method_name, *method_args) if controller_class.respond_to?(method_name)
return method_result if method_result
end
method_result
end
|
.to_i18n ⇒ Object
I18n String Generator Methods #####################################
126
127
128
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 126
def self.to_i18n
::ChupakabraTools::ClassHelper.controller_class_to_i18n(self)
end
|
.to_route_path ⇒ Object
Routes Generator Methods ########################################
138
139
140
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 138
def self.to_route_path
::ChupakabraTools::ClassHelper.controller_full_path_underscore(self)
end
|
.to_url_for(action, options = {}) ⇒ Object
Routes Generator Methods ########################################
150
151
152
153
154
155
156
157
158
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 150
def self.to_url_for(action, options = {})
options ||= {}
options.merge!(
only_path: true,
controller: self.to_route_path,
action: action
)
Rails.application.routes.url_helpers.url_for(options)
end
|
Instance Method Details
#add_new_breadcrumb(label, path = nil) ⇒ Object
104
105
106
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 104
def add_new_breadcrumb(label, path = nil)
self.kb_breadcrumbs << {label: label, url: path}
end
|
#authenticate_user ⇒ Object
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 422
def authenticate_user
time_now = DateTime.now.utc
user_remember_me = self.session[:"#{self.current_user_symbol}_remember_me"]
slided_expire_time = time_now + (user_remember_me ? 2.weeks : 1.day)
user_session_expire = self.session[:"#{self.current_user_symbol}_expire"] || slided_expire_time
user_id = self.session[self.current_user_symbol]
if user_session_expire < time_now
logger.info("User Session Expired. Expire At: #{user_session_expire}")
self.current_user_clear_info
else
if user_id
logger.info("User ID: #{user_id}")
logger.info("Slided Expire At: #{slided_expire_time}")
self.current_user = self.current_user_query_db(user_id)
self.session[:"#{self.current_user_symbol}_expire"] = slided_expire_time
else
logger.info("User ID is null")
self.current_user_clear_info
end
end
logger.info("Current User is null") if self.current_user.nil?
logger.info("Current User: #{self.current_user.full_name}") unless self.current_user.nil?
if self.current_user.nil? || self.current_user.deletion_status_id != ::ChupakabraTools::DeletionStatus.id_by_tag(:actual)
logger.info("1Current User is null") if self.current_user.nil?
self.current_user_clear_info
self.session[:return_to] = request.url
respond_to do |format|
format.json { render_json_need_authentication }
format.html { redirect_to self.get_url_to_redirect_for_authentication }
end
end
logger.info("User Authentications is Complete")
logger.info("Current User is null") if self.current_user.nil?
logger.info("Current User: #{self.current_user.full_name}") unless self.current_user.nil?
end
|
#breadcrumbs_length ⇒ Object
117
118
119
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 117
def breadcrumbs_length
self.kb_breadcrumbs.length
end
|
#check_locale_parameter ⇒ Object
def default_url_options
I18n.locale
end
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 319
def check_locale_parameter
if session[:locale]
if I18n.available_locales.include?(params[:locale].to_sym)
if params[:locale] != session[:locale]
session[:locale] = params[:locale]
I18n.locale = params[:locale]
else
I18n.locale = session[:locale]
end
else
I18n.locale = session[:locale]
end
else
I18n.locale = session[:locale]
end
end
|
#class_strong_params(form) ⇒ Object
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 174
def class_strong_params(form)
prms = []
if form.properties
form.properties.each_pair do |key, property|
unless property.read_only == :true
prms << property.name
end
end
elsif form.elements
form.elements.each do |element|
if element.is_a?(::KiruguduBase::DynamicPages::FormProperty)
unless element.read_only == :true
prms << element.name
end
end
end
end
params.require(self.entry_class.for_form_params).permit(prms)
end
|
#current_user ⇒ Object
385
386
387
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 385
def current_user
@current_user
end
|
#current_user=(value) ⇒ Object
389
390
391
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 389
def current_user= value
@current_user = value
end
|
#current_user_clear_info ⇒ Object
411
412
413
414
415
416
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 411
def current_user_clear_info
self.current_user = nil
self.session[self.current_user_symbol] = nil
self.session[:"#{self.current_user_symbol}_expire"] = DateTime.now.utc - 1.day
self.session[:"#{self.current_user_symbol}_remember_me"] = false
end
|
#current_user_query_db(user_id) ⇒ Object
418
419
420
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 418
def current_user_query_db(user_id)
::KirguduBase::Security::User.where(id: user_id).first if user_id
end
|
#current_user_set_info(user, remember_me = nil) ⇒ Object
402
403
404
405
406
407
408
409
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 402
def current_user_set_info(user, remember_me = nil)
self.current_user = user
self.session[self.current_user_symbol] = user.id
self.session[:"#{self.current_user_symbol}_expire"] = DateTime.now.utc + 1.day
self.session[:"#{self.current_user_symbol}_remember_me"] = remember_me
end
|
#current_user_symbol ⇒ Object
393
394
395
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 393
def current_user_symbol
:user_id
end
|
#entry_class ⇒ Object
75
76
77
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 75
def entry_class
self.class.get_kb_entry_class
end
|
#fake_counter_iterate(counter_name) ⇒ Object
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
664
665
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
714
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
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 617
def fake_counter_iterate(counter_name)
end
|
#get_best_locale ⇒ Object
342
343
344
345
346
347
348
349
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 342
def get_best_locale
locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first.to_sym
if I18n.available_locales.include?(locale)
locale
else
I18n.default_locale
end
end
|
#get_class_hierarchy ⇒ Object
Class Hierarchy Methods ########################################
227
228
229
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 227
def get_class_hierarchy
self.class.get_class_hierarchy
end
|
#get_class_variable(name) ⇒ Object
235
236
237
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 235
def get_class_variable(name)
self.class.get_class_variable(name)
end
|
#get_filters_for_list(list, source) ⇒ Object
Filters #########################################
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 202
def get_filters_for_list(list, source)
result = {}
if list
list.filters.each do |filter|
source_value = source[filter.name]
if [:autocomplete, :autocomplete_with_id, :text_edit, :select, :chosen_select].include?(filter.input_type)
if source_value
source_value.strip!
source_value = nil if source_value.blank?
end
end
result[filter.name] = source_value if source_value
end if list.filters
result[:page] = source[:page].to_i rescue nil
result[:per_page] = source[:per_page] rescue nil
end
result
end
|
#get_kirgudu_base_authentication_controller_setting ⇒ Object
489
490
491
492
493
494
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 489
def get_kirgudu_base_authentication_controller_setting
auth_controller = ::KirguduBase.authentications_controller
raise "Add 'KirguduBase.authentications_controller' to /initializers/kirgudu_base.rb' method" unless auth_controller
auth_controller = eval(auth_controller) if auth_controller.is_a?(String)
auth_controller
end
|
#get_layout_path(include_template = true) ⇒ Object
514
515
516
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 514
def get_layout_path(include_template = true)
self.get_view_path(:layout, include_template)
end
|
#get_template_path ⇒ Object
Views Paths #######################################
501
502
503
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 501
def get_template_path
self.class.get_method_latest_result(:get_kb_template);
end
|
#get_url_for_login(options = {}) ⇒ Object
476
477
478
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 476
def get_url_for_login( options = {})
self.get_kirgudu_base_authentication_controller_setting.to_url_for(:login, options)
end
|
#get_url_for_logout(options = {}) ⇒ Object
479
480
481
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 479
def get_url_for_logout( options = {})
self.get_kirgudu_base_authentication_controller_setting.to_url_for(:logout, options)
end
|
#get_url_for_restore_password_code(options = {}) ⇒ Object
483
484
485
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 483
def get_url_for_restore_password_code(options = {})
self.get_kirgudu_base_authentication_controller_setting.to_url_for(:restore_password_code, options)
end
|
#get_url_to_redirect_for_authentication ⇒ Object
466
467
468
469
470
471
472
473
474
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 466
def get_url_to_redirect_for_authentication
auth_controller = ::KirguduBase.authentications_controller
raise "Put in 'intializers' value for 'KirguduBase.authentications_controller' or override 'get_url_to_redirect_for_authentication' method" unless auth_controller
if auth_controller.is_a?(String)
auth_controller = eval(auth_controller)
end
auth_controller.to_url_for(:login)
end
|
#get_view_default_path(view_name) ⇒ Object
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 518
def get_view_default_path(view_name)
defaults = {
layout: "layouts/application",
page_404: "shared/page_404",
entry_not_found: "shared/entry_not_found",
index: "common/index",
new: "common/new",
edit: "common/edit",
delete: "common/delete",
show: "common/show",
management: "common/management",
sorting: "common/sorting",
dashboard: "common/dashboard"
}
defaults[view_name]
end
|
#get_view_path(view_name, include_template = true) ⇒ Object
505
506
507
508
509
510
511
512
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 505
def get_view_path(view_name, include_template = true)
view_path = self.class.get_method_latest_result(:get_kb_view_path, view_name)
view_path ||= self.get_view_default_path(view_name)
template_path = ""
template_path = self.get_template_path if include_template
include_template ? "#{template_path}/#{view_path}" : "#{view_path}"
end
|
#initialize_global_variables ⇒ Object
called in before_action in ::KirguduBase::ApplicationController
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 362
def initialize_global_variables
@template_path = self.class.get_method_latest_result(:get_kb_template)
@settings_manager = ::KirguduBase::Settings::SettingsManager.new
default_host_to_set = request.host
default_host_to_set += ":#{request.port}" if request.port && request.port != 80
Rails.application.routes.default_url_options[:host] = default_host_to_set
if Rails.env.development?
I18n.locale = :ru
end
WillPaginate.per_page = 20
end
|
#kb_breadcrumbs ⇒ Object
113
114
115
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 113
def kb_breadcrumbs
@kb_breadcrumbs ||= []
end
|
#page_for_default_redirection_after_login ⇒ Object
59
60
61
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 59
def page_for_default_redirection_after_login
end
|
#prepare_applications_data ⇒ Object
352
353
354
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 352
def prepare_applications_data
end
|
#prepare_breadcrumbs ⇒ Object
109
110
111
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 109
def prepare_breadcrumbs
end
|
#process_transaction_injections(entry, action, flow_position, filter_params, options = {}) ⇒ Object
Dynamic Transactions #########################################
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 252
def process_transaction_injections(entry, action, flow_position, filter_params, options = {})
options ||= {}
transaction_is_ok = true
classes_to_process = self.get_class_hierarchy
classes_to_process.each do |controller_klass|
if controller_klass.respond_to?(:get_kb_transaction_injections)
available_injections = controller_klass.get_kb_transaction_injections(action, flow_position)
available_injections.each do |injection|
if self.send(injection.method, entry, filter_params, options) == false
transaction_is_ok &= false
end
end if available_injections
end
end
transaction_is_ok
end
|
#render(*args) ⇒ Object
85
86
87
88
89
90
91
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 85
def render *args
self.render_breadcrumbs
super
end
|
#render_breadcrumbs ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 94
def render_breadcrumbs
end
|
#render_page_e404 ⇒ Object
762
763
764
765
766
767
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 762
def render_page_e404
respond_to do |format|
format.html { render :template => 'layouts/404', :status => 404 }
format.all { render :nothing => true, :status => "404" }
end
end
|
#set_content_type ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 64
def set_content_type
content_type = case params[:format]
when "json"
"application/json"
when "xml"
"text/xml"
end
self.["Content-Type"] = content_type if content_type
end
|
#set_i18n_locale_from_params ⇒ Object
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 278
def set_i18n_locale_from_params
if params[:locale]
if I18n.available_locales.include?(params[:locale].to_sym)
I18n.locale = params[:locale]
session[:locale] = params[:locale]
cookies.permanent[:locale_set] = params[:locale]
else
if session[:locale]
redirect_to url_for(locale: session[:locale])
elsif cookies[:locale_set]
session[:locale] = cookies[:locale_set]
params[:locale] = cookies[:locale_set]
I18n.locale = cookies[:locale_set]
else
locale = get_best_locale
params[:locale] = locale
session[:locale] = locale
cookies.permanent[:locale_set] = locale
I18n.locale = locale
end
end
elsif session[:locale]
redirect_to url_for(locale: session[:locale])
elsif cookies[:locale_set]
redirect_to url_for(locale: cookies[:locale_set])
else
redirect_to url_for(locale: get_best_locale)
end
end
|
#string_logger ⇒ Object
#######################################
540
541
542
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 540
def string_logger
@string_logger
end
|
#string_logger=(value) ⇒ Object
544
545
546
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 544
def string_logger= value
@string_logger = value
end
|
#system_logging_init ⇒ Object
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
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 572
def system_logging_init
end
|
#system_logging_write_event(source, level_id, message) ⇒ Object
605
606
607
608
609
610
611
612
613
614
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 605
def system_logging_write_event(source, level_id, message)
end
|
#to_i18n ⇒ Object
130
131
132
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 130
def to_i18n
self.class.to_i18n
end
|
#to_route_path ⇒ Object
142
143
144
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 142
def to_route_path
self.class.to_route_path
end
|
#to_url_for(action = nil, options = {}) ⇒ Object
160
161
162
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 160
def to_url_for(action = nil, options = {})
self.class.to_url_for(action, options)
end
|
#update_url_with_ajax_referer_url ⇒ Object
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
|
# File 'app/controllers/kirgudu_base/application_controller.rb', line 553
def update_url_with_ajax_referer_url
if params[:current_url]
begin
p_current_url = URI.parse(params[:current_url])
p_query = CGI.parse(p_current_url.query)
params[:page] = p_query["page"].first if p_query["page"]
params[:status_id] = p_query["status_id"].first if p_query["status_id"]
params[:website_id] = p_query["website_id"].first if p_query["website_id"] and params[:website_id].nil?
end
end
end
|