Module: Dash::Helpers
- Includes:
- Models
- Defined in:
- lib/helpers.rb
Constant Summary collapse
- @@prefs =
[["Start Time", "start"], ["Duration", "duration"], ["Width", "width"], ["Height", "height"]]
Instance Method Summary collapse
- #append_query_string(str) ⇒ Object
- #cluster_graph(g, cluster, title = "wtf") ⇒ Object
- #cluster_graph_link(dash, g, cluster) ⇒ Object
- #cluster_link(cluster) ⇒ Object
- #cluster_selector ⇒ Object
- #cluster_switcher(clusters) ⇒ Object
- #cluster_zoom_graph(g, cluster, host, title) ⇒ Object
- #cluster_zoom_link(cluster, host) ⇒ Object
-
#css_url ⇒ Object
fixme this isn’t used anymore, but should.
- #dash_link(dash, cluster) ⇒ Object
- #dash_switcher ⇒ Object
- #dash_uplink ⇒ Object
- #graph_switcher ⇒ Object
- #graph_uplink ⇒ Object
-
#header(str) ⇒ Object
fixme this is a hack.
- #host_uplink ⇒ Object
- #hosts_selector(hosts, print_clusters = false) ⇒ Object
-
#input_boxes ⇒ Object
generate the input box fields, filled in to current parameters if specified.
- #merge_opts ⇒ Object
- #nowish ⇒ Object
-
#param_lookup(name) ⇒ Object
convert keys to symbols before lookup.
- #permalink ⇒ Object
- #range_string ⇒ Object
- #refresh ⇒ Object
- #shortcuts(str) ⇒ Object
- #suggest_cluster_links(clusters, g) ⇒ Object
-
#suggest_dashboards(host, graph) ⇒ Object
it’s mildly annoying that when this set is empty there’re no uplinks consider adding a link up to the cluster (which is best we can do).
- #suggest_dashboards_links(host, graph) ⇒ Object
Instance Method Details
#append_query_string(str) ⇒ Object
114 115 116 117 118 |
# File 'lib/helpers.rb', line 114 def append_query_string(str) v = str.dup (v << "?#{request.query_string}") unless request.query_string.empty? return v end |
#cluster_graph(g, cluster, title = "wtf") ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/helpers.rb', line 17 def cluster_graph(g, cluster, title="wtf") image_url = \ @dash.render_cluster_graph(g, cluster, :title => title, :dynamic_url_opts => merge_opts) zoom_url = cluster_graph_link(@dash, g, cluster) return image_url, zoom_url end |
#cluster_graph_link(dash, g, cluster) ⇒ Object
26 27 28 29 30 |
# File 'lib/helpers.rb', line 26 def cluster_graph_link(dash, g, cluster) link = dash.graph_opts[g]["click"] || "/dash/#{cluster}/#{dash.name}/#{g.name}" return append_query_string(link) end |
#cluster_link(cluster) ⇒ Object
89 90 91 |
# File 'lib/helpers.rb', line 89 def cluster_link(cluster) return append_query_string("/dash/#{cluster}") end |
#cluster_selector ⇒ Object
143 144 145 146 |
# File 'lib/helpers.rb', line 143 def cluster_selector @clusters = settings.config.clusters.sort + ["global"] erb :'partials/cluster_selector', :layout => false end |
#cluster_switcher(clusters) ⇒ Object
130 131 132 133 |
# File 'lib/helpers.rb', line 130 def cluster_switcher(clusters) @clusters = clusters erb :'partials/cluster_switcher', :layout => false end |
#cluster_zoom_graph(g, cluster, host, title) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/helpers.rb', line 32 def cluster_zoom_graph(g, cluster, host, title) image_url = g.render_url([host.name], [cluster], :title => title, :dynamic_url_opts => merge_opts) zoom_url = cluster_zoom_link(cluster, host) return image_url, zoom_url end |
#cluster_zoom_link(cluster, host) ⇒ Object
39 40 41 |
# File 'lib/helpers.rb', line 39 def cluster_zoom_link(cluster, host) return append_query_string("/host/#{cluster}/#{host}") end |
#css_url ⇒ Object
fixme this isn’t used anymore, but should
94 95 96 97 98 99 |
# File 'lib/helpers.rb', line 94 def css_url style = File.join(settings.root, "public/style.css") mtime = File.mtime(style).to_i.to_s return \ %Q[<link href="/style.css?#{mtime}" rel="stylesheet" type="text/css">] end |
#dash_link(dash, cluster) ⇒ Object
85 86 87 |
# File 'lib/helpers.rb', line 85 def dash_link(dash, cluster) return append_query_string("/dash/#{cluster}/#{dash.name}") end |
#dash_switcher ⇒ Object
135 136 137 |
# File 'lib/helpers.rb', line 135 def dash_switcher erb :'partials/dash_switcher', :layout => false end |
#dash_uplink ⇒ Object
158 159 160 161 |
# File 'lib/helpers.rb', line 158 def dash_uplink link = append_query_string(request.path.split("/")[0..-2].join("/")) "zoom out: <a href=\"#{link}\">#{@params[:cluster]}</a>" end |
#graph_switcher ⇒ Object
139 140 141 |
# File 'lib/helpers.rb', line 139 def graph_switcher erb :'partials/graph_switcher', :layout => false end |
#graph_uplink ⇒ Object
153 154 155 156 |
# File 'lib/helpers.rb', line 153 def graph_uplink link = append_query_string(request.path.split("/")[0..-2].join("/")) "zoom out: <a href=\"#{link}\">#{@dash}</a>" end |
#header(str) ⇒ Object
fixme this is a hack
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/helpers.rb', line 164 def header(str) "<div class=\"path_container\">\n <h2>\#{@title}</h2>\n <span class=\"zoom\">\n \#{str}\n </span>\n </div>\n <div id=\"timeslice_container\">\n <h3 id=\"timeslice\">\#{range_string}</h3>\n \#{permalink unless @no_graphs}\n </div>\n" end |
#host_uplink ⇒ Object
148 149 150 151 |
# File 'lib/helpers.rb', line 148 def host_uplink link = "/dash/#{append_query_string(@host.cluster)}" "zoom out: <a href=\"#{link}\">#{@host.cluster}</a>" end |
#hosts_selector(hosts, print_clusters = false) ⇒ Object
108 109 110 111 112 |
# File 'lib/helpers.rb', line 108 def hosts_selector(hosts, print_clusters=false) @print_clusters = print_clusters @hosts = hosts erb :'partials/hosts_selector', :layout => false end |
#input_boxes ⇒ Object
generate the input box fields, filled in to current parameters if specified
80 81 82 83 |
# File 'lib/helpers.rb', line 80 def input_boxes @prefs = @@prefs erb :'partials/input_boxes', :layout => false end |
#merge_opts ⇒ Object
120 121 122 123 124 |
# File 'lib/helpers.rb', line 120 def merge_opts static_opts = ["cluster", "dashboard", "zoom", "host", "session_id"] opts = params.dup session.merge(opts).delete_if { |k,v| static_opts.member?(k) || v.empty? } end |
#nowish ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/helpers.rb', line 179 def nowish if settings.config.global_config[:now_threshold] == false return false end threshold = settings.config.global_config[:now_threshold] || 300 return @request_time.to_i - @etime.to_i < threshold end |
#param_lookup(name) ⇒ Object
convert keys to symbols before lookup
10 11 12 13 14 15 |
# File 'lib/helpers.rb', line 10 def param_lookup(name) sym_hash = {} session.each { |k,v| sym_hash[k.to_sym] = v unless v.empty? } params.each { |k,v| sym_hash[k.to_sym] = v unless v.empty? } settings.config.global_config[:url_opts].merge(sym_hash)[name.to_sym] end |
#permalink ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/helpers.rb', line 201 def permalink return "" unless @stime && @duration format = "%F %T" # chronic REALLY understands this url = request.path + "?" url << "&start=#{@stime.strftime(format)}" url << "&duration=#{ChronicDuration.output(@duration)}" "<a id=\"permalink\" href=\"#{url}\">permalink</a>" end |
#range_string ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/helpers.rb', line 187 def range_string format = settings.config.global_config[:date_format] || "%X %x" if @stime && @etime if nowish "timeslice: from #{@stime.strftime(format)}" else "timeslice: #{@stime.strftime(format)} - #{@etime.strftime(format)}" end else "invalid time range" end end |
#refresh ⇒ Object
101 102 103 104 105 106 |
# File 'lib/helpers.rb', line 101 def refresh if settings.config.global_config[:refresh_rate] != false && nowish rate = settings.config.global_config[:refresh_rate] || 60 return %Q[<meta http-equiv="refresh" content="#{rate}">] end end |
#shortcuts(str) ⇒ Object
126 127 128 129 |
# File 'lib/helpers.rb', line 126 def shortcuts(str) @str = str erb :'partials/shortcuts', :layout => false end |
#suggest_cluster_links(clusters, g) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/helpers.rb', line 43 def suggest_cluster_links(clusters, g) links = [] clusters.each do |c| href = append_query_string("/dash/#{c}/#{params[:dashboard]}/#{g.name}") links << "<a href=\"#{href}\">#{c}</a>" end return "zoom (" + links.join(", ") + ")" end |
#suggest_dashboards(host, graph) ⇒ Object
it’s mildly annoying that when this set is empty there’re no uplinks consider adding a link up to the cluster (which is best we can do)
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/helpers.rb', line 66 def suggest_dashboards(host, graph) ret = Set.new host.graphs.each do |g| Dashboard.find_by_graph(g).each do |d| valid, _ = d.get_valid_hosts(g, host['cluster']) ret << d.name if valid.member?(host) end end return ret end |
#suggest_dashboards_links(host, graph) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/helpers.rb', line 52 def suggest_dashboards_links(host, graph) suggested = suggest_dashboards(host, graph) return "" if suggested.length == 0 links = [] suggested.each do |d| links << "<a href=\"/dash/#{host.cluster}/#{append_query_string(d)}\">" + "#{d}</a>" end return "(" + links.join(", ") + ")" end |