Commit 07f196bfe299aaac6cb03d40c94c50c6e56f36f3
Committed by
Rafael Manzo
1 parent
fa3fdeb7
Exists in
staging
and in
42 other branches
[Mezuro] javascript to get processing state
Showing
3 changed files
with
56 additions
and
40 deletions
Show diff stats
plugins/mezuro/controllers/profile/mezuro_plugin_processing_controller.rb
@@ -2,16 +2,13 @@ class MezuroPluginProcessingController < MezuroPluginProfileController | @@ -2,16 +2,13 @@ class MezuroPluginProcessingController < MezuroPluginProfileController | ||
2 | 2 | ||
3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') | 3 | append_view_path File.join(File.dirname(__FILE__) + '/../../views') |
4 | 4 | ||
5 | - def render_last_state | ||
6 | - last_state = Kalibro::Processing.last_processing_state_of(params[:repository_id].to_i) | ||
7 | - render :text => last_state | 5 | + def state |
6 | + processing = processing_for_date(params[:repository_id].to_i, params[:date]) | ||
7 | + render :text => processing.state | ||
8 | end | 8 | end |
9 | 9 | ||
10 | def processing | 10 | def processing |
11 | - date = params[:date] | ||
12 | - repository_id = params[:repository_id].to_i | ||
13 | - processing_class = Kalibro::Processing | ||
14 | - @processing = date.nil? ? processing_class.processing_of(repository_id) : processing_class.processing_with_date_of(repository_id, date) | 11 | + @processing = processing_for_date(params[:repository_id].to_i, params[:date]) |
15 | if @processing.state == 'ERROR' | 12 | if @processing.state == 'ERROR' |
16 | render :partial => 'processing_error' | 13 | render :partial => 'processing_error' |
17 | else | 14 | else |
@@ -19,4 +16,15 @@ class MezuroPluginProcessingController < MezuroPluginProfileController | @@ -19,4 +16,15 @@ class MezuroPluginProcessingController < MezuroPluginProfileController | ||
19 | end | 16 | end |
20 | end | 17 | end |
21 | 18 | ||
19 | + private | ||
20 | + | ||
21 | + def processing_for_date(repository_id, date = nil) | ||
22 | + processing_class = Kalibro::Processing | ||
23 | + if date.nil? | ||
24 | + processing_class.processing_of(repository_id) | ||
25 | + else | ||
26 | + processing_class.processing_with_date_of(repository_id, date) | ||
27 | + end | ||
28 | + end | ||
29 | + | ||
22 | end | 30 | end |
plugins/mezuro/public/javascripts/processing.js
@@ -4,18 +4,19 @@ jQuery(function (){ | @@ -4,18 +4,19 @@ jQuery(function (){ | ||
4 | jQuery('.source-tree-link').live("click", reloadModule); | 4 | jQuery('.source-tree-link').live("click", reloadModule); |
5 | jQuery('[show-metric-history]').live("click", display_metric_history); //TODO review for project history | 5 | jQuery('[show-metric-history]').live("click", display_metric_history); //TODO review for project history |
6 | jQuery('[show-grade-history]').live("click", display_grade_history); //TODO review for project history | 6 | jQuery('[show-grade-history]').live("click", display_grade_history); //TODO review for project history |
7 | - jQuery('#project_date_submit').live("click", reloadProjectWithDate); //TODO review for project history | 7 | + jQuery('#project_date_submit').live("click", reloadProcessingWithDate); //TODO review for project history |
8 | showLoadingProcess(true); | 8 | showLoadingProcess(true); |
9 | showProcessing(); | 9 | showProcessing(); |
10 | }); | 10 | }); |
11 | 11 | ||
12 | function showProcessing() { | 12 | function showProcessing() { |
13 | - callAction('processing', 'processing', {}, showProcessingFor); | 13 | + repository_id = processingData('repository-id'); |
14 | + callAction('processing', 'state', {repository_id: repository_id}, showProcessingFor); | ||
14 | } | 15 | } |
15 | 16 | ||
16 | //TODO review for project history | 17 | //TODO review for project history |
17 | function display_metric_history() { | 18 | function display_metric_history() { |
18 | - var module_name = jQuery(this).attr('data-module-name'); | 19 | + var module_result_id = jQuery(this).attr('data-module-id'); |
19 | var metric_name = jQuery(this).attr('show-metric-history'); | 20 | var metric_name = jQuery(this).attr('show-metric-history'); |
20 | toggle_mezuro("." + metric_name); | 21 | toggle_mezuro("." + metric_name); |
21 | metricName = metric_name; | 22 | metricName = metric_name; |
@@ -25,7 +26,7 @@ function display_metric_history() { | @@ -25,7 +26,7 @@ function display_metric_history() { | ||
25 | 26 | ||
26 | //TODO review for project history | 27 | //TODO review for project history |
27 | function display_grade_history() { | 28 | function display_grade_history() { |
28 | - var module_name = jQuery(this).attr('data-module-name'); | 29 | + var module_name = jQuery(this).attr('data-module-id'); |
29 | toggle_mezuro("#historical-grade"); | 30 | toggle_mezuro("#historical-grade"); |
30 | callAction('module_result', 'module_result_history', {module_result_id: module_result_id}, show_grades); | 31 | callAction('module_result', 'module_result_history', {module_result_id: module_result_id}, show_grades); |
31 | return false; | 32 | return false; |
@@ -48,62 +49,69 @@ function toggle_mezuro(element){ | @@ -48,62 +49,69 @@ function toggle_mezuro(element){ | ||
48 | 49 | ||
49 | //TODO Waiting for ModuleResultController refactoring | 50 | //TODO Waiting for ModuleResultController refactoring |
50 | function reloadModule(){ | 51 | function reloadModule(){ |
51 | - var results_root_id = jQuery(this).attr('results_root_id'); | 52 | + var module_result_id = jQuery(this).attr('module_result_id'); |
52 | showLoadingProcess(false); | 53 | showLoadingProcess(false); |
53 | processingTree = true; | 54 | processingTree = true; |
54 | // callAction('module_result', 'project_tree', {results_root_id: results_root_id }, showProjectTree); | 55 | // callAction('module_result', 'project_tree', {results_root_id: results_root_id }, showProjectTree); |
55 | - callAction('module_result', 'module_result', {results_root_id: results_root_id}, showModuleResult); | 56 | + callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult); |
56 | return false; | 57 | return false; |
57 | } | 58 | } |
58 | 59 | ||
59 | //TODO review for project history | 60 | //TODO review for project history |
60 | -function reloadProjectWithDate(date){ | ||
61 | - reloadProject(date + "T00:00:00+00:00"); | 61 | +function reloadProcessingWithDate(date){ |
62 | + reloadProcessing(date + "T00:00:00+00:00"); | ||
62 | return false; | 63 | return false; |
63 | } | 64 | } |
64 | 65 | ||
65 | //TODO review for project history | 66 | //TODO review for project history |
66 | -function reloadProject(date){ | 67 | +function reloadProcessing(date){ |
68 | + repository_id = processingData('repository-id'); | ||
67 | showLoadingProcess(true); | 69 | showLoadingProcess(true); |
68 | - | ||
69 | - callAction('processing', 'processing', {date: date}, showProjectResult); | ||
70 | -// callAction('module_result', 'project_tree', {date: date}, showProjectTree); | ||
71 | - callAction('module_result', 'module_result', {date: date}, showModuleResult); | 70 | + |
71 | + callAction('processing', 'processing', {date: date, repository_id: repository_id}, function(content){ | ||
72 | + showReadyProcessing(content); | ||
73 | + var module_result_id = jQuery("#module_result_root_id").attr('module_result_root_id'); //TODO Waiting for ModuleResultController refactoring | ||
74 | + callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult); //TODO Waiting for ModuleResultController refactoring | ||
75 | + } | ||
76 | + ); | ||
72 | } | 77 | } |
73 | 78 | ||
74 | function showProcessingFor(state){ | 79 | function showProcessingFor(state){ |
80 | + repository_id = processingData('repository-id'); | ||
75 | if (state == 'ERROR') { | 81 | if (state == 'ERROR') { |
76 | jQuery('#project-state').html('<div style="color:Red">ERROR</div>'); | 82 | jQuery('#project-state').html('<div style="color:Red">ERROR</div>'); |
77 | - callAction('processing', 'processing_error', {}, showProcessing); | 83 | + callAction('processing', 'processing', {repository_id: repository_id}, showReadyProcessing); |
78 | } | 84 | } |
79 | else if (state == 'READY') { | 85 | else if (state == 'READY') { |
80 | jQuery('#msg-time').html(''); | 86 | jQuery('#msg-time').html(''); |
81 | jQuery('#processing-state').html('<div style="color:Green">READY</div>'); | 87 | jQuery('#processing-state').html('<div style="color:Green">READY</div>'); |
82 | - callAction('processing', 'processing', {}, showProcessing); | ||
83 | -// callAction('processing','project_tree', {}, showProjectTree); | ||
84 | - //var module_result_id = jQuery("#processing").attr('results_root_id'); //TODO Waiting for ModuleResultController refactoring | ||
85 | - callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult); //TODO Waiting for ModuleResultController refactoring | ||
86 | - } | 88 | + callAction('processing', 'processing', {repository_id: repository_id}, function(content){ |
89 | + showReadyProcessing(content); | ||
90 | + var module_result_id = jQuery("#module_result_root_id").attr('module_result_root_id'); //TODO Waiting for ModuleResultController refactoring | ||
91 | + callAction('module_result', 'module_result', {module_result_id: module_result_id}, showModuleResult); //TODO Waiting for ModuleResultController refactoring | ||
92 | + } | ||
93 | + ); | ||
94 | + } | ||
87 | else if (state.endsWith("ING")) { | 95 | else if (state.endsWith("ING")) { |
88 | jQuery('#processing-state').html('<div style="color:DarkGoldenRod">'+ state +'</div>'); | 96 | jQuery('#processing-state').html('<div style="color:DarkGoldenRod">'+ state +'</div>'); |
89 | jQuery('#msg-time').html("The project analysis may take long. <br/> You'll receive an e-mail when it's ready!"); | 97 | jQuery('#msg-time').html("The project analysis may take long. <br/> You'll receive an e-mail when it's ready!"); |
90 | - showProjectContentAfter(20); | ||
91 | - } | 98 | + showProcessingAfter(20); |
99 | + } | ||
92 | } | 100 | } |
93 | 101 | ||
94 | -function showProjectContentAfter(seconds){ | 102 | +function showProcessingAfter(seconds){ |
95 | if (seconds > 0){ | 103 | if (seconds > 0){ |
96 | - setTimeout(function() { showProjectContentAfter(seconds - 10);}, 10000); | 104 | + setTimeout(function() { showProcessingAfter(seconds - 10);}, 10000); |
97 | } else { | 105 | } else { |
98 | - showProjectContent(); | 106 | + showProcessing(); |
99 | } | 107 | } |
100 | } | 108 | } |
101 | 109 | ||
102 | -function showProjectResult(content) { | 110 | +function showReadyProcessing(content) { |
103 | jQuery('#processing').html(content); | 111 | jQuery('#processing').html(content); |
104 | } | 112 | } |
105 | 113 | ||
106 | -//function showProjectTree(content){ | 114 | +//function showProjectTree(content){ |
107 | // processingTree = false; | 115 | // processingTree = false; |
108 | // jQuery('#project-tree').html(content); | 116 | // jQuery('#project-tree').html(content); |
109 | // return false; | 117 | // return false; |
@@ -118,21 +126,19 @@ function showModuleResult(content){ | @@ -118,21 +126,19 @@ function showModuleResult(content){ | ||
118 | } | 126 | } |
119 | 127 | ||
120 | function callAction(controller, action, params, callback){ | 128 | function callAction(controller, action, params, callback){ |
121 | - var profile = projectContentData('profile'); | ||
122 | - var content = projectContentData('content'); | 129 | + var profile = processingData('profile'); |
130 | + var content = processingData('content'); | ||
123 | var endpoint = '/profile/' + profile + '/plugin/mezuro/' + controller + '/' + action + '/' + content; | 131 | var endpoint = '/profile/' + profile + '/plugin/mezuro/' + controller + '/' + action + '/' + content; |
124 | jQuery.get(endpoint, params, callback); | 132 | jQuery.get(endpoint, params, callback); |
125 | } | 133 | } |
126 | 134 | ||
127 | -function projectContentData(data){ | 135 | +function processingData(data){ |
128 | return jQuery('#processing').attr('data-' + data); | 136 | return jQuery('#processing').attr('data-' + data); |
129 | } | 137 | } |
130 | 138 | ||
131 | function showLoadingProcess(firstLoad){ | 139 | function showLoadingProcess(firstLoad){ |
132 | - if(firstLoad) | ||
133 | - showProjectResult("<img src='/images/loading-small.gif'/>"); | ||
134 | - | ||
135 | - showProjectTree("<img src='/images/loading-small.gif'/>"); | 140 | + if(firstLoad) |
141 | + showReadyProcessing("<img src='/images/loading-small.gif'/>"); | ||
136 | showModuleResult("<img src='/images/loading-small.gif'/>"); | 142 | showModuleResult("<img src='/images/loading-small.gif'/>"); |
137 | } | 143 | } |
138 | 144 |
plugins/mezuro/views/mezuro_plugin_processing/_processing.rhtml