Class: KirguduBase::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Extended by:
Controllers::DynamicPages::Class, Controllers::DynamicTransactions, Controllers::ObligatoryFilters
Includes:
ApplicationHelper, BreadcrumbsHelper, Controllers::DynamicPages::Instance, UrlHelper
Defined in:
app/controllers/kirgudu_base/application_controller.rb

Instance Attribute Summary

Attributes included from Controllers::DynamicPages::Class

#kirgudu_controller_options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Controllers::DynamicPages::Class

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

Methods included from Controllers::DynamicTransactions

get_kb_transaction_injections, kb_transaction_injection

Methods included from Controllers::ObligatoryFilters

get_kb_obligatory_filters, kb_obligatory_filter

Methods included from ApplicationHelper

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

Methods included from BreadcrumbsHelper

included

Methods included from UrlHelper

#url_for, #with_subdomain

Class Method Details

.get_class_hierarchyObject



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_i18nObject

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_pathObject

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_userObject



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}")
    #raise "Session Expired #{user_session_expire}, #{self.session[:"#{self.current_user_symbol}_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?
    #logger.info("1Current User deletion_status_id: #{::ChupakabraTools::DeletionStatus[self.current_user.deletion_status_id]}") unless self.current_user.deletion_status_id == ::ChupakabraTools::DeletionStatus.id_by_tag(:actual)
    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 deletion_status_id: #{::ChupakabraTools::DeletionStatus[self.current_user.deletion_status_id]}") unless ::ChupakabraTools::DeletionStatus.id_by_tag(:actual)
  logger.info("Current User: #{self.current_user.full_name}") unless self.current_user.nil?
end


117
118
119
# File 'app/controllers/kirgudu_base/application_controller.rb', line 117

def breadcrumbs_length
  self.kb_breadcrumbs.length
end

#check_locale_parameterObject

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 params[: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]
      #redirect_to home_path, notice: :wrong_locale #"Translation \"#{params[:locale]}\" not available yet."
    end
  else
    I18n.locale = session[:locale]
    #redirect_to request.url, locale: I18n.locale
  end
  #else
  #  session[:locale] = I18n.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

  #raise "#{self.entry_class.for_form_params}"
  #raise "#{prms.to_s}"
  params.require(self.entry_class.for_form_params).permit(prms)
end

#current_userObject

method for Ability



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_infoObject



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)
  #logger.info("USER is ::KirguduBase::Security::User") if user && user.is_a?(::KirguduBase::Security::User)
  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
  #logger.info("Session[:user_id]=#{self.session[:user_id]}")
end

#current_user_symbolObject



393
394
395
# File 'app/controllers/kirgudu_base/application_controller.rb', line 393

def current_user_symbol
  :user_id
end

