Class: Backend::HelpsController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/helps_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

account_lettering_states_crit, accounts_range_crit, amount_range_crit, crit_params, journal_entries_states_crit, journal_letter_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name, #session_controller?

Instance Method Details

#indexObject


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/backend/helps_controller.rb', line 44

def index
  per_page = 10
  if request.xhr?
    render inline: "<%= article(params[:article], url: {controller: :helps, action: :index, id: '\1'}, update: :helpage) -%>"
  else
    @search = {}
    page = params[:page].to_i
    page = 1 if page.zero?
    key = params[:q] || session[:help_key]
    session[:help_key] = key
    key_words = key.to_s.lower.split(/[\s\,]+/).select { |x| x.length > 1 }

    results = Ekylibre.helps[I18n.locale].values

    if key_words.any?
      @search[:words] = key_words
      reg = /(#{key_words.join("|")})/i
      results.delete_if do |details|
        file = details['file']
        File.open(file, 'rb:UTF-8') do |f|
          data = f.read
          details[:count] = data.scan(reg).size
        end
        details[:count].zero?
      end

      @search[:count] = results.size

      if results.any?
        results.sort! { |a, b| b[:count] <=> a[:count] }
        max = results.first[:count].to_i
        results.each { |r| r[:pertinence] = (max.zero? ? 0 : (100 * r[:count] / max).to_i) }
      end

      @search[:records] = results[((page - 1) * per_page)..(page * per_page - 1)]
      @search[:last_page] = (@search[:count].to_f / per_page).ceil

      if @search[:records].empty? && page > 1
        redirect_to(q: params[:q], page: 1)
      end
    end
    params[:page] = page
  end
end

#showObject


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/backend/helps_controller.rb', line 30

def show
  file = search_article(params[:id])
  if request.xhr?
    render partial: 'search', object: file
    return
  end
  @help = file
  unless Ekylibre.helps[@help]
    redirect_to action: :index
    return
  end
  t3e title: Ekylibre.helps[@help][:title]
end

#toggleObject

Save the shown/hidden state of the help


24
25
26
27
28
# File 'app/controllers/backend/helps_controller.rb', line 24

def toggle
  collapsed = !params[:collapsed].to_i.zero?
  current_user.prefer!('interface.helps.collapsed', collapsed, :boolean)
  head :ok
end