Commit 7b402ed6923d44eeddc14c27bab0d24aecde82f8

Authored by Rafael Manzo
1 parent 2d07809e

Module tree loaded via ajax

Signed-off by: Fellipe Souto Sampaio <fllsouto@gmail.com>
Signed-off by: Diego Araújo <diegoamc90@gmail.com>
app/assets/javascripts/application.js
... ... @@ -14,4 +14,5 @@
14 14 //= require jquery_ujs
15 15 //= require twitter/bootstrap
16 16 //= require turbolinks
  17 +//= require modules
17 18 //= require_tree .
... ...
app/assets/javascripts/module/graphic.js.coffee
1   -@Module = { }
2   -
3 1 class Module.Graphic
4 2 constructor: (@container, @metric_name, @module_id) ->
5 3 $('tr#'+@container).slideDown('slow')
... ...
app/assets/javascripts/module/tree.js.coffee 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class Module.Tree
  2 + @load: (loading_html, module_id) ->
  3 + $('div#module_tree').html(loading_html)
  4 + $.post '/modules/'+module_id+'/tree'
0 5 \ No newline at end of file
... ...
app/assets/javascripts/modules.js.coffee 0 → 100644
... ... @@ -0,0 +1 @@
  1 +@Module = { }
0 2 \ No newline at end of file
... ...
app/controllers/modules_controller.rb
... ... @@ -14,6 +14,11 @@ class ModulesController &lt; ApplicationController
14 14 send_data(Base64.encode64(graphic_for(values, dates)), type: 'image/png', filename: "#{params[:module_id]}-#{params[:metric_name]}.png")
15 15 end
16 16  
  17 + # POST /modules/1/tree
  18 + def load_module_tree
  19 + @root_module_result = ModuleResult.find(params[:id].to_i)
  20 + end
  21 +
17 22 private
18 23  
19 24 def graphic_for(values, dates)
... ... @@ -31,9 +36,5 @@ class ModulesController &lt; ApplicationController
31 36 graphic.to_blob
32 37 end
33 38  
34   - # POST /project/1/repositories/42/modules/24
35   - def load_tree
36   - render :partial => "modules/javascript.html.erb"
37   - end
38 39  
39 40 end
40 41 \ No newline at end of file
... ...
app/views/modules/_javascript.html.erb
... ... @@ -1 +0,0 @@
1   -<p>Testando um gif animado! GAN </p>
2 0 \ No newline at end of file
app/views/modules/_module_result.html.erb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<tr>
  2 + <td id="module_<%= module_result.id %>">
  3 + <% if module_result.folder? %>
  4 + <i class="icon-folder-close"></i>
  5 + <% else %>
  6 + <i class="icon-file"></i>
  7 + <% end %>
  8 + <%= link_to format_module_name(module_result.module.name), "#module_#{module_result.id}", onClick: "Module.Tree.load('#{escape_javascript(image_tag 'loader.gif')} Loading data. Please, wait.', #{module_result.id});" %>
  9 + </td>
  10 + <td><%= module_result.module.granularity %></td>
  11 + <td><%= format_grade(module_result.grade) %></td>
  12 +</tr>
0 13 \ No newline at end of file
... ...
app/views/modules/_module_tree.html.erb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +<p>
  2 + <strong>Name:</strong>
  3 + <%= format_module_name(@root_module_result.module.name) %>
  4 +</p>
  5 +<p>
  6 + <strong>Granularity:</strong>
  7 + <%= @root_module_result.module.granularity %>
  8 +</p>
  9 +<p>
  10 + <strong>Grade:</strong>
  11 + <%= format_grade(@root_module_result.grade) %>
  12 +</p>
  13 +<% unless @root_module_result.parent_id.nil? %>
  14 + <p id="parent"><i class="icon-arrow-up"></i><%= link_to '../', '#parent', onClick: "Module.Tree.load('#{escape_javascript(image_tag 'loader.gif')} Loading data. Please, wait.', #{@root_module_result.parent_id});" %></p>
  15 +<% end %>
  16 +<% children = @root_module_result.children %>
  17 +<% unless children.empty? %>
  18 + <table class="table table-hover">
  19 + <thead>
  20 + <th>Name</th>
  21 + <th>Granularity</th>
  22 + <th>Grade</th>
  23 + </thead>
  24 + <tbody>
  25 + <%= render partial: 'module_result', collection: children %>
  26 + </tbody>
  27 + </table>
  28 +<% end %>
0 29 \ No newline at end of file
... ...
app/views/modules/load_module_tree.js.erb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +$('div#module_tree').html('<%= escape_javascript(render partial: "module_tree") %>');
... ...
app/views/repositories/_module_result.html.erb
... ... @@ -1,12 +0,0 @@
1   -<tr>
2   - <td>
3   - <% if module_result.folder? %>
4   - <i class="icon-folder-close"></i>
5   - <% else %>
6   - <i class="icon-file"></i>
7   - <% end %>
8   - <%= link_to format_module_name(module_result.module.name), project_repository_module_path(repository.project_id, repository.id, module_result.id) %>
9   - </td>
10   - <td><%= module_result.module.granularity %></td>
11   - <td><%= format_grade(module_result.grade) %></td>
12   -</tr>
13 0 \ No newline at end of file
app/views/repositories/show.html.erb
... ... @@ -36,47 +36,11 @@
36 36 <% end %>
37 37  
38 38 <hr/>
39   - <div id="teste"></div>
40   - <script>
41   - window.onload=function(){
42   - $.post("project_load_module_tree").done(function(data){
43   - $("#teste").append(data);
44   - });
45   - }
46   - </script>
  39 +<h2>Modules Tree</h2>
  40 +<div id="module_tree"></div>
  41 +<hr/>
