Module: ApplicationHelper
- Defined in:
- app/helpers/application_helper.rb
Instance Method Summary collapse
- #client_header(title, sort_key) ⇒ Object
- #column_header(controller, param_key, title, sort_key) ⇒ Object
- #day_names ⇒ Object
- #job_header(title, sort_key) ⇒ Object
- #job_names ⇒ Object
- #media_header(title, sort_key) ⇒ Object
- #pool_header(title, sort_key) ⇒ Object
- #pretty_key(key) ⇒ Object
- #pretty_val(key, val) ⇒ Object
- #selection(hash, key, choices, selected = nil) ⇒ Object
Instance Method Details
#client_header(title, sort_key) ⇒ Object
17 18 19 |
# File 'app/helpers/application_helper.rb', line 17 def client_header(title, sort_key) column_header("client", :csort, title, sort_key) end |
#column_header(controller, param_key, title, sort_key) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/helpers/application_helper.rb', line 3 def column_header(controller, param_key, title, sort_key) s = params[param_key].scan(/([a-z]+)(-?)\.?/) header = sort_key if s[0][0] == sort_key header += ((s[0][1] == "") ? "-" : "") if s[1] then header += ("." + s[1][0] + s[1][1]); end else header += ("." + s[0][0] + s[0][1]) end content_tag('td', link_to(title, :controller => controller, param_key => header), (s[0][0] == sort_key) ? { :class => 'skey' } : nil) end |
#day_names ⇒ Object
71 72 73 74 |
# File 'app/helpers/application_helper.rb', line 71 def day_names [ [ "day", "1" ], [ "week", "7" ], [ "month", "35"], [ "year", "372"], [ "All dates", "0" ] ] end |
#job_header(title, sort_key) ⇒ Object
29 30 31 |
# File 'app/helpers/application_helper.rb', line 29 def job_header(title, sort_key) column_header("job", :jsort, title, sort_key) end |
#job_names ⇒ Object
76 77 78 79 80 |
# File 'app/helpers/application_helper.rb', line 76 def job_names jn = Job.find(:all, :order=>'name', :select=>'distinct Name,Type') jn.delete_if { |job| job.type != 'B' } jn.map { |job| [ job.name, job.name ] }.unshift([ "All jobs", "0" ]) end |
#media_header(title, sort_key) ⇒ Object
21 22 23 |
# File 'app/helpers/application_helper.rb', line 21 def media_header(title, sort_key) column_header("media", :msort, title, sort_key) end |
#pool_header(title, sort_key) ⇒ Object
25 26 27 |
# File 'app/helpers/application_helper.rb', line 25 def pool_header(title, sort_key) column_header("pool", :psort, title, sort_key) end |
#pretty_key(key) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/application_helper.rb', line 33 def pretty_key(key) key = key.downcase oops = { 'uname' => 'Unix Name', 'numvols' => 'Number of Volumes', 'volumename' => 'Volume Name', 'voluseduration' => 'Volume Use Duration', } return oops[key] if oops[key] s = key.dup s.gsub!(/^vol/, 'Volume ') s.gsub!(/poolid/, ' Pool Id') s.gsub!(/maxvol/, 'Maximum Volume') s.gsub!(/^(media|storage|label|job|migration|pool|client|use|accept|first|end)/, '\1 ') s.gsub!(/(time|base|id|retention|files?|bytes?|jobs?|written|changer|volume)$/, ' \1') s.split(' ').map{|s| s.capitalize}.join(' ') end |
#pretty_val(key, val) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/application_helper.rb', line 52 def pretty_val(key, val) case key.downcase when 'jobtdate', 'volsessiontime' val == 0 ? 'None' : Time.at(val) when 'type' type_name(val).capitalize when 'level' level_name(val).capitalize when 'jobstatus' status_name(val).capitalize when /retention/ (val / 86400).to_s + ' days' when /bytes/ number_to_human_size(val) else val.is_a?(Fixnum) ? number_with_delimiter(val) : val end end |
#selection(hash, key, choices, selected = nil) ⇒ Object
82 83 84 85 86 |
# File 'app/helpers/application_helper.rb', line 82 def selection(hash, key, choices, selected=nil) content_tag("select", (choices, selected), :id=>"#{hash}_#{key}", :name=>"#{hash}[#{key}]") end |