diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 3885622..6fc4798 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,4 +14,5 @@ //= require jquery_ujs //= require twitter/bootstrap //= require turbolinks +//= require modules //= require_tree . diff --git a/app/assets/javascripts/module/graphic.js.coffee b/app/assets/javascripts/module/graphic.js.coffee index 4a5ff2a..d068de8 100644 --- a/app/assets/javascripts/module/graphic.js.coffee +++ b/app/assets/javascripts/module/graphic.js.coffee @@ -1,5 +1,3 @@ -@Module = { } - class Module.Graphic constructor: (@container, @metric_name, @module_id) -> $('tr#'+@container).slideDown('slow') diff --git a/app/assets/javascripts/module/tree.js.coffee b/app/assets/javascripts/module/tree.js.coffee new file mode 100644 index 0000000..7ece426 --- /dev/null +++ b/app/assets/javascripts/module/tree.js.coffee @@ -0,0 +1,4 @@ +class Module.Tree + @load: (loading_html, module_id) -> + $('div#module_tree').html(loading_html) + $.post '/modules/'+module_id+'/tree' \ No newline at end of file diff --git a/app/assets/javascripts/modules.js.coffee b/app/assets/javascripts/modules.js.coffee new file mode 100644 index 0000000..a305fe3 --- /dev/null +++ b/app/assets/javascripts/modules.js.coffee @@ -0,0 +1 @@ +@Module = { } \ No newline at end of file diff --git a/app/controllers/modules_controller.rb b/app/controllers/modules_controller.rb index 4446a9c..e0a3db0 100644 --- a/app/controllers/modules_controller.rb +++ b/app/controllers/modules_controller.rb @@ -14,6 +14,11 @@ class ModulesController < ApplicationController send_data(Base64.encode64(graphic_for(values, dates)), type: 'image/png', filename: "#{params[:module_id]}-#{params[:metric_name]}.png") end + # POST /modules/1/tree + def load_module_tree + @root_module_result = ModuleResult.find(params[:id].to_i) + end + private def graphic_for(values, dates) @@ -31,9 +36,5 @@ class ModulesController < ApplicationController graphic.to_blob end - # POST /project/1/repositories/42/modules/24 - def load_tree - render :partial => "modules/javascript.html.erb" - end end \ No newline at end of file diff --git a/app/views/modules/_javascript.html.erb b/app/views/modules/_javascript.html.erb deleted file mode 100644 index 2c03e28..0000000 --- a/app/views/modules/_javascript.html.erb +++ /dev/null @@ -1 +0,0 @@ -

Testando um gif animado! GAN

\ No newline at end of file diff --git a/app/views/modules/_module_result.html.erb b/app/views/modules/_module_result.html.erb new file mode 100644 index 0000000..6640621 --- /dev/null +++ b/app/views/modules/_module_result.html.erb @@ -0,0 +1,12 @@ + + + <% if module_result.folder? %> + + <% else %> + + <% end %> + <%= 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});" %> + + <%= module_result.module.granularity %> + <%= format_grade(module_result.grade) %> + \ No newline at end of file diff --git a/app/views/modules/_module_tree.html.erb b/app/views/modules/_module_tree.html.erb new file mode 100644 index 0000000..e3d9ac6 --- /dev/null +++ b/app/views/modules/_module_tree.html.erb @@ -0,0 +1,28 @@ +

+ Name: + <%= format_module_name(@root_module_result.module.name) %> +

+

+ Granularity: + <%= @root_module_result.module.granularity %> +

+

+ Grade: + <%= format_grade(@root_module_result.grade) %> +

+<% unless @root_module_result.parent_id.nil? %> +

<%= link_to '../', '#parent', onClick: "Module.Tree.load('#{escape_javascript(image_tag 'loader.gif')} Loading data. Please, wait.', #{@root_module_result.parent_id});" %>

