Commit f874f0c2e9256d394277946a06f08e9db8c7fcea

Authored by Victor Costa
2 parents 50a6abe6 696acea8

Merge branch 'rails3_stable' of gitlab.com:participa/noosfero into rails3_stable

plugins/serpro_integration/lib/ext/community.rb
... ... @@ -3,8 +3,8 @@ require_dependency 'community'
3 3 class Community
4 4  
5 5 settings_items :allow_sonar_integration, :type => :boolean, :default => false
6   - settings_items :allow_gitlab_integration, :type => :boolean, :default => false
7   - settings_items :allow_jenkins_integration, :type => :boolean, :default => false
  6 + settings_items :allow_gitlab_integration, :type => :boolean, :default => true
  7 + settings_items :allow_jenkins_integration, :type => :boolean, :default => true
8 8  
9 9 settings_items :serpro_integration_plugin_gitlab, :type => Hash, :default => {}
10 10 settings_items :serpro_integration_plugin_jenkins, :type => Hash, :default => {}
... ... @@ -12,10 +12,9 @@ class Community
12 12  
13 13 attr_accessible :allow_unauthenticated_comments, :allow_gitlab_integration, :allow_sonar_integration, :allow_jenkins_integration, :serpro_integration_plugin_gitlab, :serpro_integration_plugin_jenkins, :serpro_integration_plugin_sonar
14 14  
15   - before_update :create_integration_projects
  15 + after_create :create_integration_projects, :if => lambda { |c| c.allow_serpro_integration?}
16 16  
17 17 def create_integration_projects
18   - return unless setting_changed?(:serpro_integration_plugin_gitlab)
19 18  
20 19 if allow_gitlab_integration
21 20 gitlab_integration = SerproIntegrationPlugin::GitlabIntegration.new(gitlab_host, gitlab_private_token)
... ... @@ -68,4 +67,10 @@ class Community
68 67 serpro_integration_plugin_jenkins[:project_name] || self.identifier
69 68 end
70 69  
  70 + def allow_serpro_integration?
  71 + return false if serpro_integration_plugin_settings.communities.blank? || serpro_integration_plugin_settings.communities[:templates].blank?
  72 + allow = serpro_integration_plugin_settings.communities[:templates].include?(self.id.to_s)
  73 + allow || serpro_integration_plugin_settings.communities[:templates].include?(self.template_id.to_s)
  74 + end
  75 +
71 76 end
... ...
plugins/serpro_integration/lib/serpro_integration_plugin/smile_block.rb
... ... @@ -33,8 +33,10 @@ class SerproIntegrationPlugin::SmileBlock < Block
33 33 #FIXME make this test
34 34 def smile_factor
35 35 collect_sonar_information
36   - factor = (self.sonar_info[METRIC_COVERAGE] * self.sonar_info[METRIC_SUCCESS_DENSITY]).to_f/1000
37   - factor
  36 + factor = 0
  37 + if self.sonar_info[METRIC_COVERAGE] && self.sonar_info[METRIC_SUCCESS_DENSITY]
  38 + factor = (self.sonar_info[METRIC_COVERAGE] * self.sonar_info[METRIC_SUCCESS_DENSITY]).to_f/1000
  39 + end
38 40 end
39 41  
40 42 #FIXME make this test
... ...
plugins/serpro_integration/views/profile-editor-extras.html.erb
1   -<script>
2   -jQuery( document ).ready(function( $ ) {
3   - function toggle_checkbox_selectors(el) {
4   - if( el.is(':checked')) {
5   - $(el.data('selector')).show('fast');
6   - } else {
7   - $(el.data('selector')).hide('fast');
8   - }
9   - }
10   - $(".toggle_checkbox").click(function() {
11   - toggle_checkbox_selectors($(this));
12   - });
13   - $(".toggle_checkbox").each(function() {
14   - toggle_checkbox_selectors($(this));
15   - });
16   -});
17   -</script>
  1 +<% if profile.allow_serpro_integration? %>
  2 + <div id='serpro-integration'>
  3 + <h2><%= _('Serpro Integration') %></h2>
18 4  
19   -<div id='serpro-integration'>
20   - <h2><%= _('Serpro Integration') %></h2>
21   -
22   - <%= render :partial => 'gitlab' %>
23   - <%= render :partial => 'jenkins' %>
24   -
25   - <div id="sonar">
26   - <h3>
27   - <%= labelled_check_box('', 'profile_data[allow_sonar_integration]', true, profile.allow_sonar_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.sonar'}) %>
28   - <%= _('Sonar Integration') %>
29   - </h3>
30   - <ul class='sonar'>
31   - <li>
32   - <%= labelled_text_field(_('Server Host'), 'profile_data[serpro_integration_plugin_sonar][host]', profile.serpro_integration_plugin_sonar[:host]) %>
33   - </li>
34   - <li>
35   - <%= labelled_text_field(_('Project: '), 'profile_data[serpro_integration_plugin_sonar][project]', profile.serpro_integration_plugin_sonar[:project]) %>
36   - </li>
37   - </ul>
  5 + <%= render :partial => 'gitlab' %>
  6 + <%= render :partial => 'jenkins' %>
38 7 </div>
39   -
40   -</div>
  8 +<% end %>
... ...
plugins/serpro_integration/views/profile_editor/_gitlab.html.erb
1 1 <div id="gitlab">
2 2  
3 3 <h3>
4   - <%= labelled_check_box('', 'profile_data[allow_gitlab_integration]', true, profile.allow_gitlab_integration, {:class => "toggle_checkbox", 'data-selector' => "ul.gitlab"}) %>
5 4 <%= _('Gitlab Integration') %>
6 5 </h3>
7 6 <ul class="gitlab">
8 7 <li>
9 8 <span class="label"><%= _('Server Host:') %><span>
10 9 <span class="value"><%= profile.gitlab_host %><span>
  10 +<!-- FIXME put the force button to works
11 11 <%= link_to _('Force'), {:controller => 'serpro_integration_plugin_myprofile', :action => 'create_gitlab'}, {:remote => true} %>
  12 +-->
12 13 </li>
13 14 <li>
14 15 <%= labelled_text_field(_('Group Name:'), 'profile_data[serpro_integration_plugin_gitlab][group]', profile.gitlab_group) %>
... ...
plugins/serpro_integration/views/profile_editor/_jenkins.html.erb
1 1 <div id="jenkins">
2 2 <h3>
3   - <%= labelled_check_box('', 'profile_data[allow_jenkins_integration]', true, profile.allow_jenkins_integration, {:class => "toggle_checkbox", 'data-selector' => 'ul.jenkins'}) %>
4 3 <%= _('Jenkins Integration') %>
5 4 </h3>
6 5 <ul class='jenkins'>
... ...
plugins/serpro_integration/views/serpro_integration_plugin_admin/index.html.erb
... ... @@ -2,6 +2,13 @@
2 2  
3 3 <%= form_for(:settings) do |f| %>
4 4  
  5 + <div class="community_settings">
  6 + <h2><%= _('Community Templates')%></h2>
  7 + <%= f.fields_for :communities, OpenStruct.new(@settings.communities) do |g| %>
  8 + <%= labelled_form_field _('Communities where integrations will be applied'), g.select("templates", @environment.communities.templates.map{|t| [t.name, t.id]},{}, :multiple => true) %>
  9 + <% end %>
  10 + </div>
  11 +
5 12 <div class="gitlab_settings">
6 13 <h2><%= _('Gitlab Settings')%></h2>
7 14 <%= f.fields_for :gitlab, OpenStruct.new(@settings.gitlab) do |g| %>
... ...