Commit b129d88bddf23ae48c197c4f6eaf1ac3f76ae5ed
Committed by
Paulo Meireles
1 parent
aef90e14
Exists in
master
and in
29 other branches
[Mezuro] refactored choose base tool and choose metric views
Showing
6 changed files
with
46 additions
and
65 deletions
Show diff stats
plugins/mezuro/controllers/myprofile/mezuro_plugin_base_tool_controller.rb
... | ... | @@ -2,16 +2,9 @@ class MezuroPluginBaseToolController < MezuroPluginMyprofileController |
2 | 2 | |
3 | 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 | 5 | def choose_metric |
11 | 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 | 8 | end |
16 | 9 | |
17 | 10 | end | ... | ... |
plugins/mezuro/lib/kalibro/base_tool.rb
... | ... | @@ -10,6 +10,11 @@ class Kalibro::BaseTool < Kalibro::Model |
10 | 10 | new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] |
11 | 11 | end |
12 | 12 | |
13 | + def self.all | |
14 | + basetools = all_names | |
15 | + basetools.map{ |name| find_by_name(name) } | |
16 | + end | |
17 | + | |
13 | 18 | def supported_metric=(value) |
14 | 19 | @supported_metric = Kalibro::NativeMetric.to_objects_array value |
15 | 20 | end | ... | ... |
plugins/mezuro/test/functional/myprofile/mezuro_plugin_base_tool_controller_test.rb
... | ... | @@ -22,20 +22,12 @@ class MezuroPluginBaseToolControllerTest < ActionController::TestCase |
22 | 22 | @content.save |
23 | 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 | 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 | 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 | 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 | 31 | assert_response 200 |
40 | 32 | end |
41 | 33 | ... | ... |
plugins/mezuro/views/content_viewer/show_configuration.rhtml
1 | 1 | <% @configuration_content = @page |
2 | 2 | @kalibro_configuration = @page.kalibro_configuration %> |
3 | +<% owner = (not user.nil?) && user.id == @profile.id %> | |
4 | + | |
3 | 5 | <% unless @page.errors[:base].nil? %> |
4 | 6 | <% if @page.errors[:base] =~ /There is no configuration named/ %> |
5 | 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 | 12 | <% else %> |
8 | 13 | <%= @page.errors[:base] %> |
9 | 14 | <% end %> |
... | ... | @@ -22,42 +27,44 @@ |
22 | 27 | |
23 | 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 | 32 | :profile => @page.profile.identifier, |
27 | - :action => "choose_base_tool", | |
33 | + :action => "choose_metric", | |
28 | 34 | :id => @configuration_content.id %><br/> |
35 | + <% end %> | |
29 | 36 | |
30 | 37 | <table> |
31 | 38 | <tr class="titles"> |
32 | 39 | <td><h5>Metric Name</h5></td> |
33 | 40 | <td><h5>Collector Name</h5></td> |
34 | 41 | <td><h5>Metric Code</h5></td> |
35 | - <td/><td/> | |
42 | + <td/> | |
36 | 43 | </tr> |
37 | 44 | <% @kalibro_configuration.metric_configurations.each do |metric_configuration| %> |
38 | 45 | <tr class="metric"> |
39 | - <td><%= metric_configuration.metric.name %></td> | |
40 | 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 | 50 | <td> |
42 | 51 | <%= metric_configuration.metric.origin %> |
43 | 52 | </td> |
44 | 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 | 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 | 58 | <td> |
50 | 59 | Compound Metric |
51 | 60 | </td> |
52 | 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 | 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 | 65 | :metric_name => metric_configuration.metric.name, :id => @configuration_content.id, |
60 | 66 | :profile => @page.profile.identifier %></td> |
67 | + <% end %> | |
61 | 68 | </tr> |
62 | 69 | <% end %> |
63 | 70 | </table> | ... | ... |
plugins/mezuro/views/mezuro_plugin_base_tool/choose_base_tool.html.erb
... | ... | @@ -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 | +       <%= 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 %> | ... | ... |