Commit 7b402ed6923d44eeddc14c27bab0d24aecde82f8
1 parent
2d07809e
Exists in
colab
and in
4 other branches
Module tree loaded via ajax
Signed-off by: Fellipe Souto Sampaio <fllsouto@gmail.com> Signed-off by: Diego Araújo <diegoamc90@gmail.com>
Showing
15 changed files
with
84 additions
and
64 deletions
Show diff stats
app/assets/javascripts/application.js
app/assets/javascripts/module/graphic.js.coffee
app/controllers/modules_controller.rb
@@ -14,6 +14,11 @@ class ModulesController < ApplicationController | @@ -14,6 +14,11 @@ class ModulesController < ApplicationController | ||
14 | send_data(Base64.encode64(graphic_for(values, dates)), type: 'image/png', filename: "#{params[:module_id]}-#{params[:metric_name]}.png") | 14 | send_data(Base64.encode64(graphic_for(values, dates)), type: 'image/png', filename: "#{params[:module_id]}-#{params[:metric_name]}.png") |
15 | end | 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 | private | 22 | private |
18 | 23 | ||
19 | def graphic_for(values, dates) | 24 | def graphic_for(values, dates) |
@@ -31,9 +36,5 @@ class ModulesController < ApplicationController | @@ -31,9 +36,5 @@ class ModulesController < ApplicationController | ||
31 | graphic.to_blob | 36 | graphic.to_blob |
32 | end | 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 | end | 40 | end |
40 | \ No newline at end of file | 41 | \ No newline at end of file |
app/views/modules/_javascript.html.erb
@@ -0,0 +1,12 @@ | @@ -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 | \ No newline at end of file | 13 | \ No newline at end of file |
@@ -0,0 +1,28 @@ | @@ -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 | \ No newline at end of file | 29 | \ No newline at end of file |
@@ -0,0 +1 @@ | @@ -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,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 | \ No newline at end of file | 0 | \ No newline at end of file |
app/views/repositories/show.html.erb
@@ -36,47 +36,11 @@ | @@ -36,47 +36,11 @@ | ||
36 | <% end %> | 36 | <% end %> |
37 | 37 | ||
38 | <hr/> | 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 | <% if @processing.ready? %> | 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 | <h2>Metric Results</h2> | 44 | <h2>Metric Results</h2> |
81 | <table class="table table-hover"> | 45 | <table class="table table-hover"> |
82 | <thead> | 46 | <thead> |
@@ -101,3 +65,9 @@ | @@ -101,3 +65,9 @@ | ||
101 | <% if project_owner? @repository.project_id %> | 65 | <% if project_owner? @repository.project_id %> |
102 | <%= link_to 'Destroy', project_repository_path(@repository.project_id, @repository.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %> | 66 | <%= link_to 'Destroy', project_repository_path(@repository.project_id, @repository.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %> |
103 | <% end %> | 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,13 +6,13 @@ Mezuro::Application.routes.draw do | ||
6 | 6 | ||
7 | resources :projects do | 7 | resources :projects do |
8 | resources :repositories, except: [:update, :index] | 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 | put '/repositories/:id' => 'repositories#update', as: :repository_update | 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 | end | 11 | end |
13 | 12 | ||
14 | #resources :modules | 13 | #resources :modules |
15 | get '/modules/metric_history' => 'modules#metric_history' | 14 | get '/modules/metric_history' => 'modules#metric_history' |
15 | + post '/modules/:id/tree' => 'modules#load_module_tree' | ||
16 | 16 | ||
17 | root "home#index" | 17 | root "home#index" |
18 | 18 |
features/repository/show.feature
@@ -59,7 +59,7 @@ Feature: Show Repository | @@ -59,7 +59,7 @@ Feature: Show Repository | ||
59 | When I visit the repository show page | 59 | When I visit the repository show page |
60 | Then I should see the given module result | 60 | Then I should see the given module result |
61 | 61 | ||
62 | - @kalibro_restart | 62 | + @kalibro_restart @javascript |
63 | Scenario: Should show children of root when the process has been finished | 63 | Scenario: Should show children of root when the process has been finished |
64 | Given I am a regular user | 64 | Given I am a regular user |
65 | And I am signed in | 65 | And I am signed in |
@@ -76,7 +76,7 @@ Feature: Show Repository | @@ -76,7 +76,7 @@ Feature: Show Repository | ||
76 | And I should see "Granularity" | 76 | And I should see "Granularity" |
77 | And I should see "Grade" | 77 | And I should see "Grade" |
78 | 78 | ||
79 | - @kalibro_restart | 79 | + @kalibro_restart @javascript |
80 | Scenario: Module navigation | 80 | Scenario: Module navigation |
81 | Given I am a regular user | 81 | Given I am a regular user |
82 | And I am signed in | 82 | And I am signed in |
@@ -0,0 +1,17 @@ | @@ -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 | \ No newline at end of file | 18 | \ No newline at end of file |
spec/routing/modules_routing_spec.rb
@@ -2,8 +2,8 @@ require "spec_helper" | @@ -2,8 +2,8 @@ require "spec_helper" | ||
2 | 2 | ||
3 | describe ModulesController do | 3 | describe ModulesController do |
4 | describe "routing" do | 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 | it { should route(:get, '/modules/metric_history'). | 7 | it { should route(:get, '/modules/metric_history'). |
8 | to(controller: :modules, action: :metric_history) } | 8 | to(controller: :modules, action: :metric_history) } |
9 | end | 9 | end |