Commit f04954a2d28cba9eba49afd99026dc4de73bf764

Authored by Rafael Manzo
Committed by Paulo Meireles
1 parent cc07efdd

Assynchornous loading and updating repository state and time

Missing acceptance tests
app/assets/javascripts/repository.js.coffee 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +class Module.Repository
  2 + constructor: (@project_id, @repository_id) ->
  3 +
  4 + poll_state: (last_state) ->
  5 + $.post '/projects/' + @project_id + '/repositories/' + @repository_id + '/state',
  6 + last_state: last_state
  7 +
  8 + schedule_poll_state: (last_state) ->
  9 + context = this
  10 + call = () ->
  11 + context.poll_state(last_state)
  12 +
  13 + setTimeout( call, 15000 ) # Delays in 15s the next call
app/controllers/repositories_controller.rb
@@ -12,7 +12,6 @@ class RepositoriesController < ApplicationController @@ -12,7 +12,6 @@ class RepositoriesController < ApplicationController
12 # GET /projects/1/repositories/1/modules/1.json 12 # GET /projects/1/repositories/1/modules/1.json
13 def show 13 def show
14 @configuration = KalibroGem::Entities::Configuration.find(@repository.configuration_id) #FIXME: As soon as the Configuration model gets created refactor this! 14 @configuration = KalibroGem::Entities::Configuration.find(@repository.configuration_id) #FIXME: As soon as the Configuration model gets created refactor this!
15 - @processing = @repository.last_processing  
16 end 15 end
17 16
18 # GET projects/1/repositories/new 17 # GET projects/1/repositories/new
app/views/repositories/_processing_information.html.erb 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +<p>
  2 + <strong>State:</strong>
  3 + <%= @processing.state %>
  4 +</p>
  5 +
  6 +<p>
  7 + <strong>Creation date:</strong>
  8 + <%= @processing.date.strftime("%Y/%m/%d at %Hh%M (%z)") %>
  9 +</p>
  10 +
  11 +<% unless @processing.process_times.nil? %>
  12 + <% @processing.process_times.each do |process_time| %>
  13 + <p>
  14 + <strong><%= process_time.state %> time:</strong>
  15 + <%= humanize_eplased_time(process_time.time) %>
  16 + </p>
  17 + <% end %>
  18 +<% end %>
0 \ No newline at end of file 19 \ No newline at end of file
app/views/repositories/load_ready_processing.js.erb
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +$('div#processing_information').html('<%= escape_javascript(render partial: "processing_information") %>');
  2 +Module.Tree.load("<%= escape_javascript(image_tag 'loader.gif') %> Loading data. Please, wait.", <%= @processing.results_root_id %>)
0 \ No newline at end of file 3 \ No newline at end of file
app/views/repositories/reload_processing.js.erb
@@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
  1 +$('div#processing_information').html('<%= escape_javascript(render partial: "processing_information") %>');
  2 +repository = new Module.Repository(<%= @repository.project_id %>, <%= @repository.id %>)
  3 +repository.schedule_poll_state('<%= @processing.state %>')
0 \ No newline at end of file 4 \ No newline at end of file
app/views/repositories/show.html.erb
@@ -36,44 +36,20 @@ @@ -36,44 +36,20 @@
36 36
37 <div id="repository-accordion"> 37 <div id="repository-accordion">
38 <h3>Processing information</h3> 38 <h3>Processing information</h3>
39 - <div>  
40 - <p>  
41 - <strong>State:</strong>  
42 - <%= @processing.state %>  
43 - </p> 39 + <div id="processing_information"><%= image_tag 'loader.gif' %> Loading data. Please, wait.</div>
44 40
45 - <p>  
46 - <strong>Creation date:</strong>  
47 - <%= @processing.date.strftime("%Y/%m/%d at %Hh%M (%z)") %>  
48 - </p> 41 + <h3>Modules Tree</h3>
  42 + <div id="module_tree"><%= image_tag 'loader.gif' %> Loading data. Please, wait.</div>
