Commit 82433ef3e6555ec36b448fa66dd0b8321fc28598

Authored by Paulo Meireles
2 parents 21fcc5c2 bbeb3b9e

Merge branch 'new_source_tree' into mezuro

plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
@@ -18,6 +18,7 @@ class MezuroPluginProfileController < ProfileController @@ -18,6 +18,7 @@ class MezuroPluginProfileController < ProfileController
18 def project_result 18 def project_result
19 content = profile.articles.find(params[:id]) 19 content = profile.articles.find(params[:id])
20 project_result = content.project_result 20 project_result = content.project_result
  21 + project = content.project
21 render :partial => 'content_viewer/project_result', :locals => { :project_result => project_result } 22 render :partial => 'content_viewer/project_result', :locals => { :project_result => project_result }
22 end 23 end
23 24
@@ -27,4 +28,11 @@ class MezuroPluginProfileController < ProfileController @@ -27,4 +28,11 @@ class MezuroPluginProfileController < ProfileController
27 render :partial => 'content_viewer/module_result', :locals => { :module_result => module_result} 28 render :partial => 'content_viewer/module_result', :locals => { :module_result => module_result}
28 end 29 end
29 30
  31 + def project_tree
  32 + content = profile.articles.find(params[:id])
  33 + project_result = content.project_result
  34 + source_tree = project_result.node_of(params[:module_name])
  35 + render :partial =>'content_viewer/source_tree', :locals => { :source_tree => source_tree, :project_name => content.project.name}
  36 + end
  37 +
30 end 38 end
plugins/mezuro/lib/kalibro/entities/entity.rb
@@ -7,7 +7,7 @@ class Kalibro::Entities::Entity @@ -7,7 +7,7 @@ class Kalibro::Entities::Entity
7 end 7 end
8 8
9 def set(field, value) 9 def set(field, value)
10 - send("#{field}=", value) 10 + send("#{field}=", value) if not field.to_s.start_with? '@'
11 end 11 end
12 12
13 def to_entity_array(value, entity_class = nil) 13 def to_entity_array(value, entity_class = nil)
@@ -50,4 +50,4 @@ class Kalibro::Entities::Entity @@ -50,4 +50,4 @@ class Kalibro::Entities::Entity
50 send("#{field}") 50 send("#{field}")
51 end 51 end
52 52
53 -end  
54 \ No newline at end of file 53 \ No newline at end of file
  54 +end
plugins/mezuro/lib/kalibro/entities/module.rb
@@ -2,4 +2,17 @@ class Kalibro::Entities::Module < Kalibro::Entities::Entity @@ -2,4 +2,17 @@ class Kalibro::Entities::Module < Kalibro::Entities::Entity
2 2
3 attr_accessor :name, :granularity 3 attr_accessor :name, :granularity
4 4
5 -end  
6 \ No newline at end of file 5 \ No newline at end of file
  6 + def self.parent_names(name)
  7 + path = []
  8 + ancestors = []
  9 + name.split(".").each do |token|
  10 + path << token
  11 + ancestors << path.join(".")
  12 + end
  13 + ancestors
  14 + end
  15 +
  16 + def ancestor_names
  17 + Kalibro::Entities::Module.parent_names(@name)
  18 + end
  19 +end
plugins/mezuro/lib/kalibro/entities/native_metric.rb
@@ -2,4 +2,4 @@ class Kalibro::Entities::NativeMetric &lt; Kalibro::Entities::Metric @@ -2,4 +2,4 @@ class Kalibro::Entities::NativeMetric &lt; Kalibro::Entities::Metric
2 2
3 attr_accessor :origin, :language 3 attr_accessor :origin, :language
4 4
5 -end  
6 \ No newline at end of file 5 \ No newline at end of file
  6 +end
