Commit 985de89523a098111fa6cfbd9affd340d784f7a3
Committed by
Paulo Meireles
1 parent
26c36652
Exists in
master
and in
28 other branches
Refactoring javascript and html for ajax-results
Showing
3 changed files
with
41 additions
and
39 deletions
Show diff stats
plugins/mezuro/public/javascripts/results.js
| 1 | 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 | 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 | 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 | 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 | 16 | </td> |
| 15 | 17 | </tr> |
| 16 | - <tr id='<%= source_tree.module_name %>_hidden'> | |
| 18 | + <tr id="<%= module_name %>_hidden" style="display: none"> | |
| 17 | 19 | <td></td> |
| 18 | - <td style='text-align: left'> | |
| 20 | + <td style="text-align: left"> | |
| 19 | 21 | <% source_tree.children.each do |child| %> |
| 20 | 22 | <%= render :partial => 'source_tree', :locals => { :source_tree => child } %> |
| 21 | 23 | <% end %> |
| ... | ... | @@ -25,9 +27,11 @@ |
| 25 | 27 | <% else %> |
| 26 | 28 | <table> |
| 27 | 29 | <tr> |
| 28 | - <td width='1'></td> | |
| 30 | + <td width="1"></td> | |
| 29 | 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 | 35 | </td> |
| 32 | 36 | </tr> |
| 33 | 37 | </table> | ... | ... |
plugins/mezuro/views/content_viewer/show_project.rhtml
| ... | ... | @@ -29,8 +29,6 @@ |
| 29 | 29 | |
| 30 | 30 | <br /> |
| 31 | 31 | |
| 32 | - | |
| 33 | - | |
| 34 | 32 | <% if ! @project.error.nil? %> |
| 35 | 33 | <h3><%= _('ERROR') %></h3> |
| 36 | 34 | <p> |
| ... | ... | @@ -66,15 +64,16 @@ |
| 66 | 64 | <td><%= @project_result.formatted_analysis_time %></td> |
| 67 | 65 | </tr> |
| 68 | 66 | </table> |
| 67 | + | |
| 69 | 68 | <h5><%= _('Source tree') %></h5> |
| 69 | + | |
| 70 | 70 | <%= render :partial => 'source_tree', :locals => { :source_tree => @project_result.source_tree } %> |
| 71 | + | |
| 71 | 72 | <div id='module-result' data-profile="<%= @page.profile.identifier %>" data-project-id='<%= @page.id %>'> |
| 72 | 73 | <%= render :partial => 'module_result', :locals => { :module_result => @page.module_result(@project.name) } %> |
| 73 | 74 | </div> |
| 74 | - <div id="loading-message"> | |
| 75 | - loading results... | |
| 76 | - </div> | |
| 77 | - <script> | |
| 75 | + | |
| 76 | + <script type="text/javascript"> | |
| 78 | 77 | jQuery(results); |
| 79 | 78 | </script> |
| 80 | 79 | <% end %> |
| 81 | 80 | \ No newline at end of file | ... | ... |