#entry_classObject



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)
  #counter_data = {}
  #counter_data[:total_name] = "Fake::Counter::Total::#{counter_name}"
  #counter_data[:quantity_per_period_name] = "Fake::Counter::#{counter_name}::QuantityPerPeriod"
  #counter_data[:period_type_name] = "Fake::Counter::#{counter_name}::PeriodType"
  #counter_data[:initial_seed_name] = "Fake::Counter::#{counter_name}::InitialSeed"
  #
  #counter_data[:local_timezone] = ActiveSupport::TimeZone.new("Moscow")
  #counter_data[:local_today] = Time.now.in_time_zone(counter_data[:local_timezone]).to_date
  #counter_data[:local_now] = Time.now.in_time_zone(counter_data[:local_timezone])
  #
  ##getting or setting number_of_orders_per_period
  #counter_data[:total] = @settings_manager.get(counter_data[:total_name])
  #unless counter_data[:total]
  #	counter_data[:total] = 846
  #	create_option(counter_data[:total_name], counter_data[:total], value_type: "integer")
  #end
  #
  ##getting or setting number_of_orders_per_period
  #counter_data[:quantity_per_period] = @settings_manager.get(counter_data[:quantity_per_period_name])
  #counter_data[:quantity_per_period] = 63 unless counter_data[:quantity_per_period]
  ##getting or setting counter_data[:period_type]
  #counter_data[:period_type] = @settings_manager.get(counter_data[:period_type_name])
  #counter_data[:period_type] = "day" unless counter_data[:period_type]
  ##getting or setting counter_data[:initial_seed]
  #counter_data[:initial_seed] = @settings_manager.get(counter_data[:initial_seed_name])
  #counter_data[:initial_seed] = 7 unless counter_data[:initial_seed]
  #
  #
  ## searchiung for period_counter in OrderCounter
  #period_counter = get_period_counter(counter_data[:local_now], counter_data[:period_type])
  #
  #
  ## string_logger.info("*****************************************************************")
  ## string_logger.info("Total Counter (before): #{total_counter}") if total_counter
  ## string_logger.info("Day Counter (before): #{day_counter}") if day_counter
  #
  #ActiveRecord::Base.transaction do
  #	unless period_counter
  #		# period_counter not found so New period_counter created
  #		period_counter = ::SystemZone::Fakes::Counter.new
  #		# calculating period_start and period_end Time
  #		if counter_data[:period_type] == "day"
  #			period_counter.start_at = counter_data[:local_now].beginning_of_day
  #			period_counter.finish_at = counter_data[:local_now].end_of_day
  #		elsif counter_data[:period_type] == "week"
  #			period_counter.start_at = counter_data[:local_now].beginning_of_week
  #			period_counter.finish_at = counter_data[:local_now].end_of_week
  #		elsif counter_data[:period_type] == "month"
  #			period_counter.start_at = counter_data[:local_now].beginning_of_month
  #			period_counter.finish_at = counter_data[:local_now].end_of_month
  #		elsif counter_data[:period_type] == "year"
  #			period_counter.start_at = counter_data[:local_now].beginning_of_year
  #			period_counter.finish_at = counter_data[:local_now].end_of_year
  #		else
  #			period_counter.start_at = counter_data[:local_now].beginning_of_day
  #			period_counter.finish_at = counter_data[:local_now].end_of_day
  #		end
  #		# initializing period_counter values
  #		period_counter.fake_initial = rand(counter_data[:initial_seed])
  #		period_counter.fake_max = counter_data[:quantity_per_period]
  #		period_counter.fake_value = period_counter.fake_initial
  #		period_counter.real_value = period_counter.fake_initial
  #		# calculate period in seconds for current period
  #		period_in_seconds = (period_counter.period_end - period_counter.period_start).round
  #		# calculate iteration period in seconds keeping in mind that we have fake_value_initial
  #		iteration_period_in_seconds = (period_in_seconds / (counter_data[:quantity_per_period] - period_counter.fake_value_initial)).round
  #		# calculating number of iteration from period start to now
  #		number_of_iteration_by_now = ((counter_data[:local_now] - period_counter.period_start).round/iteration_period_in_seconds).round
  #		#adding number_of_iteration_by_now to fake_value
  #		period_counter.fake_value += number_of_iteration_by_now
  #		period_counter.real_value += number_of_iteration_by_now
  #		# initializing next_iteration_date
  #		next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
  #		# increasing number_of_iteration_by_now by 1 while next_iteration_date < counter_data[:local_now]
  #		begin
  #			number_of_iteration_by_now += 1
  #			#period_counter.fake_value += 1
  #			#period_counter.real_value += 1
  #			next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
  #		end while next_iteration_date < counter_data[:local_now]
  #		#setting net_iteration_date
  #		period_counter.next_iteration_date = next_iteration_date
  #		counter_data[:total] += period_counter.real_value
  #		set_option_value(counter_data[:total_name], counter_data[:total])
  #	end
  #	if period_counter.next_iteration_date < counter_data[:local_now]
  #		#string_logger.info("*****************************************************************")
  #		#string_logger.info("*****************************************************************")
  #		#string_logger.info("Increasing Current OrderCounter")
  #		#string_logger.info("*****************************************************************")
  #		#string_logger.info("Fake Value: #{period_counter.fake_value}")
  #		#string_logger.info("Real Value: #{period_counter.real_value}")
  #		# calculate period in seconds for current period
  #		period_in_seconds = (period_counter.period_end - period_counter.period_start).round
  #		#string_logger.info("Period (in seconds): #{period_in_seconds}")
  #		# calculate iteration period in seconds keeping in mind that we have fake_value_initial
  #		iteration_period_in_seconds = (period_in_seconds / (counter_data[:quantity_per_period] - period_counter.fake_value_initial)).round
  #		#string_logger.info("Iteration Period (in seconds): #{iteration_period_in_seconds}")
  #		# calculating number of iteration from period start to now
  #		number_of_iteration_by_now = ((counter_data[:local_now] - period_counter.period_start).round/iteration_period_in_seconds).round
  #		#string_logger.info("Number of Iterations by Now: #{number_of_iteration_by_now}")
  #		#adding difference between number_of_iteration_by_now and fake_value to fake_value
  #		iteration_difference_by_now = number_of_iteration_by_now - period_counter.fake_value
  #		#string_logger.info("Iterations To Add (difference): #{iteration_difference_by_now}")
  #		if iteration_difference_by_now > 0
  #			period_counter.fake_value += iteration_difference_by_now
  #			period_counter.real_value += iteration_difference_by_now
  #			#increasing total counter
  #			counter_data[:total] += iteration_difference_by_now
  #			set_option_value(counter_data[:total_name], counter_data[:total])
  #
  #			#string_logger.info("Fake Value (with difference): #{period_counter.fake_value}")
  #			#string_logger.info("Real Value (with difference): #{period_counter.real_value}")
  #			# initializing next_iteration_date
  #			next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
  #			#string_logger.info("Next Iteration Date: #{next_iteration_date.in_time_zone(counter_data[:local_timezone])}")
  #			# increasing number_of_iteration_by_now by 1 while next_iteration_date < counter_data[:local_now]
  #			begin
  #				#string_logger.info("Iterrating for next iteration date")
  #				number_of_iteration_by_now += 1
  #				#period_counter.fake_value += 1
  #				#period_counter.real_value += 1
  #				next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
  #			end while next_iteration_date < counter_data[:local_now]
  #			#setting net_iteration_date
  #			period_counter.next_iteration_date = next_iteration_date
  #			#string_logger.info("*****************************************************************")
  #			#string_logger.info("*****************************************************************")
  #		end
  #	end
  #	#saving period_counter
  #	period_counter.save
  #end # end of transaction
  #
  #counter_result = {}
  #counter_result[:total] = counter_data[:total]
  #counter_result[:by_period] = period_counter.fake_value
  #
  ## string_logger.info("Total Counter: #{counter_result[:total]}")
  ## string_logger.info("Day Counter: #{counter_result[:by_period]}")
  #counter_result