+<% end %> +<% children = @root_module_result.children %> +<% unless children.empty? %> + + + + + + + + <%= render partial: 'module_result', collection: children %> + +
NameGranularityGrade
+<% end %> \ No newline at end of file diff --git a/app/views/modules/load_module_tree.js.erb b/app/views/modules/load_module_tree.js.erb new file mode 100644 index 0000000..a77b633 --- /dev/null +++ b/app/views/modules/load_module_tree.js.erb @@ -0,0 +1 @@ +$('div#module_tree').html('<%= escape_javascript(render partial: "module_tree") %>'); diff --git a/app/views/repositories/_module_result.html.erb b/app/views/repositories/_module_result.html.erb deleted file mode 100644 index 39676b5..0000000 --- a/app/views/repositories/_module_result.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - - - <% if module_result.folder? %> - - <% else %> - - <% end %> - <%= link_to format_module_name(module_result.module.name), project_repository_module_path(repository.project_id, repository.id, module_result.id) %> - - <%= module_result.module.granularity %> - <%= format_grade(module_result.grade) %> - \ No newline at end of file diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index cea7c3e..a5e1095 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -36,47 +36,11 @@ <% end %>
-
- +

Modules Tree

+
+
<% if @processing.ready? %> -

Modules Tree

-

- Name: - <%= format_module_name(@root_module_result.module.name) %> -

-

- Granularity: - <%= @root_module_result.module.granularity %> -

-

- Grade: - <%= format_grade(@root_module_result.grade) %> -

- <% unless @root_module_result.parent_id.nil? %> -

<%= link_to '../', project_repository_module_path(@repository.project_id, @repository.id, @root_module_result.parent_id) %>

- <% end %> - <% children = @root_module_result.children %> - <% unless children.empty? %> - - - - - - - - <%= render partial: 'module_result', collection: children, locals: {repository: @repository} %> - -
NameGranularityGrade
- <% end %> -
-

Metric Results

@@ -101,3 +65,9 @@ <% if project_owner? @repository.project_id %> <%= link_to 'Destroy', project_repository_path(@repository.project_id, @repository.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %> <% end %> + + diff --git a/config/routes.rb b/config/routes.rb index 5e75828..0dd8936 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,13 +6,13 @@ Mezuro::Application.routes.draw do resources :projects do resources :repositories, except: [:update, :index] - get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module + get '/repositories/:id/modules/:module_result_id' => 'repositories#show', as: :repository_module put '/repositories/:id' => 'repositories#update', as: :repository_update - post '/repositories/:id/modules/:module_result_id' => 'modules#load_tree', as: :load_module_tree end #resources :modules get '/modules/metric_history' => 'modules#metric_history' + post '/modules/:id/tree' => 'modules#load_module_tree' root "home#index" diff --git a/features/repository/show.feature b/features/repository/show.feature index 2f491b2..ff2f13a 100644 --- a/features/repository/show.feature +++ b/features/repository/show.feature @@ -59,7 +59,7 @@ Feature: Show Repository When I visit the repository show page Then I should see the given module result - @kalibro_restart + @kalibro_restart @javascript Scenario: Should show children of root when the process has been finished Given I am a regular user And I am signed in @@ -76,7 +76,7 @@ Feature: Show Repository And I should see "Granularity" And I should see "Grade" - @kalibro_restart + @kalibro_restart @javascript Scenario: Module navigation Given I am a regular user And I am signed in diff --git a/spec/controllers/modules_controller_spec.rb b/spec/controllers/modules_controller_spec.rb new file mode 100644 index 0000000..45cda58 --- /dev/null +++ b/spec/controllers/modules_controller_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe ModulesController do + describe "load_module_tree" do + render_views + + before :each do + ModuleResult.expects(:find).with(42).returns(FactoryGirl.build(:module_result)) + request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS + + post :load_module_tree, {id: 42} + end + + it { should respond_with(:success) } + it { should render_template(:load_module_tree) } + end +end \ No newline at end of file diff --git a/spec/routing/modules_routing_spec.rb b/spec/routing/modules_routing_spec.rb index e8ec703..cbe5843 100644 --- a/spec/routing/modules_routing_spec.rb +++ b/spec/routing/modules_routing_spec.rb @@ -2,8 +2,8 @@ require "spec_helper" describe ModulesController do describe "routing" do - it { should route(:post, '/projects/1/repositories/42/modules/24'). - to(controller: :modules, action: :load_tree, project_id: 1, id: 42, module_result_id: 24) } + it { should route(:post, '/modules/1/tree'). + to(controller: :modules, action: :load_module_tree, id: 1) } it { should route(:get, '/modules/metric_history'). to(controller: :modules, action: :metric_history) } end -- libgit2 0.21.2