kirgudu_base 0.0.23 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62512dde61aa7cdb3146a0f47a0a829b2ef340d7
4
- data.tar.gz: 8928e1ea07b318108bba8cce90aa2d61acf924a7
3
+ metadata.gz: ada44845151cb638bdff9d72359de28fc3ef4212
4
+ data.tar.gz: 682f789c5de778ee0a5c3f8e45345879f0cdc2ef
5
5
  SHA512:
6
- metadata.gz: 93542c4c4f5df64407e3871eb33bef7ce483abc298fb90ef2049313deda569bc8fe434c99d5f4d72e81658582da14eb35aafe16a9e90a241d7e9b774f8796ad3
7
- data.tar.gz: 0c369324f159f426bffff49f801492814987b4398d5622e49c6226af0f627bac0c896ef28acef62c223e94e06d62279ed753c7e49586b173cdfb15a6d476bc1f
6
+ metadata.gz: 88926b030fd37398d89863be78837000b23fe027ccdf379c702ab778f4612937b0ca91c90b095287d0886c1c12460faa6e446cb9832d4669228810ff1572e265
7
+ data.tar.gz: c6397005b78fa7c681abe004b8a8a48de1cbf61cb60bead76c66279be33ee9037ed4fedc84d83b0dc4c6a8d31a6d6a89106620792922dabb0a733b0dbbaaf1e8
@@ -1,804 +1,813 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module KirguduBase
3
- class ApplicationController < ActionController::Base
3
+ class ApplicationController < ActionController::Base
4
4
 
5
5
 
6
- ########################################################################################
7
- ############################## Extending Controller ####################################
8
- ########################################################################################
6
+ ########################################################################################
7
+ ############################## Extending Controller ####################################
8
+ ########################################################################################
9
9
 
10
- # DynamicPages Helper
11
- extend ::KirguduBase::Controllers::DynamicPages::Class
12
- include ::KirguduBase::Controllers::DynamicPages::Instance
10
+ # DynamicPages Helper
11
+ extend ::KirguduBase::Controllers::DynamicPages::Class
12
+ include ::KirguduBase::Controllers::DynamicPages::Instance
13
13
 
14
- # DynamicTransactions Helper
15
- extend ::KirguduBase::Controllers::DynamicTransactions
14
+ # DynamicTransactions Helper
15
+ extend ::KirguduBase::Controllers::DynamicTransactions
16
16
 
17
- # ObligatoryFilters Helper
18
- extend ::KirguduBase::Controllers::ObligatoryFilters
17
+ # ObligatoryFilters Helper
18
+ extend ::KirguduBase::Controllers::ObligatoryFilters
19
19
 
20
20
 
21
+ include ::KirguduBase::UrlHelper
22
+ include ::KirguduBase::BreadcrumbsHelper
23
+ include ::KirguduBase::ApplicationHelper
21
24
 
22
- include ::KirguduBase::UrlHelper
23
- include ::KirguduBase::BreadcrumbsHelper
24
- include ::KirguduBase::ApplicationHelper
25
25
 
26
+ ########################################################################################
27
+ ######################### Before&After Actions ###############################
28
+ ########################################################################################
26
29
 
27
- ########################################################################################
28
- ######################### Before&After Actions ###############################
29
- ########################################################################################
30
30
 
31
+ before_action :request_started # first filter of request
32
+ before_action :initialize_global_variables
31
33
 
32
- before_action :request_started # first filter of request
33
- before_action :initialize_global_variables
34
34
 
35
+ after_action :request_finished # last filter of request
35
36
 
36
- after_action :request_finished # last filter of request
37
+ ########################################################################################
38
+ ############################## Views Paths ###################################
39
+ ########################################################################################
37
40
 
38
- ########################################################################################
39
- ############################## Views Paths ###################################
40
- ########################################################################################
41
+ # template path
42
+ kb_template_path "kirgudu_base/admin/zapanel"
43
+ # layout view pathes
44
+ kb_views_paths_layout "layouts/application"
45
+ # action views pathes
46
+ kb_views_paths_dashboard "common/dashboard"
47
+ kb_views_paths_index "common/index"
48
+ kb_views_paths_new "common/new"
49
+ kb_views_paths_edit "common/edit"
50
+ kb_views_paths_delete "common/delete"
51
+ kb_views_paths_show "common/show"
52
+ kb_views_paths_management "/common/management"
53
+ kb_views_paths_sorting "/common/sorting"
54
+ # common views pathes
55
+ kb_views_paths_entry_not_found "shared/entry_not_found"
56
+ kb_views_paths_404_page "shared/page_404"
41
57
 
42
- # template path
43
- kb_template_path "kirgudu_base/admin/zapanel"
44
- # layout view pathes
45
- kb_views_paths_layout "layouts/application"
46
- # action views pathes
47
- kb_views_paths_dashboard "common/dashboard"
48
- kb_views_paths_index "common/index"
49
- kb_views_paths_new "common/new"
50
- kb_views_paths_edit "common/edit"
51
- kb_views_paths_delete "common/delete"
52
- kb_views_paths_show "common/show"
53
- kb_views_paths_management "/common/management"
54
- kb_views_paths_sorting "/common/sorting"
55
- # common views pathes
56
- kb_views_paths_entry_not_found "shared/entry_not_found"
57
- kb_views_paths_404_page "shared/page_404"
58
58
 
59
+ def page_for_default_redirection_after_login
59
60
 
61
+ end
60
62
 
61
63
 
64
+ def set_content_type
65
+ content_type = case params[:format]
66
+ when "json"
67
+ "application/json"
68
+ when "xml"
69
+ "text/xml"
70
+ end
71
+ self.headers["Content-Type"] = content_type if content_type
72
+ end
62
73
 
63
74
 
75
+ def entry_class
76
+ self.class.get_kb_entry_class
77
+ end
64
78
 
65
- def page_for_default_redirection_after_login
66
79
 
67
- end
80
+ #########################################################################################################################
81
+ ###################################### Breadcrumbs ###############################################
82
+ #########################################################################################################################
68
83
 
69
84
 
70
- def set_content_type
71
- content_type = case params[:format]
72
- when "json"
73
- "application/json"
74
- when "xml"
75
- "text/xml"
76
- end
77
- self.headers["Content-Type"] = content_type if content_type
78
- end
85
+ def render *args
86
+ self.render_breadcrumbs
79
87
 
88
+ #raise "BreadCrumbs: #{self.create_breadcrumbs}"
80
89
 
90
+ super
91
+ end
81
92
 
82
- def entry_class
83
- self.class.get_kb_entry_class
84
- end
85
93
 
94
+ def render_breadcrumbs
95
+ #if self.class.respond_to?(:dashboard_controller_class_name)
96
+ # if self.class.to_s == self.class.dashboard_controller_class_name.to_s
97
+ # add_new_breadcrumb(I18n.t("#{self.class.dashboard_controller_class_name.to_i18n}.index.title"))
98
+ # else
99
+ # add_new_breadcrumb(I18n.t("#{self.class.dashboard_controller_class_name.to_i18n}.index.title"), self.class.dashboard_controller_class_name.to_route_path)
100
+ # end
101
+ #end
102
+ end
86
103
 
104
+ def add_new_breadcrumb(label, path = nil)
105
+ self.kb_breadcrumbs << {label: label, url: path}
106
+ end
87
107
 
88
108
 
109
+ def prepare_breadcrumbs
110
+ #string_logger.info("BREADCRUMBS: #{breadcrumbs}")
111
+ end
89
112
 
90
- #########################################################################################################################
91
- ###################################### Breadcrumbs ###############################################
92
- #########################################################################################################################
113
+ def kb_breadcrumbs
114
+ @kb_breadcrumbs ||= []
115
+ end
93
116
 
