+++ /dev/null
-#
-# SonarQube, open source software quality management tool.
-# Copyright (C) 2008-2014 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# SonarQube is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# SonarQube is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-class AlertsController < ApplicationController
-
- SECTION=Navigation::SECTION_QUALITY_PROFILES
-
- #
- #
- # GET /alerts/index/<profile_id>
- #
- #
- def index
- require_parameters :id
- @profile = Profile.find(params[:id])
- @alerts = @profile.valid_alerts.sort
- @alert=Alert.new
- add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language), {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
- end
-
- #
- #
- # GET /alerts/show/<alert id>
- #
- #
- def show
- require_parameters :id
- @alert = @profile.alerts.find(params[:id])
- end
-
- #
- #
- # GET /alerts/new?profile_id=<profile id>
- #
- #
- def new
- access_denied unless has_role?(:profileadmin)
- require_parameters :profile_id
- @profile = Profile.find(params[:profile_id])
- @alert = @profile.alerts.build(params[:alert])
- render :partial => 'new', :status => 200
- end
-
-
- #
- #
- # GET /alerts/edit/<alert id>
- #
- #
- def edit
- access_denied unless has_role?(:profileadmin)
- require_parameters :id
- @alert = @profile.alerts.find(params[:id])
- end
-
-
- #
- #
- # POST /alerts/create?profile_id=<profile id>&...
- #
- #
- def create
- verify_post_request
- access_denied unless has_role?(:profileadmin)
- require_parameters :profile_id
- @profile = Profile.find(params[:profile_id])
- params[:alert][:period] = nil if params[:alert][:period] == '0'
- @alert = @profile.alerts.build(params[:alert])
-
- if @alert.save
- reportGlobalModification
- flash[:notice] = message('alerts.alert_created')
- render :text => 'ok', :status => 200
- else
- @alerts = @profile.alerts.reload
- errors = []
- @alert.errors.full_messages.each{|msg| errors<<CGI.escapeHTML(msg) + '<br/>'}
- render :text => errors, :status => 404
- end
- end
-
- #
- #
- # POST /alerts/update/<alert id>?profile_id=<profile id>
- #
- #
- def update
- verify_post_request
- access_denied unless has_role?(:profileadmin)
- require_parameters :profile_id, :id
- @profile = Profile.find(params[:profile_id])
- params[:alert][:period] = nil if params[:alert][:period] == '0'
- @alerts=@profile.alerts
- alert = @alerts.find(params[:id])
-
- if alert.update_attributes(params[:alert])
- reportGlobalModification
- flash[:notice] = message('alerts.alert_updated')
- render :text => 'ok', :status => 200
- else
- errors = []
- alert.errors.full_messages.each{|msg| errors<<CGI.escapeHTML(msg) + '<br/>'}
- render :text => errors, :status => 404
- end
- end
-
- #
- #
- # POST /alerts/delete/<alert id>?profile_id=<profile id>
- #
- #
- def delete
- verify_post_request
- access_denied unless has_role?(:profileadmin)
- require_parameters :profile_id, :id
- @profile = Profile.find(params[:profile_id])
- @alert = @profile.alerts.find(params[:id])
- @alert.destroy
- reportGlobalModification
- flash[:notice] = message('alerts.alert_deleted')
- redirect_to(:action => 'index', :id=>@profile.id)
- end
-
- private
-
- def reportGlobalModification
- Property.set(Java::OrgSonarCorePreview::PreviewCache::SONAR_PREVIEW_CACHE_LAST_UPDATE_KEY, java.lang.System.currentTimeMillis)
- end
-
-end
+++ /dev/null
-<%= form_tag({:action => 'update', :id => alert.id, :profile_id => @profile.id}, :id => "edit_alert_#{alert.id}") %>
-<table>
-<tr>
- <td nowrap>
- <%= h alert.name %>
- </td>
- <td width="10%" nowrap>
- <select id="alert_period_<%= alert.id %>" name="alert[period]">
- <%= period_select_options(alert) -%>
- </select>
- </td>
- <td width="10%" nowrap>
- <select id="alert_operator_<%= alert.id %>" name="alert[operator]">
- <% operators_for_select(alert).each do |key| %>
- <option value="<%= key -%>" <%= 'selected' if alert.operator==key -%>><%= message("alerts.operator.#{key}") -%></option>
- <% end %>
- </select>
- </td>
- <td width="15%" align="left">
- <i class="icon-alert-warn" title="<%= message('alerts.warning_tooltip') -%>"></i>
- <%= value_field(alert, alert.value_warning, 'alert[value_warning]') %> <%= alert.metric.suffix if alert.metric %>
- </td>
- <td width="15%" align="left">
- <i class="icon-alert-error" title="<%= message('alerts.error_tooltip') -%>"></i>
- <%= value_field(alert, alert.value_error, 'alert[value_error]') %> <%= alert.metric.suffix if alert.metric %>
- </td>
- <td width="120px" nowrap>
- <input id="alert_submit" type="submit" value="<%= message('update_verb') -%>"/>
- <%= link_to message('delete'), {:action => 'delete', :id => alert.id, :profile_id =>@profile.id}, :confirm => message('are_you_sure'), :method => :post, :class => 'action', :id => "delete_#{u alert.name}" %>
- </td>
-</tr>
-</table>
-<div id="alert_error_<%= alert.id -%>" class="error hidden" style="margin: 5px;"/>
-</form>
-
-<script type="text/javascript">
- $j(document).ready(function () {
- ajaxForm("edit_alert_<%= alert.id -%>", "alert_error_<%= alert.id -%>");
- });
-
- $j('#alert_period_<%= alert.id %>').select2({
- allowClear: false,
- minimumResultsForSearch: 10,
- width: '200px'
- });
-
- $j('#alert_operator_<%= alert.id %>').select2({
- allowClear: false,
- minimumResultsForSearch: 10,
- width: '150px'
- });
-</script>
+++ /dev/null
-<h3><%= message('alerts.create_alert') -%></h3>
-<%= form_tag({:action => 'create', :profile_id => @profile.id}, :id => 'new_alert_form') -%>
-<table class="spaced">
-<tr>
- <td valign="top">
- <select id="alert_metric_id" name="alert[metric_id]">
- <option value="" <%= 'selected' if @alert.metric.nil? %>></option>
- <% Metric.domains.each do |domain| %>
- <optgroup label="<%= h domain -%>">
- <% Metric.by_domain(domain).select{ |m| m.alertable? }.each do |metric| %>
- <option value="<%= metric.id -%>" <%= 'selected' if @alert.metric_id==metric.id -%>><%= metric.short_name %></option>
- <% end %>
- </optgroup>
- <% end %>
- </select>
- </td>
-
- <td width="10%" valign="top" class="alert_fields">
- <select id="alert_period" name="alert[period]">
- <%= period_select_options(@alert) -%>
- </select>
- </td>
-
- <td width="10%" valign="top" class="alert_fields">
- <select id="alert_operator" name="alert[operator]">
- <%
- default_op=default_operator(@alert)
- operators_for_select(@alert).each do |key| %>
- <option value="<%= key -%>" <%= 'selected' if default_op==key -%>><%= message("alerts.operator.#{key}") -%></option>
- <% end %>
- </select>
- </td>
-
- <td width="15%" valign="top" class="alert_fields">
- <i class="icon-alert-warn" title="<%= message('alerts.warning_tooltip') -%>"></i>
- <%= value_field(@alert, '', 'alert[value_warning]') %>
- <%= @alert.metric.suffix if @alert.metric %><br/>
- <span class="note"><%= message('alerts.warning_threshold') -%></span>
- </td>
-
- <td width="15%" valign="top" class="alert_fields">
- <i class="icon-alert-error" title="<%= message('alerts.error_tooltip') -%>"></i>
- <%= value_field(@alert, '', 'alert[value_error]') %>
- <%= @alert.metric.suffix if @alert.metric %><br/>
- <span class="note"><%= message('alerts.error_threshold') -%></span>
- </td>
-
- <td width="120px" nowrap valign="top" class="alert_fields">
- <input type="submit" value="<%= message('create') -%>" id="submit_create"/>
- </td>
-</tr>
-</table>
-<div id="alert_error" class="error hidden" style="margin: 5px;"/>
-</form>
-
-<script type="text/javascript">
-
- $j(document).ready(function () {
- ajaxForm("new_alert_form", "alert_error");
- });
-
- <% if @alert.metric.nil? -%>
- $j('.alert_fields').hide();
- <% else -%>
- $j('.alert_fields').show();
- <% end %>
-
- $j('#alert_metric_id').select2({
- allowClear: false,
- width: '250px',
- placeholder: '<%= message('alerts.select_metric') -%>'
- });
-
- $j('#alert_metric_id').change(function (event) {
- metricId = $j('#alert_metric_id').val();
- $j.ajax({
- type: 'POST',
- url: "<%= ApplicationController.root_context -%>/alerts/new?profile_id=<%= @profile.id -%>&alert[metric_id]="+ metricId,
- success: function (data) {
- $j("#new_alert_content").html(data);
- }
- });
- return false;
- });
-
- $j('#alert_period').select2({
- allowClear: false,
- minimumResultsForSearch: 10,
- width: '200px'
- });
-
- $j('#alert_operator').select2({
- allowClear: false,
- minimumResultsForSearch: 10,
- width: '150px'
- });
-
-</script>
-
-
+++ /dev/null
-<table class="spaced">
-<tr>
- <td>
- <%= h alert.name %>
- </td>
- <td width="10%">
- <%= period_label(alert) -%>
- </td>
- <td width="10%">
- <%= message("alerts.operator.#{alert.operator}") -%>
- </td>
- <td width="20%">
- <% if alert.metric && !alert.value_warning.blank? %>
- <i class="icon-alert-warn" title="<%= message('alerts.warning_tooltip') -%>"></i>
- <%= alert.value_warning %> <%= alert.metric.suffix if alert.metric %>
- <% end %>
- </td>
- <td width="20%">
- <% if alert.metric && !alert.value_error.blank? %>
- <i class="icon-alert-error" title="<%= message('alerts.error_tooltip') -%>"></i>
- <%= alert.value_error %> <%= alert.metric.suffix %>
- <% end %>
- </td>
- <td width="120px" nowrap>
-
- </td>
-</tr>
-</table>
+++ /dev/null
-<h1><%= message('alerts.editing_alert') -%></h1>
-
-<% form_for([@profile, @alert]) do |f| %>
- <%= f.error_messages %>
-
- <p>
- <%= f.label :profile_id %><br />
- <%= f.text_field :profile_id %>
- </p>
- <p>
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </p>
- <p>
- <%= f.submit message('update_verb') %>
- </p>
-<% end %>
-
-<%= link_to message('show_verb'), [@profile, @alert] %> |
-<%= link_to message('back'), profile_alerts_path(@profile) %>
+++ /dev/null
-<div class="page">
-<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Alerts'} %>
-
-<% if profiles_administrator? %>
- <div class="tabs-panel marginbottom10">
- <div id="new_alert_content">
- <%= render :partial => 'new' -%>
- </div>
- </div>
-<% else %>
- <div class="break10"> </div>
-<% end %>
-
-<% if @alerts.empty? %>
-<p id="alerts"><%= message('alerts.no_alerts') -%></p>
-<% else %>
-
- <table class="data width100 marginbottom10 spaced" id="alerts">
- <thead><tr><th></th></tr></thead>
- <tbody>
- <% for alert in @alerts %>
- <tr class="<%= cycle('even','odd') -%>">
- <td id="row_alert_<%= alert.id -%>">
- <% if profiles_administrator? %>
- <%= render :partial => 'edit', :locals => {:alert => alert} %>
- <% else %>
- <%= render :partial => 'show', :locals => {:alert => alert} %>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
-<% end %>
-
-<br/>
-<div class="help">
-<h3>Notes</h3>
-<%= message('alerts.notes.description') -%>
-<table class="data">
-<thead>
-<tr><th colspan="3"></th></tr>
-</thead>
-<tbody>
-<tr class="even"><td><i class="icon-alert-ok"></i></td><td> <%= message('alerts.notes.ok') -%></td></tr>
-<tr class="odd"><td><i class="icon-alert-warn"></i></td><td> <%= message('alerts.notes.warn') -%></td></tr>
-<tr class="even"><td><i class="icon-alert-error"></i></td><td> <%= message('alerts.notes.error') -%></td></tr>
-</tbody>
-</table>
-</div>
-
-<script>
- function ajaxForm(formId, errorId){
- var obj = $j("#"+ formId);
- obj.submit(function (event) {
- $j.ajax({
- type: 'POST',
- url: obj.attr('action'),
- data: obj.serialize(),
- success: function (data) {
- window.location.reload();
- },
- error: function (xhr, textStatus, errorThrown) {
- $j("#"+ errorId).removeClass("hidden");
- $j("#"+ errorId).html(xhr.responseText);
- }
- });
- return false;
- });
- }
-
-</script>
-</div>
+++ /dev/null
-<h1><%= message('alerts.new_alert') -%></h1>
-
-<% form_for([@profile, @alert]) do |f| %>
- <%= f.error_messages %>
-
- <p>
- <%= f.label :profile_id %><br />
- <%= f.text_field :profile_id %>
- </p>
- <p>
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </p>
- <p>
- <%= f.submit message('create') %>
- </p>
-<% end %>
-
-<%= link_to message('back'), profile_alerts_path(@profile) %>
+++ /dev/null
-<p>
- <b><%= message('profile') -%>:</b>
- <%=h @alert.profile_id %>
-</p>
-
-<p>
- <b><%= message('name') -%>:</b>
- <%=h @alert.name %>
-</p>
-
-
-<%= link_to message('edit'), edit_profile_alert_path(@profile, @alert) %> |
-<%= link_to message('back'), profile_alerts_path(@profile) %>
<li>
<a href="<%= url_for :controller => 'rules_configuration', :action => 'index', :id => @profile.id %>" <%= "class='selected'" if selected_tab=='Coding rules' -%> id="tab-rules"><%= message('coding_rules') -%></a>
</li>
- <li>
- <a href="<%= url_for :controller => 'alerts', :action => 'index', :id => @profile.id -%>" <%= "class='selected'" if selected_tab=='Alerts' -%> id="tab-alerts"><%= message('alerts') -%></a>
- </li>
<li>
<a href="<%= url_for :controller => 'profiles', :action => 'projects', :id => @profile.id -%>" <%= "class='selected'" if selected_tab=='Projects' -%> id="tab-projects"><%= message('projects') -%></a>
</li>
<tr>
<th class="left"><%= message('name') -%></th>
<th class="right"><%= message('rules') -%></th>
- <th class="right"><%= message('alerts') -%></th>
<th class="right"><%= message('projects') -%></th>
<th class="right"><%= message('default') -%></th>
<% if profiles_administrator? %>
<tbody>
<% @profiles.select { |p| p.language == language.getKey() }.each do |profile|
key = profile_key(profile)
- alerts_count = alerts_count(profile)
projects_count = projects_count(profile)
profile_rules_count = profile_rules_count(profile)
is_default_profile = !default_profile.nil? && (default_profile.name() == profile.name())
<span id="activated_rules_<%= u key -%>"><%= profile_rules_count -%></span>
</td>
- <td align="right" width="10%"><span id="alerts_<%= u key -%>"><%= alerts_count -%></span></td>
-
<td align="right" width="10%" nowrap>
<% unless is_default_profile %>
<span id="projects_<%= u key -%>"><%= projects_count -%></span>