plugins/mezuro/lib/kalibro/entities/project_result.rb
@@ -31,4 +31,29 @@ class Kalibro::Entities::ProjectResult &lt; Kalibro::Entities::Entity @@ -31,4 +31,29 @@ class Kalibro::Entities::ProjectResult &lt; Kalibro::Entities::Entity
31 ('%2d' % amount).sub(/\s/, '0') 31 ('%2d' % amount).sub(/\s/, '0')
32 end 32 end
33 33
34 -end  
35 \ No newline at end of file 34 \ No newline at end of file
  35 + def node_of(module_name)
  36 + if module_name.nil? or module_name == project.name
  37 + node = source_tree
  38 + else
  39 + node = get_node(module_name)
  40 + end
  41 + end
  42 +
  43 + def get_node(module_name)
  44 + path = Kalibro::Entities::Module.parent_names(module_name)
  45 + parent = @source_tree
  46 + path.each do |node_name|
  47 + parent = get_leaf_from(parent, node_name)
  48 + end
  49 + return parent
  50 + end
  51 +
  52 + private
  53 + def get_leaf_from(node, module_name)
  54 + node.children.each do |child_node|
  55 + return child_node if child_node.module.name == module_name
  56 + end
  57 + nil
  58 + end
  59 +
  60 +end
plugins/mezuro/lib/mezuro_plugin/project_content.rb
@@ -26,6 +26,7 @@ class MezuroPlugin::ProjectContent &lt; Article @@ -26,6 +26,7 @@ class MezuroPlugin::ProjectContent &lt; Article
26 end 26 end
27 27
28 def module_result(module_name) 28 def module_result(module_name)
  29 + module_name = project.name if module_name.nil?
29 @module_client ||= Kalibro::Client::ModuleResultClient.module_result(self, module_name) 30 @module_client ||= Kalibro::Client::ModuleResultClient.module_result(self, module_name)
30 end 31 end
31 32
plugins/mezuro/public/javascripts/project_content.js
1 -jQuery(showProjectContent); 1 +jQuery(function (){
  2 + jQuery('.source-tree-link').live("click", reloadModule);
  3 + showProjectContent();
  4 +});
2 5
3 function showProjectContent() { 6 function showProjectContent() {
4 callAction('project_state', {}, showProjectContentFor); 7 callAction('project_state', {}, showProjectContentFor);
5 } 8 }
6 9
  10 +function reloadModule(){
  11 + var module_name = jQuery(this).attr('data-module-name');
  12 + callAction('project_tree', {module_name: module_name }, showProjectTree);
  13 + callAction('module_result', {module_name: module_name}, showModuleResult);
  14 + return false;
  15 +}
  16 +
