Commit 337e1da4d41be25bb6438ffc039966b4d1471a50
Committed by
Paulo Meireles
1 parent
f6465c32
Exists in
staging
and in
42 other branches
[Mezuro] showing message of not existent project in kalibro, not working yet for configuration
Showing
9 changed files
with
131 additions
and
103 deletions
Show diff stats
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
| ... | ... | @@ -4,15 +4,17 @@ class MezuroPluginProfileController < ProfileController |
| 4 | 4 | |
| 5 | 5 | rescue_from Exception do |exception| |
| 6 | 6 | message = URI.escape(CGI.escape(exception.message),'.') |
| 7 | - redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}" | |
| 7 | + redirect_to_error_page message | |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | 10 | def error_page |
| 11 | + @message = params[:message] | |
| 11 | 12 | end |
| 12 | 13 | |
| 13 | 14 | def project_state |
| 14 | 15 | @content = profile.articles.find(params[:id]) |
| 15 | 16 | project = @content.project |
| 17 | + redirect_to_error_page(project.errors[0].message) if not project.errors.empty? | |
| 16 | 18 | state = project.kalibro_error.nil? ? project.state : "ERROR" |
| 17 | 19 | render :text => state |
| 18 | 20 | end |
| ... | ... | @@ -75,4 +77,10 @@ class MezuroPluginProfileController < ProfileController |
| 75 | 77 | metric_result.value |
| 76 | 78 | end |
| 77 | 79 | end |
| 80 | + | |
| 81 | + def redirect_to_error_page(message) | |
| 82 | + redirect_to "/profile/#{profile.identifier}/plugin/mezuro/error_page?message=#{message}" | |
| 83 | + end | |
| 84 | + | |
| 78 | 85 | end |
| 86 | + | ... | ... |
plugins/mezuro/lib/kalibro/model.rb
| ... | ... | @@ -55,10 +55,6 @@ class Kalibro::Model |
| 55 | 55 | false |
| 56 | 56 | end |
| 57 | 57 | end |
| 58 | - | |
| 59 | - def add_error(exception) | |
| 60 | - @errors << exception | |
| 61 | - end | |
| 62 | 58 | |
| 63 | 59 | def destroy |
| 64 | 60 | begin |
| ... | ... | @@ -133,4 +129,9 @@ class Kalibro::Model |
| 133 | 129 | {"#{class_name.underscore}_name".to_sym => self.name} |
| 134 | 130 | end |
| 135 | 131 | |
| 132 | + def add_error(exception) | |
| 133 | + @errors << exception | |
| 134 | + end | |
| 135 | + | |
| 136 | 136 | end |
| 137 | + | ... | ... |
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| ... | ... | @@ -25,6 +25,7 @@ class MezuroPlugin::ProjectContent < Article |
| 25 | 25 | @project ||= Kalibro::Project.find_by_name(name) |
| 26 | 26 | rescue Exception => error |
| 27 | 27 | errors.add_to_base(error.message) |
| 28 | + @project | |
| 28 | 29 | end |
| 29 | 30 | end |
| 30 | 31 | |
| ... | ... | @@ -105,7 +106,7 @@ Kalibro::ProjectResult.first_result_after(name, date) |
| 105 | 106 | end |
| 106 | 107 | |
| 107 | 108 | def destroy_project_from_service |
| 108 | - project.destroy | |
| 109 | + project.destroy unless project.nil? | |
| 109 | 110 | end |
| 110 | 111 | |
| 111 | 112 | end | ... | ... |
plugins/mezuro/test/functional/mezuro_plugin_profile_controller_test.rb
| ... | ... | @@ -25,14 +25,21 @@ class MezuroPluginProfileControllerTest < ActionController::TestCase |
| 25 | 25 | @content.save |
| 26 | 26 | end |
| 27 | 27 | |
| 28 | - should 'test project state without error' do | |
| 28 | + should 'show an error page if an exception is raised' do | |
| 29 | + Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns(Exception.new(:message => "Error message")) | |
| 30 | + get :project_state, :profile => @profile.identifier, :id => @content.id | |
| 31 | + assert_response 302 | |
| 32 | + assert_select('h2', 'An error occured: ') | |
| 33 | + end | |
| 34 | + | |
| 35 | + should 'test project state without kalibro_error' do | |
| 29 | 36 | Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash}) |
| 30 | 37 | get :project_state, :profile => @profile.identifier, :id => @content.id |
| 31 | 38 | assert_response 200 |
| 32 | 39 | assert_equal @content, assigns(:content) |
| 33 | 40 | end |
| 34 | 41 | |
| 35 | - should 'test project state with error' do | |
| 42 | + should 'test project state with kalibro_error' do | |
| 36 | 43 | Kalibro::Project.expects(:request).with("Project", :get_project, :project_name => @project.name).returns({:project => @project.to_hash.merge({:error => ErrorFixtures.error_hash})}) |
| 37 | 44 | get :project_state, :profile => @profile.identifier, :id => @content.id |
| 38 | 45 | assert_response 200 | ... | ... |
plugins/mezuro/views/content_viewer/show_configuration.rhtml
| 1 | 1 | <% @configuration_content = @page |
| 2 | 2 | @configuration = @page.configuration %> |
| 3 | +<% unless @page.errors[:base].nil? %> | |
| 4 | + <% if @page.errors[:base] =~ /There is no project named/ %> | |
| 5 | + <h3>Warning:</h3> | |
| 6 | + <p>This Configuration doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p> | |
| 7 | + <% else %> | |
| 8 | + <%= @page.errors[:base] %> | |
| 9 | + <% end %> | |
| 10 | +<% else %> | |
| 3 | 11 | |
| 4 | -<table id="project_info"> | |
| 5 | - <tr> | |
| 6 | - <td><%= _('Name') %></td> | |
| 7 | - <td><%= @configuration.name %></td> | |
| 8 | - </tr> | |
| 9 | - <tr> | |
| 10 | - <td><%= _('Description') %></td> | |
| 11 | - <td><%= @configuration.description %></td> | |
| 12 | - </tr> | |
| 13 | -</table> | |
| 12 | + <table id="project_info"> | |
| 13 | + <tr> | |
| 14 | + <td><%= _('Name') %></td> | |
| 15 | + <td><%= @configuration.name %></td> | |
| 16 | + </tr> | |
| 17 | + <tr> | |
| 18 | + <td><%= _('Description') %></td> | |
| 19 | + <td><%= @configuration.description %></td> | |
| 20 | + </tr> | |
| 21 | + </table> | |
| 14 | 22 | |
| 15 | -<br/> | |
| 23 | + <br/> | |
| 16 | 24 | |
| 17 | -<%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile", | |
| 18 | -:action => "choose_base_tool", :params => { :id => @configuration_content.id } %><br/> | |
| 25 | + <%= link_to "#{image_tag ('/plugins/mezuro/images/plus.png')}Add Metric", :controller => "mezuro_plugin_myprofile", | |
| 26 | + :action => "choose_base_tool", :params => { :id => @configuration_content.id } %><br/> | |
| 19 | 27 | |
| 20 | -<table> | |
| 21 | - <tr class="titles"> | |
| 22 | - <td><h5>Metric Name</h5></td> | |
| 23 | - <td><h5>Collector Name</h5></td> | |
| 24 | - <td><h5>Metric Code</h5></td> | |
| 25 | - <td/><td/> | |
| 26 | - </tr> | |
| 27 | - <% @configuration.metric_configurations.each do |metric_configuration| %> | |
| 28 | - <tr class="metric"> | |
| 29 | - <td><%= metric_configuration.metric.name %></td> | |
| 30 | - <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %> | |
| 31 | - <td> | |
| 32 | - <%= metric_configuration.metric.origin %> | |
| 33 | - </td> | |
| 34 | - <td><%= metric_configuration.code %></td> | |
| 35 | - <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params => | |
| 36 | - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
| 37 | - <% else %> | |
| 38 | - <td> | |
| 39 | - Compound Metric | |
| 40 | - </td> | |
| 41 | - <td><%= metric_configuration.code %></td> | |
| 42 | - <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params => | |
| 43 | - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
| 44 | - <% end %> | |
| 45 | - | |
| 46 | - <td><%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params => | |
| 47 | - {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
| 28 | + <table> | |
| 29 | + <tr class="titles"> | |
| 30 | + <td><h5>Metric Name</h5></td> | |
| 31 | + <td><h5>Collector Name</h5></td> | |
| 32 | + <td><h5>Metric Code</h5></td> | |
| 33 | + <td/><td/> | |
| 48 | 34 | </tr> |
| 49 | - <% end %> | |
| 50 | -</table> | |
| 35 | + <% @configuration.metric_configurations.each do |metric_configuration| %> | |
| 36 | + <tr class="metric"> | |
| 37 | + <td><%= metric_configuration.metric.name %></td> | |
| 38 | + <% if metric_configuration.metric.instance_of? Kalibro::NativeMetric %> | |
| 39 | + <td> | |
| 40 | + <%= metric_configuration.metric.origin %> | |
| 41 | + </td> | |
| 42 | + <td><%= metric_configuration.code %></td> | |
| 43 | + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_metric_configuration", :params => | |
| 44 | + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
| 45 | + <% else %> | |
| 46 | + <td> | |
| 47 | + Compound Metric | |
| 48 | + </td> | |
| 49 | + <td><%= metric_configuration.code %></td> | |
| 50 | + <td><%= link_to "Edit", :controller => "mezuro_plugin_myprofile", :action => "edit_compound_metric_configuration", :params => | |
| 51 | + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
| 52 | + <% end %> | |
| 53 | + | |
| 54 | + <td><%= link_to "Remove", :controller => "mezuro_plugin_myprofile", :action => "remove_metric_configuration", :params => | |
| 55 | + {:metric_name => metric_configuration.metric.name, :id => @configuration_content.id} %></td> | |
| 56 | + </tr> | |
| 57 | + <% end %> | |
| 58 | + </table> | |
| 59 | +<% end %> | ... | ... |
plugins/mezuro/views/content_viewer/show_project.rhtml
| ... | ... | @@ -2,60 +2,58 @@ |
| 2 | 2 | |
| 3 | 3 | <% @project = @page.project %> |
| 4 | 4 | <% unless @page.errors[:base].nil? %> |
| 5 | - <%= @page.errors[:base] %> | |
| 6 | -<% else %> | |
| 7 | - | |
| 8 | - <% if (@project==nil) %> | |
| 5 | + <% if @page.errors[:base] =~ /There is no project named/ %> | |
| 9 | 6 | <h3>Warning:</h3> |
| 10 | 7 | <p>This project doesn't exist on the Web Service. Do you want to <a href="/myprofile/<%= @page.profile.name %>/cms/destroy/<%= @page.id%>">delete</a> or <a href="/myprofile/<%= @page.profile.name %>/cms/edit/<%= @page.id%>">save it again</a>?</p> |
| 11 | 8 | <% else %> |
| 9 | + <%= @page.errors[:base] %> | |
| 10 | + <% end %> | |
| 11 | +<% else %> | |
| 12 | 12 | |
| 13 | + <table> | |
| 14 | + <tr> | |
| 15 | + <td><%= _('Name') %></td> | |
| 16 | + <td><%= @project.name %></td> | |
| 17 | + </tr> | |
| 18 | + <tr> | |
| 19 | + <td><%= _('License') %></td> | |
| 20 | + <td><%= @project.license %></td> | |
| 21 | + </tr> | |
| 22 | + <tr> | |
| 23 | + <td><%= _('Description') %></td> | |
| 24 | + <td><%= @project.description %></td> | |
| 25 | + </tr> | |
| 26 | + <tr> | |
| 27 | + <td><%= _('Repository type') %></td> | |
| 28 | + <td><%= @project.repository.type %></td> | |
| 29 | + </tr> | |
| 30 | + <tr> | |
| 31 | + <td><%= _('Repository address') %></td> | |
| 32 | + <td><%= @project.repository.address %></td> | |
| 33 | + </tr> | |
| 34 | + <tr> | |
| 35 | + <td><%= _('Configuration') %></td> | |
| 36 | + <td><%= @project.configuration_name %></td> | |
| 37 | + </tr> | |
| 38 | + <tr> | |
| 39 | + <td><%= _('Periodicity') %></td> | |
| 40 | + <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td> | |
| 41 | + </tr> | |
| 42 | + <tr> | |
| 43 | + <td><%= _('Status')%></td> | |
| 44 | + <td> | |
| 45 | + <div id="project-state"><%= @project.state %></div> | |
| 46 | + <div id="msg-time"></div> | |
| 47 | + </td> | |
| 48 | + </tr> | |
| 49 | + </table> | |
| 13 | 50 | |
| 14 | - <table> | |
| 15 | - <tr> | |
| 16 | - <td><%= _('Name') %></td> | |
| 17 | - <td><%= @project.name %></td> | |
| 18 | - </tr> | |
| 19 | - <tr> | |
| 20 | - <td><%= _('License') %></td> | |
| 21 | - <td><%= @project.license %></td> | |
| 22 | - </tr> | |
| 23 | - <tr> | |
| 24 | - <td><%= _('Description') %></td> | |
| 25 | - <td><%= @project.description %></td> | |
| 26 | - </tr> | |
| 27 | - <tr> | |
| 28 | - <td><%= _('Repository type') %></td> | |
| 29 | - <td><%= @project.repository.type %></td> | |
| 30 | - </tr> | |
| 31 | - <tr> | |
| 32 | - <td><%= _('Repository address') %></td> | |
| 33 | - <td><%= @project.repository.address %></td> | |
| 34 | - </tr> | |
| 35 | - <tr> | |
| 36 | - <td><%= _('Configuration') %></td> | |
| 37 | - <td><%= @project.configuration_name %></td> | |
| 38 | - </tr> | |
| 39 | - <tr> | |
| 40 | - <td><%= _('Periodicity') %></td> | |
| 41 | - <td><%= MezuroPlugin::Helpers::ContentViewerHelper.get_periodicity_option(@page.periodicity_in_days) %></td> | |
| 42 | - </tr> | |
| 43 | - <tr> | |
| 44 | - <td><%= _('Status')%></td> | |
| 45 | - <td> | |
| 46 | - <div id="project-state"><%= @project.state %></div> | |
| 47 | - <div id="msg-time"></div> | |
| 48 | - </td> | |
| 49 | - </tr> | |
| 50 | - </table> | |
| 51 | - | |
| 52 | - <br /> | |
| 51 | + <br /> | |
| 53 | 52 | |
| 54 | - <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>" | |
| 55 | - data-project-name="<%= @project.name %>"> | |
| 56 | - </div> | |
| 57 | - <div id="project-tree"></div> | |
| 58 | - <div id="module-result"> | |
| 59 | - </div> | |
| 60 | - <% end %> | |
| 53 | + <div id="project-result" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>" | |
| 54 | + data-project-name="<%= @project.name %>"> | |
| 55 | + </div> | |
| 56 | + <div id="project-tree"></div> | |
| 57 | + <div id="module-result"> | |
| 58 | + </div> | |
| 61 | 59 | <% end %> | ... | ... |
plugins/mezuro/views/mezuro_plugin_myprofile/error_page.html.erb
plugins/mezuro/views/mezuro_plugin_profile/error_page.html.erb
0 → 100644