49 43
50 - <% unless @processing.process_times.nil? %>  
51 - <% @processing.process_times.each do |process_time| %>  
52 - <p>  
53 - <strong><%= process_time.state %> time:</strong>  
54 - <%= humanize_eplased_time(process_time.time) %>  
55 - </p>  
56 - <% end %>  
57 - <% end %>  
58 - </div>  
59 -  
60 - <% if @processing.ready? %>  
61 - <h3>Modules Tree</h3>  
62 - <div id="module_tree"></div>  
63 -  
64 - <h3>Metric Results</h3>  
65 - <div id="metric_results"></div>  
66 -  
67 - <% end %> 44 + <h3>Metric Results</h3>
  45 + <div id="metric_results"><%= image_tag 'loader.gif' %> Loading data. Please, wait.</div>
68 </div> 46 </div>
69 <script type="text/javascript"> 47 <script type="text/javascript">
70 - <% if @processing.ready? %>  
71 $(document).ready(function () { 48 $(document).ready(function () {
72 - Module.Tree.load("<%= escape_javascript(image_tag 'loader.gif') %> Loading data. Please, wait.", <%= @processing.results_root_id %>); 49 + (new Module.Repository(<%= @repository.project_id %>, <%= @repository.id %>)).poll_state('')
73 }); 50 });
74 - <% end %>  
75 51
76 - //Loads the accorcion 52 + //Loads the accordion
77 $(function() { 53 $(function() {
78 $( "#repository-accordion" ).accordion({ 54 $( "#repository-accordion" ).accordion({
79 heightStyle: "content" 55 heightStyle: "content"
features/repository/show.feature
@@ -59,10 +59,10 @@ Feature: Show Repository @@ -59,10 +59,10 @@ Feature: Show Repository
59 And I should see "Configuration" 59 And I should see "Configuration"
60 And I should see "State" 60 And I should see "State"
61 And I should see "Creation date" 61 And I should see "Creation date"
62 - And I should not see Metric  
63 - And I should not see Value  
64 - And I should not see Weight  
65 - And I should not see Threshold 62 + When I click the "Metric Results" h3
  63 + Then I should see "Loading data. Please, wait."
  64 + When I click the "Modules Tree" h3
  65 + Then I should see "Loading data. Please, wait."
66 66
67 @kalibro_restart @javascript 67 @kalibro_restart @javascript
68 Scenario: Should show modules directories root when the process has been finished 68 Scenario: Should show modules directories root when the process has been finished
spec/controllers/repositories_controller_spec.rb
@@ -86,7 +86,6 @@ describe RepositoriesController do @@ -86,7 +86,6 @@ describe RepositoriesController do
86 before :each do 86 before :each do
87 processing = FactoryGirl.build(:processing) 87 processing = FactoryGirl.build(:processing)
88 88
89 - repository.expects(:last_processing).returns(processing)  
90 KalibroGem::Entities::Configuration.expects(:find).with(repository.id).returns(FactoryGirl.build(:configuration)) 89 KalibroGem::Entities::Configuration.expects(:find).with(repository.id).returns(FactoryGirl.build(:configuration))
91 Repository.expects(:find).with(repository.id).returns(repository) 90 Repository.expects(:find).with(repository.id).returns(repository)
92 91
@@ -101,7 +100,6 @@ describe RepositoriesController do @@ -101,7 +100,6 @@ describe RepositoriesController do
101 before :each do 100 before :each do
102 processing = FactoryGirl.build(:processing) 101 processing = FactoryGirl.build(:processing)
103 102
104 - repository.expects(:last_processing).returns(processing)  
105 KalibroGem::Entities::Configuration.expects(:find).with(repository.id).returns(FactoryGirl.build(:configuration)) 103 KalibroGem::Entities::Configuration.expects(:find).with(repository.id).returns(FactoryGirl.build(:configuration))
106 Repository.expects(:find).with(repository.id).returns(repository) 104 Repository.expects(:find).with(repository.id).returns(repository)
107 105