7 function showProjectContentFor(state){ 17 function showProjectContentFor(state){
8 if (state == 'ERROR') 18 if (state == 'ERROR')
9 - callAction('project_error', {}, setProjectContent);  
10 - else if (state == 'READY')  
11 - callAction('project_result', {}, setProjectContent); 19 + callAction('project_error', {}, showProjectResult);
  20 + else if (state == 'READY') {
  21 + callAction('project_result', {}, showProjectResult);
  22 + callAction('project_tree', {}, showProjectTree);
  23 + callAction('module_result', {}, showModuleResult);
  24 + }
12 else if (state.endsWith("ING")) 25 else if (state.endsWith("ING"))
13 showProjectContentAfter(20); 26 showProjectContentAfter(20);
14 } 27 }
@@ -23,19 +36,15 @@ function showProjectContentAfter(seconds){ @@ -23,19 +36,15 @@ function showProjectContentAfter(seconds){
23 } 36 }
24 } 37 }
25 38
26 -function setProjectContent(content){  
27 - jQuery('#project-content').html(content);  
28 - jQuery('.module-result-link').click(showModuleResult); 39 +function showProjectResult(content) {
  40 + jQuery('#project-result').html(content);
29 } 41 }
30 42
31 -function showModuleResult(){  
32 - var module_name = jQuery(this).attr('data-module-name');  
33 - setModuleResult("Loading results for " + module_name + "...");  
34 - callAction('module_result', {module_name: module_name}, setModuleResult);  
35 - return false; 43 +function showProjectTree(content){
  44 + jQuery('#project-tree').html(content);
36 } 45 }
37 46
38 -function setModuleResult(content){ 47 +function showModuleResult(content){
39 jQuery('#module-result').html(content); 48 jQuery('#module-result').html(content);
40 } 49 }
41 50
@@ -47,11 +56,5 @@ function callAction(action, params, callback){ @@ -47,11 +56,5 @@ function callAction(action, params, callback){
47 } 56 }
48 57
49 function projectContentData(data){ 58 function projectContentData(data){
50 - return jQuery('#project-content').attr('data-' + data); 59 + return jQuery('#project-result').attr('data-' + data);
51 } 60 }
52 -  
53 -function sourceNodeToggle(id){  
54 - var suffixes = ['_hidden', '_plus', '_minus'];  
55 - for (var i in suffixes)  
56 - jQuery('#' + id + suffixes[i]).toggle();  
57 -}  
58 \ No newline at end of file 61 \ No newline at end of file
plugins/mezuro/test/fixtures/module_node_fixtures.rb
@@ -3,7 +3,9 @@ class ModuleNodeFixtures @@ -3,7 +3,9 @@ class ModuleNodeFixtures
3 def self.qt_calculator_tree 3 def self.qt_calculator_tree
4 node = Kalibro::Entities::ModuleNode.new 4 node = Kalibro::Entities::ModuleNode.new
5 node.module = ModuleFixtures.qt_calculator 5 node.module = ModuleFixtures.qt_calculator
6 - node.children = [new_node('Dialog', 'CLASS'), new_node('main', 'CLASS')] 6 + org_node = new_node('org', 'PACKAGE')
  7 + org_node.children = [new_node('org.Window', 'CLASS')]
  8 + node.children = [new_node('Dialog', 'CLASS'), new_node('main', 'CLASS'), org_node]
7 node 9 node
8 end 10 end
9 11
@@ -11,7 +13,9 @@ class ModuleNodeFixtures @@ -11,7 +13,9 @@ class ModuleNodeFixtures
11 {:module => ModuleFixtures.qt_calculator_hash, 13 {:module => ModuleFixtures.qt_calculator_hash,
12 :child => [ 14 :child => [
13 {:module => {:name => 'Dialog', :granularity => 'CLASS'}}, 15 {:module => {:name => 'Dialog', :granularity => 'CLASS'}},
14 - {:module => {:name => 'main', :granularity => 'CLASS'}} 16 + {:module => {:name => 'main', :granularity => 'CLASS'}},
  17 + {:module => {:name => 'org', :granularity => 'PACKAGE'},
  18 + :child => [{:module => {:name => 'org.Window', :granularity => 'CLASS'}}]}
15 ] 19 ]
16 } 20 }
17 end 21 end
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -54,10 +54,10 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase @@ -54,10 +54,10 @@ class MezuroPluginProfileControllerTest &lt; ActionController::TestCase
54 Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result) 54 Kalibro::Client::ProjectResultClient.expects(:last_result).with(@name).returns(@project_result)
55 get :project_result, :profile => @profile.identifier, :id => @content.id 55 get :project_result, :profile => @profile.identifier, :id => @content.id
56 assert_response 200 56 assert_response 200
57 - assert_select('h3', 'LAST RESULT') 57 + assert_select('h4', 'Last Result')
58 end 58 end
59 59
60 - should 'get metric results for a module' do 60 + should 'get module result' do
61 create_project_content 61 create_project_content
62 Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @name).returns(@module_result) 62 Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @name).returns(@module_result)
63 get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name 63 get :module_result, :profile => @profile.identifier, :id => @content.id, :module_name => @name
plugins/mezuro/test/unit/kalibro/entities/module_test.rb
@@ -17,4 +17,14 @@ class ModuleTest &lt; ActiveSupport::TestCase @@ -17,4 +17,14 @@ class ModuleTest &lt; ActiveSupport::TestCase
17 assert_equal @hash, @module.to_hash 17 assert_equal @hash, @module.to_hash
18 end 18 end
19 19
20 -end  
21 \ No newline at end of file 20 \ No newline at end of file
  21 + should 'list ancestor names' do
  22 + @module.name = "org.kalibro.core"
  23 + assert_equal ["org", "org.kalibro", "org.kalibro.core"], @module.ancestor_names
  24 + end
  25 +
  26 + should 'list ancestor with one name' do
  27 + @module.name = "org"
  28 + assert_equal ["org"], @module.ancestor_names
  29 + end
  30 +
  31 +end
