Commit 985de89523a098111fa6cfbd9affd340d784f7a3

Authored by Carlos Morais + Paulo Meirelles
Committed by Paulo Meireles
1 parent 26c36652

Refactoring javascript and html for ajax-results

plugins/mezuro/public/javascripts/results.js
1 function results($) { 1 function results($) {
2 - $('.mezuro-display-metrics').click(function() {  
3 - var profile = $('#module-result').attr('data-profile');  
4 - var project = $('#module-result').attr('data-project-id');  
5 - var module_name = $(this).attr('data-module-name');  
6 - var endpoint = '/profile/' + profile + '/plugins/mezuro/metrics/' + project;  
7 - show_loading_message();  
8 - $.get(endpoint, {module_name: module_name}, function(content) {  
9 - $('#module-result').html(content);  
10 - show_result_table();  
11 - });  
12 - return false;  
13 - }); 2 + $('.module-result-link').click(show_module_result);
14 } 3 }
15 -function show_loading_message() {  
16 - jQuery('#loading-message').attr("style", "display: inline");  
17 - jQuery('#module-result').attr("style", "display: none"); 4 +
  5 +function show_module_result(){
  6 + var profile = jQuery('#module-result').attr('data-profile');
  7 + var project = jQuery('#module-result').attr('data-project-id');
  8 + var module_name = jQuery(this).attr('data-module-name');
  9 + var endpoint = '/profile/' + profile + '/plugins/mezuro/metrics/' + project;
  10 + show_loading_message(module_name);
  11 + jQuery.get(endpoint, {module_name: module_name}, show_result_table);
  12 + return false;
18 } 13 }
19 -function show_result_table(){  
20 - jQuery('#loading-message').attr("style", "display: none");  
21 - jQuery('#module-result').attr("style", "display: inline"); 14 +
  15 +function show_loading_message(module_name) {
  16 + jQuery('#module-result').html("Loading results for " + module_name + "...");
  17 +}
  18 +
  19 +function show_result_table(content){
  20 + jQuery('#module-result').html(content);
22 } 21 }
23 \ No newline at end of file 22 \ No newline at end of file
plugins/mezuro/views/content_viewer/_source_tree.rhtml
1 -<% if source_tree.children && !source_tree.children.empty? %> 1 +<% module_name = source_tree.module_name %>
  2 +<% module_label = "#{module_name} (#{source_tree.granularity})" %>
  3 +<% if source_tree.children %>
2 <table> 4 <table>
3 - <tr>  
4 - <td width='10%'>  
5 - <img id='<%= source_tree.module_name %>_plus' onclick="toogle('<%= source_tree.module_name %>')"  
6 - alt='+' src='/plugins/mezuro/images/plus.png' class='link'  
7 - style='display: none'/>  
8 - <img id='<%= source_tree.module_name %>_minus' onclick="toogle('<%= source_tree.module_name %>')"  
9 - alt='-' src='/plugins/mezuro/images/minus.png' class='link'  
10 - />  
11 - </td> 5 + <tr>
  6 + <td width="10%">
  7 + <img alt="+" src="/plugins/mezuro/images/plus.png" class="link"
  8 + id="<%= module_name %>_plus" onclick="toogle('<%= module_name %>')"/>
  9 + <img alt="-" src="/plugins/mezuro/images/minus.png" class="link"
  10 + id="<%= module_name %>_minus" onclick="toogle('<%= module_name %>')" style="display: none"/>
  11 + </td>
12 <td> 12 <td>
13 - <a href="#" class='mezuro-display-metrics' data-module-name='<%= source_tree.module_name %>'><%= source_tree.module_name %> (<%= source_tree.granularity %>)</a> 13 + <a href="#" class="module-result-link" data-module-name="<%= module_name %>">
  14 + <%= module_label %>
  15 + </a>
14 </td> 16 </td>
15 </tr> 17 </tr>
16 - <tr id='<%= source_tree.module_name %>_hidden'> 18 + <tr id="<%= module_name %>_hidden" style="display: none">
17 <td></td> 19 <td></td>
18 - <td style='text-align: left'> 20 + <td style="text-align: left">
19 <% source_tree.children.each do |child| %> 21 <% source_tree.children.each do |child| %>
20 <%= render :partial => 'source_tree', :locals => { :source_tree => child } %> 22 <%= render :partial => 'source_tree', :locals => { :source_tree => child } %>
21 <% end %> 23 <% end %>
@@ -25,9 +27,11 @@ @@ -25,9 +27,11 @@
25 <% else %> 27 <% else %>
26 <table> 28 <table>
27 <tr> 29 <tr>
28 - <td width='1'></td> 30 + <td width="1"></td>
29 <td> 31 <td>
30 - <a href="#" class='mezuro-display-metrics' data-module-name='<%= source_tree.module_name %>'><%= source_tree.module_name %> (<%= source_tree.granularity %>)</a> 32 + <a href="#" class="module-result-link" data-module-name="<%= module_name %>">
  33 + <%= module_label %>
  34 + </a>
31 </td> 35 </td>
32 </tr> 36 </tr>
33 </table> 37 </table>
plugins/mezuro/views/content_viewer/show_project.rhtml
@@ -29,8 +29,6 @@ @@ -29,8 +29,6 @@
29 29
30 <br /> 30 <br />
31 31
32 -  
33 -  
34 <% if ! @project.error.nil? %> 32 <% if ! @project.error.nil? %>
35 <h3><%= _('ERROR') %></h3> 33 <h3><%= _('ERROR') %></h3>
36 <p> 34 <p>
@@ -66,15 +64,16 @@ @@ -66,15 +64,16 @@
66 <td><%= @project_result.formatted_analysis_time %></td> 64 <td><%= @project_result.formatted_analysis_time %></td>
67 </tr> 65 </tr>
68 </table> 66 </table>
  67 +
69 <h5><%= _('Source tree') %></h5> 68 <h5><%= _('Source tree') %></h5>
  69 +
70 <%= render :partial => 'source_tree', :locals => { :source_tree => @project_result.source_tree } %> 70 <%= render :partial => 'source_tree', :locals => { :source_tree => @project_result.source_tree } %>
  71 +
71 <div id='module-result' data-profile="<%= @page.profile.identifier %>" data-project-id='<%= @page.id %>'> 72 <div id='module-result' data-profile="<%= @page.profile.identifier %>" data-project-id='<%= @page.id %>'>
72 <%= render :partial => 'module_result', :locals => { :module_result => @page.module_result(@project.name) } %> 73 <%= render :partial => 'module_result', :locals => { :module_result => @page.module_result(@project.name) } %>
73 </div> 74 </div>
74 - <div id="loading-message">  
75 - loading results...  
76 - </div>  
77 - <script> 75 +
  76 + <script type="text/javascript">
78 jQuery(results); 77 jQuery(results);
79 </script> 78 </script>
80 <% end %> 79 <% end %>
81 \ No newline at end of file 80 \ No newline at end of file