Commit 37ed6703935affe806bbb45a4713214afc42ed1a

Authored by Alessandro Palmeira
Committed by Paulo Meireles
2 parents 2ba6f013 67aa673b

Merge branch 'format' into mezuro-dev

plugins/mezuro/controllers/myprofile/mezuro_plugin_base_tool_controller.rb
@@ -2,16 +2,9 @@ class MezuroPluginBaseToolController < MezuroPluginMyprofileController @@ -2,16 +2,9 @@ class MezuroPluginBaseToolController < MezuroPluginMyprofileController
2 2
3 append_view_path File.join(File.dirname(__FILE__) + '/../../views') 3 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
4 4
5 - def choose_base_tool  
6 - @configuration_content = profile.articles.find(params[:id])  
7 - @base_tools = Kalibro::BaseTool.all_names  
8 - end  
9 -  
10 def choose_metric 5 def choose_metric
11 @configuration_content = profile.articles.find(params[:id]) 6 @configuration_content = profile.articles.find(params[:id])
12 - @base_tool = params[:base_tool]  
13 - base_tool = Kalibro::BaseTool.find_by_name(@base_tool)  
14 - @supported_metrics = base_tool.nil? ? [] : base_tool.supported_metrics 7 + @base_tools = Kalibro::BaseTool.all
15 end 8 end
16 9
17 end 10 end
plugins/mezuro/lib/kalibro/base_tool.rb
@@ -10,6 +10,11 @@ class Kalibro::BaseTool < Kalibro::Model @@ -10,6 +10,11 @@ class Kalibro::BaseTool < Kalibro::Model
10 new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] 10 new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool]
11 end 11 end
12 12
  13 + def self.all
  14 + basetools = all_names
  15 + basetools.map{ |name| find_by_name(name) }
  16 + end
  17 +
13 def supported_metric=(value) 18 def supported_metric=(value)
14 @supported_metric = Kalibro::NativeMetric.to_objects_array value 19 @supported_metric = Kalibro::NativeMetric.to_objects_array value
15 end 20 end
plugins/mezuro/lib/mezuro_plugin.rb
@@ -22,6 +22,15 @@ class MezuroPlugin < Noosfero::Plugin @@ -22,6 +22,15 @@ class MezuroPlugin < Noosfero::Plugin
22 end 22 end
23 end 23 end
24 24
  25 + def control_panel_buttons
  26 + if context.profile.is_a?(Community)
  27 + {:title => _('Mezuro Project'), :url => {:controller => 'cms', :action => 'new', :profile => context.profile.identifier, :type => 'MezuroPlugin::ProjectContent'} }
  28 + else
  29 + {:title => _('Mezuro Configuration'), :url => {:controller => 'cms', :action => 'new', :profile => context.profile.identifier, :type => 'MezuroPlugin::ConfigurationContent'} }
  30 + end
  31 + end
  32 +
  33 +
25 def stylesheet? 34 def stylesheet?
26 true 35 true
27 end 36 end
plugins/mezuro/test/functional/myprofile/mezuro_plugin_base_tool_controller_test.rb
@@ -22,20 +22,12 @@ class MezuroPluginBaseToolControllerTest < ActionController::TestCase @@ -22,20 +22,12 @@ class MezuroPluginBaseToolControllerTest < ActionController::TestCase
22 @content.save 22 @content.save
23 end 23 end
24 24
25 - should 'test choose base tool' do  
26 - Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name})  
27 - get :choose_base_tool, :profile => @profile.identifier, :id => @content.id  
28 - assert_equal [@base_tool.name], assigns(:base_tools)  
29 - assert_equal @content, assigns(:configuration_content)  
30 - assert_response 200  
31 - end  
32 -  
33 should 'test choose metric' do 25 should 'test choose metric' do
  26 + Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool_names).returns({:base_tool_name => @base_tool.name})
34 Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash}) 27 Kalibro::BaseTool.expects(:request).with("BaseTool", :get_base_tool, {:base_tool_name => @base_tool.name}).returns({:base_tool => @base_tool_hash})
35 - get :choose_metric, :profile => @profile.identifier, :id => @content.id, :base_tool => @base_tool.name 28 + get :choose_metric, :profile => @profile.identifier, :id => @content.id
  29 + assert_equal @base_tool.name, assigns(:base_tools).first.name