plugins/mezuro/test/unit/kalibro/entities/project_result_test.rb
@@ -24,5 +24,26 @@ class ProjectResultTest &lt; ActiveSupport::TestCase @@ -24,5 +24,26 @@ class ProjectResultTest &lt; ActiveSupport::TestCase
24 should 'retrieve formatted analysis time' do 24 should 'retrieve formatted analysis time' do
25 assert_equal '00:00:01', @result.formatted_analysis_time 25 assert_equal '00:00:01', @result.formatted_analysis_time
26 end 26 end
  27 +
  28 + should 'retrieve module node' do
  29 + node = @result.get_node("main")
  30 + assert_equal @hash[:source_tree][:child][1], node.to_hash
  31 + end
  32 +
  33 + should 'retrive complex module' do
  34 + node = @result.get_node("org.Window")
  35 + assert_equal @hash[:source_tree][:child][2][:child].first, node.to_hash
  36 + end
  37 +
  38 + should 'return source tree node when nil is given' do
  39 + assert_equal @hash[:source_tree], @result.node_of(nil).to_hash
  40 + end
27 41
28 -end  
29 \ No newline at end of file 42 \ No newline at end of file
  43 + should 'return source tree node when project name is given' do
  44 + assert_equal @hash[:source_tree], @result.node_of(@result.project.name).to_hash
  45 + end
  46 +
  47 + should 'return correct node when module name is given' do
  48 + assert_equal @hash[:source_tree][:child][1], @result.node_of("main").to_hash
  49 + end
  50 +end
plugins/mezuro/test/unit/mezuro_plugin/project_content_test.rb
@@ -50,6 +50,20 @@ class ProjectContentTest &lt; ActiveSupport::TestCase @@ -50,6 +50,20 @@ class ProjectContentTest &lt; ActiveSupport::TestCase
50 assert_equal module_result, @content.module_result(module_name) 50 assert_equal module_result, @content.module_result(module_name)
51 end 51 end
52 52
  53 + should 'get module result root when nil is given' do
  54 + module_result = mock
  55 + Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @project.name).
  56 + returns(module_result)
  57 + assert_equal module_result, @content.module_result(nil)
  58 + end
  59 +
  60 + should 'get module result root when project name is give' do
  61 + module_result = mock
  62 + Kalibro::Client::ModuleResultClient.expects(:module_result).with(@content, @project.name).
  63 + returns(module_result)
  64 + assert_equal module_result, @content.module_result(@project.name)
  65 + end
  66 +
