Commit 07f196bfe299aaac6cb03d40c94c50c6e56f36f3
Committed by
Rafael Manzo
1 parent
fa3fdeb7
Exists in
master
and in
28 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 | 2 | |
3 | 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 | 8 | end |
9 | 9 | |
10 | 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 | 12 | if @processing.state == 'ERROR' |
16 | 13 | render :partial => 'processing_error' |
17 | 14 | else |
... | ... | @@ -19,4 +16,15 @@ class MezuroPluginProcessingController < MezuroPluginProfileController |
19 | 16 | end |
20 | 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 | 30 | end | ... | ... |
plugins/mezuro/public/javascripts/processing.js
... | ... | @@ -4,18 +4,19 @@ jQuery(function (){ |
4 | 4 | jQuery('.source-tree-link').live("click", reloadModule); |
5 | 5 | jQuery('[show-metric-history]').live("click", display_metric_history); //TODO review for project history |
6 | 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 | 8 | showLoadingProcess(true); |
9 | 9 | showProcessing(); |
10 | 10 | }); |
11 | 11 | |
12 | 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 | 17 | //TODO review for project history |
17 | 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 | 20 | var metric_name = jQuery(this).attr('show-metric-history'); |
20 | 21 | toggle_mezuro("." + metric_name); |
21 | 22 | metricName = metric_name; |
... | ... | @@ -25,7 +26,7 @@ function display_metric_history() { |
25 | 26 | |
26 | 27 | //TODO review for project history |
27 | 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 | 30 | toggle_mezuro("#historical-grade"); |
30 | 31 | callAction('module_result', 'module_result_history', {module_result_id: module_result_id}, show_grades); |
31 | 32 | return false; |
... | ... | @@ -48,62 +49,69 @@ function toggle_mezuro(element){ |
48 | 49 | |
49 | 50 | //TODO Waiting for ModuleResultController refactoring |
50 | 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 | 53 | showLoadingProcess(false); |
53 | 54 | processingTree = true; |
54 | 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 | 57 | return false; |
57 | 58 | } |
58 | 59 | |
59 | 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 | 63 | return false; |
63 | 64 | } |
64 | 65 | |
65 | 66 | //TODO review for project history |
66 | -function reloadProject(date){ | |
67 | +function reloadProcessing(date){ | |
68 | + repository_id = processingData('repository-id'); | |
67 | 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 | 79 | function showProcessingFor(state){ |
80 | + repository_id = processingData('repository-id'); | |
75 | 81 | if (state == 'ERROR') { |
76 | 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 | 85 | else if (state == 'READY') { |
80 | 86 | jQuery('#msg-time').html(''); |
81 | 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 | 95 | else if (state.endsWith("ING")) { |
88 | 96 | jQuery('#processing-state').html('<div style="color:DarkGoldenRod">'+ state +'</div>'); |
89 | 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 | 103 | if (seconds > 0){ |
96 | - setTimeout(function() { showProjectContentAfter(seconds - 10);}, 10000); | |
104 | + setTimeout(function() { showProcessingAfter(seconds - 10);}, 10000); | |
97 | 105 | } else { |
98 | - showProjectContent(); | |
106 | + showProcessing(); | |
99 | 107 | } |
100 | 108 | } |
101 | 109 | |
102 | -function showProjectResult(content) { | |
110 | +function showReadyProcessing(content) { | |
103 | 111 | jQuery('#processing').html(content); |
104 | 112 | } |
105 | 113 | |
106 | -//function showProjectTree(content){ | |
114 | +//function showProjectTree(content){ | |
107 | 115 | // processingTree = false; |
108 | 116 | // jQuery('#project-tree').html(content); |
109 | 117 | // return false; |
... | ... | @@ -118,21 +126,19 @@ function showModuleResult(content){ |
118 | 126 | } |
119 | 127 | |
120 | 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 | 131 | var endpoint = '/profile/' + profile + '/plugin/mezuro/' + controller + '/' + action + '/' + content; |
124 | 132 | jQuery.get(endpoint, params, callback); |
125 | 133 | } |
126 | 134 | |
127 | -function projectContentData(data){ | |
135 | +function processingData(data){ | |
128 | 136 | return jQuery('#processing').attr('data-' + data); |
129 | 137 | } |
130 | 138 | |
131 | 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 | 142 | showModuleResult("<img src='/images/loading-small.gif'/>"); |
137 | 143 | } |
138 | 144 | ... | ... |