36 assert_equal @content, assigns(:configuration_content) 30 assert_equal @content, assigns(:configuration_content)
37 - assert_equal @base_tool.name, assigns(:base_tool)  
38 - assert_equal @base_tool.supported_metric[0].name, assigns(:supported_metrics)[0].name  
39 assert_response 200 31 assert_response 200
40 end 32 end
41 33
plugins/mezuro/views/content_viewer/_metric_configuration_form.rhtml 0 → 100644
@@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
  1 +<% form_for :metric_configuration, :url => {:action =>"update_metric_configuration", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>
  2 + <%= hidden_field_tag :id, @configuration_content.id %>
  3 + <%= f.hidden_field :configuration_name, :value => @configuration_content.name %>
  4 +
  5 + <% f.fields_for :metric do |m| %>
  6 +
  7 + <% @metric.language.each do |language| %>
  8 + <%= m.hidden_field :language, :multiple => true, :value => language %>
  9 + <% end %>
  10 +
  11 + <%= m.hidden_field "scope", :value => @metric.scope %>
  12 + <p>
  13 + <b><%= m.label :origin, "Collector Name:" %></b>
  14 + <%= @metric.origin %>
  15 + <%= m.hidden_field "origin", :value => @metric.origin %>
  16 + </p>
  17 + <p>
  18 + <b><%= m.label :metric_name, "Metric Name:" %></b>
  19 + <%= @metric.name %>
  20 + <%= m.hidden_field "name", :value => @metric.name %>
  21 + </p>
  22 + <% end %>
  23 + <p>
  24 + <b><%= f.label :code, "Code:" %></b>
  25 + <%= @metric_configuration.code %>
  26 + <%= f.hidden_field "code", :value => @metric_configuration.code %>
  27 + </p>
  28 + <p>
  29 + <b><%= f.label :aggregation_form, "Aggregation Form:" %></b>
  30 + <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],
  31 + ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %>
  32 + </p>
  33 + <p>
  34 + <b><%= f.label :weight, "Weight:" %></b>
  35 + <%= f.text_field "weight", :value => @metric_configuration.weight %>
  36 + </p>
  37 +
  38 + <p>
  39 + <%= f.submit "Save" %>
  40 + </p>
  41 +<% end %>
plugins/mezuro/views/content_viewer/_metric_configuration_view.rhtml 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +<p>
  2 + <b>Collector Name:</b> <%= @metric.origin %>
  3 +</p>
  4 +<p>
  5 + <b>Metric Name:</b> <%= @metric.name %>
  6 +</p>
  7 +<p>
  8 + <b>Code:</b> <%= @metric_configuration.code %>
  9 +</p>
  10 +<p>
  11 + <b>Aggregation Form:</b> <%= @metric_configuration.aggregation_form %>
  12 +</p>
  13 +<p>
  14 + <b>Weight:</b> <%= @metric_configuration.weight %>
  15 +</p>
plugins/mezuro/views/content_viewer/show_configuration.rhtml
1 <% @configuration_content = @page 1 <% @configuration_content = @page
2 @kalibro_configuration = @page.kalibro_configuration %> 2 @kalibro_configuration = @page.kalibro_configuration %>
  3 +<% owner = (not user.nil?) && user.id == @profile.id %>
  4 +
3 <% unless @page.errors[:base].nil? %> 5 <% unless @page.errors[:base].nil? %>
4 <% if @page.errors[:base] =~ /There is no configuration named/ %> 6 <% if @page.errors[:base] =~ /There is no configuration named/ %>
5 <h3>Warning:</h3> 7 <h3>Warning:</h3>
6 - <p>This Configuration doesn't exist on the Web Service. Do you want to <%= link_to 'delete', :action => 'destroy', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %> or <%= link_to 'save it again', :action => 'edit', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %>?</p> 8 + <p>This Configuration doesn't exist on the Web Service.</p>
  9 + <% if owner %>
  10 + <p> Do you want to <%= link_to 'delete', :action => 'destroy', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %> or <%= link_to 'save it again', :action => 'edit', :controller => 'cms', :profile => @page.profile.identifier, :id => @page.id %>?</p>
  11 + <% end %>
7 <% else %> 12 <% else %>
8 <%= @page.errors[:base] %> 13 <%= @page.errors[:base] %>
9 <% end %> 14 <% end %>
@@ -22,42 +27,44 @@ @@ -22,42 +27,44 @@
22 27
23 <br/> 28 <br/>
24 29
25 - <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_base_tool", 30 + <% if owner %>
  31 + <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_base_tool",