53 should 'send project to service after saving' do 67 should 'send project to service after saving' do
54 @content.expects :send_project_to_service 68 @content.expects :send_project_to_service
55 @content.run_callbacks :after_save 69 @content.run_callbacks :after_save
plugins/mezuro/views/content_viewer/_project_result.rhtml
1 -<h3><%= _('LAST RESULT') %></h3> 1 +<h4><%= _('Last Result') %></h4>
2 2
3 <table> 3 <table>
4 <tr> 4 <tr>
@@ -14,9 +14,3 @@ @@ -14,9 +14,3 @@
14 <td><%= project_result.formatted_analysis_time %></td> 14 <td><%= project_result.formatted_analysis_time %></td>
15 </tr> 15 </tr>
16 </table> 16 </table>
17 -  
18 -<h4><%= _('Source tree') %></h4>  
19 -<%= render :partial => 'content_viewer/source_tree', :locals => { :source_tree => project_result.source_tree } %>  
20 -  
21 -<div id='module-result'>  
22 -</div>  
plugins/mezuro/views/content_viewer/_source_tree.rhtml
  1 +<h4><%= _('Source tree') %></h4>
1 <% module_name = source_tree.module.name %> 2 <% module_name = source_tree.module.name %>
2 <% module_label = "#{module_name} (#{source_tree.module.granularity})" %> 3 <% module_label = "#{module_name} (#{source_tree.module.granularity})" %>
  4 +
  5 +<% if module_name != project_name %>
  6 + <a href="#" class="source-tree-link" data-module-name="<%= project_name %>">
  7 + <%= project_name %>
  8 + </a>
  9 +<% end %>
  10 +
  11 + <% split_link = source_tree.module.ancestor_names %>
  12 + <% split_link.each do |link| %>
  13 + <a href="#" class="source-tree-link" data-module-name="<%= link %>">
  14 + <%= link.split(".").last %>
  15 + </a>
  16 +<% end %>
  17 +
3 <% if source_tree.children %> 18 <% if source_tree.children %>
4 <table> 19 <table>
5 - <tr>  
6 - <td width="10%">  
7 - <img alt="+" src="/plugins/mezuro/images/plus.png" class="link"  
8 - id="<%= module_name %>_plus" onclick="sourceNodeToggle('<%= module_name %>')"/>  
9 - <img alt="-" src="/plugins/mezuro/images/minus.png" class="link" style="display: none"  
10 - id="<%= module_name %>_minus" onclick="sourceNodeToggle('<%= module_name %>')"/>  
11 - </td>  
12 - <td>  
13 - <a href="#" class="module-result-link" data-module-name="<%= module_name %>">  
14 - <%= module_label %>  
15 - </a>  
16 - </td>  
17 - </tr>  
18 - <tr id="<%= module_name %>_hidden" style="display: none">  
19 - <td></td>  
20 - <td style="text-align: left">  
21 - <% source_tree.children.each do |child| %>  
22 - <%= render :partial => 'content_viewer/source_tree', :locals => { :source_tree => child } %>  
23 - <% end %>  
24 - </td>  
25 - </tr>  
26 - </table>  
27 -<% else %>  
28 - <table>  
29 - <tr>  
30 - <td width="1"></td>  
31 - <td>  
32 - <a href="#" class="module-result-link" data-module-name="<%= module_name %>">  
33 - <%= module_label %>  
34 - </a>  
35 - </td>  
36 - </tr> 20 + <% source_tree.children.each do |child| %>
  21 + <tr>
  22 + <td>
  23 + <a href='#' class="source-tree-link" data-module-name="<%= child.module.name %>">
  24 + <%= "#{child.module.name} (#{child.module.granularity})" %>
  25 + </td>
  26 + </tr>
  27 + <% end %>
37 </table> 28 </table>
38 <% end %> 29 <% end %>
plugins/mezuro/views/content_viewer/show_project.rhtml
@@ -30,6 +30,8 @@ @@ -30,6 +30,8 @@
30 30
31 <br /> 31 <br />
32 32
33 -<div id="project-content" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"> 33 +<div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>">
34 <h3><%= _('Processing ') + @project.name + '...' %></h3> 34 <h3><%= _('Processing ') + @project.name + '...' %></h3>
35 -</div>  
36 \ No newline at end of file 35 \ No newline at end of file
  36 +</div>
  37 +<div id="project-tree"></div>
  38 +<div id="module-result"></div>