has_many :alerts, :dependent => :delete_all
has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule']
has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :include => ['active_rule_parameters', 'active_rule_note']
- has_many :projects, :class_name => 'Project', :finder_sql => %q(
- select prj.* from projects prj, properties prop where prj.id=prop.resource_id and prop.resource_id is not null and prop.prop_key='sonar.profile.#{language}' and prop.text_value='#{name}'
- )
has_many :changes, :class_name => 'ActiveRuleChange', :dependent => :destroy
has_many :children, :class_name => 'Profile', :finder_sql => %q(
select c.* from rules_profiles c where c.parent_name='#{name}' and c.language='#{language}'
self
end
+ def projects?
+ !projects.empty?
+ end
+
+ def projects
+ @projects ||=
+ begin
+ Project.find(:all,
+ :conditions => ['id in (select prop.resource_id from properties prop where prop.resource_id is not null and prop.prop_key=? and prop.text_value=?)', "sonar.profile.#{language}", name])
+ end
+ end
+
+ def sorted_projects
+ Api::Utils.insensitive_sort(projects){|p| p.name}
+ end
+
def add_project_id(project_id)
Property.set("sonar.profile.#{language}", name, project_id)
+ @projects = nil
end
def remove_projects
Property.clear_for_resources("sonar.profile.#{language}", name)
+ @projects = nil
end
def self.reset_default_profile_for_project_id(lang, project_id)
})</script>
</form>
- <% unless @profile.projects.empty? %>
- <table class="data">
+ <% if @profile.projects? %>
+ <table class="data" id="projects-table">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
- <% @profile.projects.each do |project| %>
+ <% @profile.sorted_projects.each do |project| %>
<tr class="<%= cycle('even', 'odd') -%>">
<td class="thin">
<%= link_to_action message('remove'),
</tr>
</tfoot>
</table>
-
-
<% end %>
<% else %>
- <% if @profile.projects.empty? %>
+ <% if !@profile.projects? %>
<p><%= message('quality_profiles.no_projects_associated_to_profile_x', :params => @profile.name) -%></p>
<% else %>
<p><%= message('quality_profiles.projects_warning') -%></p>
</tr>
</thead>
<tbody>
- <% @profile.projects.each do |project| %>
+ <% @profile.sorted_projects.each do |project| %>
<tr class="<%= cycle('even', 'odd') -%>">
<td><%= h project.name -%> <span class="small gray"><%= h project.key -%></span></td>
</tr>