94
-
95
- def render *args
96
- self.render_breadcrumbs
97
-
98
- #raise "BreadCrumbs: #{self.create_breadcrumbs}"
99
-
100
- super
101
- end
102
-
103
-
104
- def render_breadcrumbs
105
- #if self.class.respond_to?(:dashboard_controller_class_name)
106
- # if self.class.to_s == self.class.dashboard_controller_class_name.to_s
107
- # add_new_breadcrumb(I18n.t("#{self.class.dashboard_controller_class_name.to_i18n}.index.title"))
108
- # else
109
- # add_new_breadcrumb(I18n.t("#{self.class.dashboard_controller_class_name.to_i18n}.index.title"), self.class.dashboard_controller_class_name.to_route_path)
110
- # end
111
- #end
112
- end
113
-
114
- def add_new_breadcrumb(label, path = nil)
115
- self.kb_breadcrumbs << {label: label, url: path}
116
- end
117
-
118
-
119
- def prepare_breadcrumbs
120
- #string_logger.info("BREADCRUMBS: #{breadcrumbs}")
121
- end
122
-
123
- def kb_breadcrumbs
124
- @kb_breadcrumbs ||= []
125
- end
126
-
127
- def breadcrumbs_length
128
- self.kb_breadcrumbs.length
129
- end
130
-
131
-
132
- #########################################################################################################################
133
- ############################# I18n String Generator Methods #####################################
134
- #########################################################################################################################
135
-
136
- def self.to_i18n
137
- ::ChupakabraTools::ClassHelper.controller_class_to_i18n(self)
138
- end
139
-
140
- def to_i18n
141
- self.class.to_i18n
142
- end
143
-
144
- #########################################################################################################################
145
- ############################### Routes Generator Methods ########################################
146
- #########################################################################################################################
147
-
148
- def self.to_route_path
149
- ::ChupakabraTools::ClassHelper.controller_full_path_underscore(self)
150
- end
151
-
152
- def to_route_path
153
- self.class.to_route_path
154
- end
155
-
156
- #########################################################################################################################
157
- ############################### Routes Generator Methods ########################################
158
- #########################################################################################################################
159
-
160
- def self.to_url_for(action, options = {})
161
- options ||= {}
162
- options.merge!(
163
- only_path: true,
164
- controller: self.to_route_path,
165
- action: action
166
- )
167
- Rails.application.routes.url_helpers.url_for(options)
168
- end
169
-
170
- def to_url_for(action = nil, options = {})
171
- self.class.to_url_for(action, options)
172
- end
173
-
174
- #########################################################################################################################
175
- #################################### Routes Injection ############################################
176
- #########################################################################################################################
177
-
178
-
179
- #########################################################################################################################
180
- ##################################### Strong Parameters ###########################################
181
- #########################################################################################################################
182
-
183
-
184
- def class_strong_params(form)
185
- prms = []
186
- if form.properties
187
- form.properties.each_pair do |key, property|
188
- unless property.read_only == :true
189
- prms << property.name
190
- end
191
- end
192
- elsif form.elements
193
- form.elements.each do |element|
194
- if element.is_a?(::KiruguduBase::DynamicPages::FormProperty)
195
- unless element.read_only == :true
196
- prms << element.name
197
- end
198
- end
199
- end
200
- end
201
-
202
- #raise "#{self.entry_class.for_form_params}"
203
- #raise "#{prms.to_s}"
204
- params.require(self.entry_class.for_form_params).permit(prms)
205
- end
206
-
207
-
208
- #########################################################################################################################
209
- ################################### Filters #########################################
210
- #########################################################################################################################
211
-
212
- def get_filters_for_list(list, source)
213
- result = {}
214
- if list
215
- list.filters.each do |filter|
216
- source_value = source[filter.name]
217
- if [:autocomplete, :autocomplete_with_id, :text_edit, :select, :chosen_select].include?(filter.input_type)
218
- if source_value
219
- source_value.strip!
220
- source_value = nil if source_value.blank?
221
- end
222
- end
223
- result[filter.name] = source_value if source_value
224
- end if list.filters
225
-
226
- result[:page] = source[:page].to_i rescue nil
227
- result[:per_page] = source[:per_page] rescue nil
228
- end
229
- result
230
- end
231
-
232
-
233
- #########################################################################################################################
234
- ################################## Class Hierarchy Methods ########################################
235
- #########################################################################################################################
236
-
237
- def get_class_hierarchy
238
- self.class.get_class_hierarchy
239
- end
240
-
241
- def self.get_class_hierarchy
242
- ::ChupakabraTools::ClassHelper.get_controller_hierarchy(self)
243
- end
244
-
245
- def get_class_variable(name)
246
- self.class.get_class_variable(name)
247
- end
248
-
249
- def self.get_method_latest_result(method_name, *method_args)
250
- method_result = nil
251
- self.get_class_hierarchy.each do |controller_class|
252
- method_result = controller_class.send(method_name, *method_args) if controller_class.respond_to?(method_name)
253
- return method_result if method_result
254
- end
255
- method_result
256
- end
257
-
258
- #########################################################################################################################
259
- ################################### Dynamic Transactions #########################################
260
- #########################################################################################################################
261
-
262
- def process_transaction_injections(entry, action, flow_position, filter_params, options = {})
263
- options ||= {}
264
-
265
- transaction_is_ok = true
266
-
267
- classes_to_process = self.get_class_hierarchy
268
- classes_to_process.each do |controller_klass|
269
- if controller_klass.respond_to?(:get_kb_transaction_injections)
270
- available_injections = controller_klass.get_kb_transaction_injections(action, flow_position)
271
- available_injections.each do |injection|
272
- #raise "Processing Transaction Injection. Class: #{controller_klass.to_s}, Injection: #{injection.to_json}"
273
- if self.send(injection.method, entry, filter_params, options) == false
274
- transaction_is_ok &= false
275
- end
276
- end if available_injections
277
- end
278
- end
279
- transaction_is_ok
280
- end
281
-
282
-
283
-
284
- #########################################################################################################################
285
- ###################################### Locale Methods #############################################
286
- #########################################################################################################################
287
-
288
-
289
- def set_i18n_locale_from_params
290
- if params[:locale]
291
- if I18n.available_locales.include?(params[:locale].to_sym)
292
- I18n.locale = params[:locale]
293
- session[:locale] = params[:locale]
294
- cookies.permanent[:locale_set] = params[:locale]
295
- else
296
- if session[:locale]
297
- #params[:locale] = session[:locale]
298
- #I18n.locale = session[:locale]
299
- #locale_redirect(session[:locale])
300
- #redirect_to request.url #, notice: "Translation \"#{params[:locale]}\" not available."
301
- #@string_logger.error flash.now[:notice]
302
- redirect_to url_for(locale: session[:locale])
303
- elsif cookies[:locale_set]
304
- session[:locale] = cookies[:locale_set]
305
- params[:locale] = cookies[:locale_set]
306
- I18n.locale = cookies[:locale_set]
307
- #locale_redirect(session[:locale])
308
- else
309
- locale = get_best_locale
310
- params[:locale] = locale
311
- session[:locale] = locale
312
- cookies.permanent[:locale_set] = locale
313
- I18n.locale = locale
314
- #locale_redirect(I18n.locale)
315
- end
316
- end
317
- elsif session[:locale]
318
- redirect_to url_for(locale: session[:locale])
319
- elsif cookies[:locale_set]
320
- redirect_to url_for(locale: cookies[:locale_set])
321
- else
322
- redirect_to url_for(locale: get_best_locale)
323
- end
324
- end
325
-
326
- #def default_url_options
327
- # {locale: I18n.locale}
328
- #end
329
-
330
- def check_locale_parameter
331
- if session[:locale]
332
- #if params[:locale]
333
- if I18n.available_locales.include?(params[:locale].to_sym)
334
- if params[:locale] != session[:locale]
335
- session[:locale] = params[:locale]
336
- I18n.locale = params[:locale]
337
- else
338
- I18n.locale = session[:locale]
339
- end
340
- else
341
- I18n.locale = session[:locale]
342
- #redirect_to home_path, notice: :wrong_locale #"Translation \"#{params[:locale]}\" not available yet."
343
- end
344
- else
345
- I18n.locale = session[:locale]
346
- #redirect_to request.url, locale: I18n.locale
347
- end
348
- #else
349
- # session[:locale] = I18n.locale
350
- #end
351
- end
352
-
353
- def get_best_locale
354
- locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first.to_sym
355
- if I18n.available_locales.include?(locale)
356
- locale
357
- else
358
- I18n.default_locale
359
- end
360
- end
361
-
362
-
363
- def prepare_applications_data
364
-
365
- end
366
-
367
-
368
- #########################################################################################################################
369
- ##################################### Global Variables ############################################
370
- #########################################################################################################################
371
-
372
- # called in before_action in ::KirguduBase::ApplicationController
373
- def initialize_global_variables
374
-
375
- @template_path = self.class.get_method_latest_result(:get_kb_template)
376
-
377
- @settings_manager = ::KirguduBase::Settings::SettingsManager.new
378
-
379
- default_host_to_set = request.host
380
- default_host_to_set += ":#{request.port}" if request.port && request.port != 80
381
-
382
- Rails.application.routes.default_url_options[:host] = default_host_to_set
383
-
384
- if Rails.env.development?
385
- I18n.locale = :ru
386
- end
387
-
388
- WillPaginate.per_page = 20
389
- end
390
-
391
- #########################################################################################################################
392
- #################################### Current User To Override ############################################
393
- #########################################################################################################################
394
-
395
- # method for Ability
396
- def current_user
397
- @current_user
398
- end
399
-
400
- def current_user= value
401
- @current_user = value
402
- end
403
-
404
- def current_user_symbol
405
- :user_id
406
- end
407
-
408
- #########################################################################################################################
409
- ####################################### Current User ##############################################
410
- #########################################################################################################################
411
-
412
-
413
- def current_user_set_info(user, remember_me = nil)
414
- #logger.info("USER is ::KirguduBase::Security::User") if user && user.is_a?(::KirguduBase::Security::User)
415
- self.current_user = user
416
- self.session[self.current_user_symbol] = user.id
417
- self.session[:"#{self.current_user_symbol}_expire"] = DateTime.now.utc + 1.day
418
- self.session[:"#{self.current_user_symbol}_remember_me"] = remember_me
419
- #logger.info("Session[:user_id]=#{self.session[:user_id]}")
420
- end
421
-
422
- def current_user_clear_info
423
- self.current_user = nil
424
- self.session[self.current_user_symbol] = nil
425
- self.session[:"#{self.current_user_symbol}_expire"] = DateTime.now.utc - 1.day
426
- self.session[:"#{self.current_user_symbol}_remember_me"] = false
427
- end
428
-
429
- def current_user_query_db(user_id)
430
- ::KirguduBase::Security::User.where(id: user_id).first if user_id
431
- end
432
-
433
- def authenticate_user
434
- time_now = DateTime.now.utc
435
- user_remember_me = self.session[:"#{self.current_user_symbol}_remember_me"]
436
- slided_expire_time = time_now + (user_remember_me ? 2.weeks : 1.day)
437
- user_session_expire = self.session[:"#{self.current_user_symbol}_expire"] || slided_expire_time
438
- user_id = self.session[self.current_user_symbol]
439
-
440
- if user_session_expire < time_now
441
- logger.info("User Session Expired. Expire At: #{user_session_expire}")
442
- #raise "Session Expired #{user_session_expire}, #{self.session[:"#{self.current_user_symbol}_expire"]}"
443
- self.current_user_clear_info
444
- else
445
- if user_id
446
- logger.info("User ID: #{user_id}")
447
- logger.info("Slided Expire At: #{slided_expire_time}")
448
- self.current_user = self.current_user_query_db(user_id)
449
- self.session[:"#{self.current_user_symbol}_expire"] = slided_expire_time
450
- else
451
- logger.info("User ID is null")
452
- self.current_user_clear_info
453
- end
454
- end
455
-
456
- logger.info("Current User is null") if self.current_user.nil?
457
- logger.info("Current User: #{self.current_user.full_name}") unless self.current_user.nil?
458
-
459
-
460
- if self.current_user.nil? || self.current_user.deletion_status_id != ::ChupakabraTools::DeletionStatus.id_by_tag(:actual)
461
- logger.info("1Current User is null") if self.current_user.nil?
462
- #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)
463
- self.current_user_clear_info
464
- self.session[:return_to] = request.url
465
- respond_to do |format|
466
- format.json { render_json_need_authentication }
467
- format.html { redirect_to self.get_url_to_redirect_for_authentication }
468
- end
469
- end
470
-
471
- logger.info("User Authentications is Complete")
472
- logger.info("Current User is null") if self.current_user.nil?
473
- #logger.info("Current User deletion_status_id: #{::ChupakabraTools::DeletionStatus[self.current_user.deletion_status_id]}") unless ::ChupakabraTools::DeletionStatus.id_by_tag(:actual)
474
- logger.info("Current User: #{self.current_user.full_name}") unless self.current_user.nil?
475
- end
476
-
477
- def get_url_to_redirect_for_authentication
478
- auth_controller = ::KirguduBase.authentications_controller
479
- raise "Put in 'intializers' value for 'KirguduBase.authentications_controller' or override 'get_url_to_redirect_for_authentication' method" unless auth_controller
480
-
481
- if auth_controller.is_a?(String)
482
- auth_controller = eval(auth_controller)
483
- end
484
- auth_controller.to_url_for(:login)
485
- end
486
-
487
-
488
- ##############################################################################################
489
- ##################################### Views Paths #######################################
490
- ##############################################################################################
491
-
492
- def get_template_path
493
- self.class.get_method_latest_result(:get_kb_template);
494
- end
495
-
496
- def get_view_path(view_name, include_template = true)
497
- view_path = self.class.get_method_latest_result(:get_kb_view_path, view_name)
498
- view_path ||= self.get_view_default_path(view_name)
499
- template_path = ""
500
- template_path = self.get_template_path if include_template
501
-
502
- include_template ? "#{template_path}/#{view_path}" : "#{view_path}"
503
- end
504
-
505
- def get_layout_path(include_template = true)
506
- self.get_view_path(:layout, include_template)
507
- end
508
-
509
- def get_view_default_path(view_name)
510
- defaults = {
511
- layout: "layouts/application",
512
- page_404: "shared/page_404",
513
- entry_not_found: "shared/entry_not_found",
514
- index: "common/index",
515
- new: "common/new",
516
- edit: "common/edit",
517
- delete: "common/delete",
518
- show: "common/show",
519
- management: "common/management",
520
- sorting: "common/sorting",
521
- dashboard: "common/dashboard"
522
- }
523
- defaults[view_name]
524
- end
525
-
526
-
527
- ##############################################################################################
528
- ############################################# #######################################
529
- ##############################################################################################
530
-
531
- def string_logger
532
- @string_logger
533
- end
534
-
535
- def string_logger= value
536
- @string_logger = value
537
- end
538
-
539
- ##############################################################################################
540
- ############################################# #######################################
541
- ##############################################################################################
542
-
543
-
544
- def update_url_with_ajax_referer_url
545
- if params[:current_url]
546
- begin
547
- p_current_url = URI.parse(params[:current_url])
548
- p_query = CGI.parse(p_current_url.query)
549
-
550
- #string_logger.info("Current URL: #{p_current_url}")
551
- #string_logger.info("Current URL QUERY : #{p_query}")
552
-
553
- params[:page] = p_query["page"].first if p_query["page"]
554
- params[:status_id] = p_query["status_id"].first if p_query["status_id"]
555
- params[:website_id] = p_query["website_id"].first if p_query["website_id"] and params[:website_id].nil?
556
-
557
- #string_logger.info("Params After Loading from Current URL: #{params}")
558
- end
559
- end
560
- end
561
-
562
-
563
- def system_logging_init
564
- #@logging_options = Hash.new
565
- #
566
- #@logging_options[:status] = @settings_manager.get("SystemZone::Logging::Status")
567
- #unless @logging_options[:status]
568
- # @logging_options[:status] = false
569
- #end
570
- #@logging_options[:level] = @settings_manager.get("SystemZone::Logging::Level")
571
- #unless @logging_options[:level]
572
- # @logging_options[:level] = ::SystemZone::Logging::Event::LEVEL_SYSTEM
573
- #end
574
- #
575
- #if @logging_options[:status] == true
576
- # @logging_request = ::SystemZone::Logging::Request.new
577
- # @logging_request.ip = request.remote_ip
578
- # @logging_request.serve_id = 1 #FIX: change in future to identify servers
579
- # @logging_request.session_id = request.session[:session_id] ? request.session[:session_id] : ''
580
- # @logging_request.controller_name = controller_path
581
- # @logging_request.action_name = self.action_name
582
- # @logging_request.http_method = request.method
583
- # @logging_request.params = params.to_json
584
- # @logging_request.agent = request.env["HTTP_USER_AGENT"]
585
- # @logging_request.os = http_request_retrieve_operating_system(request.env["HTTP_USER_AGENT"])
586
- # #@logging_request.screen = request.env["HTTP_USER_AGENT"]
587
- # @logging_request.referer_url = request.referer
588
- # @logging_request.url = request.referer
589
- # @logging_request.user_id = @current_user.id if @current_user && @current_user.id
590
- # @logging_request.client_id = current_client.id if current_client && current_client.id
591
- # @logging_request.save
592
- #end
593
-
594
- end
595
-
596
- def system_logging_write_event(source, level_id, message)
597
- #if @logging_options[:status] == true && @logging_request && (level_id == ::SystemZone::Logging::Event::LEVEL_SYSTEM || level_id <= @logging_options[:level])
598
- # current_event = ::SystemZone::Logging::Event.new
599
- # current_event.request = @logging_request
600
- # current_event.source = source && !source.blank? ? source : self.action_name
601
- # current_event.level_id = level_id
602
- # current_event.message = message
603
- # current_event.save
604
- #end
605
- end
606
-
607
-
608
- def fake_counter_iterate(counter_name)
609
- #counter_data = {}
610
- #counter_data[:total_name] = "Fake::Counter::Total::#{counter_name}"
611
- #counter_data[:quantity_per_period_name] = "Fake::Counter::#{counter_name}::QuantityPerPeriod"
612
- #counter_data[:period_type_name] = "Fake::Counter::#{counter_name}::PeriodType"
613
- #counter_data[:initial_seed_name] = "Fake::Counter::#{counter_name}::InitialSeed"
614
- #
615
- #counter_data[:local_timezone] = ActiveSupport::TimeZone.new("Moscow")
616
- #counter_data[:local_today] = Time.now.in_time_zone(counter_data[:local_timezone]).to_date
617
- #counter_data[:local_now] = Time.now.in_time_zone(counter_data[:local_timezone])
618
- #
619
- ##getting or setting number_of_orders_per_period
620
- #counter_data[:total] = @settings_manager.get(counter_data[:total_name])
621
- #unless counter_data[:total]
622
- # counter_data[:total] = 846
623
- # create_option(counter_data[:total_name], counter_data[:total], value_type: "integer")
624
- #end
625
- #
626
- ##getting or setting number_of_orders_per_period
627
- #counter_data[:quantity_per_period] = @settings_manager.get(counter_data[:quantity_per_period_name])
628
- #counter_data[:quantity_per_period] = 63 unless counter_data[:quantity_per_period]
629
- ##getting or setting counter_data[:period_type]
630
- #counter_data[:period_type] = @settings_manager.get(counter_data[:period_type_name])
631
- #counter_data[:period_type] = "day" unless counter_data[:period_type]
632
- ##getting or setting counter_data[:initial_seed]
633
- #counter_data[:initial_seed] = @settings_manager.get(counter_data[:initial_seed_name])
634
- #counter_data[:initial_seed] = 7 unless counter_data[:initial_seed]
635
- #
636
- #
637
- ## searchiung for period_counter in OrderCounter
638
- #period_counter = get_period_counter(counter_data[:local_now], counter_data[:period_type])
639
- #
640
- #
641
- ## string_logger.info("*****************************************************************")
642
- ## string_logger.info("Total Counter (before): #{total_counter}") if total_counter
643
- ## string_logger.info("Day Counter (before): #{day_counter}") if day_counter
644
- #
645
- #ActiveRecord::Base.transaction do
646
- # unless period_counter
647
- # # period_counter not found so New period_counter created
648
- # period_counter = ::SystemZone::Fakes::Counter.new
649
- # # calculating period_start and period_end Time
650
- # if counter_data[:period_type] == "day"
651
- # period_counter.start_at = counter_data[:local_now].beginning_of_day
652
- # period_counter.finish_at = counter_data[:local_now].end_of_day
653
- # elsif counter_data[:period_type] == "week"
654
- # period_counter.start_at = counter_data[:local_now].beginning_of_week
655
- # period_counter.finish_at = counter_data[:local_now].end_of_week
656
- # elsif counter_data[:period_type] == "month"
657
- # period_counter.start_at = counter_data[:local_now].beginning_of_month
658
- # period_counter.finish_at = counter_data[:local_now].end_of_month
659
- # elsif counter_data[:period_type] == "year"
660
- # period_counter.start_at = counter_data[:local_now].beginning_of_year
661
- # period_counter.finish_at = counter_data[:local_now].end_of_year
662
- # else
663
- # period_counter.start_at = counter_data[:local_now].beginning_of_day
664
- # period_counter.finish_at = counter_data[:local_now].end_of_day
665
- # end
666
- # # initializing period_counter values
667
- # period_counter.fake_initial = rand(counter_data[:initial_seed])
668
- # period_counter.fake_max = counter_data[:quantity_per_period]
669
- # period_counter.fake_value = period_counter.fake_initial
670
- # period_counter.real_value = period_counter.fake_initial
671
- # # calculate period in seconds for current period
672
- # period_in_seconds = (period_counter.period_end - period_counter.period_start).round
673
- # # calculate iteration period in seconds keeping in mind that we have fake_value_initial
674
- # iteration_period_in_seconds = (period_in_seconds / (counter_data[:quantity_per_period] - period_counter.fake_value_initial)).round
675
- # # calculating number of iteration from period start to now
676
- # number_of_iteration_by_now = ((counter_data[:local_now] - period_counter.period_start).round/iteration_period_in_seconds).round
677
- # #adding number_of_iteration_by_now to fake_value
678
- # period_counter.fake_value += number_of_iteration_by_now
679
- # period_counter.real_value += number_of_iteration_by_now
680
- # # initializing next_iteration_date
681
- # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
682
- # # increasing number_of_iteration_by_now by 1 while next_iteration_date < counter_data[:local_now]
683
- # begin
684
- # number_of_iteration_by_now += 1
685
- # #period_counter.fake_value += 1
686
- # #period_counter.real_value += 1
687
- # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
688
- # end while next_iteration_date < counter_data[:local_now]
689
- # #setting net_iteration_date
690
- # period_counter.next_iteration_date = next_iteration_date
691
- # counter_data[:total] += period_counter.real_value
692
- # set_option_value(counter_data[:total_name], counter_data[:total])
693
- # end
694
- # if period_counter.next_iteration_date < counter_data[:local_now]
695
- # #string_logger.info("*****************************************************************")
696
- # #string_logger.info("*****************************************************************")
697
- # #string_logger.info("Increasing Current OrderCounter")
698
- # #string_logger.info("*****************************************************************")
699
- # #string_logger.info("Fake Value: #{period_counter.fake_value}")
700
- # #string_logger.info("Real Value: #{period_counter.real_value}")
701
- # # calculate period in seconds for current period
702
- # period_in_seconds = (period_counter.period_end - period_counter.period_start).round
703
- # #string_logger.info("Period (in seconds): #{period_in_seconds}")
704
- # # calculate iteration period in seconds keeping in mind that we have fake_value_initial
705
- # iteration_period_in_seconds = (period_in_seconds / (counter_data[:quantity_per_period] - period_counter.fake_value_initial)).round
706
- # #string_logger.info("Iteration Period (in seconds): #{iteration_period_in_seconds}")
707
- # # calculating number of iteration from period start to now
708
- # number_of_iteration_by_now = ((counter_data[:local_now] - period_counter.period_start).round/iteration_period_in_seconds).round
709
- # #string_logger.info("Number of Iterations by Now: #{number_of_iteration_by_now}")
710
- # #adding difference between number_of_iteration_by_now and fake_value to fake_value
711
- # iteration_difference_by_now = number_of_iteration_by_now - period_counter.fake_value
712
- # #string_logger.info("Iterations To Add (difference): #{iteration_difference_by_now}")
713
- # if iteration_difference_by_now > 0
714
- # period_counter.fake_value += iteration_difference_by_now
715
- # period_counter.real_value += iteration_difference_by_now
716
- # #increasing total counter
717
- # counter_data[:total] += iteration_difference_by_now
718
- # set_option_value(counter_data[:total_name], counter_data[:total])
719
- #
720
- # #string_logger.info("Fake Value (with difference): #{period_counter.fake_value}")
721
- # #string_logger.info("Real Value (with difference): #{period_counter.real_value}")
722
- # # initializing next_iteration_date
723
- # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
724
- # #string_logger.info("Next Iteration Date: #{next_iteration_date.in_time_zone(counter_data[:local_timezone])}")
725
- # # increasing number_of_iteration_by_now by 1 while next_iteration_date < counter_data[:local_now]
726
- # begin
727
- # #string_logger.info("Iterrating for next iteration date")
728
- # number_of_iteration_by_now += 1
729
- # #period_counter.fake_value += 1
730
- # #period_counter.real_value += 1
731
- # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
732
- # end while next_iteration_date < counter_data[:local_now]
733
- # #setting net_iteration_date
734
- # period_counter.next_iteration_date = next_iteration_date
735
- # #string_logger.info("*****************************************************************")
736
- # #string_logger.info("*****************************************************************")
737
- # end
738
- # end
739
- # #saving period_counter
740
- # period_counter.save
741
- #end # end of transaction
742
- #
743
- #counter_result = {}
744
- #counter_result[:total] = counter_data[:total]
745
- #counter_result[:by_period] = period_counter.fake_value
746
- #
747
- ## string_logger.info("Total Counter: #{counter_result[:total]}")
748
- ## string_logger.info("Day Counter: #{counter_result[:by_period]}")
749
- #counter_result
750
- end
751
-
752
-
753
- def render_page_e404
754
- respond_to do |format|
755
- format.html { render :template => 'layouts/404', :status => 404 }
756
- format.all { render :nothing => true, :status => "404" }
757
- end
758
- end
759
-
760
- #rescue_from ActiveRecord::RecordNotFound , :with => :e404
761
-
762
- # rescue_from ActiveRecord::RecordInvalid , :with => :e404
763
-
764
- #rescue_from ActionController::RoutingError , :with => :e404
765
-
766
- #rescue_from ActiveRecord::ActiveRecordError , :with => :e404
767
-
768
- #rescue_from ArgumentError , :with => :e404
769
-
770
- #rescue_from Exception, :with => :e404
771
-
772
-
773
- #rescue_from CanCan::AccessDenied do |exception|
774
- # respond_to do |format|
775
- # format.html { render :template => '/shared/access_denied.html.erb', :status => 404 }
776
- # format.all { render :nothing => true, :status => "404" }
777
- # end
778
- #end
779
-
780
-
781
- # ***********************************************************************************************
782
- # ************************************** PRIVATE METHODS ****************************************
783
- # ***********************************************************************************************
784
- private
785
-
786
-
787
- def debugger_before_action
788
-
789
- end
790
-
791
- def debugger_after_action
792
-
793
- end
794
-
795
-
796
- def request_started
797
-
798
- end
799
-
800
- def request_finished
801
-
802
- end
803
- end
117
+ def breadcrumbs_length
118
+ self.kb_breadcrumbs.length
119
+ end
120
+
121
+
122
+ #########################################################################################################################
123
+ ############################# I18n String Generator Methods #####################################
124
+ #########################################################################################################################
125
+
126
+ def self.to_i18n
127
+ ::ChupakabraTools::ClassHelper.controller_class_to_i18n(self)
128
+ end
129
+
130
+ def to_i18n
131
+ self.class.to_i18n
132
+ end
133
+
134
+ #########################################################################################################################
135
+ ############################### Routes Generator Methods ########################################
136
+ #########################################################################################################################
137
+
138
+ def self.to_route_path
139
+ ::ChupakabraTools::ClassHelper.controller_full_path_underscore(self)
140
+ end
141
+
142
+ def to_route_path
143
+ self.class.to_route_path
144
+ end
145
+
146
+ #########################################################################################################################
147
+ ############################### Routes Generator Methods ########################################
148
+ #########################################################################################################################
149
+
150
+ def self.to_url_for(action, options = {})
151
+ options ||= {}
152
+ options.merge!(
153
+ only_path: true,
154
+ controller: self.to_route_path,
155
+ action: action
156
+ )
157
+ Rails.application.routes.url_helpers.url_for(options)
158
+ end
159
+
160
+ def to_url_for(action = nil, options = {})
161
+ self.class.to_url_for(action, options)
162
+ end
163
+
164
+ #########################################################################################################################
165
+ #################################### Routes Injection ############################################
166
+ #########################################################################################################################
167
+
168
+
169
+ #########################################################################################################################
170
+ ##################################### Strong Parameters ###########################################
171
+ #########################################################################################################################
172
+
173
+
174
+ def class_strong_params(form)
175
+ prms = []
176
+ if form.properties
177
+ form.properties.each_pair do |key, property|
178
+ unless property.read_only == :true
179
+ prms << property.name
180
+ end
181
+ end
182
+ elsif form.elements
183
+ form.elements.each do |element|
184
+ if element.is_a?(::KiruguduBase::DynamicPages::FormProperty)
185
+ unless element.read_only == :true
186
+ prms << element.name
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ #raise "#{self.entry_class.for_form_params}"
193
+ #raise "#{prms.to_s}"
194
+ params.require(self.entry_class.for_form_params).permit(prms)
195
+ end
196
+
197
+
198
+ #########################################################################################################################
199
+ ################################### Filters #########################################
200
+ #########################################################################################################################
201
+
202
+ def get_filters_for_list(list, source)
203
+ result = {}
204
+ if list
205
+ list.filters.each do |filter|
206
+ source_value = source[filter.name]
207
+ if [:autocomplete, :autocomplete_with_id, :text_edit, :select, :chosen_select].include?(filter.input_type)
208
+ if source_value
209
+ source_value.strip!
210
+ source_value = nil if source_value.blank?
211
+ end
212
+ end
213
+ result[filter.name] = source_value if source_value
214
+ end if list.filters
215
+
216
+ result[:page] = source[:page].to_i rescue nil
217
+ result[:per_page] = source[:per_page] rescue nil
218
+ end
219
+ result
220
+ end
221
+
222
+
223
+ #########################################################################################################################
224
+ ################################## Class Hierarchy Methods ########################################
225
+ #########################################################################################################################
226
+
227
+ def get_class_hierarchy
228
+ self.class.get_class_hierarchy
229
+ end
230
+
231
+ def self.get_class_hierarchy
232
+ ::ChupakabraTools::ClassHelper.get_controller_hierarchy(self)
233
+ end
234
+
235
+ def get_class_variable(name)
236
+ self.class.get_class_variable(name)
237
+ end
238
+
239
+ def self.get_method_latest_result(method_name, *method_args)
240
+ method_result = nil
241
+ self.get_class_hierarchy.each do |controller_class|
242
+ method_result = controller_class.send(method_name, *method_args) if controller_class.respond_to?(method_name)
243
+ return method_result if method_result
244
+ end
245
+ method_result
246
+ end
247
+
248
+ #########################################################################################################################
249
+ ################################### Dynamic Transactions #########################################
250
+ #########################################################################################################################
251
+
252
+ def process_transaction_injections(entry, action, flow_position, filter_params, options = {})
253
+ options ||= {}
254
+
255
+ transaction_is_ok = true
256
+
257
+ classes_to_process = self.get_class_hierarchy
258
+ classes_to_process.each do |controller_klass|
259
+ if controller_klass.respond_to?(:get_kb_transaction_injections)
260
+ available_injections = controller_klass.get_kb_transaction_injections(action, flow_position)
261
+ available_injections.each do |injection|
262
+ #raise "Processing Transaction Injection. Class: #{controller_klass.to_s}, Injection: #{injection.to_json}"
263
+ if self.send(injection.method, entry, filter_params, options) == false
264
+ transaction_is_ok &= false
265
+ end
266
+ end if available_injections
267
+ end
268
+ end
269
+ transaction_is_ok
270
+ end
271
+
272
+
273
+ #########################################################################################################################
274
+ ###################################### Locale Methods #############################################
275
+ #########################################################################################################################
276
+
277
+
278
+ def set_i18n_locale_from_params
279
+ if params[:locale]
280
+ if I18n.available_locales.include?(params[:locale].to_sym)
281
+ I18n.locale = params[:locale]
282
+ session[:locale] = params[:locale]
283
+ cookies.permanent[:locale_set] = params[:locale]
284
+ else
285
+ if session[:locale]
286
+ #params[:locale] = session[:locale]
287
+ #I18n.locale = session[:locale]
288
+ #locale_redirect(session[:locale])
289
+ #redirect_to request.url #, notice: "Translation \"#{params[:locale]}\" not available."
290
+ #@string_logger.error flash.now[:notice]
291
+ redirect_to url_for(locale: session[:locale])
292
+ elsif cookies[:locale_set]
293
+ session[:locale] = cookies[:locale_set]
294
+ params[:locale] = cookies[:locale_set]
295
+ I18n.locale = cookies[:locale_set]
296
+ #locale_redirect(session[:locale])
297
+ else
298
+ locale = get_best_locale
299
+ params[:locale] = locale
300
+ session[:locale] = locale
301
+ cookies.permanent[:locale_set] = locale
302
+ I18n.locale = locale
303
+ #locale_redirect(I18n.locale)
304
+ end
305
+ end
306
+ elsif session[:locale]
307
+ redirect_to url_for(locale: session[:locale])
308
+ elsif cookies[:locale_set]
309
+ redirect_to url_for(locale: cookies[:locale_set])
310
+ else
311
+ redirect_to url_for(locale: get_best_locale)
312
+ end
313
+ end
314
+
315
+ #def default_url_options
316
+ # {locale: I18n.locale}
317
+ #end
318
+
319
+ def check_locale_parameter
320
+ if session[:locale]
321
+ #if params[:locale]
322
+ if I18n.available_locales.include?(params[:locale].to_sym)
323
+ if params[:locale] != session[:locale]
324
+ session[:locale] = params[:locale]
325
+ I18n.locale = params[:locale]
326
+ else
327
+ I18n.locale = session[:locale]
328
+ end
329
+ else
330
+ I18n.locale = session[:locale]
331
+ #redirect_to home_path, notice: :wrong_locale #"Translation \"#{params[:locale]}\" not available yet."
332
+ end
333
+ else
334
+ I18n.locale = session[:locale]
335
+ #redirect_to request.url, locale: I18n.locale
336
+ end
337
+ #else
338
+ # session[:locale] = I18n.locale
339
+ #end
340
+ end
341
+
342
+ def get_best_locale
343
+ locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first.to_sym
344
+ if I18n.available_locales.include?(locale)
345
+ locale
346
+ else
347
+ I18n.default_locale
348
+ end
349
+ end
350
+
351
+
352
+ def prepare_applications_data
353
+
354
+ end
355
+
356
+
357
+ #########################################################################################################################
358
+ ##################################### Global Variables ############################################
359
+ #########################################################################################################################
360
+
361
+ # called in before_action in ::KirguduBase::ApplicationController
362
+ def initialize_global_variables
363
+
364
+ @template_path = self.class.get_method_latest_result(:get_kb_template)
365
+
366
+ @settings_manager = ::KirguduBase::Settings::SettingsManager.new
367
+
368
+ default_host_to_set = request.host
369
+ default_host_to_set += ":#{request.port}" if request.port && request.port != 80
370
+
371
+ Rails.application.routes.default_url_options[:host] = default_host_to_set
372
+
373
+ if Rails.env.development?
374
+ I18n.locale = :ru
375
+ end
376
+
377
+ WillPaginate.per_page = 20
378
+ end
379
+
380
+ #########################################################################################################################
381
+ #################################### Current User To Override ############################################
382
+ #########################################################################################################################
383
+
384
+ # method for Ability
385
+ def current_user
386
+ @current_user
387
+ end
388
+
389
+ def current_user= value
390
+ @current_user = value
391
+ end
392
+
393
+ def current_user_symbol
394
+ :user_id
395
+ end
396
+
397
+ #########################################################################################################################
398
+ ####################################### Current User ##############################################
399
+ #########################################################################################################################
400
+
401
+
402
+ def current_user_set_info(user, remember_me = nil)
403
+ #logger.info("USER is ::KirguduBase::Security::User") if user && user.is_a?(::KirguduBase::Security::User)
404
+ self.current_user = user
405
+ self.session[self.current_user_symbol] = user.id
406
+ self.session[:"#{self.current_user_symbol}_expire"] = DateTime.now.utc + 1.day
407
+ self.session[:"#{self.current_user_symbol}_remember_me"] = remember_me
408
+ #logger.info("Session[:user_id]=#{self.session[:user_id]}")
409
+ end
410
+
411
+ def current_user_clear_info
412
+ self.current_user = nil
413
+ self.session[self.current_user_symbol] = nil
414
+ self.session[:"#{self.current_user_symbol}_expire"] = DateTime.now.utc - 1.day
415
+ self.session[:"#{self.current_user_symbol}_remember_me"] = false
416
+ end
417
+
418
+ def current_user_query_db(user_id)
419
+ ::KirguduBase::Security::User.where(id: user_id).first if user_id
420
+ end
421
+
422
+ def authenticate_user
423
+ time_now = DateTime.now.utc
424
+ user_remember_me = self.session[:"#{self.current_user_symbol}_remember_me"]
425
+ slided_expire_time = time_now + (user_remember_me ? 2.weeks : 1.day)
426
+ user_session_expire = self.session[:"#{self.current_user_symbol}_expire"] || slided_expire_time
427
+ user_id = self.session[self.current_user_symbol]
428
+
429
+ if user_session_expire < time_now
430
+ logger.info("User Session Expired. Expire At: #{user_session_expire}")
431
+ #raise "Session Expired #{user_session_expire}, #{self.session[:"#{self.current_user_symbol}_expire"]}"
432
+ self.current_user_clear_info
433
+ else
434
+ if user_id
435
+ logger.info("User ID: #{user_id}")
436
+ logger.info("Slided Expire At: #{slided_expire_time}")
437
+ self.current_user = self.current_user_query_db(user_id)
438
+ self.session[:"#{self.current_user_symbol}_expire"] = slided_expire_time
439
+ else
440
+ logger.info("User ID is null")
441
+ self.current_user_clear_info
442
+ end
443
+ end
444
+
445
+ logger.info("Current User is null") if self.current_user.nil?
446
+ logger.info("Current User: #{self.current_user.full_name}") unless self.current_user.nil?
447
+
448
+
449
+ if self.current_user.nil? || self.current_user.deletion_status_id != ::ChupakabraTools::DeletionStatus.id_by_tag(:actual)
450
+ logger.info("1Current User is null") if self.current_user.nil?
451
+ #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)
452
+ self.current_user_clear_info
453
+ self.session[:return_to] = request.url
454
+ respond_to do |format|
455
+ format.json { render_json_need_authentication }
456
+ format.html { redirect_to self.get_url_to_redirect_for_authentication }
457
+ end
458
+ end
459
+
460
+ logger.info("User Authentications is Complete")
461
+ logger.info("Current User is null") if self.current_user.nil?
462
+ #logger.info("Current User deletion_status_id: #{::ChupakabraTools::DeletionStatus[self.current_user.deletion_status_id]}") unless ::ChupakabraTools::DeletionStatus.id_by_tag(:actual)
463
+ logger.info("Current User: #{self.current_user.full_name}") unless self.current_user.nil?
464
+ end
465
+
466
+ def get_url_to_redirect_for_authentication
467
+ auth_controller = ::KirguduBase.authentications_controller
468
+ raise "Put in 'intializers' value for 'KirguduBase.authentications_controller' or override 'get_url_to_redirect_for_authentication' method" unless auth_controller
469
+
470
+ if auth_controller.is_a?(String)
471
+ auth_controller = eval(auth_controller)
472
+ end
473
+ auth_controller.to_url_for(:login)
474
+ end
475
+
476
+ def get_url_for_login( options = {})
477
+ self.get_kirgudu_base_authentication_controller_setting.to_url_for(:login, options)
478
+ end
479
+ def get_url_for_logout( options = {})
480
+ self.get_kirgudu_base_authentication_controller_setting.to_url_for(:logout, options)
481
+ end
482
+
483
+ def get_url_for_restore_password_code(options = {})
484
+ self.get_kirgudu_base_authentication_controller_setting.to_url_for(:restore_password_code, options)
485
+ end
486
+
487
+
488
+
489
+ def get_kirgudu_base_authentication_controller_setting
490
+ auth_controller = ::KirguduBase.authentications_controller
491
+ raise "Add 'KirguduBase.authentications_controller' to /initializers/kirgudu_base.rb' method" unless auth_controller
492
+ auth_controller = eval(auth_controller) if auth_controller.is_a?(String)
493
+ auth_controller
494
+ end
495
+
496
+
497
+ ##############################################################################################
498
+ ##################################### Views Paths #######################################
499
+ ##############################################################################################
500
+
501
+ def get_template_path
502
+ self.class.get_method_latest_result(:get_kb_template);
503
+ end
504
+
505
+ def get_view_path(view_name, include_template = true)
506
+ view_path = self.class.get_method_latest_result(:get_kb_view_path, view_name)
507
+ view_path ||= self.get_view_default_path(view_name)
508
+ template_path = ""
509
+ template_path = self.get_template_path if include_template
510
+
511
+ include_template ? "#{template_path}/#{view_path}" : "#{view_path}"
512
+ end
513
+
514
+ def get_layout_path(include_template = true)
515
+ self.get_view_path(:layout, include_template)
516
+ end
517
+
518
+ def get_view_default_path(view_name)
519
+ defaults = {
520
+ layout: "layouts/application",
521
+ page_404: "shared/page_404",
522
+ entry_not_found: "shared/entry_not_found",
523
+ index: "common/index",
524
+ new: "common/new",
525
+ edit: "common/edit",
526
+ delete: "common/delete",
527
+ show: "common/show",
528
+ management: "common/management",
529
+ sorting: "common/sorting",
530
+ dashboard: "common/dashboard"
531
+ }
532
+ defaults[view_name]
533
+ end
534
+
535
+
536
+ ##############################################################################################
537
+ ############################################# #######################################
538
+ ##############################################################################################
539
+
540
+ def string_logger
541
+ @string_logger
542
+ end
543
+
544
+ def string_logger= value
545
+ @string_logger = value
546
+ end
547
+
548
+ ##############################################################################################
549
+ ############################################# #######################################
550
+ ##############################################################################################
551
+
552
+
553
+ def update_url_with_ajax_referer_url
554
+ if params[:current_url]
555
+ begin
556
+ p_current_url = URI.parse(params[:current_url])
557
+ p_query = CGI.parse(p_current_url.query)
558
+
559
+ #string_logger.info("Current URL: #{p_current_url}")
560
+ #string_logger.info("Current URL QUERY : #{p_query}")
561
+
562
+ params[:page] = p_query["page"].first if p_query["page"]
563
+ params[:status_id] = p_query["status_id"].first if p_query["status_id"]
564
+ params[:website_id] = p_query["website_id"].first if p_query["website_id"] and params[:website_id].nil?
565
+
566
+ #string_logger.info("Params After Loading from Current URL: #{params}")
567
+ end
568
+ end
569
+ end
570
+
571
+
572
+ def system_logging_init
573
+ #@logging_options = Hash.new
574
+ #
575
+ #@logging_options[:status] = @settings_manager.get("SystemZone::Logging::Status")
576
+ #unless @logging_options[:status]
577
+ # @logging_options[:status] = false
578
+ #end
579
+ #@logging_options[:level] = @settings_manager.get("SystemZone::Logging::Level")
580
+ #unless @logging_options[:level]
581
+ # @logging_options[:level] = ::SystemZone::Logging::Event::LEVEL_SYSTEM
582
+ #end
583
+ #
584
+ #if @logging_options[:status] == true
585
+ # @logging_request = ::SystemZone::Logging::Request.new
586
+ # @logging_request.ip = request.remote_ip
587
+ # @logging_request.serve_id = 1 #FIX: change in future to identify servers
588
+ # @logging_request.session_id = request.session[:session_id] ? request.session[:session_id] : ''
589
+ # @logging_request.controller_name = controller_path
590
+ # @logging_request.action_name = self.action_name
591
+ # @logging_request.http_method = request.method
592
+ # @logging_request.params = params.to_json
593
+ # @logging_request.agent = request.env["HTTP_USER_AGENT"]
594
+ # @logging_request.os = http_request_retrieve_operating_system(request.env["HTTP_USER_AGENT"])
595
+ # #@logging_request.screen = request.env["HTTP_USER_AGENT"]
596
+ # @logging_request.referer_url = request.referer
597
+ # @logging_request.url = request.referer
598
+ # @logging_request.user_id = @current_user.id if @current_user && @current_user.id
599
+ # @logging_request.client_id = current_client.id if current_client && current_client.id
600
+ # @logging_request.save
601
+ #end
602
+
603
+ end
604
+
605
+ def system_logging_write_event(source, level_id, message)
606
+ #if @logging_options[:status] == true && @logging_request && (level_id == ::SystemZone::Logging::Event::LEVEL_SYSTEM || level_id <= @logging_options[:level])
607
+ # current_event = ::SystemZone::Logging::Event.new
608
+ # current_event.request = @logging_request
609
+ # current_event.source = source && !source.blank? ? source : self.action_name
610
+ # current_event.level_id = level_id
611
+ # current_event.message = message
612
+ # current_event.save
613
+ #end
614
+ end
615
+
616
+
617
+ def fake_counter_iterate(counter_name)
618
+ #counter_data = {}
619
+ #counter_data[:total_name] = "Fake::Counter::Total::#{counter_name}"
620
+ #counter_data[:quantity_per_period_name] = "Fake::Counter::#{counter_name}::QuantityPerPeriod"
621
+ #counter_data[:period_type_name] = "Fake::Counter::#{counter_name}::PeriodType"
622
+ #counter_data[:initial_seed_name] = "Fake::Counter::#{counter_name}::InitialSeed"
623
+ #
624
+ #counter_data[:local_timezone] = ActiveSupport::TimeZone.new("Moscow")
625
+ #counter_data[:local_today] = Time.now.in_time_zone(counter_data[:local_timezone]).to_date
626
+ #counter_data[:local_now] = Time.now.in_time_zone(counter_data[:local_timezone])
627
+ #
628
+ ##getting or setting number_of_orders_per_period
629
+ #counter_data[:total] = @settings_manager.get(counter_data[:total_name])
630
+ #unless counter_data[:total]
631
+ # counter_data[:total] = 846
632
+ # create_option(counter_data[:total_name], counter_data[:total], value_type: "integer")
633
+ #end
634
+ #
635
+ ##getting or setting number_of_orders_per_period
636
+ #counter_data[:quantity_per_period] = @settings_manager.get(counter_data[:quantity_per_period_name])
637
+ #counter_data[:quantity_per_period] = 63 unless counter_data[:quantity_per_period]
638
+ ##getting or setting counter_data[:period_type]
639
+ #counter_data[:period_type] = @settings_manager.get(counter_data[:period_type_name])
640
+ #counter_data[:period_type] = "day" unless counter_data[:period_type]
641
+ ##getting or setting counter_data[:initial_seed]
642
+ #counter_data[:initial_seed] = @settings_manager.get(counter_data[:initial_seed_name])
643
+ #counter_data[:initial_seed] = 7 unless counter_data[:initial_seed]
644
+ #
645
+ #
646
+ ## searchiung for period_counter in OrderCounter
647
+ #period_counter = get_period_counter(counter_data[:local_now], counter_data[:period_type])
648
+ #
649
+ #
650
+ ## string_logger.info("*****************************************************************")
651
+ ## string_logger.info("Total Counter (before): #{total_counter}") if total_counter
652
+ ## string_logger.info("Day Counter (before): #{day_counter}") if day_counter
653
+ #
654
+ #ActiveRecord::Base.transaction do
655
+ # unless period_counter
656
+ # # period_counter not found so New period_counter created
657
+ # period_counter = ::SystemZone::Fakes::Counter.new
658
+ # # calculating period_start and period_end Time
659
+ # if counter_data[:period_type] == "day"
660
+ # period_counter.start_at = counter_data[:local_now].beginning_of_day
661
+ # period_counter.finish_at = counter_data[:local_now].end_of_day
662
+ # elsif counter_data[:period_type] == "week"
663
+ # period_counter.start_at = counter_data[:local_now].beginning_of_week
664
+ # period_counter.finish_at = counter_data[:local_now].end_of_week
665
+ # elsif counter_data[:period_type] == "month"
666
+ # period_counter.start_at = counter_data[:local_now].beginning_of_month
667
+ # period_counter.finish_at = counter_data[:local_now].end_of_month
668
+ # elsif counter_data[:period_type] == "year"
669
+ # period_counter.start_at = counter_data[:local_now].beginning_of_year
670
+ # period_counter.finish_at = counter_data[:local_now].end_of_year
671
+ # else
672
+ # period_counter.start_at = counter_data[:local_now].beginning_of_day
673
+ # period_counter.finish_at = counter_data[:local_now].end_of_day
674
+ # end
675
+ # # initializing period_counter values
676
+ # period_counter.fake_initial = rand(counter_data[:initial_seed])
677
+ # period_counter.fake_max = counter_data[:quantity_per_period]
678
+ # period_counter.fake_value = period_counter.fake_initial
679
+ # period_counter.real_value = period_counter.fake_initial
680
+ # # calculate period in seconds for current period
681
+ # period_in_seconds = (period_counter.period_end - period_counter.period_start).round
682
+ # # calculate iteration period in seconds keeping in mind that we have fake_value_initial
683
+ # iteration_period_in_seconds = (period_in_seconds / (counter_data[:quantity_per_period] - period_counter.fake_value_initial)).round
684
+ # # calculating number of iteration from period start to now
685
+ # number_of_iteration_by_now = ((counter_data[:local_now] - period_counter.period_start).round/iteration_period_in_seconds).round
686
+ # #adding number_of_iteration_by_now to fake_value
687
+ # period_counter.fake_value += number_of_iteration_by_now
688
+ # period_counter.real_value += number_of_iteration_by_now
689
+ # # initializing next_iteration_date
690
+ # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
691
+ # # increasing number_of_iteration_by_now by 1 while next_iteration_date < counter_data[:local_now]
692
+ # begin
693
+ # number_of_iteration_by_now += 1
694
+ # #period_counter.fake_value += 1
695
+ # #period_counter.real_value += 1
696
+ # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
697
+ # end while next_iteration_date < counter_data[:local_now]
698
+ # #setting net_iteration_date
699
+ # period_counter.next_iteration_date = next_iteration_date
700
+ # counter_data[:total] += period_counter.real_value
701
+ # set_option_value(counter_data[:total_name], counter_data[:total])
702
+ # end
703
+ # if period_counter.next_iteration_date < counter_data[:local_now]
704
+ # #string_logger.info("*****************************************************************")
705
+ # #string_logger.info("*****************************************************************")
706
+ # #string_logger.info("Increasing Current OrderCounter")
707
+ # #string_logger.info("*****************************************************************")
708
+ # #string_logger.info("Fake Value: #{period_counter.fake_value}")
709
+ # #string_logger.info("Real Value: #{period_counter.real_value}")
710
+ # # calculate period in seconds for current period
711
+ # period_in_seconds = (period_counter.period_end - period_counter.period_start).round
712
+ # #string_logger.info("Period (in seconds): #{period_in_seconds}")
713
+ # # calculate iteration period in seconds keeping in mind that we have fake_value_initial
714
+ # iteration_period_in_seconds = (period_in_seconds / (counter_data[:quantity_per_period] - period_counter.fake_value_initial)).round
715
+ # #string_logger.info("Iteration Period (in seconds): #{iteration_period_in_seconds}")
716
+ # # calculating number of iteration from period start to now
717
+ # number_of_iteration_by_now = ((counter_data[:local_now] - period_counter.period_start).round/iteration_period_in_seconds).round
718
+ # #string_logger.info("Number of Iterations by Now: #{number_of_iteration_by_now}")
719
+ # #adding difference between number_of_iteration_by_now and fake_value to fake_value
720
+ # iteration_difference_by_now = number_of_iteration_by_now - period_counter.fake_value
721
+ # #string_logger.info("Iterations To Add (difference): #{iteration_difference_by_now}")
722
+ # if iteration_difference_by_now > 0
723
+ # period_counter.fake_value += iteration_difference_by_now
724
+ # period_counter.real_value += iteration_difference_by_now
725
+ # #increasing total counter
726
+ # counter_data[:total] += iteration_difference_by_now
727
+ # set_option_value(counter_data[:total_name], counter_data[:total])
728
+ #
729
+ # #string_logger.info("Fake Value (with difference): #{period_counter.fake_value}")
730
+ # #string_logger.info("Real Value (with difference): #{period_counter.real_value}")
731
+ # # initializing next_iteration_date
732
+ # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
733
+ # #string_logger.info("Next Iteration Date: #{next_iteration_date.in_time_zone(counter_data[:local_timezone])}")
734
+ # # increasing number_of_iteration_by_now by 1 while next_iteration_date < counter_data[:local_now]
735
+ # begin
736
+ # #string_logger.info("Iterrating for next iteration date")
737
+ # number_of_iteration_by_now += 1
738
+ # #period_counter.fake_value += 1
739
+ # #period_counter.real_value += 1
740
+ # next_iteration_date = period_counter.period_start + number_of_iteration_by_now * iteration_period_in_seconds
741
+ # end while next_iteration_date < counter_data[:local_now]
742
+ # #setting net_iteration_date
743
+ # period_counter.next_iteration_date = next_iteration_date
744
+ # #string_logger.info("*****************************************************************")
745
+ # #string_logger.info("*****************************************************************")
746
+ # end
747
+ # end
748
+ # #saving period_counter
749
+ # period_counter.save
750
+ #end # end of transaction
751
+ #
752
+ #counter_result = {}
753
+ #counter_result[:total] = counter_data[:total]
754
+ #counter_result[:by_period] = period_counter.fake_value
755
+ #
756
+ ## string_logger.info("Total Counter: #{counter_result[:total]}")
757
+ ## string_logger.info("Day Counter: #{counter_result[:by_period]}")
758
+ #counter_result
759
+ end
760
+
761
+
762
+ def render_page_e404
763
+ respond_to do |format|
764
+ format.html { render :template => 'layouts/404', :status => 404 }
765
+ format.all { render :nothing => true, :status => "404" }
766
+ end
767
+ end
768
+
769
+ #rescue_from ActiveRecord::RecordNotFound , :with => :e404
770
+
771
+ # rescue_from ActiveRecord::RecordInvalid , :with => :e404
772
+
773
+ #rescue_from ActionController::RoutingError , :with => :e404
774
+
775
+ #rescue_from ActiveRecord::ActiveRecordError , :with => :e404
776
+
777
+ #rescue_from ArgumentError , :with => :e404
778
+
779
+ #rescue_from Exception, :with => :e404
780
+
781
+
782
+ #rescue_from CanCan::AccessDenied do |exception|
783
+ # respond_to do |format|
784
+ # format.html { render :template => '/shared/access_denied.html.erb', :status => 404 }
785
+ # format.all { render :nothing => true, :status => "404" }
786
+ # end
787
+ #end
788
+
789
+
790
+ # ***********************************************************************************************
791
+ # ************************************** PRIVATE METHODS ****************************************
792
+ # ***********************************************************************************************
793
+ private
794
+
795
+
796
+ def debugger_before_action
797
+
798
+ end
799
+
800
+ def debugger_after_action
801
+
802
+ end
803
+
804
+
805
+ def request_started
806
+
807
+ end
808
+
809
+ def request_finished
810
+
811
+ end
812
+ end
804
813
  end