module ApplicationHelper 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 def client_header(title, sort_key) column_header("client", :csort, title, sort_key) end def media_header(title, sort_key) column_header("media", :msort, title, sort_key) end def pool_header(title, sort_key) column_header("pool", :psort, title, sort_key) end def job_header(title, sort_key) column_header("job", :jsort, title, sort_key) end 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 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 def day_names [ [ "day", "1" ], [ "week", "7" ], [ "month", "35"], [ "year", "372"], [ "All dates", "0" ] ] end 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 def selection(hash, key, choices, selected=nil) content_tag("select", options_for_select(choices, selected), :id=>"#{hash}_#{key}", :name=>"#{hash}[#{key}]") end end