26 :profile => @page.profile.identifier, 32 :profile => @page.profile.identifier,
27 - :action => "choose_base_tool", 33 + :action => "choose_metric",
28 :id => @configuration_content.id %><br/> 34 :id => @configuration_content.id %><br/>
  35 + <% end %>
29 36
30 <table> 37 <table>
31 <tr class="titles"> 38 <tr class="titles">
32 <td><h5>Metric Name</h5></td> 39 <td><h5>Metric Name</h5></td>
33 <td><h5>Collector Name</h5></td> 40 <td><h5>Collector Name</h5></td>
34 <td><h5>Metric Code</h5></td> 41 <td><h5>Metric Code</h5></td>
35 - <td/><td/> 42 + <td/>
36 </tr> 43 </tr>
37 <% @kalibro_configuration.metric_configurations.each do |metric_configuration| %> 44 <% @kalibro_configuration.metric_configurations.each do |metric_configuration| %>
38 <tr class="metric"> 45 <tr class="metric">
39 - <td><%= metric_configuration.metric.name %></td>  
40 <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %> 46 <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %>
  47 + <td><%= link_to metric_configuration.metric.name, :controller => "mezuro_plugin_metric_configuration", :action => "edit_metric_configuration",
  48 + :metric_name => metric_configuration.metric.name, :id => @configuration_content.id,
  49 + :profile => @page.profile.identifier %></td>
41 <td> 50 <td>
42 <%= metric_configuration.metric.origin %> 51 <%= metric_configuration.metric.origin %>
43 </td> 52 </td>
44 <td><%= metric_configuration.code %></td> 53 <td><%= metric_configuration.code %></td>
45 - <td><%= link_to "Edit", :controller => "mezuro_plugin_metric_configuration", :action => "edit_metric_configuration",  
46 - :metric_name => metric_configuration.metric.name, :id => @configuration_content.id,  
47 - :profile => @page.profile.identifier %></td>  
48 <% else %> 54 <% else %>
  55 + <td><%= link_to metric_configuration.metric.name, :controller => "mezuro_plugin_metric_configuration",
  56 + :action => "edit_compound_metric_configuration", :metric_name => metric_configuration.metric.name,
  57 + :id => @configuration_content.id, :profile => @page.profile.identifier %></td>
49 <td> 58 <td>
50 Compound Metric 59 Compound Metric
51 </td> 60 </td>
52 <td><%= metric_configuration.code %></td> 61 <td><%= metric_configuration.code %></td>
53 - <td><%= link_to "Edit", :controller => "mezuro_plugin_metric_configuration",  
54 - :action => "edit_compound_metric_configuration", :metric_name => metric_configuration.metric.name,  
55 - :id => @configuration_content.id, :profile => @page.profile.identifier %></td>  
56 <% end %> 62 <% end %>
57 -  
58 - <td><%= link_to "Remove", :controller => "mezuro_plugin_metric_configuration", :action => "remove_metric_configuration", 63 + <% if owner %>
  64 + <td><%= link_to "Remove", :controller => "mezuro_plugin_metric_configuration", :action => "remove_metric_configuration",
59 :metric_name => metric_configuration.metric.name, :id => @configuration_content.id, 65 :metric_name => metric_configuration.metric.name, :id => @configuration_content.id,
60 :profile => @page.profile.identifier %></td> 66 :profile => @page.profile.identifier %></td>
  67 + <% end %>
