Revision ee878ae8
Added by Ohad Levy over 12 years ago
- ID ee878ae8d644d902f3a9b60a2eb34a3c1a31eea1
app/controllers/facts_controller.rb | ||
---|---|---|
class FactsController < ApplicationController
|
||
before_filter :valid_request?
|
||
|
||
def index
|
||
# we currently only support JSON in this controller
|
||
return not_found unless api_request?
|
||
|
||
render :json => FactName.no_timestamp_fact
|
||
end
|
||
|
||
def show
|
||
@fact = FactName.find(params[:id])
|
||
begin
|
||
data = {:name => @fact.name, :values => FactValue.count_each(@fact.name).to_a }
|
||
rescue
|
||
data = @fact
|
||
end
|
||
render :json => data
|
||
end
|
||
|
||
private
|
||
|
||
# we currently only support JSON in this controller
|
||
def valid_request?
|
||
return not_found unless api_request?
|
||
end
|
||
|
||
end
|
app/views/fact_values/index.html.erb | ||
---|---|---|
</td>
|
||
<% end %>
|
||
<td>
|
||
<%= link_to_function image_tag("pie_chart_icon.png", :alt => "Show distribution chart"),
|
||
"get_pie_chart('fact_chart-#{fact_value.fact_name_id}', '#{fact_path(fact_value.fact_name_id)}')" %>
|
||
<%= link_to h(fact_value.fact_name.name),
|
||
fact_values_path("search" => "name = #{fact_value.name}"),
|
||
:title => "Show all #{fact_value.name} fact values" %>
|
app/views/facts/show.html.erb | ||
---|---|---|
<% title @fact.name %>
|
||
|
||
<%= pie_chart @fact.name, "#{@fact.name.camelize} Distribution", FactValue.count_each(@fact.name) %>
|
config/routes.rb | ||
---|---|---|
map.resources :common_parameters, :collection => {:auto_complete_search => :get}
|
||
map.resources :environments, :collection => {:import_environments => :get, :obsolete_and_new => :post, :auto_complete_search => :get}
|
||
map.resources :fact_values, :only => [:create, :index], :collection => { :auto_complete_search => :get }
|
||
map.resources :facts, :only => [:index], :requirements => {:id => /[^\/]+/} do |facts|
|
||
map.resources :facts, :only => [:index, :show], :requirements => {:id => /[^\/]+/} do |facts|
|
||
facts.resources :values, :requirements => {:id => /[^\/]+/}, :only => :index, :controller => :fact_values
|
||
end
|
||
map.resources :ptables, :collection => {:auto_complete_search => :get}
|
public/javascripts/application.js | ||
---|---|---|
|
||
return false;
|
||
}
|
||
|
||
function get_pie_chart(div, url) {
|
||
if($("#"+div)[0] == undefined)
|
||
{
|
||
var html = $('<div id= '+ div + ' class="fact_chart" ></div>').appendTo('body');
|
||
$.getJSON(url, function(data) { pie_chart(div, data.name, data.values);
|
||
html.dialog({
|
||
width: 600,
|
||
resizable: false,
|
||
title: data.name + ' distribution',
|
||
close: function(event, ui){
|
||
$("#"+div).remove();
|
||
}
|
||
});
|
||
});
|
||
} else {$("#"+div).dialog("moveToTop");}
|
||
}
|
||
|
||
function pie_chart(div, title, data) {
|
||
new Highcharts.Chart({
|
||
chart: {
|
||
renderTo: div,
|
||
borderWidth: 0,
|
||
backgroundColor: {
|
||
linearGradient: [0, 0, 0, 200],
|
||
stops: [
|
||
[0, '#ffffff'],
|
||
[1, '#EDF6FC']
|
||
]}
|
||
},
|
||
credits: {
|
||
enabled: false,
|
||
},
|
||
title: {
|
||
text: title
|
||
},
|
||
tooltip: {
|
||
formatter: function() {
|
||
return '<b>'+ this.point.name +'</b>: '+ this.y;
|
||
}
|
||
},
|
||
plotOptions: {
|
||
pie: {
|
||
allowPointSelect: true,
|
||
cursor: 'pointer',
|
||
dataLabels: {
|
||
enabled: true,
|
||
formatter: function() {
|
||
return '<b>'+ this.point.name +'</b>: '+ this.y;
|
||
}
|
||
}
|
||
}
|
||
},
|
||
series: [{
|
||
type: 'pie',
|
||
name: '',
|
||
data: data
|
||
}]
|
||
});
|
||
};
|
public/stylesheets/style.css | ||
---|---|---|
.grey {
|
||
color:#aaa;
|
||
}
|
||
|
||
.fact_chart {
|
||
height: 400px !important;
|
||
width: 600px !important;
|
||
padding: 0 !important;
|
||
overflow: hidden;
|
||
display: none;
|
||
}
|
Also available in: Unified diff
fixes #1161 - adds graph per facts
Signed-off-by: Amos Benari <abenari@redhat.com>