Module: ArHelpControl
- Defined in:
- app/controls/ar_help_control.rb
Overview
Controls for creating help files
Class Method Summary collapse
-
.choices_for_form_name(session) ⇒ Object
Will return choices for selecting help file name, based on forms already present in forms directory.
-
.choices_for_locales ⇒ Object
Will return choices for language select on form.
-
.choices_for_project ⇒ Object
Will return choices for select project input field on a form.
Instance Method Summary collapse
-
#before_edit ⇒ Object
Will read data from help file.
-
#before_save ⇒ Object
Will save data to help file.
-
#data_filter ⇒ Object
Will return query to report data.
-
#new_record ⇒ Object
Will populate fields with default values.
-
#project_refresh ⇒ Object
Will fill ar_temp with help documents found in a defined project directory.
Class Method Details
.choices_for_form_name(session) ⇒ Object
Will return choices for selecting help file name, based on forms already present in forms directory.
116 117 118 |
# File 'app/controls/ar_help_control.rb', line 116 def self.choices_for_form_name(session) Dir["#{session[:help_project]}/*.yml"].map { |file_name| File.basename(file_name,'.*') }.sort end |
.choices_for_locales ⇒ Object
Will return choices for language select on form. Choices can be either set by ar_locales document in ar_big_table or can be acquired from Rails default locale
124 125 126 127 128 129 130 |
# File 'app/controls/ar_help_control.rb', line 124 def self.choices_for_locales choices = ArBigTable.choices_for('ar_locales') return choices unless choices[0, 0] == I18n.t('agile.error') choices = [I18n.default_locale] + I18n.fallbacks.map(&:first) choices.map(&:to_s).uniq end |
.choices_for_project ⇒ Object
Will return choices for select project input field on a form
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controls/ar_help_control.rb', line 97 def self.choices_for_project r = Agile.paths(:forms).map do |path| path = path.to_s a = path.split('/') project = a[a.size - 3] project = if project == 'app' a[a.size - 4] + ' : ' + a.last(2).join('/') else project + ' : ' + a.last end [project, path] end [[I18n.t('agile.ar_help.project'), nil]] + r.sort end |
Instance Method Details
#before_edit ⇒ Object
Will read data from help file
67 68 69 70 71 72 73 |
# File 'app/controls/ar_help_control.rb', line 67 def before_edit file_name = "#{session[:help_project]}/help/#{@record.form_name}.#{session[:help_lang]}" data = YAML.load_file(file_name) @record.index = data['index'] @record.form = data['form'] flash[:warning] = "Use only in development!" unless Rails.env.development? end |
#before_save ⇒ Object
Will save data to help file
78 79 80 81 82 83 |
# File 'app/controls/ar_help_control.rb', line 78 def before_save rec = params[:record] file_name = "#{session[:help_project]}/help/#{@record.form_name}.#{@record.lang}" data = { 'index' => @record.index, 'form' => @record.form } File.write(file_name, data.to_yaml) end |
#data_filter ⇒ Object
Will return query to report data
88 89 90 |
# File 'app/controls/ar_help_control.rb', line 88 def data_filter ArTemp.where(key: temp_key).order(:order) end |
#new_record ⇒ Object
Will populate fields with default values
59 60 61 62 |
# File 'app/controls/ar_help_control.rb', line 59 def new_record @record.project = session[:help_project] @record.lang = session[:help_lang] end |
#project_refresh ⇒ Object
Will fill ar_temp with help documents found in a defined project directory.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controls/ar_help_control.rb', line 32 def project_refresh ArTemp.clear(temp_key) if params[:record][:select_project].present? # far less complicated if saved to session session[:help_project] = params[:record][:select_project] session[:help_lang] = params[:record][:lang_1] help_dir_name = "#{session[:help_project]}/help/" # create help directory if not yet exists FileUtils.mkdir(help_dir_name) unless File.exist?(help_dir_name) Dir["#{help_dir_name}*"].each do |file_name| lang = File.extname(file_name).sub('.', '') next unless lang == session[:help_lang] ArTemp.new(key: temp_key, project: session[:help_project], form_name: File.basename(file_name, '.*'), lang: lang, updated_at: File.mtime(file_name)).save end end render json: { url: url_for(controller: :agile, table: :ar_temp, form_name: :agile_help) } end |