61 </tr> 68 </tr>
62 <% end %> 69 <% end %>
63 </table> 70 </table>
plugins/mezuro/views/mezuro_plugin_base_tool/choose_base_tool.html.erb
@@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
1 -<h2><%= @configuration_content.name%> Configuration</h2>  
2 -  
3 -<%= link_to "New Compound Metric", :controller => "mezuro_plugin_metric_configuration", :action => "new_compound_metric_configuration",  
4 - :id => @configuration_content.id %>  
5 -  
6 -<h5>Base Tools:</h5>  
7 -<table id="project_info">  
8 - <% @base_tools.each do |base_tool| %>  
9 - <tr>  
10 - <td>  
11 - <%= link_to base_tool, :controller => "mezuro_plugin_base_tool", :action => "choose_metric", :base_tool => base_tool,  
12 - :id => @configuration_content.id %>  
13 - </td>  
14 - </tr>  
15 - <% end %>  
16 -</table>  
plugins/mezuro/views/mezuro_plugin_base_tool/choose_metric.html.erb
1 -<h2><%= @configuration_content.name %> Configuration</h2> 1 +<h2><%= @configuration_content.name%> Configuration</h2>
2 2
3 -<table id="project_info">  
4 - <tr>  
5 - <h5>Metric Collector: <%= @base_tool %></h5>  
6 - </tr>  
7 - <tr>  
8 - <h5>Choose a metric to add:</h5>  
9 - </tr>  
10 - <% @supported_metrics.each do |metric| %>  
11 - <tr class="metric" title="<%= metric.name %>">  
12 - <td>  
13 - <%= link_to metric.name, :controller => "mezuro_plugin_metric_configuration", :action => "new_metric_configuration",  
14 - :metric_name => metric.name, :base_tool => @base_tool, :id => @configuration_content.id %>  
15 - </td>  
16 - </tr>  
17 - <% end %>  
18 -</table> 3 +<%= link_to "New Compound Metric", :controller => "mezuro_plugin_metric_configuration", :action => "new_compound_metric_configuration",
  4 + :id => @configuration_content.id %>
  5 +
  6 +<h5>Base Tools:</h5>
  7 +<% @base_tools.each do |base_tool| %>
  8 + <h4><%= link_to base_tool.name, "#", :onclick => "jQuery(\"\##{base_tool.name}\").toggle();"%></h4>
  9 + <hr/>
  10 +
  11 + <div id="<%=base_tool.name%>" style="display:none">
  12 + <% base_tool.supported_metrics.each do |metric| %>
  13 + &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<%= link_to metric.name, :controller => "mezuro_plugin_metric_configuration", :action => "new_metric_configuration",
  14 + :metric_name => metric.name, :base_tool => base_tool.name, :id => @configuration_content.id %>
  15 + <hr size="1" width="93%"/>
  16 + <% end %>
  17 + </div>
  18 +<% end %>
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_compound_metric_configuration.html.erb
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 </p> 23 </p>
24 <p> 24 <p>
25 <%= m.label :script, "Script:" %> 25 <%= m.label :script, "Script:" %>
26 - <%= m.text_area "script", :value => @metric.script %> 26 + <%= m.text_area "script", :value => @metric.script, :rows => 5 %>
27 </p> 27 </p>
28 <% end %> 28 <% end %>
29 <p> 29 <p>
plugins/mezuro/views/mezuro_plugin_metric_configuration/edit_metric_configuration.html.erb
@@ -4,54 +4,14 @@ @@ -4,54 +4,14 @@
4 4
5 <h2><%= @configuration_content.name %> Configuration</h2> 5 <h2><%= @configuration_content.name %> Configuration</h2>
6 6
7 -<% form_for :metric_configuration, :url => {:action =>"update_metric_configuration", :controller => "mezuro_plugin_metric_configuration"}, :method => :get do |f| %>  
8 - <%= hidden_field_tag :id, @configuration_content.id %>  
9 - <%= f.hidden_field :configuration_name, :value => @configuration_content.name %>  
10 -  
11 - <% f.fields_for :metric do |m| %>  
12 -  
13 - <% @metric.language.each do |language| %>  
14 - <%= m.hidden_field :language, :multiple => true, :value => language %>  
15 - <% end %>  
16 -  
17 - <%= m.hidden_field "scope", :value => @metric.scope %>  
18 - <p>  
19 - <%= m.label :origin, "Collector Name:" %>  
20 - <%= @metric.origin %>  
21 - <%= m.hidden_field "origin", :value => @metric.origin %>  
22 - </p>  
23 - <p>  
24 - <%= m.label :metric_name, "Metric Name:" %>  
25 - <%= @metric.name %>  
26 - <%= m.hidden_field "name", :value => @metric.name %>  
27 - </p>  
28 - <!--<p>-->  
29 - <% m.label :description, "Description:" %>  
30 - <% @metric.description %>  
31 - <% m.hidden_field "description", :value => @metric.description %>  
32 - <!--</p>-->  
33 - <% end %>  
34 - <p>  
35 - <%= f.label :code, "Code:" %>  
36 - <%= @metric_configuration.code %>  
37 - <%= f.hidden_field "code", :value => @metric_configuration.code %>  
38 - </p>  
39 - <p>  
40 - <%= f.label :aggregation_form, "Aggregation Form:" %>  
41 - <%= f.select :aggregation_form, [["Average","AVERAGE"], ["Median", "MEDIAN"], ["Maximum", "MAXIMUM"], ["Minimum", "MINIMUM"],  
42 - ["Count", "COUNT"], ["Standard Deviation", "STANDARD_DEVIATION"]] %>  
43 - </p>  
44 - <p>  
45 - <%= f.label :weight, "Weight:" %>  
46 - <%= f.text_field "weight", :value => @metric_configuration.weight %>  
47 - </p> 7 +<% owner = (not user.nil?) && user.id == @profile.id %>
48 8
49 - <p>  
50 - <%= f.submit "Save" %>  
51 - </p> 9 +<% if owner %>
  10 + <%= render :partial => "content_viewer/metric_configuration_form" %>
  11 +<% else %>
  12 + <%= render :partial => "content_viewer/metric_configuration_view" %>
