Commit b5c3370fca0dacce12153d2ec71d7ac3f69d75f3
Committed by
João M. M. da Silva
1 parent
9e4baa71
Exists in
master
and in
29 other branches
[Mezuro] Fixed exceptions handling in controller
Showing
3 changed files
with
61 additions
and
32 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
... | ... | @@ -31,7 +31,9 @@ class MezuroPluginMyprofileController < ProfileController |
31 | 31 | def new_compound_metric_configuration |
32 | 32 | @configuration_content = profile.articles.find(params[:id]) |
33 | 33 | @metric_configurations = @configuration_content.metric_configurations |
34 | - look_for_configuration_content_errors | |
34 | + if configuration_content_has_errors? | |
35 | + redirect_to_error_page @configuration_content.errors[:base] | |
36 | + end | |
35 | 37 | end |
36 | 38 | |
37 | 39 | def edit_metric_configuration |
... | ... | @@ -50,8 +52,13 @@ class MezuroPluginMyprofileController < ProfileController |
50 | 52 | def create_metric_configuration |
51 | 53 | id = params[:id] |
52 | 54 | metric_name = params[:metric_configuration][:metric][:name] |
53 | - (Kalibro::MetricConfiguration.new(params[:metric_configuration])).save | |
54 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | |
55 | + metric_configuration = Kalibro::MetricConfiguration.new(params[:metric_configuration]) | |
56 | + metric_configuration.save | |
57 | + if metric_configuration_has_errors? metric_configuration | |
58 | + redirect_to_error_page metric_configuration.errors[0].message | |
59 | + else | |
60 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | |
61 | + end | |
55 | 62 | end |
56 | 63 | |
57 | 64 | def create_compound_metric_configuration |
... | ... | @@ -59,8 +66,11 @@ class MezuroPluginMyprofileController < ProfileController |
59 | 66 | metric_name = params[:metric_configuration][:metric][:name] |
60 | 67 | metric_configuration = Kalibro::MetricConfiguration.new(params[:metric_configuration]) |
61 | 68 | metric_configuration.save |
62 | - look_for_model_error metric_configuration | |
63 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | |
69 | + if metric_configuration_has_errors? metric_configuration | |
70 | + redirect_to_error_page metric_configuration.errors[0].message | |
71 | + else | |
72 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | |
73 | + end | |
64 | 74 | end |
65 | 75 | |
66 | 76 | def update_metric_configuration |
... | ... | @@ -68,8 +78,11 @@ class MezuroPluginMyprofileController < ProfileController |
68 | 78 | metric_name = params[:metric_configuration][:metric][:name] |
69 | 79 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) |
70 | 80 | metric_configuration.update_attributes params[:metric_configuration] |
71 | - look_for_model_error metric_configuration | |
72 | - redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | |
81 | + if metric_configuration_has_errors? metric_configuration | |
82 | + redirect_to_error_page metric_configuration.errors[0].message | |
83 | + else | |
84 | + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | |
85 | + end | |
73 | 86 | end |
74 | 87 | |
75 | 88 | def update_compound_metric_configuration |
... | ... | @@ -77,8 +90,11 @@ class MezuroPluginMyprofileController < ProfileController |
77 | 90 | metric_name = params[:metric_configuration][:metric][:name] |
78 | 91 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) |
79 | 92 | metric_configuration.update_attributes params[:metric_configuration] |
80 | - look_for_model_error metric_configuration | |
81 | - redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | |
93 | + if metric_configuration_has_errors? metric_configuration | |
94 | + redirect_to_error_page metric_configuration.errors[0].message | |
95 | + else | |
96 | + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | |
97 | + end | |
82 | 98 | end |
83 | 99 | |
84 | 100 | def remove_metric_configuration |
... | ... | @@ -86,8 +102,11 @@ class MezuroPluginMyprofileController < ProfileController |
86 | 102 | metric_name = params[:metric_name] |
87 | 103 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) |
88 | 104 | metric_configuration.destroy |
89 | - look_for_model_error metric_configuration | |
90 | - redirect_to "/#{profile.identifier}/#{configuration_content.slug}" | |
105 | + if metric_configuration_has_errors? metric_configuration | |
106 | + redirect_to_error_page metric_configuration.errors[0].message | |
107 | + else | |
108 | + redirect_to "/#{profile.identifier}/#{configuration_content.slug}" | |
109 | + end | |
91 | 110 | end |
92 | 111 | |
93 | 112 | def new_range |
... | ... | @@ -111,7 +130,9 @@ class MezuroPluginMyprofileController < ProfileController |
111 | 130 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) |
112 | 131 | metric_configuration.add_range(@range) |
113 | 132 | metric_configuration.save |
114 | - look_for_model_error metric_configuration | |
133 | + if metric_configuration_has_errors? metric_configuration | |
134 | + redirect_to_error_page metric_configuration.errors[0].message | |
135 | + end | |
115 | 136 | end |
116 | 137 | |
117 | 138 | def update_range |
... | ... | @@ -122,7 +143,9 @@ class MezuroPluginMyprofileController < ProfileController |
122 | 143 | index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } |
123 | 144 | metric_configuration.ranges[index] = Kalibro::Range.new params[:range] |
124 | 145 | metric_configuration.save |
125 | - look_for_model_error metric_configuration | |
146 | + if metric_configuration_has_errors? metric_configuration | |
147 | + redirect_to_error_page metric_configuration.errors[0].message | |
148 | + end | |
126 | 149 | end |
127 | 150 | |
128 | 151 | def remove_range |
... | ... | @@ -132,27 +155,31 @@ class MezuroPluginMyprofileController < ProfileController |
132 | 155 | metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) |
133 | 156 | metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } |
134 | 157 | metric_configuration.save |
135 | - | |
136 | - formatted_metric_name = metric_name.gsub(/\s/, '+') | |
137 | - if metric_configuration.metric.class == Kalibro::CompoundMetric | |
138 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | |
158 | + if metric_configuration_has_errors? metric_configuration | |
159 | + redirect_to_error_page metric_configuration.errors[0].message | |
139 | 160 | else |
140 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | |
161 | + formatted_metric_name = metric_name.gsub(/\s/, '+') | |
162 | + if metric_configuration.metric.class == Kalibro::CompoundMetric | |
163 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | |
164 | + else | |
165 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | |
166 | + end | |
141 | 167 | end |
142 | 168 | end |
143 | 169 | |
144 | 170 | private |
145 | 171 | |
146 | 172 | def redirect_to_error_page(message) |
173 | + message = URI.escape(CGI.escape(message),'.') | |
147 | 174 | redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}" |
148 | 175 | end |
149 | 176 | |
150 | - def look_for_configuration_content_errors | |
151 | - redirect_to_error_page(@configuration_content.errors[:base]) if not @configuration_content.errors.nil? | |
177 | + def configuration_content_has_errors? | |
178 | + not @configuration_content.errors[:base].nil? | |
152 | 179 | end |
153 | 180 | |
154 | - def look_for_model_error(model) | |
155 | - redirect_to_error_page(model.errors[0].message) if not model.errors.empty? | |
181 | + def metric_configuration_has_errors? metric_configuration | |
182 | + not metric_configuration.errors.empty? | |
156 | 183 | end |
157 | 184 | |
158 | 185 | end | ... | ... |
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
... | ... | @@ -9,7 +9,7 @@ class MezuroPluginProfileController < ProfileController |
9 | 9 | def project_state |
10 | 10 | @content = profile.articles.find(params[:id]) |
11 | 11 | project = @content.project |
12 | - if project_content_errors? | |
12 | + if project_content_has_errors? | |
13 | 13 | redirect_to_error_page(@content.errors[:base]) |
14 | 14 | else |
15 | 15 | state = project.kalibro_error.nil? ? project.state : "ERROR" |
... | ... | @@ -20,7 +20,7 @@ class MezuroPluginProfileController < ProfileController |
20 | 20 | def project_error |
21 | 21 | @content = profile.articles.find(params[:id]) |
22 | 22 | @project = @content.project |
23 | - if project_content_errors? | |
23 | + if project_content_has_errors? | |
24 | 24 | redirect_to_error_page(@content.errors[:base]) |
25 | 25 | else |
26 | 26 | render :partial => 'content_viewer/project_error' |
... | ... | @@ -31,7 +31,7 @@ class MezuroPluginProfileController < ProfileController |
31 | 31 | @content = profile.articles.find(params[:id]) |
32 | 32 | date = params[:date] |
33 | 33 | @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) |
34 | - if project_content_errors? | |
34 | + if project_content_has_errors? | |
35 | 35 | redirect_to_error_page(@content.errors[:base]) |
36 | 36 | else |
37 | 37 | render :partial => 'content_viewer/project_result' |
... | ... | @@ -41,7 +41,7 @@ class MezuroPluginProfileController < ProfileController |
41 | 41 | def module_result |
42 | 42 | @content = profile.articles.find(params[:id]) |
43 | 43 | @module_result = @content.module_result(params) |
44 | - if project_content_errors? | |
44 | + if project_content_has_errors? | |
45 | 45 | redirect_to_error_page(@content.errors[:base]) |
46 | 46 | else |
47 | 47 | render :partial => 'content_viewer/module_result' |
... | ... | @@ -53,7 +53,7 @@ class MezuroPluginProfileController < ProfileController |
53 | 53 | date = params[:date] |
54 | 54 | project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) |
55 | 55 | @project_name = @content.project.name if not @content.project.nil? |
56 | - if project_content_errors? | |
56 | + if project_content_has_errors? | |
57 | 57 | redirect_to_error_page(@content.errors[:base]) |
58 | 58 | else |
59 | 59 | @source_tree = project_result.node_of(params[:module_name]) |
... | ... | @@ -65,7 +65,7 @@ class MezuroPluginProfileController < ProfileController |
65 | 65 | metric_name = params[:metric_name] |
66 | 66 | @content = profile.articles.find(params[:id]) |
67 | 67 | module_history = @content.result_history(params[:module_name]) |
68 | - if project_content_errors? | |
68 | + if project_content_has_errors? | |
69 | 69 | redirect_to_error_page(@content.errors[:base]) |
70 | 70 | else |
71 | 71 | @score_history = filtering_metric_history(metric_name, module_history) |
... | ... | @@ -76,7 +76,7 @@ class MezuroPluginProfileController < ProfileController |
76 | 76 | def module_grade_history |
77 | 77 | @content = profile.articles.find(params[:id]) |
78 | 78 | modules_results = @content.result_history(params[:module_name]) |
79 | - if project_content_errors? | |
79 | + if project_content_has_errors? | |
80 | 80 | redirect_to_error_page(@content.errors[:base]) |
81 | 81 | else |
82 | 82 | @score_history = modules_results.collect { |module_result| module_result.grade } |
... | ... | @@ -104,8 +104,8 @@ class MezuroPluginProfileController < ProfileController |
104 | 104 | redirect_to "/profile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}" |
105 | 105 | end |
106 | 106 | |
107 | - def project_content_errors? | |
108 | - not @content.errors.nil? | |
107 | + def project_content_has_errors? | |
108 | + not @content.errors[:base].nil? | |
109 | 109 | end |
110 | 110 | end |
111 | 111 | ... | ... |
plugins/mezuro/public/javascripts/validations.js
... | ... | @@ -3,7 +3,9 @@ jQuery(function (){ |
3 | 3 | jQuery('#metric_configuration_submit').live("click", validate_metric_configuration); |
4 | 4 | }); |
5 | 5 | |
6 | - | |
6 | +function validate_code(code){ | |
7 | + return true; | |
8 | +} | |
7 | 9 | |
8 | 10 | function validate_metric_configuration(){ |
9 | 11 | var code = jQuery('#metric_configuration_code').val(); | ... | ... |