end

#get_best_localeObject



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_hierarchyObject

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_settingObject



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_pathObject

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 ( 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_authenticationObject



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_variablesObject

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_breadcrumbsObject



113
114
115
# File 'app/controllers/kirgudu_base/application_controller.rb', line 113

def kb_breadcrumbs
  @kb_breadcrumbs ||= []
end

#page_for_default_redirection_after_loginObject



59
60
61
# File 'app/controllers/kirgudu_base/application_controller.rb', line 59

def 

end

#prepare_applications_dataObject



352
353
354
# File 'app/controllers/kirgudu_base/application_controller.rb', line 352

def prepare_applications_data

end

#prepare_breadcrumbsObject



109
110
111
# File 'app/controllers/kirgudu_base/application_controller.rb', line 109

def prepare_breadcrumbs
  #string_logger.info("BREADCRUMBS: #{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|
        #raise "Processing Transaction Injection. Class: #{controller_klass.to_s}, Injection: #{injection.to_json}"
        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

  #raise "BreadCrumbs: #{self.create_breadcrumbs}"

  super
end

#render_breadcrumbsObject



94
95
96
97
98
99
100
101
102
# File 'app/controllers/kirgudu_base/application_controller.rb', line 94

def render_breadcrumbs
  #if self.class.respond_to?(:dashboard_controller_class_name)
  #	if self.class.to_s == self.class.dashboard_controller_class_name.to_s
  #		add_new_breadcrumb(I18n.t("#{self.class.dashboard_controller_class_name.to_i18n}.index.title"))
  #	else
  #		add_new_breadcrumb(I18n.t("#{self.class.dashboard_controller_class_name.to_i18n}.index.title"), self.class.dashboard_controller_class_name.to_route_path)
  #	end
  #end
end

#render_page_e404Object



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_typeObject



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.headers["Content-Type"] = content_type if content_type
end

#set_i18n_locale_from_paramsObject



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]
        #params[:locale] = session[:locale]
        #I18n.locale = session[:locale]
        #locale_redirect(session[:locale])
        #redirect_to request.url  #, notice: "Translation \"#{params[:locale]}\" not available."
        #@string_logger.error flash.now[:notice]
        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]
        #locale_redirect(session[:locale])
      else
        locale = get_best_locale
        params[:locale] = locale
        session[:locale] = locale
        cookies.permanent[:locale_set] = locale
        I18n.locale = locale
        #locale_redirect(I18n.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_loggerObject