47 42  
48 43 <% if @processing.ready? %>
49   - <h2>Modules Tree</h2>
50   - <p>
51   - <strong>Name:</strong>
52   - <%= format_module_name(@root_module_result.module.name) %>
53   - </p>
54   - <p>
55   - <strong>Granularity:</strong>
56   - <%= @root_module_result.module.granularity %>
57   - </p>
58   - <p>
59   - <strong>Grade:</strong>
60   - <%= format_grade(@root_module_result.grade) %>
61   - </p>
62   - <% unless @root_module_result.parent_id.nil? %>
63   - <p><i class="icon-arrow-up"></i><%= link_to '../', project_repository_module_path(@repository.project_id, @repository.id, @root_module_result.parent_id) %></p>
64   - <% end %>
65   - <% children = @root_module_result.children %>
66   - <% unless children.empty? %>
67   - <table class="table table-hover">
68   - <thead>
69   - <th>Name</th>
70   - <th>Granularity</th>
71   - <th>Grade</th>
72   - </thead>
73   - <tbody>
74   - <%= render partial: 'module_result', collection: children, locals: {repository: @repository} %>
75   - </tbody>
76   - </table>
77   - <% end %>
78   - <hr/>
79   -
80 44 <h2>Metric Results</h2>
81 45 <table class="table table-hover">
82 46 <thead>
... ... @@ -101,3 +65,9 @@
101 65 <% if project_owner? @repository.project_id %>
102 66 <%= link_to 'Destroy', project_repository_path(@repository.project_id, @repository.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %>
103 67 <% end %>
  68 +
  69 +<script type="text/javascript">
  70 + $(document).ready(function () {
  71 + Module.Tree.load("<%= escape_javascript(image_tag 'loader.gif') %> Loading data. Please, wait.", <%= @processing.results_root_id %>);
  72 + });
  73 +</script>
... ...
config/routes.rb
... ... @@ -6,13 +6,13 @@ Mezuro::Application.routes.draw do
6 6  
7 7 resources :projects do
8 8 resources :repositories, except: [:update, :index]
9   - get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module
  9 + get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module
10 10 put '/repositories/:id' => 'repositories#update', as: :repository_update
11   - post '/repositories/:id/modules/:module_result_id' => 'modules#load_tree', as: :load_module_tree
12 11 end
13 12  
14 13 #resources :modules
15 14 get '/modules/metric_history' => 'modules#metric_history'
  15 + post '/modules/:id/tree' => 'modules#load_module_tree'
16 16  
17 17 root "home#index"
18 18  
... ...
features/repository/show.feature
... ... @@ -59,7 +59,7 @@ Feature: Show Repository
59 59 When I visit the repository show page
60 60 Then I should see the given module result
61 61  
62   - @kalibro_restart
  62 + @kalibro_restart @javascript
63 63 Scenario: Should show children of root when the process has been finished
64 64 Given I am a regular user
65 65 And I am signed in
... ... @@ -76,7 +76,7 @@ Feature: Show Repository
76 76 And I should see "Granularity"
77 77 And I should see "Grade"
78 78  
79   - @kalibro_restart
  79 + @kalibro_restart @javascript
80 80 Scenario: Module navigation
81 81 Given I am a regular user
82 82 And I am signed in
... ...
spec/controllers/modules_controller_spec.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +require 'spec_helper'
  2 +
  3 +describe ModulesController do
  4 + describe "load_module_tree" do
  5 + render_views
  6 +
  7 + before :each do
  8 + ModuleResult.expects(:find).with(42).returns(FactoryGirl.build(:module_result))
  9 + request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS
  10 +
  11 + post :load_module_tree, {id: 42}
  12 + end
  13 +
  14 + it { should respond_with(:success) }
  15 + it { should render_template(:load_module_tree) }
  16 + end
  17 +end
0 18 \ No newline at end of file
... ...
spec/routing/modules_routing_spec.rb
... ... @@ -2,8 +2,8 @@ require &quot;spec_helper&quot;
2 2  
3 3 describe ModulesController do
4 4 describe "routing" do
5   - it { should route(:post, '/projects/1/repositories/42/modules/24').
6   - to(controller: :modules, action: :load_tree, project_id: 1, id: 42, module_result_id: 24) }
  5 + it { should route(:post, '/modules/1/tree').
  6 + to(controller: :modules, action: :load_module_tree, id: 1) }
7 7 it { should route(:get, '/modules/metric_history').
8 8 to(controller: :modules, action: :metric_history) }
9 9 end
... ...