ANY_SELECTION = []
RULE_PRIORITIES = Sonar::RulePriority.as_options.reverse
- def index
- require_parameters :id
-
- call_backend do
- @profile = Internal.quality_profiles.profile(params[:id].to_i)
- not_found('Profile not found') unless @profile
- @parent_profile = Internal.quality_profiles.parent(@profile) if @profile.parent()
-
- add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
- {:name => @profile.name, :url => {:controller => 'rules_configuration', :action => 'index', :id => @profile.id}}
-
- init_params
- @criteria_params = criteria_params
- stop_watch = Internal.profiling.start("rules", "BASIC")
-
- @pagination = Api::Pagination.new(params)
- paging = Java::OrgSonarServerPaging::Paging.create(@pagination.per_page.to_i, @pagination.page.to_i)
-
- criteria = init_criteria
- query = Java::OrgSonarServerQualityprofile::ProfileRuleQuery::parse(criteria.to_java)
- if @activation==STATUS_ACTIVE
- result = Internal.quality_profiles.searchProfileRules(query, paging)
- else
- result = Internal.quality_profiles.searchInactiveProfileRules(query, paging)
- end
-
- @pagination.count = result.paging.total
- unless @searchtext.blank? && @tags.empty?
- if @activation == STATUS_ACTIVE
- @hidden_inactives = Internal.quality_profiles.countInactiveProfileRules(query)
- else
- @hidden_actives = Internal.quality_profiles.countProfileRules(query)
- end
- end
- stop_watch.stop("found #{@pagination.count} rules with criteria #{criteria.to_json}, displaying #{@pagination.per_page} items")
-
- @current_rules = result.rules
-
- @select_repositories = ANY_SELECTION + java_facade.getRuleRepositoriesByLanguage(@profile.language).collect { |repo| [repo.name(), repo.key()] }.to_a.sort
- @select_priority = ANY_SELECTION + RULE_PRIORITIES
- @select_activation = [[message('active'), STATUS_ACTIVE], [message('inactive'), STATUS_INACTIVE]]
- @select_inheritance = [[message('any'), 'any'], [message('rules_configuration.not_inherited'), 'NOT'], [message('rules_configuration.inherited'), 'INHERITED'],
- [message('rules_configuration.overrides'), 'OVERRIDES']]
- @select_status = ANY_SELECTION + [[message('rules.status.beta'), Rule::STATUS_BETA],
- [message('rules.status.deprecated'), Rule::STATUS_DEPRECATED],
- [message('rules.status.ready'), Rule::STATUS_READY]]
- @select_sort_by = [[message('rules_configuration.rule_name'), Rule::SORT_BY_RULE_NAME], [message('rules_configuration.creation_date'), Rule::SORT_BY_CREATION_DATE]]
- @select_tags = ANY_SELECTION + Internal.rule_tags.listAllTags().to_a.sort
- end
- end
-
#
#
+++ /dev/null
-<div class="page">
-<script>
- var localModifications=false;
-
- function get_level_for_rule(rule_select_box,rule_check_box) {
- return rule_check_box.prop('checked') ? rule_select_box.val() : '';
- }
-
- function submitBulkForm() {
- if (localModifications) {
- alert("Please refresh the search results before.");
- $j('#bulk-form').reset();
- } else {
- $j('#bulk-form').submit();
- $j('#select-bulk-change').select2('disable');
- }
- return !localModifications;
- }
-
- function expand_rules(){
- $j('.rule-desc').show();
- }
-
- function collapse_rules(){
- $j('.rule-desc').hide();
- }
-
- function submitSearch() {
- $j("#rules-search-form").submit();
- }
-
- function submitSortBy(){
- $j('#sort_by').val($j('#select-rules-sort-by').val());
- $j("#rules-search-form").submit();
- }
-</script>
-<%= render :partial => 'profiles/tabs', :locals => {:selected_tab=>'Coding rules'} %>
-
-<% enable_modification = profiles_administrator? %>
-<div class="tabs-panel marginbottom10 background-gray">
-
-<% form_tag({:action => 'index'}, {:id => 'rules-search-form', :method => 'get'}) do %>
- <%= hidden_field_tag "sort_by", @sort_by, :id => 'sort_by' %>
-
- <div class="table" id="search_table">
- <div class="rule-search top">
- <span class="note"><%= message('name') -%>/<%= message('key') -%></span><br/>
- <%= text_field_tag "searchtext", @searchtext, :id => 'searchtext' %>
- </div>
- <div class="rule-search top">
- <span class="note"><%= message('rules_configuration.repository') -%></span><br/>
- <%= dropdown_tag "repositories", options_for_select(@select_repositories, @repositories), {
- :show_search_box => true,
- :width => '120px',
- :placeholder => message('any')
- }, {:id => 'search_repository', :multiple => true} -%>
- </div>
- <div class="rule-search top">
- <span class="note"><%= message('severity') -%></span><br/>
- <%= dropdown_tag "priorities", options_for_select(@select_priority, @priorities), {
- :show_search_box => true,
- :width => '90px',
- :placeholder => message('any')
- }, {:id => 'search_priority', :multiple => true} -%>
- </div>
- <div class="rule-search top">
- <span class="note"><%= message('activation') -%></span><br/>
- <%= dropdown_tag "rule_activation", options_for_select(@select_activation, @activation), {
- :width => '100px'
- }, {:id => 'search_activation'} -%>
- </div>
- <div class="rule-search top">
- <span class="note"><%= message('rules_configuration.status_filters') -%></span><br/>
- <%= dropdown_tag "status", options_for_select(@select_status, @status), {
- :show_search_box => true,
- :width => '120px',
- :placeholder => message('any')
- }, {:id => 'search_status', :multiple => true} -%>
- </div>
- <% if @profile.isInherited() %>
- <div class="rule-search top">
- <span class="note"><%= message('inheritance') -%></span><br/>
- <%= dropdown_tag "inheritance", options_for_select(@select_inheritance, @inheritance), {
- :width => '120px'
- }, {:id => 'search_inheritance'} -%>
- </div>
- <% end %>
- <div class="rule-search top">
- <span class="note"><%= message('rules_configuration.tags_filters') -%></span><br/>
- <%= dropdown_tag "tags", options_for_select(@select_tags, @tags), {
- :show_search_box => true,
- :width => '120px',
- :placeholder => message('any')
- }, {:id => 'search_tag', :multiple => true} -%>
- </div>
- <div class="rule-search">
- <br/>
- <%= submit_tag message('search_verb'), :id => 'submit_search', :onclick => 'submitSearch();' %>
- </div>
- </div>
-
-<% end %>
-</div>
-<div class="line-block marginbottom10">
- <% if enable_modification && @current_rules.size>0 %>
- <ul style="float: right" class="horizontal">
- <li class="marginleft10">
- <div class="bulk-edit"><i class="icon-bulk-change"></i> <%= message('bulk_change') -%>:
- <form action="<%= ApplicationController.root_context -%>/rules_configuration/bulk_edit?<%= @criteria_params.to_query -%>" method="POST" id="bulk-form"
- style="display: inline; vertical-align: middle; padding-right:5px">
- <input type="hidden" name="id" value="<%= @profile.id -%>"/>
- <%= dropdown_tag "bulk_action", options_for_select([ ["", ""], [message('activate_all'), "activate"], [message('deactivate_all'), "deactivate"] ], ''), {
- :width => '110px'
- }, {:onChange => 'submitBulkForm()', :id => 'select-bulk-change'} -%>
- </form>
- </div>
- </li>
- </ul>
- <% end %>
- <h2>
- <% if @hidden_actives && @hidden_actives>0 %>
- <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'ACTIVE'}) -%>"
- id="active-rules-link">+<%= message('rules_configuration.x_found_in_active_rules', :params => @hidden_actives) -%></a></span><% end %>
- <% if @hidden_inactives && @hidden_inactives>0 %>
- <span class="small"><a href="<%= url_for params.merge({:rule_activation => 'INACTIVE'}) -%>"
- id="inactive-rules-link">+<%= message('rules_configuration.x_found_in_inactive_rules', :params => @hidden_inactives) -%></a></span><% end %>
- </h2>
-</div>
-<table class="table table-bordered width100 spacer-bottom" id="result_table">
- <thead>
- <tr>
- <th class="left" nowrap><%= message('active') -%>/<%= message('severity') -%></th>
- <th class="left"><%= message('name') -%> <span style="font-weight: normal">
- [<%= link_to_function(message('rules_configuration.expand'), "expand_rules()") %> / <%= link_to_function(message('rules_configuration.collapse'), "collapse_rules()") %>]</span></th>
- <th class="right" nowrap>
- <span class="middle"><%= message('rules_configuration.sort_by') -%></span>
- <% form_tag({:action => 'index'}, :class=> 'middle', :style => 'display:inline-block') do %>
- <%= dropdown_tag "sort_by", options_for_select(@select_sort_by, @sort_by), {
- :width => '120px'
- }, {:id => 'select-rules-sort-by', :onChange => 'submitSortBy()'} -%>
- <% end %>
- </th>
- </tr>
-</thead>
-
-<%= table_pagination(@pagination, :colspan => 2) { |label, page_id| link_to(label, params.merge({:page => page_id}))} -%>
-
-<tbody>
-<% if @current_rules.empty? %>
-<tr><td colspan="3" class="even"><%= message('no_results') -%>.</td></tr>
-<% end %>
-<%
- @current_rules.each do |rule|
-%>
- <tr id="rule_<%= rule.id -%>">
- <%= render :partial => 'rule', :object => rule, :locals => {:rule => rule, :profile => @profile, :parent_profile => @parent_profile} %>
- </tr>
-<% end %>
-</tbody>
-</table>
-</div>