#######################################



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_initObject



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
  #@logging_options = Hash.new
  #
  #@logging_options[:status] = @settings_manager.get("SystemZone::Logging::Status")
  #unless @logging_options[:status]
  #	@logging_options[:status] = false
  #end
  #@logging_options[:level] = @settings_manager.get("SystemZone::Logging::Level")
  #unless @logging_options[:level]
  #	@logging_options[:level] = ::SystemZone::Logging::Event::LEVEL_SYSTEM
  #end
  #
  #if @logging_options[:status] == true
  #	@logging_request = ::SystemZone::Logging::Request.new
  #	@logging_request.ip = request.remote_ip
  #	@logging_request.serve_id = 1 #FIX: change in future to identify servers
  #	@logging_request.session_id = request.session[:session_id] ? request.session[:session_id] : ''
  #	@logging_request.controller_name = controller_path
  #	@logging_request.action_name = self.action_name
  #	@logging_request.http_method = request.method
  #	@logging_request.params = params.to_json
  #	@logging_request.agent = request.env["HTTP_USER_AGENT"]
  #	@logging_request.os = http_request_retrieve_operating_system(request.env["HTTP_USER_AGENT"])
  #	                              #@logging_request.screen = request.env["HTTP_USER_AGENT"]
  #	@logging_request.referer_url = request.referer
  #	@logging_request.url = request.referer
  #	@logging_request.user_id = @current_user.id if @current_user && @current_user.id
  #	@logging_request.client_id = current_client.id if current_client && current_client.id
  #	@logging_request.save
  #end

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)
  #if @logging_options[:status] == true && @logging_request && (level_id == ::SystemZone::Logging::Event::LEVEL_SYSTEM || level_id <= @logging_options[:level])
  #	current_event = ::SystemZone::Logging::Event.new
  #	current_event.request = @logging_request
  #	current_event.source = source && !source.blank? ? source : self.action_name
  #	current_event.level_id = level_id
  #	current_event.message = message
  #	current_event.save
  #end
end

#to_i18nObject



130
131
132
# File 'app/controllers/kirgudu_base/application_controller.rb', line 130

def to_i18n
  self.class.to_i18n
end

#to_route_pathObject



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_urlObject



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)

      #string_logger.info("Current URL: #{p_current_url}")
      #string_logger.info("Current URL QUERY : #{p_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?

      #string_logger.info("Params After Loading from Current URL: #{params}")
    end
  end
end