Commit 1c31fda6eed536f74ceeef71e7b2f12cb866ea45

Authored by Alessandro Palmeira + Carlos Morais
Committed by Carlos Morais
1 parent c72e0722

[Mezuro] Ajax selecting partials

plugins/mezuro/public/javascripts/dynamic.js
1 function dynamic($) { 1 function dynamic($) {
2 - $('.module-result-link').click(show_module_result); 2 + $.get(endpoint('project_state'), {}, select_project_partial);
3 } 3 }
4 4
5 function endpoint(action){ 5 function endpoint(action){
6 - var profile = jQuery('#ids').attr('data-profile');  
7 - var project = jQuery('#ids').attr('data-content'); 6 + var profile = jQuery('#project-content').attr('data-profile');
  7 + var project = jQuery('#project-content').attr('data-content');
8 return '/profile/' + profile + '/plugins/mezuro/' + action + '/' + project; 8 return '/profile/' + profile + '/plugins/mezuro/' + action + '/' + project;
9 } 9 }
10 10
  11 +function select_project_partial(state){
  12 + var action;
  13 + if (state == 'ERROR')
  14 + action = 'project_error';
  15 + else if (state == 'READY')
  16 + action = 'project_result';
  17 + else
  18 + action = 'project_processing';
  19 + jQuery.get(endpoint(action), {}, show_project_content);
  20 +}
  21 +
  22 +function show_project_content(content){
  23 + jQuery('#project-content').html(content);
  24 + jQuery('.module-result-link').click(show_module_result);
  25 + return false;
  26 +}
  27 +
11 function show_module_result(){ 28 function show_module_result(){
12 var module_name = jQuery(this).attr('data-module-name'); 29 var module_name = jQuery(this).attr('data-module-name');
13 jQuery('#module-result').html("Loading results for " + module_name + "..."); 30 jQuery('#module-result').html("Loading results for " + module_name + "...");
14 - jQuery.get(endpoint('module_result'), {module_name: module_name}, show_result_table); 31 + jQuery.get(endpoint('module_result'), { module_name: module_name }, show_result_table);
15 return false; 32 return false;
16 } 33 }
17 34
18 function show_result_table(content){ 35 function show_result_table(content){
19 jQuery('#module-result').html(content); 36 jQuery('#module-result').html(content);
20 } 37 }
21 -  
22 -function show_autoreload($){  
23 - jQuery('#autoreload').html('Loading results for ...' + project_name); // #FIXME  
24 - jQuery.get(endpoint('project_result'), {project_name: project_name}, show_page_with_results);  
25 - return false;  
26 -}  
27 -  
28 -function show_page_with_results(content){  
29 - var done = true; // FIXME; test the content in some way  
30 - if (done) {  
31 - jQuery('#autoreload').html(content);  
32 - } else {  
33 - var wait = 10; // FIXME; how many seconds to wait?  
34 - setTimeout(function() {  
35 - show_autoreload(jQuery);  
36 - }, wait * 1000);  
37 - }  
38 -}  
39 \ No newline at end of file 38 \ No newline at end of file
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
@@ -59,10 +59,9 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase @@ -59,10 +59,9 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase
59 should 'get project processing' do 59 should 'get project processing' do
60 create_project_content 60 create_project_content
61 Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project) 61 Kalibro::Client::ProjectClient.expects(:project).with(@name).returns(@project)
62 - @project.expects(:state).returns("LOADING")  
63 get :project_processing, :profile => @profile.identifier, :id => @content.id 62 get :project_processing, :profile => @profile.identifier, :id => @content.id
64 assert_response 200 63 assert_response 200
65 - assert_select('h3', 'Service is loading Qt-Calculator...') 64 + assert_select('h3', 'Service is processing Qt-Calculator...')
66 end 65 end
67 66
68 should 'get error state if project has error' do 67 should 'get error state if project has error' do
plugins/mezuro/views/content_viewer/_project_processing.rhtml
1 -<h3><%= _('Service is ') + project.state.downcase + ' ' + project.name + '...' %></h3>  
2 \ No newline at end of file 1 \ No newline at end of file
  2 +<h3><%= _('Service is processing ') + project.name + '...' %></h3>
3 \ No newline at end of file 3 \ No newline at end of file
plugins/mezuro/views/content_viewer/show_project.rhtml
@@ -29,15 +29,9 @@ @@ -29,15 +29,9 @@
29 29
30 <br /> 30 <br />
31 31
32 -<% if ! @project.error.nil? %>  
33 - <%= render :partial => 'content_viewer/project_error', :locals => { :project => @project } %>  
34 -<% elsif @project.state.end_with?('ING') #Loading or analyzing%>  
35 - <%= render :partial => 'content_viewer/project_processing', :locals => { :project => @project } %>  
36 -<% elsif @project.state == 'READY' %>  
37 - <%= render :partial => 'content_viewer/project_result', :locals => { :project_result => @page.project_result } %>  
38 -<% end %>  
39 -  
40 -<div id="ids" data-profile="<%= @page.profile.identifier %>" data-content='<%= @page.id %>'/> 32 +<div id="project-content" data-profile="<%= @page.profile.identifier %>" data-content='<%= @page.id %>'>
  33 + <%= _('Loading project content...') %>
  34 +</div>
41 35
42 <script type="text/javascript"> 36 <script type="text/javascript">
43 jQuery(dynamic); 37 jQuery(dynamic);