52 <% end %> 13 <% end %>
53 14
54 -  
55 <h5> Ranges </h5><br/> 15 <h5> Ranges </h5><br/>
56 16
57 <table id="ranges"> 17 <table id="ranges">
@@ -83,6 +43,8 @@ @@ -83,6 +43,8 @@
83 </table> 43 </table>
84 44
85 <br/> 45 <br/>
86 -<%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_name => @metric.name} %> 46 +<% if owner %>
  47 + <%= link_to_remote "New Range", :url => {:action =>"new_range", :controller => "mezuro_plugin_range", :id => @configuration_content.id, :metric_name => @metric.name} %>
  48 +<% end %>
87 <div id="range_form" style="display:none"></div> 49 <div id="range_form" style="display:none"></div>
88 50
plugins/mezuro/views/mezuro_plugin_metric_configuration/new_compound_metric_configuration.html.erb
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 </p> 20 </p>
21 <p> 21 <p>
22 <%= m.label :script, "Script:" %> 22 <%= m.label :script, "Script:" %>
23 - <%= m.text_area "script" %> 23 + <%= m.text_area "script", :rows => 5 %>
24 </p> 24 </p>
25 <% end %> 25 <% end %>
26 <p> 26 <p>
plugins/mezuro/views/mezuro_plugin_range/_range.html.erb
@@ -12,6 +12,13 @@ @@ -12,6 +12,13 @@
12 <%=range.grade%> 12 <%=range.grade%>
13 </td> 13 </td>
14 <td bgcolor="#<%= range.color[2..-1] %>"></td> 14 <td bgcolor="#<%= range.color[2..-1] %>"></td>
15 - <td><%= link_to_remote "Edit", :url => {:action =>"edit_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning} %></td>  
16 - <td><%= link_to "Remove", :action =>"remove_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning %></td> 15 + <% if (not user.nil?) && user.id == @profile.id %>
  16 + <td><%= link_to_remote "Edit", :url => {:action =>"edit_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning} %>
  17 + </td>
  18 + <td><%= link_to "Remove", :action =>"remove_range", :controller => "mezuro_plugin_range", :id => params[:id], :metric_name => params[:metric_name], :beginning_id => range.beginning %>
  19 + </td>
  20 + <% else %>
  21 + <td></td>
  22 + <td></td>
  23 + <% end %>
17 </tr> 24 </tr>
plugins/mezuro/views/mezuro_plugin_range/_range_form.html.erb
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 <%= f.label :beginning, "(*) Beginning:" %> 14 <%= f.label :beginning, "(*) Beginning:" %>
15 </td> 15 </td>
16 <td> 16 <td>
17 - <%= f.text_field :beginning, :value => @range.beginning %> 17 + <%= f.text_field :beginning, :value => @range.beginning , :id => 'beginning' %>&nbsp;<%= link_to('-&#8734', 'javascript:void(0)', :onClick => "jQuery( '#beginning' ).val('-INF');") %>
18 </td> 18 </td>
19 </tr> 19 </tr>
20 <tr> 20 <tr>
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 <%= f.label :end, "(*) End:" %> 22 <%= f.label :end, "(*) End:" %>
23 </td> 23 </td>
24 <td> 24 <td>
25 - <%= f.text_field :end, :value => @range.end %> 25 + <%= f.text_field :end, :value => @range.end, :id => "end" %>&nbsp;<%= link_to('+&#8734', 'javascript:void(0)', :onClick => "jQuery( '#end' ).val('+INF');") %>
26 </td> 26 </td>
27 </tr> 27 </tr>
28 <tr> 28 <tr>
@@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
46 <%= f.label :comments, "Comments:" %> 46 <%= f.label :comments, "Comments:" %>
47 </td> 47 </td>
48 <td> 48 <td>
49 - <%= f.text_field :comments %> 49 + <%= f.text_area :comments, :rows => 3 %>
50 </td> 50 </td>
51 </tr> 51 </tr>
52 </table> 52 </table>