# Ruby on Rails has a single logger "rails", so it's not possible to distinguish profiling logs
# from error logs. For this reason a standard SLF4J logger is used instead of logger.error().
java_facade.logError("Fail to render: #{request.url}\n#{Api::Utils.exception_message(error)}")
- render :file => "#{Rails.public_path}/500.html", :status => 500
+
+ if request.xhr?
+ message = error.respond_to?('message') ? error.message : error.to_s
+ render :text => message, :status => 500
+ else
+ render :file => "#{Rails.public_path}/500.html", :status => 500
+ end
end
end
include REXML
SECTION=Navigation::SECTION_RESOURCE
- helper :dashboard, SourceHelper
+ helper :dashboard
+ helper SourceHelper
verify :method => :post, :only => [:create_violation]
load_extensions()
if @extension
- if (@extension.getId()=='violations')
+ if @extension.getId()=='violations'
render_violations()
elsif (@extension.getId()=='coverage')
render_coverage()
end
# Ajax request to display a form to create a review anywhere in source code
- #
- #== Parameters
- #
- # * 'resource'
- # * 'line'
def show_create_violation_form
@line = params[:line].to_i
@colspan = params[:colspan].to_i
+ @from = params[:from]
render :partial => 'resource/create_violation_form'
end
def create_violation
resource = Project.by_key(params[:resource])
access_denied unless resource && current_user
- rule = Review.find_or_create_rule(params[:category])
- violation = RuleFailure.create_manual!(resource, rule, params)
- violation.create_review!(
+
+ bad_request('Empty rule') if params[:category].blank?
+ bad_request('Empty message') if params[:message].blank?
+ bad_request('Missing severity') if params[:severity].blank?
+
+ Review.transaction do
+ rule = Review.find_or_create_rule(params[:category])
+ violation = RuleFailure.create_manual!(resource, rule, params)
+ violation.create_review!(
:assignee => current_user,
:user => current_user,
:status => Review::STATUS_OPEN,
:manual_violation => true)
- redirect_to :action => 'index', :id => resource.id
+ end
+
+ if params[:from]=='drilldown'
+ render :js => "d(#{resource.id})"
+ else
+ render :update do |page|
+ page.redirect_to :controller => 'resource', :action => 'index', :id => resource.key, :tab => 'violations'
+ end
+ end
end
private
end
end
- if !params[:tab].blank?
+ if params[:tab].present?
@extension=@extensions.find { |extension| extension.getId()==params[:tab] }
- elsif !params[:metric].blank?
+ elsif !params[:metric].blank?
metric=Metric.by_key(params[:metric])
@extension=@extensions.find { |extension| extension.getDefaultTabForMetrics().include?(metric.key) }
end
param_id_value = param_value
unless param_id_value.blank?
- user = User.find(:all, :conditions => [ "login = ?", param_id_value ]).first
+ user = User.find(:first, :conditions => [ "login = ?", param_id_value ])
param_displayed_value = user.name if user
param_displayed_value += " (#{message('me').downcase})" if user && current_user && current_user.login == param_id_value
end
end
def self.exception_message(exception)
- result = (exception.respond_to?(:message) ? "#{exception.message}\n" : "#{message}\n")
+ result = (exception.respond_to?(:message) ? "#{exception.message}\n" : "#{exception}\n")
if exception.respond_to? :backtrace
result << "\t" + exception.backtrace.join("\n\t") + "\n"
end
-<%= render :partial => 'resource/javascript' -%>
+<%= render :partial => 'resource/javascript', :locals => {:from => 'drilldown'} -%>
<%= render :partial => 'header' -%>
<% if params[:period] && @snapshot.project_snapshot.periods? %>
-<%= render :partial => 'resource/javascript' -%>
+<%= render :partial => 'resource/javascript', :locals => {:from => 'drilldown'} -%>
<%= render :partial => 'header' -%>
-
<div id="snapshot_title" class="page_title">
<h4>
<%
<%= javascript_include_tag 'protovis-sonar' %>
<%= javascript_include_tag 'duplications' %>
<% end %>
-<!--[if lte IE 6]>
-<link href="<%= ApplicationController.root_context -%>/ie6/index" media="all" rel="stylesheet" type="text/css" />
-<![endif]-->
-<!--[if lt IE 9]>
-<%= javascript_include_tag 'protovis-msie-shim' -%>
-<![endif]-->
+<!--[if lte IE 6]><link href="<%= ApplicationController.root_context -%>/ie6/index" media="all" rel="stylesheet" type="text/css" /><![endif]-->
+<!--[if lte IE 8]><%= javascript_include_tag 'protovis-msie' -%><![endif]-->
<link rel="shortcut icon" type="image/x-icon" href="<%= image_path('favicon.ico') -%>" />
<%
if @project %>
<td class="nothing"></td>
<% end %>
<td class="violations">
- <form action="<%= ApplicationController.root_context -%>/resource/create_violation" method="POST">
+ <% form_remote_tag :url => "#{ApplicationController.root_context}/resource/create_violation", :failure => "$('errorViolationForm#{@line}').update(request.responseText);$('errorViolationForm#{@line}').show()" do -%>
<input type="hidden" name="resource" value="<%= params[:resource] -%>">
<input type="hidden" name="line" value="<%= @line -%>">
+ <input type="hidden" name="from" value="<%= @from -%>">
<div class="violation">
<div class="vtitle">
- <select name="severity">
+ <select name="severity" class="withIcons">
<% Severity::SEVERITIES.each do |severity| %>
- <option value="<%= severity -%>" <%= 'selected' if severity==Severity::MAJOR -%>><%= message("severity.#{severity}") -%></option>
+ <option class="sev_<%= severity -%>" value="<%= severity -%>" <%= 'selected' if severity==Severity::MAJOR -%>><%= message("severity.#{severity}") -%></option>
<% end %>
</select>
- <img src="/dev/images/sep12.png">
+ <img src="<%= ApplicationController.root_context -%>/images/sep12.png">
- Rule: <input type="text" name="category" size="50" maxlength="50">
+ Rule: <input type="text" name="category" size="80">
</div>
<div class="discussionComment first">
- <textarea name="message" class="width100"></textarea>
- <br/>
+ <table class="width100">
+ <tr>
+ <td style="vertical-align:top">
+ <textarea rows="5" name="message" style="width: 100%"></textarea>
+ </td>
+ <td class="sep"></td>
+ <td style="vertical-align:top;width: 90px">
+ <%= render :partial => 'markdown/help' -%>
+ </td>
+ </tr>
+ </table>
+ <div class="error" id="errorViolationForm<%= @line-%>" style="display: none"></div>
<input type="submit" value="Create Violation"> <a href="#" onclick="return hVF(<%= @line -%>)">Cancel</a>
</div>
</div>
- </form>
+ <% end %>
</td>
</tr>
\ No newline at end of file
'pos' + line,
'<%= ApplicationController.root_context -%>/resource/show_create_violation_form',
{
- parameters: {resource: resource, line: line, colspan: colspan},
+ parameters: {resource: resource, line: line, colspan: colspan, from: '<%= from -%>'},
asynchronous:true,
insertion: 'after'
});
<ul class="tabs" >
<% if request.xhr? %>
<% @extensions.each do |extension| %>
- <li><a href="#" onclick="loadAjaxTab('<%= @resource.id -%>','<%= extension.getId() -%>',<%= display_title -%>)" class="<%= 'selected' if @extension && @extension.getId()==extension.getId() -%>"><%= message(extension.getId() + '.page', :default => extension.getTitle()) %></a></li>
+ <li><a href="#" onclick="return loadAjaxTab('<%= @resource.id -%>','<%= extension.getId() -%>',<%= display_title -%>)" class="<%= 'selected' if @extension && @extension.getId()==extension.getId() -%>"><%= message(extension.getId() + '.page', :default => extension.getTitle()) %></a></li>
<% end %>
<% else %>
<script>function loadTab(url) {$('resource-loading').show();document.location.href=url;return false;}</script>
<% @extensions.each do |extension| %>
- <li><a href="#" onClick="loadTab('<%= url_for(:overwrite_params => {:tab => extension.getId(), :metric => nil}) -%>')" class="<%= 'selected' if @extension && @extension.getId()==extension.getId() -%>"><%= message(extension.getId() + '.page', :default => extension.getTitle()) %></a></li>
+ <li><a href="#" onClick="return loadTab('<%= url_for(:overwrite_params => {:tab => extension.getId(), :metric => nil}) -%>')" class="<%= 'selected' if @extension && @extension.getId()==extension.getId() -%>"><%= message(extension.getId() + '.page', :default => extension.getTitle()) %></a></li>
<% end %>
<% end %>
<li>
<%= render :partial => 'tabs' -%>
-<%= render :partial => 'resource/javascript' -%>
+<%= render :partial => 'resource/javascript', :locals => {:from => 'resource'} -%>
<%= render :partial => "resource/header_#{@extension.getId()}" -%>
<% if @display_violations && @global_violations && @global_violations.size>0 -%>