Commit d02d6e2c7b7b4cd18e0de9930d0596c715198732
Exists in
master
and in
28 other branches
Merge branch 'master' into antispam
Conflicts: app/views/admin_panel/index.rhtml
Showing
245 changed files
with
10618 additions
and
5672 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 245 files displayed.
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +class LicensesController < AdminController | ||
2 | + protect 'manage_environment_licenses', :environment | ||
3 | + | ||
4 | + def index | ||
5 | + @licenses = environment.licenses | ||
6 | + end | ||
7 | + | ||
8 | + def create | ||
9 | + @license = License.new(params[:license]) | ||
10 | + if request.post? | ||
11 | + begin | ||
12 | + @license.environment = environment | ||
13 | + @license.save! | ||
14 | + session[:notice] = _('License created') | ||
15 | + redirect_to :action => 'index' | ||
16 | + rescue | ||
17 | + session[:notice] = _('License could not be created') | ||
18 | + end | ||
19 | + end | ||
20 | + end | ||
21 | + | ||
22 | + def edit | ||
23 | + @license = environment.licenses.find(params[:license_id]) | ||
24 | + if request.post? | ||
25 | + begin | ||
26 | + @license.update_attributes!(params[:license]) | ||
27 | + session[:notice] = _('License updated') | ||
28 | + redirect_to :action => 'index' | ||
29 | + rescue | ||
30 | + session[:notice] = _('License could not be updated') | ||
31 | + end | ||
32 | + end | ||
33 | + end | ||
34 | + | ||
35 | + def remove | ||
36 | + @license = environment.licenses.find(params[:license_id]) | ||
37 | + if request.post? | ||
38 | + begin | ||
39 | + @license.destroy | ||
40 | + session[:notice] = _('License removed') | ||
41 | + rescue | ||
42 | + session[:notice] = _('License could not be removed') | ||
43 | + end | ||
44 | + else | ||
45 | + session[:notice] = _('License could not be removed') | ||
46 | + end | ||
47 | + redirect_to :action => 'index' | ||
48 | + end | ||
49 | + | ||
50 | +end |
@@ -0,0 +1,52 @@ | @@ -0,0 +1,52 @@ | ||
1 | +class TemplatesController < AdminController | ||
2 | + protect 'manage_environment_templates', :environment | ||
3 | + | ||
4 | + def create_person_template | ||
5 | + if request.post? | ||
6 | + begin | ||
7 | + identifier = params[:name].to_slug | ||
8 | + password = Digest::MD5.hexdigest(rand.to_s) | ||
9 | + template = User.new(:login => identifier, :email => identifier+'@templates.noo', :password => password, :password_confirmation => password, :person_data => {:name => params[:name], :is_template => true}) | ||
10 | + template.save! | ||
11 | + session[:notice] = _('New template created') | ||
12 | + redirect_to :action => 'index' | ||
13 | + rescue | ||
14 | + @error = _('Name has already been taken') | ||
15 | + end | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
19 | + def create_community_template | ||
20 | + if request.post? | ||
21 | + begin | ||
22 | + create_organization_template(Community) | ||
23 | + session[:notice] = _('New template created') | ||
24 | + redirect_to :action => 'index' | ||
25 | + rescue | ||
26 | + @error = _('Name has already been taken') | ||
27 | + end | ||
28 | + end | ||
29 | + end | ||
30 | + | ||
31 | + def create_enterprise_template | ||
32 | + if request.post? | ||
33 | + begin | ||
34 | + create_organization_template(Enterprise) | ||
35 | + session[:notice] = _('New template created') | ||
36 | + redirect_to :action => 'index' | ||
37 | + rescue | ||
38 | + @error = _('Name has already been taken') | ||
39 | + end | ||
40 | + end | ||
41 | + end | ||
42 | + | ||
43 | + private | ||
44 | + | ||
45 | + def create_organization_template(klass) | ||
46 | + identifier = params[:name].to_slug | ||
47 | + template = klass.new(:name => params[:name], :identifier => identifier, :is_template => true) | ||
48 | + template.save! | ||
49 | + end | ||
50 | + | ||
51 | +end | ||
52 | + |
app/controllers/public/content_viewer_controller.rb
@@ -99,6 +99,14 @@ class ContentViewerController < ApplicationController | @@ -99,6 +99,14 @@ class ContentViewerController < ApplicationController | ||
99 | @images = @images.paginate(:per_page => per_page, :page => params[:npage]) unless params[:slideshow] | 99 | @images = @images.paginate(:per_page => per_page, :page => params[:npage]) unless params[:slideshow] |
100 | end | 100 | end |
101 | 101 | ||
102 | + @unfollow_form = params[:unfollow] && params[:unfollow] == 'true' | ||
103 | + if params[:unfollow] && params[:unfollow] == 'commit' && request.post? | ||
104 | + @page.followers -= [params[:email]] | ||
105 | + if @page.save | ||
106 | + session[:notice] = _("Notification of new comments to '%s' was successfully canceled") % params[:email] | ||
107 | + end | ||
108 | + end | ||
109 | + | ||
102 | @comments = @page.comments(true).as_thread | 110 | @comments = @page.comments(true).as_thread |
103 | @comments_count = @page.comments.count | 111 | @comments_count = @page.comments.count |
104 | if params[:slideshow] | 112 | if params[:slideshow] |
app/helpers/application_helper.rb
@@ -1331,4 +1331,21 @@ module ApplicationHelper | @@ -1331,4 +1331,21 @@ module ApplicationHelper | ||
1331 | _("Are you sure that you want to remove the item \"#{article.name}\"?") | 1331 | _("Are you sure that you want to remove the item \"#{article.name}\"?") |
1332 | end | 1332 | end |
1333 | end | 1333 | end |
1334 | + | ||
1335 | + def template_options(klass, field_name) | ||
1336 | + return '' if klass.templates.count == 0 | ||
1337 | + return hidden_field_tag("#{field_name}[template_id]", klass.templates.first.id) if klass.templates.count == 1 | ||
1338 | + | ||
1339 | + counter = 0 | ||
1340 | + radios = klass.templates.map do |template| | ||
1341 | + counter += 1 | ||
1342 | + content_tag('li', labelled_radio_button(template.name, "#{field_name}[template_id]", template.id, counter==1)) | ||
1343 | + end.join("\n") | ||
1344 | + | ||
1345 | + content_tag('div', content_tag('span', _('Template:')) + | ||
1346 | + content_tag('ul', radios, :style => 'list-style: none; padding-left: 0; margin-top: 0.5em;'), | ||
1347 | + :id => 'template-options', | ||
1348 | + :style => 'margin-top: 1em' | ||
1349 | + ) | ||
1350 | + end | ||
1334 | end | 1351 | end |
app/models/article.rb
@@ -34,9 +34,12 @@ class Article < ActiveRecord::Base | @@ -34,9 +34,12 @@ class Article < ActiveRecord::Base | ||
34 | settings_items :display_hits, :type => :boolean, :default => true | 34 | settings_items :display_hits, :type => :boolean, :default => true |
35 | settings_items :author_name, :type => :string, :default => "" | 35 | settings_items :author_name, :type => :string, :default => "" |
36 | settings_items :allow_members_to_edit, :type => :boolean, :default => false | 36 | settings_items :allow_members_to_edit, :type => :boolean, :default => false |
37 | + settings_items :followers, :type => Array, :default => [] | ||
37 | 38 | ||
38 | belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' | 39 | belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' |
39 | 40 | ||
41 | + belongs_to :license | ||
42 | + | ||
40 | has_many :translations, :class_name => 'Article', :foreign_key => :translation_of_id | 43 | has_many :translations, :class_name => 'Article', :foreign_key => :translation_of_id |
41 | belongs_to :translation_of, :class_name => 'Article', :foreign_key => :translation_of_id | 44 | belongs_to :translation_of, :class_name => 'Article', :foreign_key => :translation_of_id |
42 | before_destroy :rotate_translations | 45 | before_destroy :rotate_translations |
app/models/comment.rb
@@ -75,11 +75,30 @@ class Comment < ActiveRecord::Base | @@ -75,11 +75,30 @@ class Comment < ActiveRecord::Base | ||
75 | article.comments_updated if article.kind_of?(Article) | 75 | article.comments_updated if article.kind_of?(Article) |
76 | end | 76 | end |
77 | 77 | ||
78 | - after_create do |comment| | ||
79 | - if comment.source.kind_of?(Article) && comment.article.notify_comments? && !comment.article.profile.notification_emails.empty? | ||
80 | - Comment::Notifier.deliver_mail(comment) | 78 | + after_create :new_follower |
79 | + def new_follower | ||
80 | + if source.kind_of?(Article) | ||
81 | + article.followers += [author_email] | ||
82 | + article.followers -= article.profile.notification_emails | ||
83 | + article.followers.uniq! | ||
84 | + article.save | ||
85 | + end | ||
86 | + end | ||
87 | + | ||
88 | + after_create :notify_by_mail | ||
89 | + def notify_by_mail | ||
90 | + if source.kind_of?(Article) && article.notify_comments? | ||
91 | + if !article.profile.notification_emails.empty? | ||
92 | + Comment::Notifier.deliver_mail(self) | ||
93 | + end | ||
94 | + emails = article.followers - [author_email] | ||
95 | + if !emails.empty? | ||
96 | + Comment::Notifier.deliver_mail_to_followers(self, emails) | ||
97 | + end | ||
81 | end | 98 | end |
99 | + end | ||
82 | 100 | ||
101 | + after_create do |comment| | ||
83 | if comment.source.kind_of?(Article) | 102 | if comment.source.kind_of?(Article) |
84 | comment.article.create_activity if comment.article.activity.nil? | 103 | comment.article.create_activity if comment.article.activity.nil? |
85 | if comment.article.activity | 104 | if comment.article.activity |
@@ -138,6 +157,22 @@ class Comment < ActiveRecord::Base | @@ -138,6 +157,22 @@ class Comment < ActiveRecord::Base | ||
138 | :environment => profile.environment.name, | 157 | :environment => profile.environment.name, |
139 | :url => profile.environment.top_url | 158 | :url => profile.environment.top_url |
140 | end | 159 | end |
160 | + def mail_to_followers(comment, emails) | ||
161 | + profile = comment.article.profile | ||
162 | + bcc emails | ||
163 | + from "#{profile.environment.name} <#{profile.environment.contact_email}>" | ||
164 | + subject _("[%s] %s commented on a content of %s") % [profile.environment.name, comment.author_name, profile.short_name] | ||
165 | + body :recipient => profile.nickname || profile.name, | ||
166 | + :sender => comment.author_name, | ||
167 | + :sender_link => comment.author_link, | ||
168 | + :article_title => comment.article.name, | ||
169 | + :comment_url => comment.url, | ||
170 | + :unsubscribe_url => comment.article.view_url.merge({:unfollow => true}), | ||
171 | + :comment_title => comment.title, | ||
172 | + :comment_body => comment.body, | ||
173 | + :environment => profile.environment.name, | ||
174 | + :url => profile.environment.top_url | ||
175 | + end | ||
141 | end | 176 | end |
142 | 177 | ||
143 | def rejected? | 178 | def rejected? |
app/models/community.rb
@@ -61,10 +61,10 @@ class Community < Organization | @@ -61,10 +61,10 @@ class Community < Organization | ||
61 | 61 | ||
62 | def name=(value) | 62 | def name=(value) |
63 | super(value) | 63 | super(value) |
64 | - self.identifier = value.to_slug | 64 | + self.identifier ||= value.to_slug |
65 | end | 65 | end |
66 | 66 | ||
67 | - def template | 67 | + def default_template |
68 | environment.community_template | 68 | environment.community_template |
69 | end | 69 | end |
70 | 70 |
app/models/enterprise.rb
@@ -154,13 +154,14 @@ class Enterprise < Organization | @@ -154,13 +154,14 @@ class Enterprise < Organization | ||
154 | true | 154 | true |
155 | end | 155 | end |
156 | 156 | ||
157 | - def template | ||
158 | - if enabled? | ||
159 | - environment.enterprise_template | ||
160 | - else | ||
161 | - environment.inactive_enterprise_template | ||
162 | - end | 157 | + def default_template |
158 | + environment.enterprise_template | ||
159 | + end | ||
160 | + | ||
161 | + def template_with_inactive_enterprise | ||
162 | + !enabled? ? environment.inactive_enterprise_template : template_without_inactive_enterprise | ||
163 | end | 163 | end |
164 | + alias_method_chain :template, :inactive_enterprise | ||
164 | 165 | ||
165 | def control_panel_settings_button | 166 | def control_panel_settings_button |
166 | {:title => __('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} | 167 | {:title => __('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} |
app/models/environment.rb
@@ -24,6 +24,8 @@ class Environment < ActiveRecord::Base | @@ -24,6 +24,8 @@ class Environment < ActiveRecord::Base | ||
24 | 'manage_environment_roles' => N_('Manage environment roles'), | 24 | 'manage_environment_roles' => N_('Manage environment roles'), |
25 | 'manage_environment_validators' => N_('Manage environment validators'), | 25 | 'manage_environment_validators' => N_('Manage environment validators'), |
26 | 'manage_environment_users' => N_('Manage environment users'), | 26 | 'manage_environment_users' => N_('Manage environment users'), |
27 | + 'manage_environment_templates' => N_('Manage environment templates'), | ||
28 | + 'manage_environment_licenses' => N_('Manage environment licenses'), | ||
27 | } | 29 | } |
28 | 30 | ||
29 | module Roles | 31 | module Roles |
@@ -158,6 +160,7 @@ class Environment < ActiveRecord::Base | @@ -158,6 +160,7 @@ class Environment < ActiveRecord::Base | ||
158 | has_many :products, :through => :enterprises | 160 | has_many :products, :through => :enterprises |
159 | has_many :people | 161 | has_many :people |
160 | has_many :communities | 162 | has_many :communities |
163 | + has_many :licenses | ||
161 | 164 | ||
162 | has_many :categories | 165 | has_many :categories |
163 | has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' | 166 | has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' |
@@ -719,12 +722,12 @@ class Environment < ActiveRecord::Base | @@ -719,12 +722,12 @@ class Environment < ActiveRecord::Base | ||
719 | 722 | ||
720 | def create_templates | 723 | def create_templates |
721 | pre = self.name.to_slug + '_' | 724 | pre = self.name.to_slug + '_' |
722 | - ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false).id | ||
723 | - inactive_enterprise_tmpl = Enterprise.create!(:name => 'Inactive Enterprise template', :identifier => pre + 'inactive_enterprise_template', :environment => self, :visible => false) | ||
724 | - com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false).id | 725 | + ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false, :is_template => true).id |
726 | + inactive_enterprise_tmpl = Enterprise.create!(:name => 'Inactive Enterprise template', :identifier => pre + 'inactive_enterprise_template', :environment => self, :visible => false, :is_template => true) | ||
727 | + com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false, :is_template => true).id | ||
725 | pass = Digest::MD5.hexdigest rand.to_s | 728 | pass = Digest::MD5.hexdigest rand.to_s |
726 | user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person | 729 | user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person |
727 | - user.update_attributes(:visible => false, :name => "Person template") | 730 | + user.update_attributes(:visible => false, :name => "Person template", :is_template => true) |
728 | usr_id = user.id | 731 | usr_id = user.id |
729 | self.settings[:enterprise_template_id] = ent_id | 732 | self.settings[:enterprise_template_id] = ent_id |
730 | self.inactive_enterprise_template = inactive_enterprise_tmpl | 733 | self.inactive_enterprise_template = inactive_enterprise_tmpl |
@@ -740,6 +743,18 @@ class Environment < ActiveRecord::Base | @@ -740,6 +743,18 @@ class Environment < ActiveRecord::Base | ||
740 | end | 743 | end |
741 | end | 744 | end |
742 | 745 | ||
746 | + after_create :create_default_licenses | ||
747 | + def create_default_licenses | ||
748 | + License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => self) | ||
749 | + License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => self) | ||
750 | + License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => self) | ||
751 | + License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => self) | ||
752 | + License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => self) | ||
753 | + License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => self) | ||
754 | + License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => self) | ||
755 | + License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => self) | ||
756 | + end | ||
757 | + | ||
743 | def highlighted_products_with_image(options = {}) | 758 | def highlighted_products_with_image(options = {}) |
744 | Product.find(:all, {:conditions => {:highlighted => true, :enterprise_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) | 759 | Product.find(:all, {:conditions => {:highlighted => true, :enterprise_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) |
745 | end | 760 | end |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +class License < ActiveRecord::Base | ||
2 | + belongs_to :environment | ||
3 | + has_many :content, :class_name => 'Article', :foreign_key => 'license_id' | ||
4 | + | ||
5 | + validates_presence_of :name, :environment | ||
6 | + validates_presence_of :slug, :if => lambda {|license| license.name.present?} | ||
7 | + validates_uniqueness_of :slug, :scope => :environment_id | ||
8 | + | ||
9 | + before_validation do |license| | ||
10 | + license.slug ||= license.name.to_slug if license.name.present? | ||
11 | + end | ||
12 | +end |
app/models/organization.rb
app/models/person.rb
app/models/profile.rb
@@ -65,6 +65,7 @@ class Profile < ActiveRecord::Base | @@ -65,6 +65,7 @@ class Profile < ActiveRecord::Base | ||
65 | #FIXME: these will work only if the subclass is already loaded | 65 | #FIXME: these will work only if the subclass is already loaded |
66 | named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 66 | named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
67 | named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 67 | named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
68 | + named_scope :templates, :conditions => {:is_template => true} | ||
68 | 69 | ||
69 | def members | 70 | def members |
70 | Person.members_of(self) | 71 | Person.members_of(self) |
@@ -98,6 +99,7 @@ class Profile < ActiveRecord::Base | @@ -98,6 +99,7 @@ class Profile < ActiveRecord::Base | ||
98 | has_many :action_tracker_notifications, :foreign_key => 'profile_id' | 99 | has_many :action_tracker_notifications, :foreign_key => 'profile_id' |
99 | has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' | 100 | has_many :tracked_notifications, :through => :action_tracker_notifications, :source => :action_tracker, :order => 'updated_at DESC' |
100 | has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC", :dependent => :destroy | 101 | has_many :scraps_received, :class_name => 'Scrap', :foreign_key => :receiver_id, :order => "updated_at DESC", :dependent => :destroy |
102 | + belongs_to :template, :class_name => 'Profile', :foreign_key => 'template_id' | ||
101 | 103 | ||
102 | # FIXME ugly workaround | 104 | # FIXME ugly workaround |
103 | def self.human_attribute_name(attrib) | 105 | def self.human_attribute_name(attrib) |
@@ -274,8 +276,14 @@ class Profile < ActiveRecord::Base | @@ -274,8 +276,14 @@ class Profile < ActiveRecord::Base | ||
274 | validates_format_of :identifier, :with => IDENTIFIER_FORMAT, :if => lambda { |profile| !profile.identifier.blank? } | 276 | validates_format_of :identifier, :with => IDENTIFIER_FORMAT, :if => lambda { |profile| !profile.identifier.blank? } |
275 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS | 277 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS |
276 | validates_uniqueness_of :identifier, :scope => :environment_id | 278 | validates_uniqueness_of :identifier, :scope => :environment_id |
277 | - | ||
278 | validates_length_of :nickname, :maximum => 16, :allow_nil => true | 279 | validates_length_of :nickname, :maximum => 16, :allow_nil => true |
280 | + validate :valid_template | ||
281 | + | ||
282 | + def valid_template | ||
283 | + if template_id.present? and !template.is_template | ||
284 | + errors.add(:template, _('is not a template.')) | ||
285 | + end | ||
286 | + end | ||
279 | 287 | ||
280 | before_create :set_default_environment | 288 | before_create :set_default_environment |
281 | def set_default_environment | 289 | def set_default_environment |
@@ -322,10 +330,15 @@ class Profile < ActiveRecord::Base | @@ -322,10 +330,15 @@ class Profile < ActiveRecord::Base | ||
322 | end | 330 | end |
323 | 331 | ||
324 | # this method should be overwritten to provide the correct template | 332 | # this method should be overwritten to provide the correct template |
325 | - def template | 333 | + def default_template |
326 | nil | 334 | nil |
327 | end | 335 | end |
328 | 336 | ||
337 | + def template_with_default | ||
338 | + template_without_default || default_template | ||
339 | + end | ||
340 | + alias_method_chain :template, :default | ||
341 | + | ||
329 | def apply_template(template, options = {:copy_articles => true}) | 342 | def apply_template(template, options = {:copy_articles => true}) |
330 | copy_blocks_from(template) | 343 | copy_blocks_from(template) |
331 | copy_articles_from(template) if options[:copy_articles] | 344 | copy_articles_from(template) if options[:copy_articles] |
app/models/user.rb
@@ -114,6 +114,7 @@ class User < ActiveRecord::Base | @@ -114,6 +114,7 @@ class User < ActiveRecord::Base | ||
114 | 114 | ||
115 | # Activates the user in the database. | 115 | # Activates the user in the database. |
116 | def activate | 116 | def activate |
117 | + return false unless self.person | ||
117 | self.activated_at = Time.now.utc | 118 | self.activated_at = Time.now.utc |
118 | self.activation_code = nil | 119 | self.activation_code = nil |
119 | self.person.visible = true | 120 | self.person.visible = true |
app/views/account/_signup_form.rhtml
@@ -69,6 +69,8 @@ | @@ -69,6 +69,8 @@ | ||
69 | 69 | ||
70 | <div id="signup-form-profile"> | 70 | <div id="signup-form-profile"> |
71 | 71 | ||
72 | + <%= template_options(Person, 'profile_data') %> | ||
73 | + | ||
72 | <% labelled_fields_for :profile_data, @person do |f| %> | 74 | <% labelled_fields_for :profile_data, @person do |f| %> |
73 | <%= render :partial => 'profile_editor/person_form', :locals => {:f => f} %> | 75 | <%= render :partial => 'profile_editor/person_form', :locals => {:f => f} %> |
74 | <% end %> | 76 | <% end %> |
app/views/admin_panel/edit_templates.rhtml
@@ -1,10 +0,0 @@ | @@ -1,10 +0,0 @@ | ||
1 | -<h1><%= _('Edit Templates') %></h1> | ||
2 | - | ||
3 | -<ul> | ||
4 | -<% [[_('Edit Person Template'), environment.person_template], | ||
5 | - [_('Edit Community Template'), environment.community_template], | ||
6 | - [__('Edit Enterprise Template'), environment.enterprise_template], | ||
7 | - [__('Edit Inactive Enterprise Template'), environment.inactive_enterprise_template]].select{|i| i[1]}.each do |row| %> | ||
8 | -<li><%= link_to row[0], :controller => 'profile_editor', :profile => row[1].identifier %></li> | ||
9 | -<% end %> | ||
10 | -</ul> |
app/views/admin_panel/index.rhtml
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | <tr><td><%= link_to _('Plugins'), :controller => 'plugins' %></td></tr> | 8 | <tr><td><%= link_to _('Plugins'), :controller => 'plugins' %></td></tr> |
9 | <tr><td><%= link_to _('Sideboxes'), :controller => 'environment_design'%></td></tr> | 9 | <tr><td><%= link_to _('Sideboxes'), :controller => 'environment_design'%></td></tr> |
10 | <tr><td><%= link_to _('Homepage'), :action => 'set_portal_community' %></td></tr> | 10 | <tr><td><%= link_to _('Homepage'), :action => 'set_portal_community' %></td></tr> |
11 | + <tr><td><%= link_to _('Manage Licenses'), :controller =>'licenses' %></td></tr> | ||
11 | </table> | 12 | </table> |
12 | 13 | ||
13 | <h2><%= _('Profiles') %></h2> | 14 | <h2><%= _('Profiles') %></h2> |
@@ -15,7 +16,7 @@ | @@ -15,7 +16,7 @@ | ||
15 | <table> | 16 | <table> |
16 | <tr><td><%= link_to _('User roles'), :controller => 'role' %></td></tr> | 17 | <tr><td><%= link_to _('User roles'), :controller => 'role' %></td></tr> |
17 | <tr><td><%= link_to _('Users'), :controller => 'users' %></td></tr> | 18 | <tr><td><%= link_to _('Users'), :controller => 'users' %></td></tr> |
18 | - <tr><td><%= link_to _('Profile templates'), :action => 'edit_templates' %></td></tr> | 19 | + <tr><td><%= link_to _('Profile templates'), :action => 'templates' %></td></tr> |
19 | <tr><td><%= link_to _('Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr> | 20 | <tr><td><%= link_to _('Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr> |
20 | </table> | 21 | </table> |
21 | 22 |
app/views/cms/_blog.rhtml
@@ -6,6 +6,8 @@ | @@ -6,6 +6,8 @@ | ||
6 | 6 | ||
7 | <%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %> | 7 | <%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %> |
8 | 8 | ||
9 | +<%= render :partial => 'general_fields' %> | ||
10 | + | ||
9 | <script type="text/javascript"> | 11 | <script type="text/javascript"> |
10 | function submit_button(index) { | 12 | function submit_button(index) { |
11 | return $("article_slug").form.select("input.submit")[index]; | 13 | return $("article_slug").form.select("input.submit")[index]; |
app/views/cms/_event.rhtml
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | 5 | ||
6 | <%= required f.text_field('name', :size => '64') %> | 6 | <%= required f.text_field('name', :size => '64') %> |
7 | 7 | ||
8 | +<%= render :partial => 'general_fields' %> | ||
8 | <%= render :partial => 'translatable' %> | 9 | <%= render :partial => 'translatable' %> |
9 | 10 | ||
10 | <%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> | 11 | <%= labelled_form_field(_('Start date'), pick_date(:article, :start_date)) %> |
app/views/cms/_folder.rhtml
1 | <%= required_fields_message %> | 1 | <%= required_fields_message %> |
2 | 2 | ||
3 | <%= required f.text_field('name', :size => '64') %> | 3 | <%= required f.text_field('name', :size => '64') %> |
4 | +<%= render :partial => 'general_fields' %> | ||
4 | 5 | ||
5 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %> | 6 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %> |
app/views/cms/_forum.rhtml
@@ -6,6 +6,8 @@ | @@ -6,6 +6,8 @@ | ||
6 | 6 | ||
7 | <%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %> | 7 | <%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %> |
8 | 8 | ||
9 | +<%= render :partial => 'general_fields' %> | ||
10 | + | ||
9 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> | 11 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> |
10 | 12 | ||
11 | <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> | 13 | <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> |
app/views/cms/_gallery.rhtml
@@ -2,4 +2,6 @@ | @@ -2,4 +2,6 @@ | ||
2 | 2 | ||
3 | <%= required f.text_field('name', :size => '64') %> | 3 | <%= required f.text_field('name', :size => '64') %> |
4 | 4 | ||
5 | +<%= render :partial => 'general_fields' %> | ||
6 | + | ||
5 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %> | 7 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %> |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +<%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %> |
app/views/cms/_published_article.rhtml
1 | <%= f.text_field 'name', :size => '64' %> | 1 | <%= f.text_field 'name', :size => '64' %> |
2 | +<%= render :partial => 'general_fields' %> | ||
2 | 3 | ||
3 | <p><%= _('This is a republication of "%s", by %s.') % [link_to(h(@article.reference_article.name), @article.reference_article.url), @article.reference_article.profile.name] %></p> | 4 | <p><%= _('This is a republication of "%s", by %s.') % [link_to(h(@article.reference_article.name), @article.reference_article.url), @article.reference_article.profile.name] %></p> |
app/views/cms/_raw_html_article.rhtml
@@ -2,5 +2,6 @@ | @@ -2,5 +2,6 @@ | ||
2 | 2 | ||
3 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> | 3 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> |
4 | 4 | ||
5 | +<%= render :partial => 'general_fields' %> | ||
5 | <%= render :partial => 'translatable' %> | 6 | <%= render :partial => 'translatable' %> |
6 | <%= render :partial => 'shared/lead_and_body' %> | 7 | <%= render :partial => 'shared/lead_and_body' %> |
app/views/cms/_rss_feed.rhtml
@@ -2,6 +2,8 @@ | @@ -2,6 +2,8 @@ | ||
2 | 2 | ||
3 | <%= required f.text_field(:name) %> | 3 | <%= required f.text_field(:name) %> |
4 | 4 | ||
5 | +<%= render :partial => 'general_fields' %> | ||
6 | + | ||
5 | <%= required labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> | 7 | <%= required labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> |
6 | 8 | ||
7 | <%= labelled_form_field(_('Include in RSS Feed only posts from language:'), f.select(:language, [[_('All'), nil ]] + Noosfero.locales.map { |k,v| [v, k]})) %> | 9 | <%= labelled_form_field(_('Include in RSS Feed only posts from language:'), f.select(:language, [[_('All'), nil ]] + Noosfero.locales.map { |k,v| [v, k]})) %> |
app/views/cms/_textile_article.rhtml
@@ -4,5 +4,6 @@ | @@ -4,5 +4,6 @@ | ||
4 | 4 | ||
5 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '72')) %> | 5 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '72')) %> |
6 | 6 | ||
7 | +<%= render :partial => 'general_fields' %> | ||
7 | <%= render :partial => 'translatable' %> | 8 | <%= render :partial => 'translatable' %> |
8 | <%= render :partial => 'shared/lead_and_body' %> | 9 | <%= render :partial => 'shared/lead_and_body' %> |
app/views/cms/_tiny_mce_article.rhtml
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | <div> | 5 | <div> |
6 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> | 6 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> |
7 | 7 | ||
8 | + <%= render :partial => 'general_fields' %> | ||
8 | <%= render :partial => 'translatable' %> | 9 | <%= render :partial => 'translatable' %> |
9 | <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> | 10 | <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> |
10 | </div> | 11 | </div> |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +<%= _('Hi!') %> | ||
2 | + | ||
3 | +<%= word_wrap(_('%{sender} (%{sender_link}) commented on the content "%{article_title}".') % { :sender => @sender, :sender_link => url_for(@sender_link), :article_title => @article_title }) %> | ||
4 | + | ||
5 | +<%= word_wrap(_('Title: %s') % @comment_title) if @comment_title %> | ||
6 | + | ||
7 | +<%= _("Comment:") %> | ||
8 | +------------------------------------------------------------------------------- | ||
9 | +<%= word_wrap(@comment_body) %> | ||
10 | +------------------------------------------------------------------------------- | ||
11 | + | ||
12 | +<%= _('Click on the address below to view this comment:') %> | ||
13 | +<%= url_for @comment_url %> | ||
14 | + | ||
15 | +<%= _('Click on the address below to cancel the notification of new comments:') %> | ||
16 | +<%= url_for @unsubscribe_url %> | ||
17 | + | ||
18 | +<%= _("Greetings,") %> | ||
19 | + | ||
20 | +-- | ||
21 | +<%= _('%s team.') % @environment %> | ||
22 | +<%= url_for @url %> |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +<% if @unfollow_form %> | ||
2 | +<div class='unfollow-article'> | ||
3 | + <h1><%= _('Cancel notification of new comments') %></h1> | ||
4 | + <p><%= _("Fill in the following field with your e-mail if you don't want to be notified when this content receives new comments anymore.") %></p> | ||
5 | + <% form_tag(@page.view_url.merge({:only_path => true}), {:method => 'post', :class => 'comment_form'}) do %> | ||
6 | + <%= hidden_field_tag(:unfollow, 'commit') %> | ||
7 | + <%= labelled_form_field(_('Enter your e-Mail'), text_field_tag(:email, nil, {:size => 40})) %> | ||
8 | + <% button_bar do %> | ||
9 | + <%= submit_button(:ok, _('Cancel notifications for e-mail above') ) %> | ||
10 | + <% end %> | ||
11 | + <% end %> | ||
12 | +</div> | ||
13 | +<% end %> |
app/views/content_viewer/view_page.rhtml
@@ -6,12 +6,30 @@ | @@ -6,12 +6,30 @@ | ||
6 | 6 | ||
7 | <div id="article" class="<%= @page.css_class_name %>"> | 7 | <div id="article" class="<%= @page.css_class_name %>"> |
8 | 8 | ||
9 | +<%= render :partial => 'confirm_unfollow' %> | ||
10 | + | ||
9 | <div id="article-toolbar"></div> | 11 | <div id="article-toolbar"></div> |
10 | 12 | ||
11 | <script type="text/javascript"> | 13 | <script type="text/javascript"> |
12 | <%= remote_function :update => "article-toolbar", :url => @page.url.merge({ :toolbar => true, :only_path => true }) %> | 14 | <%= remote_function :update => "article-toolbar", :url => @page.url.merge({ :toolbar => true, :only_path => true }) %> |
13 | </script> | 15 | </script> |
14 | 16 | ||
17 | +<% if @page.display_hits? || @page.license.present? %> | ||
18 | + <div id='article-sub-header'> | ||
19 | + <% if @page.display_hits? %> | ||
20 | + <div id="article-hits"> | ||
21 | + <%= n_('Viewed one time', 'Viewed %{num} times', @page.hits) % { :num => @page.hits } %> | ||
22 | + </div> | ||
23 | + <% end %> | ||
24 | + | ||
25 | + <% if @page.license.present? %> | ||
26 | + <div id="article-license"> | ||
27 | + <%= _('Licensed under %s') % (@page.license.url.present? ? link_to(@page.license.name, @page.license.url, :target => '_blank') : @page.license.name) %> | ||
28 | + </div> | ||
29 | + <% end %> | ||
30 | + </div> | ||
31 | +<% end %> | ||
32 | + | ||
15 | <% if !@page.tags.empty? %> | 33 | <% if !@page.tags.empty? %> |
16 | <div id="article-tags"> | 34 | <div id="article-tags"> |
17 | <%= _("This article's tags:") %> | 35 | <%= _("This article's tags:") %> |
@@ -19,12 +37,6 @@ | @@ -19,12 +37,6 @@ | ||
19 | </div> | 37 | </div> |
20 | <% end %> | 38 | <% end %> |
21 | 39 | ||
22 | -<% if @page.display_hits? %> | ||
23 | - <div id="article-hits"> | ||
24 | - <%= n_('Viewed one time', 'Viewed %{num} times', @page.hits) % { :num => @page.hits } %> | ||
25 | - </div> | ||
26 | -<% end %> | ||
27 | - | ||
28 | <% if @page.parent && !@page.parent.path.blank? %> | 40 | <% if @page.parent && !@page.parent.path.blank? %> |
29 | <div id="article-parent"> | 41 | <div id="article-parent"> |
30 | <%= button(:back, _('Go back to %s') % @page.parent.short_title, @page.parent.url) %> | 42 | <%= button(:back, _('Go back to %s') % @page.parent.short_title, @page.parent.url) %> |
app/views/edit_template/index.rhtml
@@ -1,14 +0,0 @@ | @@ -1,14 +0,0 @@ | ||
1 | -mexendo o contedudo para ver como fica a parada toda | ||
2 | -mexendo o contedudo para ver como fica a parada toda | ||
3 | -mexendo o contedudo para ver como fica a parada toda | ||
4 | -mexendo o contedudo para ver como fica a parada toda | ||
5 | -mexendo o contedudo para ver como fica a parada toda | ||
6 | -mexendo o contedudo para ver como fica a parada toda | ||
7 | -mexendo o contedudo para ver como fica a parada toda | ||
8 | -mexendo o contedudo para ver como fica a parada toda | ||
9 | -mexendo o contedudo para ver como fica a parada toda | ||
10 | -mexendo o contedudo para ver como fica a parada toda | ||
11 | -mexendo o contedudo para ver como fica a parada toda | ||
12 | -mexendo o contedudo para ver como fica a parada toda | ||
13 | -mexendo o contedudo para ver como fica a parada toda | ||
14 | - |
app/views/enterprise_registration/basic_information.rhtml
@@ -28,6 +28,8 @@ | @@ -28,6 +28,8 @@ | ||
28 | <%= hidden_field_tag 'create_enterprise[target_id]', environment.id %> | 28 | <%= hidden_field_tag 'create_enterprise[target_id]', environment.id %> |
29 | <% end %> | 29 | <% end %> |
30 | 30 | ||
31 | + <%= template_options(Enterprise, 'create_enterprise')%> | ||
32 | + | ||
31 | <% button_bar do %> | 33 | <% button_bar do %> |
32 | <%= submit_button('next', _('Next'), :cancel => {:profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile"}) %> | 34 | <%= submit_button('next', _('Next'), :cancel => {:profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile"}) %> |
33 | <% end %> | 35 | <% end %> |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +<%= error_messages_for :license %> | ||
2 | + | ||
3 | +<% form_for :license, @license do |f| %> | ||
4 | + <%= hidden_field_tag(:license_id, params[:license_id]) %> | ||
5 | + <%= required labelled_form_field(_('Name'), f.text_field(:name)) %> | ||
6 | + <%= labelled_form_field(_('License url'), f.text_field(:url)) %> | ||
7 | + | ||
8 | + <% button_bar do %> | ||
9 | + <%= submit_button('save', _('Save'))%> | ||
10 | + <%= button('cancel', _('Cancel'), {:action => 'index'})%> | ||
11 | + <% end %> | ||
12 | +<% end %> |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +<h1><%= _('Manage licenses') %></h1> | ||
2 | +<table style='overflow: hidden;'> | ||
3 | + <tr> | ||
4 | + <th style='width: 25%'><%= _('Name') %></th> | ||
5 | + <th style='width: 60%'><%= _('Url reference') %></th> | ||
6 | + <th style='width: 15%'><%= _('Actions') %></th> | ||
7 | + </tr> | ||
8 | + <% @licenses.each do |license| %> | ||
9 | + <tr> | ||
10 | + <td title="<%= license.name%>"><%= truncate(license.name, :length => 19) %></td> | ||
11 | + <td title="<%= license.url %>"><%= license.url.present? ? link_to(truncate(license.url, :length => 60), license.url, :target => '_blank') : '' %></td> | ||
12 | + <td style='white-space: nowrap;'> | ||
13 | + <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> | ||
14 | + <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :method => 'post', :confirm => _('Are you sure you want to remove this license?') %></td> | ||
15 | + </tr> | ||
16 | + <% end %> | ||
17 | +</table> | ||
18 | + | ||
19 | +<% button_bar do %> | ||
20 | + <%= button(:add, _('Add a new license'), :action => 'create')%> | ||
21 | + <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %> | ||
22 | +<% end %> |
app/views/memberships/new_community.rhtml
@@ -38,6 +38,8 @@ | @@ -38,6 +38,8 @@ | ||
38 | </div> | 38 | </div> |
39 | </div> | 39 | </div> |
40 | 40 | ||
41 | + <%= template_options(Community, 'community')%> | ||
42 | + | ||
41 | <% button_bar do %> | 43 | <% button_bar do %> |
42 | <%= submit_button(:save, _('Create')) %> | 44 | <%= submit_button(:save, _('Create')) %> |
43 | <%= button(:cancel, _('Cancel'), :action => 'index') %> | 45 | <%= button(:cancel, _('Cancel'), :action => 'index') %> |
app/views/profile_editor/edit.rhtml
@@ -4,6 +4,12 @@ | @@ -4,6 +4,12 @@ | ||
4 | 4 | ||
5 | <% labelled_form_for :profile_data, @profile, :html => { :id => 'profile-data', :multipart => true } do |f| %> | 5 | <% labelled_form_for :profile_data, @profile, :html => { :id => 'profile-data', :multipart => true } do |f| %> |
6 | 6 | ||
7 | + <% if user.has_permission?('manage_environment_templates', profile.environment) %> | ||
8 | + <div id="profile-is-template"> | ||
9 | + <%= labelled_check_box(_('This profile is a template'), 'profile_data[is_template]', true, @profile.is_template) %> | ||
10 | + </div> | ||
11 | + <% end %> | ||
12 | + | ||
7 | <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> | 13 | <%= render :partial => partial_for_class(@profile.class), :locals => { :f => f } %> |
8 | 14 | ||
9 | <% unless @profile.person? && @environment.active_person_fields.include?('image') %> | 15 | <% unless @profile.person? && @environment.active_person_fields.include?('image') %> |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +<% if @error %> | ||
2 | + <div class="errorExplanation" id="errorExplanation"> | ||
3 | + <h2><%= _('The template could not be saved') %></h2> | ||
4 | + <p><%= _('There were problems with the following fields:') %> </p> | ||
5 | + <ul> | ||
6 | + <li><%= @error %></li> | ||
7 | + </ul> | ||
8 | + </div> | ||
9 | +<% end %> | ||
10 | + | ||
11 | +<% form_tag do %> | ||
12 | + <%= labelled_text_field(_('Name')+': ', :name)%> | ||
13 | + | ||
14 | + <% button_bar do %> | ||
15 | + <%= submit_button('save', _('Save'))%> | ||
16 | + <%= button('cancel', _('Cancel'), {:action => 'index'})%> | ||
17 | + <% end %> | ||
18 | +<% end %> | ||
19 | + |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +<% title = case @kind | ||
2 | + when 'person' | ||
3 | + | ||
4 | + when 'community' | ||
5 | + _('Create community template') | ||
6 | + when 'enterprise' | ||
7 | + _('Create enterprise template') | ||
8 | +end %> | ||
9 | + | ||
10 | +<h1><%= _('Create person template') %></h1> | ||
11 | + | ||
12 | +<%= render :partial => 'create_template_form' %> |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +<h1><%= _('Edit Templates') %></h1> | ||
2 | + | ||
3 | +<%= _('Manage the templates used on creation of profiles') %> | ||
4 | + | ||
5 | +<% list_of_templates = [[_('Person') , Person.templates , 'person' ], | ||
6 | + [_('Community') , Community.templates , 'community' ], | ||
7 | + [_('Enterprise'), Enterprise.templates, 'enterprise']] %> | ||
8 | + | ||
9 | +<% list_of_templates.each do |title, templates, kind|%> | ||
10 | + <div class='template-kind'> | ||
11 | + <h2><%= title %></h2> | ||
12 | + <%= button :add, _('New...'), {:action => "create_#{kind}_template"}, :title => _("Create a new template for %s") % title.downcase %> | ||
13 | + <ul> | ||
14 | + <% templates.each do |template| %> | ||
15 | + <li> | ||
16 | + <%= image_tag "icons-app/#{kind}-icon.png" %> | ||
17 | + <%= link_to(template.name, {:controller => 'profile_editor', :profile => template.identifier}, :title => _('Edit template "%s"') % template.name ) %> | ||
18 | + </li> | ||
19 | + <% end %> | ||
20 | + </ul> | ||
21 | + </div> | ||
22 | +<% end %> | ||
23 | + | ||
24 | +<% button_bar do %> | ||
25 | + <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %> | ||
26 | +<% end %> |
db/migrate/20120710033223_add_template_and_is_template_fields.rb
0 → 100644
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +class AddTemplateAndIsTemplateFields < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + add_column :profiles, :is_template, :boolean, :default => false | ||
4 | + add_column :profiles, :template_id, :integer | ||
5 | + end | ||
6 | + | ||
7 | + def self.down | ||
8 | + remove_column :profiles, :is_template | ||
9 | + remove_column :profiles, :template_id | ||
10 | + end | ||
11 | +end |
db/migrate/20120710062802_fill_is_template_field_on_basic_templates.rb
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +class CreateLicenses < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :licenses do |t| | ||
4 | + t.string :name, :null => false | ||
5 | + t.string :slug, :null => false | ||
6 | + t.string :url | ||
7 | + t.references :environment, :null => false | ||
8 | + end | ||
9 | + end | ||
10 | + | ||
11 | + def self.down | ||
12 | + drop_table :licenses | ||
13 | + end | ||
14 | +end |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +class AddLicenseToArticle < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + add_column :articles, :license_id, :integer | ||
4 | + add_column :article_versions, :license_id, :integer | ||
5 | + end | ||
6 | + | ||
7 | + def self.down | ||
8 | + remove_column :articles, :license_id | ||
9 | + remove_column :article_versions, :license_id | ||
10 | + end | ||
11 | +end |
db/migrate/20120716161506_add_manage_environment_license_to_admin_role.rb
0 → 100644
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +class AddManageEnvironmentLicenseToAdminRole < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + Environment.all.map(&:id).each do |id| | ||
4 | + role = Environment::Roles.admin(id) | ||
5 | + role.permissions << 'manage_environment_licenses' | ||
6 | + role.save! | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
10 | + def self.down | ||
11 | + Environment.all.map(&:id).each do |id| | ||
12 | + role = Environment::Roles.admin(id) | ||
13 | + role.permissions -= ['manage_environment_licenses'] | ||
14 | + role.save! | ||
15 | + end | ||
16 | + end | ||
17 | +end |
db/migrate/20120718145131_add_manage_environment_templates_to_admin_role.rb
0 → 100644
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +class AddManageEnvironmentTemplatesToAdminRole < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + Environment.all.map(&:id).each do |id| | ||
4 | + role = Environment::Roles.admin(id) | ||
5 | + role.permissions << 'manage_environment_templates' | ||
6 | + role.save! | ||
7 | + end | ||
8 | + end | ||
9 | + | ||
10 | + def self.down | ||
11 | + Environment.all.map(&:id).each do |id| | ||
12 | + role = Environment::Roles.admin(id) | ||
13 | + role.permissions -= ['manage_environment_templates'] | ||
14 | + role.save! | ||
15 | + end | ||
16 | + end | ||
17 | +end |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +class CreateDefaultLicenses < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + Environment.all.each do |environment| | ||
4 | + License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => environment) | ||
5 | + License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => environment) | ||
6 | + License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => environment) | ||
7 | + License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => environment) | ||
8 | + License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => environment) | ||
9 | + License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => environment) | ||
10 | + License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => environment) | ||
11 | + License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => environment) | ||
12 | + end | ||
13 | + end | ||
14 | + | ||
15 | + def self.down | ||
16 | + licenses = [] | ||
17 | + licenses += License.find(:all, :conditions => {:name => 'CC (by)'}) | ||
18 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nd)'}) | ||
19 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-sa)'}) | ||
20 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc)'}) | ||
21 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-nd)'}) | ||
22 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-sa)'}) | ||
23 | + licenses += License.find(:all, :conditions => {:name => 'Free Art'}) | ||
24 | + licenses += License.find(:all, :conditions => {:name => 'GNU FDL'}) | ||
25 | + licenses.compact.map(&:destroy) | ||
26 | + end | ||
27 | +end |
db/schema.rb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | # | 9 | # |
10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | ||
12 | -ActiveRecord::Schema.define(:version => 20120411132751) do | 12 | +ActiveRecord::Schema.define(:version => 20120718162001) do |
13 | 13 | ||
14 | create_table "abuse_reports", :force => true do |t| | 14 | create_table "abuse_reports", :force => true do |t| |
15 | t.integer "reporter_id" | 15 | t.integer "reporter_id" |
@@ -85,6 +85,7 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | @@ -85,6 +85,7 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | ||
85 | t.integer "translation_of_id" | 85 | t.integer "translation_of_id" |
86 | t.string "language" | 86 | t.string "language" |
87 | t.string "source_name" | 87 | t.string "source_name" |
88 | + t.integer "license_id" | ||
88 | end | 89 | end |
89 | 90 | ||
90 | create_table "articles", :force => true do |t| | 91 | create_table "articles", :force => true do |t| |
@@ -125,6 +126,7 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | @@ -125,6 +126,7 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | ||
125 | t.integer "translation_of_id" | 126 | t.integer "translation_of_id" |
126 | t.string "language" | 127 | t.string "language" |
127 | t.string "source_name" | 128 | t.string "source_name" |
129 | + t.integer "license_id" | ||
128 | end | 130 | end |
129 | 131 | ||
130 | add_index "articles", ["translation_of_id"], :name => "index_articles_on_translation_of_id" | 132 | add_index "articles", ["translation_of_id"], :name => "index_articles_on_translation_of_id" |
@@ -314,6 +316,13 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | @@ -314,6 +316,13 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | ||
314 | add_index "inputs", ["product_category_id"], :name => "index_inputs_on_product_category_id" | 316 | add_index "inputs", ["product_category_id"], :name => "index_inputs_on_product_category_id" |
315 | add_index "inputs", ["product_id"], :name => "index_inputs_on_product_id" | 317 | add_index "inputs", ["product_id"], :name => "index_inputs_on_product_id" |
316 | 318 | ||
319 | + create_table "licenses", :force => true do |t| | ||
320 | + t.string "name", :null => false | ||
321 | + t.string "slug", :null => false | ||
322 | + t.string "url" | ||
323 | + t.integer "environment_id", :null => false | ||
324 | + end | ||
325 | + | ||
317 | create_table "mailing_sents", :force => true do |t| | 326 | create_table "mailing_sents", :force => true do |t| |
318 | t.integer "mailing_id" | 327 | t.integer "mailing_id" |
319 | t.integer "person_id" | 328 | t.integer "person_id" |
@@ -425,6 +434,8 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | @@ -425,6 +434,8 @@ ActiveRecord::Schema.define(:version => 20120411132751) do | ||
425 | t.boolean "validated", :default => true | 434 | t.boolean "validated", :default => true |
426 | t.string "cnpj" | 435 | t.string "cnpj" |
427 | t.string "national_region_code" | 436 | t.string "national_region_code" |
437 | + t.boolean "is_template", :default => false | ||
438 | + t.integer "template_id" | ||
428 | end | 439 | end |
429 | 440 | ||
430 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" | 441 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" |
debian/control
@@ -47,11 +47,12 @@ Depends: | @@ -47,11 +47,12 @@ Depends: | ||
47 | memcached, | 47 | memcached, |
48 | debconf, | 48 | debconf, |
49 | dbconfig-common, | 49 | dbconfig-common, |
50 | - postgresql, | ||
51 | adduser, | 50 | adduser, |
52 | exim4 | mail-transport-agent, | 51 | exim4 | mail-transport-agent, |
53 | ${misc:Depends} | 52 | ${misc:Depends} |
54 | -Recommends: postgresql-client | 53 | +Recommends: |
54 | + postgresql, | ||
55 | + postgresql-client | ||
55 | Description: free web-based platform for social networks | 56 | Description: free web-based platform for social networks |
56 | Noosfero is a web platform for social and solidarity economy networks with | 57 | Noosfero is a web platform for social and solidarity economy networks with |
57 | blog, e-Porfolios, CMS, RSS, thematic discussion, events agenda and collective | 58 | blog, e-Porfolios, CMS, RSS, thematic discussion, events agenda and collective |
debian/thin.yml
features/edit_environment_templates.feature
1 | Feature: edit environment templates | 1 | Feature: edit environment templates |
2 | As an administrator | 2 | As an administrator |
3 | - I want edit templates | 3 | + I want to edit templates |
4 | 4 | ||
5 | Background: | 5 | Background: |
6 | Given that the default environment have all profile templates | 6 | Given that the default environment have all profile templates |
@@ -9,37 +9,37 @@ Feature: edit environment templates | @@ -9,37 +9,37 @@ Feature: edit environment templates | ||
9 | Given I am logged in as admin | 9 | Given I am logged in as admin |
10 | When I follow "Administration" | 10 | When I follow "Administration" |
11 | And I follow "Edit Templates" | 11 | And I follow "Edit Templates" |
12 | - Then I should see "Edit Person Template" link | ||
13 | - And I should see "Edit Community Template" link | ||
14 | - And I should see "Edit Enterprise Template" link | ||
15 | - And I should see "Edit Inactive Enterprise Template" link | 12 | + Then I should see "Person template" link |
13 | + And I should see "Community template" link | ||
14 | + And I should see "Enterprise template" link | ||
15 | + And I should see "Inactive Enterprise template" link | ||
16 | 16 | ||
17 | Scenario: Go to control panel of person template | 17 | Scenario: Go to control panel of person template |
18 | Given I am logged in as admin | 18 | Given I am logged in as admin |
19 | When I follow "Administration" | 19 | When I follow "Administration" |
20 | And I follow "Edit Templates" | 20 | And I follow "Edit Templates" |
21 | - And I follow "Edit Person Template" | 21 | + And I follow "Person template" |
22 | Then I should be on Person template's control panel | 22 | Then I should be on Person template's control panel |
23 | 23 | ||
24 | Scenario: Go to control panel of enterprise template | 24 | Scenario: Go to control panel of enterprise template |
25 | Given I am logged in as admin | 25 | Given I am logged in as admin |
26 | When I follow "Administration" | 26 | When I follow "Administration" |
27 | And I follow "Edit Templates" | 27 | And I follow "Edit Templates" |
28 | - And I follow "Edit Enterprise Template" | 28 | + And I follow "Enterprise template" |
29 | Then I should be on Enterprise template's control panel | 29 | Then I should be on Enterprise template's control panel |
30 | 30 | ||
31 | Scenario: Go to control panel of inactive enterprise template | 31 | Scenario: Go to control panel of inactive enterprise template |
32 | Given I am logged in as admin | 32 | Given I am logged in as admin |
33 | When I follow "Administration" | 33 | When I follow "Administration" |
34 | And I follow "Edit Templates" | 34 | And I follow "Edit Templates" |
35 | - And I follow "Edit Inactive Enterprise Template" | 35 | + And I follow "Inactive enterprise template" |
36 | Then I should be on Inactive Enterprise template's control panel | 36 | Then I should be on Inactive Enterprise template's control panel |
37 | 37 | ||
38 | Scenario: Go to control panel of community template | 38 | Scenario: Go to control panel of community template |
39 | Given I am logged in as admin | 39 | Given I am logged in as admin |
40 | When I follow "Administration" | 40 | When I follow "Administration" |
41 | And I follow "Edit Templates" | 41 | And I follow "Edit Templates" |
42 | - And I follow "Edit Community Template" | 42 | + And I follow "Community template" |
43 | Then I should be on Community template's control panel | 43 | Then I should be on Community template's control panel |
44 | 44 | ||
45 | Scenario: Not see link to edit an unexistent template | 45 | Scenario: Not see link to edit an unexistent template |
@@ -47,7 +47,7 @@ Feature: edit environment templates | @@ -47,7 +47,7 @@ Feature: edit environment templates | ||
47 | And I am logged in as admin | 47 | And I am logged in as admin |
48 | When I follow "Administration" | 48 | When I follow "Administration" |
49 | And I follow "Edit Templates" | 49 | And I follow "Edit Templates" |
50 | - Then I should see "Edit Person Template" link | ||
51 | - And I should see "Edit Community Template" link | ||
52 | - And I should see "Edit Enterprise Template" link | ||
53 | - And I should not see "Edit Inactive Enterprise Template" link | 50 | + Then I should see "Person template" link |
51 | + And I should see "Community template" link | ||
52 | + And I should see "Enterprise template" link | ||
53 | + And I should not see "Inactive enterprise template" link |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +Then /^I directly delete content with name "([^\"]*)" for testing purposes$/ do |content_name| | ||
2 | + Article.find_by_name(content_name).destroy | ||
3 | +end | ||
4 | + | ||
5 | +Then /^I should be at the url "([^\"]*)"$/ do |url| | ||
6 | + if response.class.to_s == 'Webrat::SeleniumResponse' | ||
7 | + URI.parse(response.selenium.get_location).path.should == url | ||
8 | + else | ||
9 | + URI.parse(current_url).path.should == url | ||
10 | + end | ||
11 | +end | ||
12 | + | ||
13 | +Then /^I don't fill anything$/ do | ||
14 | +end |
plugins/mezuro/AUTHORS
1 | -KALIBRO PLUGIN AUTHORS | ||
2 | -===================== | 1 | +Mezuro Authors |
2 | +============== | ||
3 | 3 | ||
4 | -Copyright 2010-2011 | ||
5 | - Almir Alves Pereira (almir.sne at gmail.com) | ||
6 | - Andre Casimiro (ah.casimiro at gmail.com) | ||
7 | - Carlos Morais (carlos88morais at gmail.com) | ||
8 | - Everton Santos (everton2x4 at gmail.com) | ||
9 | - Paulo Meirelles (paulo at softwarelivre.org) | ||
10 | - Rafael Messias (rmmartins at gmail.com) | 4 | +Copyright 2010-2012 |
5 | +------------------- | ||
11 | 6 | ||
12 | -Collaborators: | ||
13 | -- Ana Paula Oliveira dos Santos (ana at ime.usp.br) | ||
14 | -- Lucianna Almeida (lucianna.th at gmail.com) | ||
15 | -- Joao Machini (joao.machini at gmail.com) | ||
16 | -- Rodrigo Souto (rodrigo@colivre.coop.br) | ||
17 | -- Thiago Colucci (ticolucci at gmail.com) | ||
18 | -- Vinicius Daros (vinicius.k.daros at gmail.com) | ||
19 | -- Viviane Almeida Santos (viviane.almeida at gmail.com) | 7 | + Almir Alves Pereira (almir.sne at gmail.com) |
8 | + Alessandro Palmeira (alessandro.palmeira at gmail.com) | ||
9 | + Andre Casimiro (ah.casimiro at gmail.com) | ||
10 | + Antonio Terceiro (terceiro at colivre.coop.br) | ||
11 | + Caio Salgado (caio.csalgado at gmail.com) | ||
12 | + Carlos Morais (carlos88morais at gmail.com) | ||
13 | + Diego Araújo (diegoamc90 at gmail.com) | ||
14 | + Everton Santos (everton2x4 at gmail.com) | ||
15 | + Jefferson Fernandes (jeffs.fernandes at gmail.com) | ||
16 | + Joao Machini (joao.machini at gmail.com) | ||
17 | + João da Silva (jaodsilv@linux.ime.usp.br) | ||
18 | + Paulo Meirelles (paulo at softwarelivre.org) | ||
19 | + Rafael Manso (rr.manzo at gmail.com) | ||
20 | + Rafael Messias (rmmartins at gmail.com) | ||
21 | + Renan Teruo (renanteruoc at gmail.com) | ||
22 | + Rodrigo Souto (rodrigo at colivre.coop.br) | ||
23 | + | ||
24 | +Collaborators (from USP Lab XP course 2010 on another code) | ||
25 | +----------------------------------------------------------- | ||
26 | + | ||
27 | + Ana Paula Oliveira dos Santos (anapaulao.santos at gmail.com) | ||
28 | + Lucianna Almeida (lucianna.th at gmail.com) | ||
29 | + Thiago Colucci (ticolucci at gmail.com) | ||
30 | + Vinicius Daros (vinicius.k.daros at gmail.com) | ||
31 | + Viviane Almeida Santos (viviane.almeida at gmail.com) | ||
32 | + | ||
33 | +Advisors | ||
34 | +-------- | ||
35 | + | ||
36 | + Fabio Kon (fabio.kon at ime.usp.br) | ||
37 | + Alfredo Goldman (gold at ime.usp.br) | ||
20 | 38 |
plugins/mezuro/README
1 | -README - Mezuro (Kalibro Plugin) | 1 | +README - Mezuro (Mezuro Plugin) |
2 | ================================ | 2 | ================================ |
3 | 3 | ||
4 | -Mezuro is source code tracking network based on Noosfero Platform with Kalibro Plugin to access Kalibro Web Service. | 4 | +Mezuro is a source code tracking platform based on Noosfero social networking |
5 | +platform with Mezuro Plugin actived to access Kalibro Web Service. | ||
6 | + | ||
5 | 7 | ||
6 | INSTALL | 8 | INSTALL |
7 | ======= | 9 | ======= |
8 | 10 | ||
9 | -See the Noosfero install file and include Ruby gem Savon: | 11 | +Dependences |
12 | +----------- | ||
13 | + | ||
14 | +See the Noosfero install file. After install Noosfero, install Mezuro dependences: | ||
10 | 15 | ||
11 | -gem install savon | 16 | +$ gem install nokogiri -v 1.5.0 |
17 | +$ gem install savon -v 0.9.7 | ||
18 | +$ gem install googlecharts | ||
12 | 19 | ||
13 | -Also, you need to enable Mezuro Plugin in the Noosfero: | 20 | +Enable Plugin |
21 | +------------- | ||
22 | + | ||
23 | +Also, you need to enable Mezuro Plugin at you Noosfero: | ||
14 | 24 | ||
15 | cd <your_noosfero_dir> | 25 | cd <your_noosfero_dir> |
16 | ./script/noosfero-plugins enable mezuro | 26 | ./script/noosfero-plugins enable mezuro |
17 | 27 | ||
18 | -To run Mezuro (kalibro Plugin) and its acceptance tests, you need to install the Kalibro Service. | 28 | + |
29 | +Install Service | ||
30 | +--------------- | ||
31 | + | ||
32 | +To run Mezuro (Noosfero with Mezuro Plugin), you need to install the Kalibro | ||
33 | +Service. | ||
34 | + | ||
19 | For that, access https://gitorious.org/kalibro/kalibro/blobs/master/INSTALL | 35 | For that, access https://gitorious.org/kalibro/kalibro/blobs/master/INSTALL |
20 | 36 | ||
21 | 37 | ||
22 | -SOURCE CODE | 38 | +Configure Service Address |
39 | +------------------------- | ||
40 | + | ||
41 | +Finally, copy service.yaml.example to service.yaml and define your Kalibro | ||
42 | +Service address: | ||
43 | + | ||
44 | +$ cd <your_noosfero_dir>/plugin/mezuro | ||
45 | +$ cp service.yaml.example service.yaml | ||
46 | + | ||
47 | +If you install Kalibro Service at localhost, just keep the default | ||
48 | +adress: | ||
49 | + | ||
50 | +http://localhost:8080/KalibroService/ | ||
51 | + | ||
52 | +Applying Mezuro Theme | ||
53 | +--------------------- | ||
54 | + | ||
55 | +$ cd public/designs/themes && rm -f default | ||
56 | +$ git clone git://gitorious.org/mezuro/mezuro-theme.git | ||
57 | +$ ln -s mezuro-theme/ default && cd ../../../ | ||
58 | + | ||
59 | +Active Plugin | ||
60 | +------------- | ||
61 | + | ||
62 | +As a Noosfero administrator user, go to administrator panel: | ||
63 | + | ||
64 | +- Click on "Enable/disable plugins" option | ||
65 | +- Click on "Mezuro Plugin" check-box | ||
66 | + | ||
67 | + | ||
68 | +DEVELOPMENT | ||
23 | =========== | 69 | =========== |
24 | 70 | ||
25 | -To get the Mezuro (Noosfero with Kalibro Plugin) development repository: | 71 | +Get the Mezuro (Noosfero with Mezuro Plugin) development repository: |
26 | 72 | ||
27 | -git clone https://gitorious.org/+mezuro/noosfero/mezuro-noosfero-plugin | ||
28 | -cd mezuro-noosfero-plugin | ||
29 | -git checkout mezuro | 73 | +$ git clone https://gitorious.org/+mezuro/noosfero/mezuro |
74 | +$ cd mezuro | ||
75 | +$ git checkout mezuro | ||
30 | 76 | ||
31 | -AUTHORS | ||
32 | -======= | 77 | +Running Mezuro tests |
78 | +-------------------- | ||
33 | 79 | ||
34 | -Please see the file AUTHORS. | 80 | +$ rake test:noosfero_plugins:mezuro |
35 | 81 | ||
36 | -BUGS | ||
37 | -==== | ||
38 | 82 | ||
39 | -If you found any bug, please report at mezuro@listas.softwarelivre.org | ||
40 | -(http://listas.softwarelivre.org/cgi-bin/mailman/listinfo/mezuro) | 83 | +Get Involved |
84 | +============ | ||
85 | + | ||
86 | +If you found any bug and/or want to collaborate, please send an e-mail to | ||
87 | +paulo@softwarelivre.org | ||
88 | + | ||
41 | 89 | ||
42 | LICENSE | 90 | LICENSE |
43 | ======= | 91 | ======= |
44 | -Copyright (c) The Authors developers. | 92 | + |
93 | +Copyright (c) The Author developers. | ||
45 | 94 | ||
46 | See Noosfero license. | 95 | See Noosfero license. |
47 | 96 | ||
48 | 97 | ||
98 | +AUTHORS | ||
99 | +======= | ||
100 | + | ||
101 | +Please, see the Mezuro AUTHORS file. | ||
102 | + | ||
103 | + | ||
49 | ACKNOWLEDGMENTS | 104 | ACKNOWLEDGMENTS |
50 | =============== | 105 | =============== |
51 | 106 | ||
52 | The authors have been supported by organizations: | 107 | The authors have been supported by organizations: |
53 | 108 | ||
109 | +University of São Paulo (USP) | ||
110 | +FLOSS Competence Center | ||
111 | +http://ccsl.ime.usp.br | ||
112 | + | ||
54 | Brazilian National Research Council (CNPQ) | 113 | Brazilian National Research Council (CNPQ) |
55 | http://www.cnpq.br/ | 114 | http://www.cnpq.br/ |
56 | - | ||
57 | -USP FLOSS Competence Center | ||
58 | -http://ccsl.ime.usp.br/ |
@@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
1 | +README/TODO do branch cucumber_tests | ||
2 | + | ||
3 | +Tarefas: | ||
4 | +- Escrever uma história (procurar uma já escrita) para isso | ||
5 | +- Descobrir o porquê dos erros nos testes do mezuro (repository_url) | ||
6 | +- Dar rebase com o mezuro-dev (os tais testes passam no mezuro-dev) | ||
7 | +- Fazer mais testes | ||
8 | +- Ver como/quando o selenium pode ser integrado ao projeto (conversar com noosfero/ talvez até tentar implementar alguma coisa??) | ||
9 | + | ||
10 | + | ||
11 | +Testes de aceitação a serem feitos: (* já feito) | ||
12 | + | ||
13 | +Projetos: | ||
14 | + Criar | ||
15 | + * correto | ||
16 | + * errado | ||
17 | + duplicado | ||
18 | + Editar | ||
19 | + correto | ||
20 | + errado | ||
21 | + Deletar(não precisa fazer - problema do noosfero) | ||
22 | + | ||
23 | +Configurações: | ||
24 | + criar | ||
25 | + *correta | ||
26 | + *errado (sem titulo) | ||
27 | + *duplicada | ||
28 | + editar - verificar se mantem as metricas | ||
29 | + correto | ||
30 | + não é possível mudar o titulo | ||
31 | + deletar (não precisa fazer - problema do noosfero) | ||
32 | + metricas: | ||
33 | + criar | ||
34 | + nativa: | ||
35 | + *correta | ||
36 | + *errada | ||
37 | + duplicada (é pra funcionar?) | ||
38 | + composta: | ||
39 | + *correta | ||
40 | + errada | ||
41 | + duplicada | ||
42 | + editar | ||
43 | + para metrica correta | ||
44 | + para metrica errada | ||
45 | + *deletar | ||
46 | + ranges: | ||
47 | + criar | ||
48 | + *range correto | ||
49 | + range errado | ||
50 | + todos os casos | ||
51 | + editar | ||
52 | + para range correto | ||
53 | + para range errado | ||
54 | + deletar | ||
55 | + | ||
56 | +Testes falhando: | ||
57 | + | ||
58 | +Arquivo adding_metric_configuration.feature: | ||
59 | + Scenario: adding a native metric configuration without code | ||
60 | + Precisa do selenium para ver em qual página está. | ||
61 | + Scenario: adding a compound metric configuration | ||
62 | + Scenario: adding a compound metric configuration with invalid script | ||
63 | + As métricas compostas não estão salvando direito. | ||
64 | + | ||
65 | + | ||
66 | +Arquivo creating_project.feature: | ||
67 | + Scenario: I create a Kalibro project with valid attributes | ||
68 | + ás vezes falha por erro de já existir na Kalibro. Esse erro teóricamente já havia sido resolvido. | ||
69 | + | ||
70 | + | ||
71 | +Arquivo adding_ranges.feature: | ||
72 | + Scenario: adding a range to a metric configuration | ||
73 | + Precisa do selenium para esperar a página carregar. |
plugins/mezuro/controllers/mezuro_plugin_myprofile_controller.rb
0 → 100644
@@ -0,0 +1,126 @@ | @@ -0,0 +1,126 @@ | ||
1 | +class MezuroPluginMyprofileController < ProfileController | ||
2 | + | ||
3 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | ||
4 | + | ||
5 | + | ||
6 | + def choose_base_tool | ||
7 | + @configuration_content = profile.articles.find(params[:id]) | ||
8 | + @base_tools = Kalibro::BaseTool.all_names | ||
9 | + end | ||
10 | + | ||
11 | + def choose_metric | ||
12 | + @configuration_content = profile.articles.find(params[:id]) | ||
13 | + @base_tool = params[:base_tool] | ||
14 | + @supported_metrics = Kalibro::BaseTool.find_by_name(@base_tool).supported_metrics | ||
15 | + end | ||
16 | + | ||
17 | + def new_metric_configuration | ||
18 | + @configuration_content = profile.articles.find(params[:id]) | ||
19 | + @metric = Kalibro::BaseTool.find_by_name(params[:base_tool]).metric params[:metric_name] | ||
20 | + end | ||
21 | + | ||
22 | + def new_compound_metric_configuration | ||
23 | + @configuration_content = profile.articles.find(params[:id]) | ||
24 | + @metric_configurations = @configuration_content.metric_configurations | ||
25 | + end | ||
26 | + | ||
27 | + def edit_metric_configuration | ||
28 | + @configuration_content = profile.articles.find(params[:id]) | ||
29 | + @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) | ||
30 | + @metric = @metric_configuration.metric | ||
31 | + end | ||
32 | + | ||
33 | + def edit_compound_metric_configuration | ||
34 | + @configuration_content = profile.articles.find(params[:id]) | ||
35 | + @metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, params[:metric_name]) | ||
36 | + @metric_configurations = @configuration_content.metric_configurations | ||
37 | + @metric = @metric_configuration.metric | ||
38 | + end | ||
39 | + | ||
40 | + def create_metric_configuration | ||
41 | + id = params[:id] | ||
42 | + metric_name = params[:metric_configuration][:metric][:name] | ||
43 | + (Kalibro::MetricConfiguration.new(params[:metric_configuration])).save | ||
44 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | ||
45 | + end | ||
46 | + | ||
47 | + def create_compound_metric_configuration | ||
48 | + id = params[:id] | ||
49 | + metric_name = params[:metric_configuration][:metric][:name] | ||
50 | + Kalibro::MetricConfiguration.new(params[:metric_configuration]).save | ||
51 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{id}&metric_name=#{metric_name.gsub(/\s/, '+')}" | ||
52 | + end | ||
53 | + | ||
54 | + def update_metric_configuration | ||
55 | + @configuration_content = profile.articles.find(params[:id]) | ||
56 | + metric_name = params[:metric_configuration][:metric][:name] | ||
57 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | ||
58 | + metric_configuration.update_attributes params[:metric_configuration] | ||
59 | + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | ||
60 | + end | ||
61 | + | ||
62 | + def update_compound_metric_configuration | ||
63 | + @configuration_content = profile.articles.find(params[:id]) | ||
64 | + metric_name = params[:metric_configuration][:metric][:name] | ||
65 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | ||
66 | + metric_configuration.update_attributes params[:metric_configuration] | ||
67 | + redirect_to "/#{profile.identifier}/#{@configuration_content.slug}" | ||
68 | + end | ||
69 | + | ||
70 | + def remove_metric_configuration | ||
71 | + configuration_content = profile.articles.find(params[:id]) | ||
72 | + metric_name = params[:metric_name] | ||
73 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | ||
74 | + metric_configuration.destroy | ||
75 | + redirect_to "/#{profile.identifier}/#{configuration_content.slug}" | ||
76 | + end | ||
77 | + | ||
78 | + def new_range | ||
79 | + @configuration_content = profile.articles.find(params[:id]) | ||
80 | + @metric_name = params[:metric_name] | ||
81 | + @range = Kalibro::Range.new | ||
82 | + end | ||
83 | + | ||
84 | + def edit_range | ||
85 | + @configuration_content = profile.articles.find(params[:id]) | ||
86 | + @metric_name = params[:metric_name] | ||
87 | + @beginning_id = params[:beginning_id] | ||
88 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, @metric_name) | ||
89 | + @range = metric_configuration.ranges.find{|range| range.beginning == @beginning_id.to_f || @beginning_id =="-INF" } | ||
90 | + end | ||
91 | + | ||
92 | + def create_range | ||
93 | + @configuration_content = profile.articles.find(params[:id]) | ||
94 | + @range = Kalibro::Range.new params[:range] | ||
95 | + metric_name = params[:metric_name] | ||
96 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(@configuration_content.name, metric_name) | ||
97 | + metric_configuration.add_range(@range) | ||
98 | + metric_configuration.save | ||
99 | + end | ||
100 | + | ||
101 | + def update_range | ||
102 | + configuration_content = profile.articles.find(params[:id]) | ||
103 | + metric_name = params[:metric_name] | ||
104 | + beginning_id = params[:beginning_id] | ||
105 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | ||
106 | + index = metric_configuration.ranges.index{ |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | ||
107 | + metric_configuration.ranges[index] = Kalibro::Range.new params[:range] | ||
108 | + metric_configuration.save | ||
109 | + end | ||
110 | + | ||
111 | + def remove_range | ||
112 | + configuration_content = profile.articles.find(params[:id]) | ||
113 | + metric_name = params[:metric_name] | ||
114 | + beginning_id = params[:beginning_id] | ||
115 | + metric_configuration = Kalibro::MetricConfiguration.find_by_configuration_name_and_metric_name(configuration_content.name, metric_name) | ||
116 | + metric_configuration.ranges.delete_if { |range| range.beginning == beginning_id.to_f || beginning_id == "-INF" } | ||
117 | + metric_configuration.save | ||
118 | + formatted_metric_name = metric_name.gsub(/\s/, '+') | ||
119 | + if metric_configuration.metric.class == Kalibro::CompoundMetric | ||
120 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_compound_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | ||
121 | + else | ||
122 | + redirect_to "/myprofile/#{profile.identifier}/plugin/mezuro/edit_metric_configuration?id=#{configuration_content.id}&metric_name=#{formatted_metric_name}" | ||
123 | + end | ||
124 | + end | ||
125 | + | ||
126 | +end |
plugins/mezuro/controllers/mezuro_plugin_profile_controller.rb
1 | class MezuroPluginProfileController < ProfileController | 1 | class MezuroPluginProfileController < ProfileController |
2 | 2 | ||
3 | - def metrics | ||
4 | - project_content = profile.articles.find(params[:id]) | ||
5 | - module_name = params[:module_name] | ||
6 | - render :partial => 'content_viewer/module_result', :locals => { :module_result => project_content.module_result(module_name) } | 3 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') |
4 | + | ||
5 | + def project_state | ||
6 | + @content = profile.articles.find(params[:id]) | ||
7 | + project = @content.project | ||
8 | + state = project.error.nil? ? project.state : "ERROR" | ||
9 | + render :text => state | ||
7 | end | 10 | end |
8 | 11 | ||
12 | + def project_error | ||
13 | + @content = profile.articles.find(params[:id]) | ||
14 | + @project = @content.project | ||
15 | + render :partial => 'content_viewer/project_error' | ||
16 | + end | ||
17 | + | ||
18 | + def project_result | ||
19 | + @content = profile.articles.find(params[:id]) | ||
20 | + date = params[:date] | ||
21 | + @project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) | ||
22 | + render :partial => 'content_viewer/project_result' | ||
23 | + end | ||
24 | + | ||
25 | + def module_result | ||
26 | + @content = profile.articles.find(params[:id]) | ||
27 | + @module_result = @content.module_result(params) | ||
28 | + render :partial => 'content_viewer/module_result' | ||
29 | + end | ||
30 | + | ||
31 | + def project_tree | ||
32 | + @content = profile.articles.find(params[:id]) | ||
33 | + date = params[:date] | ||
34 | + project_result = date.nil? ? @content.project_result : @content.project_result_with_date(date) | ||
35 | + @project_name = @content.project.name | ||
36 | + @source_tree = project_result.node_of(params[:module_name]) | ||
37 | + render :partial =>'content_viewer/source_tree' | ||
38 | + end | ||
39 | + | ||
40 | + def module_metrics_history | ||
41 | + metric_name = params[:metric_name] | ||
42 | + @content = profile.articles.find(params[:id]) | ||
43 | + module_history = @content.result_history(params[:module_name]) | ||
44 | + @score_history = filtering_metric_history(metric_name, module_history) | ||
45 | + render :partial => 'content_viewer/score_history' | ||
46 | + end | ||
47 | + | ||
48 | + def module_grade_history | ||
49 | + @content = profile.articles.find(params[:id]) | ||
50 | + modules_results = @content.result_history(params[:module_name]) | ||
51 | + @score_history = modules_results.collect { |module_result| module_result.grade } | ||
52 | + render :partial => 'content_viewer/score_history' | ||
53 | + end | ||
54 | + | ||
55 | + private | ||
56 | + | ||
57 | + def filtering_metric_history(metric_name, module_history) | ||
58 | + metrics_history = module_history.map do |module_result| | ||
59 | + module_result.metric_results | ||
60 | + end | ||
61 | + metric_history = metrics_history.map do |array_of_metric_result| | ||
62 | + (array_of_metric_result.select do |metric_result| | ||
63 | + metric_result.metric.name.delete("() ") == metric_name | ||
64 | + end).first | ||
65 | + end | ||
66 | + metric_history.map do |metric_result| | ||
67 | + metric_result.value | ||
68 | + end | ||
69 | + end | ||
9 | end | 70 | end |
plugins/mezuro/features/mezuro.feature
@@ -1,69 +0,0 @@ | @@ -1,69 +0,0 @@ | ||
1 | -Feature: mezuro content | ||
2 | - As a noosfero user | ||
3 | - I want to create a Kalibro project | ||
4 | - | ||
5 | - Background: | ||
6 | - Given the following users | ||
7 | - | login | name | | ||
8 | - | joaosilva | Joao Silva | | ||
9 | - And I am logged in as "joaosilva" | ||
10 | - And "Mezuro" plugin is enabled | ||
11 | - And the following community | ||
12 | - | identifier | name | | ||
13 | - | mycommunity | My Community | | ||
14 | - And "Joao Silva" is admin of "My Community" | ||
15 | - | ||
16 | - Scenario: I see Kalibro project as an option to new content | ||
17 | - Given I am on My Community's cms | ||
18 | - When I follow "New content" | ||
19 | - Then I should see "Kalibro project" | ||
20 | - | ||
21 | - Scenario: I see Kalibro project's input form | ||
22 | - Given I am on My Community's cms | ||
23 | - When I follow "New content" | ||
24 | - And I follow "Kalibro project" | ||
25 | - Then I should see "Title" | ||
26 | - And I should see "License" | ||
27 | - And I should see "Repository type" | ||
28 | - And I should see "GIT" | ||
29 | - And I should see "REMOTE_ZIP" | ||
30 | - And I should see "REMOTE_TARBALL" | ||
31 | - And I should see "SUBVERSION" | ||
32 | - And I should see "Repository url" | ||
33 | - And I should see "Configuration" | ||
34 | - And I should see "Kalibro for Java" | ||
35 | - | ||
36 | - Scenario: I create a sample mezuro content | ||
37 | - Given I am on My Community's cms | ||
38 | - When I create a content of type "Kalibro project" with the following data | ||
39 | - | Title | Sample project | | ||
40 | - | License | BSD | | ||
41 | - | Repository type | GIT | | ||
42 | - | Repository url | git://example | | ||
43 | - Then I should see "Sample project" | ||
44 | - And I should see "Viewed one time" | ||
45 | - And I should see "BSD" | ||
46 | - | ||
47 | - Scenario: I create a real mezuro content | ||
48 | - Given I am on My Community's cms | ||
49 | - When I create a content of type "Kalibro project" with the following data | ||
50 | - | Title | Qt-Calculator | | ||
51 | - | License | GPL 2.0 | | ||
52 | - | Repository type | SUBVERSION | | ||
53 | - | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator | | ||
54 | - Then I should see "Qt-Calculator" | ||
55 | - | ||
56 | - Scenario: I see results from a real Kalibro project | ||
57 | - Given I am on My Community's cms | ||
58 | - When I create a content of type "Kalibro project" with the following data | ||
59 | - | Title | Qt-Calculator | | ||
60 | - | License | GPL | | ||
61 | - | Repository type | SUBVERSION | | ||
62 | - | Repository url | https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator | | ||
63 | - | Configuration | Kalibro for Java | | ||
64 | - Then I should see "Qt-Calculator" | ||
65 | - And I should see "GPL" | ||
66 | - And I should see "SUBVERSION" | ||
67 | - And I should see "https://qt-calculator.svn.sourceforge.net/svnroot/qt-calculator" | ||
68 | - And I should see "Kalibro for Java" | ||
69 | - And I should see "Kalibro Service is loading the source code" |
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +class Kalibro::BaseTool < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :name, :description, :supported_metric | ||
4 | + | ||
5 | + def self.all_names | ||
6 | + request("BaseTool", :get_base_tool_names)[:base_tool_name].to_a | ||
7 | + end | ||
8 | + | ||
9 | + def self.find_by_name(base_tool_name) | ||
10 | + new request("BaseTool", :get_base_tool, {:base_tool_name => base_tool_name})[:base_tool] | ||
11 | + end | ||
12 | + | ||
13 | + def supported_metric=(value) | ||
14 | + @supported_metric = Kalibro::NativeMetric.to_objects_array value | ||
15 | + end | ||
16 | + | ||
17 | + def supported_metrics | ||
18 | + @supported_metric | ||
19 | + end | ||
20 | + | ||
21 | + def supported_metrics=(supported_metrics) | ||
22 | + @supported_metric = supported_metrics | ||
23 | + end | ||
24 | + | ||
25 | + def metric(name) | ||
26 | + supported_metrics.find {|metric| metric.name == name} | ||
27 | + end | ||
28 | + | ||
29 | +end |
plugins/mezuro/lib/kalibro/client/base_tool_client.rb
@@ -1,16 +0,0 @@ | @@ -1,16 +0,0 @@ | ||
1 | -class Kalibro::Client::BaseToolClient | ||
2 | - | ||
3 | - def initialize | ||
4 | - @port = Kalibro::Client::Port.new('BaseTool') | ||
5 | - end | ||
6 | - | ||
7 | - def base_tool_names | ||
8 | - @port.request(:get_base_tool_names)[:base_tool_name].to_a | ||
9 | - end | ||
10 | - | ||
11 | - def base_tool(name) | ||
12 | - hash = @port.request(:get_base_tool, {:base_tool_name => name})[:base_tool] | ||
13 | - Kalibro::Entities::BaseTool.from_hash(hash) | ||
14 | - end | ||
15 | - | ||
16 | -end | ||
17 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/client/configuration_client.rb
@@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
1 | -class Kalibro::Client::ConfigurationClient | ||
2 | - | ||
3 | - def initialize | ||
4 | - @port = Kalibro::Client::Port.new('Configuration') | ||
5 | - end | ||
6 | - | ||
7 | - def save(configuration) | ||
8 | - @port.request(:save_configuration, {:configuration => configuration.to_hash}) | ||
9 | - end | ||
10 | - | ||
11 | - def self.save(configuration) | ||
12 | - new.save(configuration) | ||
13 | - end | ||
14 | - | ||
15 | - def configuration_names | ||
16 | - @port.request(:get_configuration_names)[:configuration_name].to_a | ||
17 | - end | ||
18 | - | ||
19 | - def configuration(name) | ||
20 | - hash = @port.request(:get_configuration, {:configuration_name => name})[:configuration] | ||
21 | - Kalibro::Entities::Configuration.from_hash(hash) | ||
22 | - end | ||
23 | - | ||
24 | - def remove(configuration_name) | ||
25 | - @port.request(:remove_configuration, {:configuration_name => configuration_name}) | ||
26 | - end | ||
27 | - | ||
28 | - def self.remove(configuration_name) | ||
29 | - new.remove(configuration_name) | ||
30 | - end | ||
31 | -end |
plugins/mezuro/lib/kalibro/client/kalibro_client.rb
@@ -1,19 +0,0 @@ | @@ -1,19 +0,0 @@ | ||
1 | -class Kalibro::Client::KalibroClient | ||
2 | - | ||
3 | - def initialize | ||
4 | - @port = Kalibro::Client::Port.new('Kalibro') | ||
5 | - end | ||
6 | - | ||
7 | - def supported_repository_types | ||
8 | - @port.request(:get_supported_repository_types)[:repository_type].to_a | ||
9 | - end | ||
10 | - | ||
11 | - def process_project(project_name) | ||
12 | - @port.request(:process_project, {:project_name => project_name}) | ||
13 | - end | ||
14 | - | ||
15 | - def self.process_project(project_name) | ||
16 | - new.process_project(project_name) | ||
17 | - end | ||
18 | - | ||
19 | -end |
plugins/mezuro/lib/kalibro/client/module_result_client.rb
@@ -1,27 +0,0 @@ | @@ -1,27 +0,0 @@ | ||
1 | -class Kalibro::Client::ModuleResultClient | ||
2 | - | ||
3 | - def initialize | ||
4 | - @port = Kalibro::Client::Port.new('ModuleResult') | ||
5 | - end | ||
6 | - | ||
7 | - def module_result(project_name, module_name, date) | ||
8 | - hash = @port.request(:get_module_result, | ||
9 | - {:project_name => project_name, :module_name => module_name, | ||
10 | - :date => date_with_milliseconds(date)})[:module_result] | ||
11 | - Kalibro::Entities::ModuleResult.from_hash(hash) | ||
12 | - end | ||
13 | - | ||
14 | - def result_history(project_name, module_name) | ||
15 | - value = @port.request(:get_result_history, | ||
16 | - {:project_name => project_name, :module_name => module_name})[:module_result] | ||
17 | - Kalibro::Entities::Entity.new.to_entity_array(value, Kalibro::Entities::ModuleResult) | ||
18 | - end | ||
19 | - | ||
20 | - private | ||
21 | - | ||
22 | - def date_with_milliseconds(date) | ||
23 | - milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | ||
24 | - date.to_s[0..18] + milliseconds + date.to_s[19..-1] | ||
25 | - end | ||
26 | - | ||
27 | -end | ||
28 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/client/port.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -require 'savon' | ||
2 | - | ||
3 | -Savon.configure do |config| | ||
4 | - config.log = HTTPI.log = (RAILS_ENV == 'development') | ||
5 | -end | ||
6 | - | ||
7 | -class Kalibro::Client::Port | ||
8 | - | ||
9 | - def initialize(endpoint) | ||
10 | - @client = Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | ||
11 | - end | ||
12 | - | ||
13 | - def service_address | ||
14 | - if @service_address.nil? | ||
15 | - service_file = "#{RAILS_ROOT}/plugins/mezuro/SERVICE" | ||
16 | - File.open(service_file).each_line{ | line | @service_address = line } | ||
17 | - end | ||
18 | - @service_address | ||
19 | - end | ||
20 | - | ||
21 | - def request(action, request_body = nil) | ||
22 | - response = @client.request(:kalibro, action) { soap.body = request_body } | ||
23 | - response.to_hash["#{action}_response".to_sym] | ||
24 | - end | ||
25 | - | ||
26 | -end |
plugins/mezuro/lib/kalibro/client/project_client.rb
@@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
1 | -class Kalibro::Client::ProjectClient | ||
2 | - | ||
3 | - def initialize | ||
4 | - @port = Kalibro::Client::Port.new('Project') | ||
5 | - end | ||
6 | - | ||
7 | - def save(project) | ||
8 | - @port.request(:save_project, {:project => project.to_hash}) | ||
9 | - end | ||
10 | - | ||
11 | - def self.save(project) | ||
12 | - new.save(project) | ||
13 | - end | ||
14 | - | ||
15 | - def project_names | ||
16 | - @port.request(:get_project_names)[:project_name].to_a | ||
17 | - end | ||
18 | - | ||
19 | - def project(name) | ||
20 | - hash = @port.request(:get_project, {:project_name => name})[:project] | ||
21 | - Kalibro::Entities::Project.from_hash(hash) | ||
22 | - end | ||
23 | - | ||
24 | - def remove(project_name) | ||
25 | - @port.request(:remove_project, {:project_name => project_name}) | ||
26 | - end | ||
27 | - | ||
28 | - def self.remove(project_name) | ||
29 | - new.remove(project_name) | ||
30 | - end | ||
31 | -end |
plugins/mezuro/lib/kalibro/client/project_result_client.rb
@@ -1,41 +0,0 @@ | @@ -1,41 +0,0 @@ | ||
1 | -class Kalibro::Client::ProjectResultClient | ||
2 | - | ||
3 | - def initialize | ||
4 | - @port = Kalibro::Client::Port.new('ProjectResult') | ||
5 | - end | ||
6 | - | ||
7 | - def has_results_for(project_name) | ||
8 | - @port.request(:has_results_for, {:project_name => project_name})[:has_results] | ||
9 | - end | ||
10 | - | ||
11 | - def has_results_before(project_name, date) | ||
12 | - @port.request(:has_results_before, {:project_name => project_name, :date => date})[:has_results] | ||
13 | - end | ||
14 | - | ||
15 | - def has_results_after(project_name, date) | ||
16 | - @port.request(:has_results_after, {:project_name => project_name, :date => date})[:has_results] | ||
17 | - end | ||
18 | - | ||
19 | - def first_result(project_name) | ||
20 | - hash = @port.request(:get_first_result_of, {:project_name => project_name})[:project_result] | ||
21 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
22 | - end | ||
23 | - | ||
24 | - def last_result(project_name) | ||
25 | - hash = @port.request(:get_last_result_of, {:project_name => project_name})[:project_result] | ||
26 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
27 | - end | ||
28 | - | ||
29 | - def first_result_after(project_name, date) | ||
30 | - request_body = {:project_name => project_name, :date => date} | ||
31 | - hash = @port.request(:get_first_result_after, request_body)[:project_result] | ||
32 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
33 | - end | ||
34 | - | ||
35 | - def last_result_before(project_name, date) | ||
36 | - request_body = {:project_name => project_name, :date => date} | ||
37 | - hash = @port.request(:get_last_result_before, request_body)[:project_result] | ||
38 | - Kalibro::Entities::ProjectResult.from_hash(hash) | ||
39 | - end | ||
40 | - | ||
41 | -end | ||
42 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/compound_metric_with_error.rb
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class Kalibro::CompoundMetricWithError < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :metric, :error | ||
4 | + | ||
5 | + def metric=(value) | ||
6 | + @metric = Kalibro::CompoundMetric.to_object value | ||
7 | + end | ||
8 | + | ||
9 | + def error=(value) | ||
10 | + @error = Kalibro::Error.to_object value | ||
11 | + end | ||
12 | + | ||
13 | +end |
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +class Kalibro::Configuration < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :name, :description, :metric_configuration | ||
4 | + | ||
5 | + def metric_configuration=(value) | ||
6 | + @metric_configuration = Kalibro::MetricConfiguration.to_objects_array value | ||
7 | + end | ||
8 | + | ||
9 | + def metric_configurations | ||
10 | + if @metric_configuration != nil | ||
11 | + @metric_configuration | ||
12 | + else | ||
13 | + [] | ||
14 | + end | ||
15 | + end | ||
16 | + | ||
17 | + def metric_configurations=(metric_configurations) | ||
18 | + @metric_configuration = metric_configurations | ||
19 | + end | ||
20 | + | ||
21 | + def self.find_by_name(configuration_name) | ||
22 | + begin | ||
23 | + new request("Configuration", :get_configuration, {:configuration_name => configuration_name})[:configuration] | ||
24 | + rescue Exception => error | ||
25 | + nil | ||
26 | + end | ||
27 | + end | ||
28 | + | ||
29 | + def self.all_names | ||
30 | + begin | ||
31 | + request("Configuration", :get_configuration_names)[:configuration_name] | ||
32 | + rescue Exception | ||
33 | + [] | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + def update_attributes(attributes={}) | ||
38 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | ||
39 | + save | ||
40 | + end | ||
41 | + | ||
42 | + def metric_configurations_hash | ||
43 | + self.to_hash[:metric_configuration] | ||
44 | + end | ||
45 | +end |
plugins/mezuro/lib/kalibro/entities/base_tool.rb
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -class Kalibro::Entities::BaseTool < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :name, :description, :supported_metric | ||
4 | - | ||
5 | - def supported_metric=(value) | ||
6 | - @supported_metric = to_entity_array(value, Kalibro::Entities::NativeMetric) | ||
7 | - end | ||
8 | - | ||
9 | - def supported_metrics | ||
10 | - @supported_metric | ||
11 | - end | ||
12 | - | ||
13 | - def supported_metrics=(supported_metrics) | ||
14 | - @supported_metric = supported_metrics | ||
15 | - end | ||
16 | - | ||
17 | -end | ||
18 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/compound_metric.rb
plugins/mezuro/lib/kalibro/entities/compound_metric_with_error.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -class Kalibro::Entities::CompoundMetricWithError < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :metric, :error | ||
4 | - | ||
5 | - def metric=(value) | ||
6 | - @metric = to_entity(value, Kalibro::Entities::CompoundMetric) | ||
7 | - end | ||
8 | - | ||
9 | - def error=(value) | ||
10 | - @error = to_entity(value, Kalibro::Entities::Error) | ||
11 | - end | ||
12 | - | ||
13 | -end | ||
14 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/configuration.rb
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -class Kalibro::Entities::Configuration < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :name, :description, :metric_configuration | ||
4 | - | ||
5 | - def metric_configuration=(value) | ||
6 | - @metric_configuration = to_entity_array(value, Kalibro::Entities::MetricConfiguration) | ||
7 | - end | ||
8 | - | ||
9 | - def metric_configurations | ||
10 | - @metric_configuration | ||
11 | - end | ||
12 | - | ||
13 | - def metric_configurations=(metric_configurations) | ||
14 | - @metric_configuration = metric_configurations | ||
15 | - end | ||
16 | - | ||
17 | -end |
plugins/mezuro/lib/kalibro/entities/entity.rb
@@ -1,53 +0,0 @@ | @@ -1,53 +0,0 @@ | ||
1 | -class Kalibro::Entities::Entity | ||
2 | - | ||
3 | - def self.from_hash(hash) | ||
4 | - entity = self.new | ||
5 | - hash.each { |field, value| entity.set(field, value) } | ||
6 | - entity | ||
7 | - end | ||
8 | - | ||
9 | - def set(field, value) | ||
10 | - send("#{field}=", value) | ||
11 | - end | ||
12 | - | ||
13 | - def to_entity_array(value, entity_class = nil) | ||
14 | - array = value.kind_of?(Array) ? value : [value] | ||
15 | - array.each.collect { |element| to_entity(element, entity_class) } | ||
16 | - end | ||
17 | - | ||
18 | - def to_entity(value, entity_class) | ||
19 | - value.kind_of?(Hash) ? entity_class.from_hash(value) : value | ||
20 | - end | ||
21 | - | ||
22 | - def to_hash | ||
23 | - hash = Hash.new | ||
24 | - fields.each do |field| | ||
25 | - field_value = self.get(field) | ||
26 | - hash[field] = convert_to_hash(field_value) if ! field_value.nil? | ||
27 | - end | ||
28 | - hash | ||
29 | - end | ||
30 | - | ||
31 | - def convert_to_hash(value) | ||
32 | - return value.collect { |element| convert_to_hash(element) } if value.kind_of?(Array) | ||
33 | - return value.to_hash if value.kind_of?(Kalibro::Entities::Entity) | ||
34 | - value | ||
35 | - end | ||
36 | - | ||
37 | - def ==(other) | ||
38 | - begin | ||
39 | - fields.each.inject(true) { |equal, field| equal && (self.get(field) == other.get(field)) } | ||
40 | - rescue NoMethodError | ||
41 | - false | ||
42 | - end | ||
43 | - end | ||
44 | - | ||
45 | - def fields | ||
46 | - instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } | ||
47 | - end | ||
48 | - | ||
49 | - def get(field) | ||
50 | - send("#{field}") | ||
51 | - end | ||
52 | - | ||
53 | -end | ||
54 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/error.rb
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -class Kalibro::Entities::Error < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :message, :stack_trace_element | ||
4 | - | ||
5 | - def stack_trace_element=(value) | ||
6 | - @stack_trace_element = to_entity_array(value, Kalibro::Entities::StackTraceElement) | ||
7 | - end | ||
8 | - | ||
9 | - def stack_trace | ||
10 | - @stack_trace_element | ||
11 | - end | ||
12 | - | ||
13 | - def stack_trace=(stack_trace) | ||
14 | - @stack_trace_element = stack_trace | ||
15 | - end | ||
16 | - | ||
17 | -end | ||
18 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/metric.rb
plugins/mezuro/lib/kalibro/entities/metric_configuration.rb
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -class Kalibro::Entities::MetricConfiguration < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :metric, :code, :weight, :aggregation_form, :range | ||
4 | - | ||
5 | - def metric=(value) | ||
6 | - if value.kind_of?(Hash) | ||
7 | - @metric = to_entity(value, Kalibro::Entities::CompoundMetric) if value.has_key?(:script) | ||
8 | - @metric = to_entity(value, Kalibro::Entities::NativeMetric) if value.has_key?(:origin) | ||
9 | - else | ||
10 | - @metric = value | ||
11 | - end | ||
12 | - end | ||
13 | - | ||
14 | - def range=(value) | ||
15 | - @range = to_entity_array(value, Kalibro::Entities::Range) | ||
16 | - end | ||
17 | - | ||
18 | - def ranges | ||
19 | - @range | ||
20 | - end | ||
21 | - | ||
22 | - def ranges=(ranges) | ||
23 | - @range = ranges | ||
24 | - end | ||
25 | - | ||
26 | -end | ||
27 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/metric_result.rb
@@ -1,33 +0,0 @@ | @@ -1,33 +0,0 @@ | ||
1 | -class Kalibro::Entities::MetricResult < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :metric, :value, :range, :descendent_result, :weight | ||
4 | - | ||
5 | - def metric=(value) | ||
6 | - if value.kind_of?(Hash) | ||
7 | - if value.has_key?(:script) | ||
8 | - @metric = to_entity(value, Kalibro::Entities::CompoundMetric) | ||
9 | - else | ||
10 | - @metric = to_entity(value, Kalibro::Entities::NativeMetric) | ||
11 | - end | ||
12 | - else | ||
13 | - @metric = value | ||
14 | - end | ||
15 | - end | ||
16 | - | ||
17 | - def range=(value) | ||
18 | - @range = to_entity(value, Kalibro::Entities::Range) | ||
19 | - end | ||
20 | - | ||
21 | - def descendent_result=(value) | ||
22 | - @descendent_result = to_entity_array(value) | ||
23 | - end | ||
24 | - | ||
25 | - def descendent_results | ||
26 | - @descendent_result | ||
27 | - end | ||
28 | - | ||
29 | - def descendent_results=(descendent_results) | ||
30 | - @descendent_result = descendent_results | ||
31 | - end | ||
32 | - | ||
33 | -end |
plugins/mezuro/lib/kalibro/entities/module.rb
plugins/mezuro/lib/kalibro/entities/module_node.rb
@@ -1,29 +0,0 @@ | @@ -1,29 +0,0 @@ | ||
1 | -class Kalibro::Entities::ModuleNode < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :module, :child | ||
4 | - | ||
5 | - def module=(value) | ||
6 | - @module = to_entity(value, Kalibro::Entities::Module) | ||
7 | - end | ||
8 | - | ||
9 | - def module_name | ||
10 | - @module.name | ||
11 | - end | ||
12 | - | ||
13 | - def granularity | ||
14 | - @module.granularity | ||
15 | - end | ||
16 | - | ||
17 | - def child=(value) | ||
18 | - @child = to_entity_array(value, Kalibro::Entities::ModuleNode) | ||
19 | - end | ||
20 | - | ||
21 | - def children | ||
22 | - @child | ||
23 | - end | ||
24 | - | ||
25 | - def children=(children) | ||
26 | - @child = children | ||
27 | - end | ||
28 | - | ||
29 | -end |
plugins/mezuro/lib/kalibro/entities/module_result.rb
@@ -1,33 +0,0 @@ | @@ -1,33 +0,0 @@ | ||
1 | -class Kalibro::Entities::ModuleResult < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error | ||
4 | - | ||
5 | - def module=(value) | ||
6 | - @module = to_entity(value, Kalibro::Entities::Module) | ||
7 | - end | ||
8 | - | ||
9 | - def metric_result=(value) | ||
10 | - @metric_result = to_entity_array(value, Kalibro::Entities::MetricResult) | ||
11 | - end | ||
12 | - | ||
13 | - def metric_results | ||
14 | - @metric_result | ||
15 | - end | ||
16 | - | ||
17 | - def metric_results=(metric_results) | ||
18 | - @metric_result = metric_results | ||
19 | - end | ||
20 | - | ||
21 | - def compound_metric_with_error=(value) | ||
22 | - @compound_metric_with_error = to_entity_array(value, Kalibro::Entities::CompoundMetricWithError) | ||
23 | - end | ||
24 | - | ||
25 | - def compound_metrics_with_error | ||
26 | - @compound_metric_with_error | ||
27 | - end | ||
28 | - | ||
29 | - def compound_metrics_with_error=(compound_metrics_with_error) | ||
30 | - @compound_metric_with_error = compound_metrics_with_error | ||
31 | - end | ||
32 | - | ||
33 | -end | ||
34 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/native_metric.rb
plugins/mezuro/lib/kalibro/entities/project.rb
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -class Kalibro::Entities::Project < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :name, :license, :description, :repository, :configuration_name, :state, :error | ||
4 | - | ||
5 | - def repository=(value) | ||
6 | - @repository = to_entity(value, Kalibro::Entities::Repository) | ||
7 | - end | ||
8 | - | ||
9 | - def error=(value) | ||
10 | - @error = to_entity(value, Kalibro::Entities::Error) | ||
11 | - end | ||
12 | - | ||
13 | -end | ||
14 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/project_result.rb
@@ -1,34 +0,0 @@ | @@ -1,34 +0,0 @@ | ||
1 | -class Kalibro::Entities::ProjectResult < Kalibro::Entities::Entity | ||
2 | - | ||
3 | - attr_accessor :project, :date, :load_time, :analysis_time, :source_tree | ||
4 | - | ||
5 | - def project=(value) | ||
6 | - @project = to_entity(value, Kalibro::Entities::Project) | ||
7 | - end | ||
8 | - | ||
9 | - def source_tree=(value) | ||
10 | - @source_tree = to_entity(value, Kalibro::Entities::ModuleNode) | ||
11 | - end | ||
12 | - | ||
13 | - def formatted_load_time | ||
14 | - format_milliseconds(@load_time) | ||
15 | - end | ||
16 | - | ||
17 | - def formatted_analysis_time | ||
18 | - format_milliseconds(@analysis_time) | ||
19 | - end | ||
20 | - | ||
21 | - def format_milliseconds(value) | ||
22 | - seconds = value.to_i/1000 | ||
23 | - hours = seconds/3600 | ||
24 | - seconds -= hours * 3600 | ||
25 | - minutes = seconds/60 | ||
26 | - seconds -= minutes * 60 | ||
27 | - "#{format(hours)}:#{format(minutes)}:#{format(seconds)}" | ||
28 | - end | ||
29 | - | ||
30 | - def format(amount) | ||
31 | - ('%2d' % amount).sub(/\s/, '0') | ||
32 | - end | ||
33 | - | ||
34 | -end | ||
35 | \ No newline at end of file | 0 | \ No newline at end of file |
plugins/mezuro/lib/kalibro/entities/range.rb
plugins/mezuro/lib/kalibro/entities/repository.rb
plugins/mezuro/lib/kalibro/entities/stack_trace_element.rb
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +class Kalibro::Error < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :error_class, :message, :stack_trace_element, :cause | ||
4 | + | ||
5 | + def stack_trace_element=(value) | ||
6 | + @stack_trace_element = Kalibro::StackTraceElement.to_objects_array value | ||
7 | + end | ||
8 | + | ||
9 | + def stack_trace | ||
10 | + @stack_trace_element | ||
11 | + end | ||
12 | + | ||
13 | + def stack_trace=(stack_trace) | ||
14 | + @stack_trace_element = stack_trace | ||
15 | + end | ||
16 | + | ||
17 | + def cause=(cause_value) | ||
18 | + @cause = Kalibro::Error.to_object cause_value | ||
19 | + end | ||
20 | + | ||
21 | +end |
@@ -0,0 +1,72 @@ | @@ -0,0 +1,72 @@ | ||
1 | +class Kalibro::MetricConfiguration < Kalibro::Model | ||
2 | + | ||
3 | + NATIVE_TYPE='native' | ||
4 | + COMPOUND_TYPE='compound' | ||
5 | + | ||
6 | + attr_accessor :metric, :code, :weight, :aggregation_form, :range, :configuration_name | ||
7 | + | ||
8 | + def metric=(value) | ||
9 | + if value.kind_of?(Hash) | ||
10 | + @metric = native?(value) ? Kalibro::NativeMetric.to_object(value) : Kalibro::CompoundMetric.to_object(value) | ||
11 | + else | ||
12 | + @metric = value | ||
13 | + end | ||
14 | + end | ||
15 | + | ||
16 | + def weight=(value) | ||
17 | + @weight = value.to_f | ||
18 | + end | ||
19 | + | ||
20 | + def range=(value) | ||
21 | + @range = Kalibro::Range.to_objects_array value | ||
22 | + end | ||
23 | + | ||
24 | + def add_range(new_range) | ||
25 | + @range = [] if @range.nil? | ||
26 | + @range << new_range | ||
27 | + end | ||
28 | + | ||
29 | + def ranges | ||
30 | + @range | ||
31 | + end | ||
32 | + | ||
33 | + def ranges=(ranges) | ||
34 | + @range = ranges | ||
35 | + end | ||
36 | + | ||
37 | + def update_attributes(attributes={}) | ||
38 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | ||
39 | + save | ||
40 | + end | ||
41 | + | ||
42 | + def self.find_by_configuration_name_and_metric_name(configuration_name, metric_name) | ||
43 | + metric_configuration = new request("MetricConfiguration", :get_metric_configuration, { | ||
44 | + :configuration_name => configuration_name, | ||
45 | + :metric_name => metric_name | ||
46 | + })[:metric_configuration] | ||
47 | + metric_configuration.configuration_name = configuration_name | ||
48 | + metric_configuration | ||
49 | + end | ||
50 | + | ||
51 | + def destroy | ||
52 | + self.class.request("MetricConfiguration", :remove_metric_configuration, { | ||
53 | + :configuration_name => configuration_name, | ||
54 | + :metric_name=> metric.name | ||
55 | + }) | ||
56 | + end | ||
57 | + | ||
58 | + def to_hash | ||
59 | + super :except => [:configuration_name] | ||
60 | + end | ||
61 | + | ||
62 | + private | ||
63 | + | ||
64 | + def native?(value) | ||
65 | + value.has_key?(:origin) ? true : false | ||
66 | + end | ||
67 | + | ||
68 | + def save_params | ||
69 | + {:metric_configuration => to_hash, :configuration_name => configuration_name} | ||
70 | + end | ||
71 | + | ||
72 | +end |
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +class Kalibro::MetricResult < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :metric, :value, :range, :descendent_result, :weight | ||
4 | + | ||
5 | + def metric=(value) | ||
6 | + if value.kind_of?(Hash) | ||
7 | + @metric = native?(value) ? Kalibro::NativeMetric.to_object(value) : Kalibro::CompoundMetric.to_object(value) | ||
8 | + else | ||
9 | + @metric = value | ||
10 | + end | ||
11 | + end | ||
12 | + | ||
13 | + def value=(value) | ||
14 | + @value = value.to_f | ||
15 | + end | ||
16 | + | ||
17 | + def range=(value) | ||
18 | + @range = Kalibro::Range.to_object value | ||
19 | + end | ||
20 | + | ||
21 | + def descendent_result=(value) | ||
22 | + array = value.kind_of?(Array) ? value : [value] | ||
23 | + @descendent_result = array.collect {|element| element.to_f} | ||
24 | + end | ||
25 | + | ||
26 | + def descendent_results | ||
27 | + @descendent_result | ||
28 | + end | ||
29 | + | ||
30 | + def descendent_results=(descendent_results) | ||
31 | + @descendent_result = descendent_results | ||
32 | + end | ||
33 | + | ||
34 | + private | ||
35 | + | ||
36 | + def native?(value) | ||
37 | + value.has_key?(:origin) ? true : false | ||
38 | + end | ||
39 | + | ||
40 | +end |
@@ -0,0 +1,126 @@ | @@ -0,0 +1,126 @@ | ||
1 | +class Kalibro::Model | ||
2 | + | ||
3 | + def initialize(attributes={}) | ||
4 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | ||
5 | + end | ||
6 | + | ||
7 | + def to_hash(options={}) | ||
8 | + hash = Hash.new | ||
9 | + excepts = !options[:except].nil? ? options[:except] : [] | ||
10 | + fields.each do |field| | ||
11 | + if(!excepts.include?(field)) | ||
12 | + field_value = send(field) | ||
13 | + hash[field] = convert_to_hash(field_value) if ! field_value.nil? | ||
14 | + if field_value.is_a?(Kalibro::Model) | ||
15 | + hash = {:attributes! => {}}.merge(hash) | ||
16 | + hash[:attributes!][field.to_sym] = { | ||
17 | + 'xmlns:xsi'=> 'http://www.w3.org/2001/XMLSchema-instance', | ||
18 | + 'xsi:type' => 'kalibro:' + xml_class_name(field_value) } | ||
19 | + end | ||
20 | + end | ||
21 | + end | ||
22 | + hash | ||
23 | + end | ||
24 | + | ||
25 | + def self.request(endpoint, action, request_body = nil) | ||
26 | + response = client(endpoint).request(:kalibro, action) { soap.body = request_body } | ||
27 | + response.to_hash["#{action}_response".to_sym] # response is a Savon::SOAP::Response, and to_hash is a Savon::SOAP::Response method | ||
28 | + end | ||
29 | + | ||
30 | + def self.to_objects_array value | ||
31 | + array = value.kind_of?(Array) ? value : [value] | ||
32 | + array.each.collect { |element| to_object(element) } | ||
33 | + end | ||
34 | + | ||
35 | + def self.to_object value | ||
36 | + value.kind_of?(Hash) ? new(value) : value | ||
37 | + end | ||
38 | + | ||
39 | + def self.create(attributes={}) | ||
40 | + new_model = new attributes | ||
41 | + new_model.save | ||
42 | + new_model | ||
43 | + end | ||
44 | + | ||
45 | + def save | ||
46 | + begin | ||
47 | + self.class.request(save_endpoint, save_action, save_params) | ||
48 | + true | ||
49 | + rescue Exception => error | ||
50 | + false | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | + def destroy | ||
55 | + begin | ||
56 | + self.class.request(destroy_endpoint, destroy_action, destroy_params) | ||
57 | + rescue Exception | ||
58 | + end | ||
59 | + end | ||
60 | + | ||
61 | + protected | ||
62 | + | ||
63 | + def fields | ||
64 | + instance_variable_names.each.collect { |variable| variable.to_s.sub(/@/, '').to_sym } | ||
65 | + end | ||
66 | + | ||
67 | + def convert_to_hash(value) | ||
68 | + return value if value.nil? | ||
69 | + return value.collect { |element| convert_to_hash(element) } if value.is_a?(Array) | ||
70 | + return value.to_hash if value.is_a?(Kalibro::Model) | ||
71 | + return self.class.date_with_milliseconds(value) if value.is_a?(DateTime) | ||
72 | + return 'INF' if value.is_a?(Float) and value.infinite? == 1 | ||
73 | + return '-INF' if value.is_a?(Float) and value.infinite? == -1 | ||
74 | + value | ||
75 | + end | ||
76 | + | ||
77 | + def xml_class_name(object) | ||
78 | + xml_name = object.class.name | ||
79 | + xml_name["Kalibro::"] = "" | ||
80 | + xml_name[0..0] = xml_name[0..0].downcase | ||
81 | + xml_name + "Xml" | ||
82 | + end | ||
83 | + | ||
84 | + def self.client(endpoint) | ||
85 | + service_address = YAML.load_file("#{RAILS_ROOT}/plugins/mezuro/service.yaml") | ||
86 | + Savon::Client.new("#{service_address}#{endpoint}Endpoint/?wsdl") | ||
87 | + end | ||
88 | + | ||
89 | + def self.is_valid?(field) | ||
90 | + field.to_s[0] != '@' and field != :attributes! and (field.to_s =~ /xsi/).nil? | ||
91 | + end | ||
92 | + | ||
93 | + def self.date_with_milliseconds(date) | ||
94 | + milliseconds = "." + (date.sec_fraction * 60 * 60 * 24 * 1000).to_s | ||
95 | + date.to_s[0..18] + milliseconds + date.to_s[19..-1] | ||
96 | + end | ||
97 | + | ||
98 | + def class_name | ||
99 | + self.class.name.gsub(/Kalibro::/,"") | ||
100 | + end | ||
101 | + | ||
102 | + def save_endpoint | ||
103 | + class_name | ||
104 | + end | ||
105 | + | ||
106 | + def save_action | ||
107 | + "save_#{class_name.underscore}".to_sym | ||
108 | + end | ||
109 | + | ||
110 | + def save_params | ||
111 | + {class_name.underscore.to_sym => self.to_hash} | ||
112 | + end | ||
113 | + | ||
114 | + def destroy_endpoint | ||
115 | + class_name | ||
116 | + end | ||
117 | + | ||
118 | + def destroy_action | ||
119 | + "remove_#{class_name.underscore}".to_sym | ||
120 | + end | ||
121 | + | ||
122 | + def destroy_params | ||
123 | + {"#{class_name.underscore}_name".to_sym => self.name} | ||
124 | + end | ||
125 | + | ||
126 | +end |
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +class Kalibro::Module < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :name, :granularity | ||
4 | + | ||
5 | + def self.parent_names(name) | ||
6 | + path = [] | ||
7 | + ancestors = [] | ||
8 | + name.split(".").each do |token| | ||
9 | + path << token | ||
10 | + ancestors << path.join(".") | ||
11 | + end | ||
12 | + ancestors | ||
13 | + end | ||
14 | + | ||
15 | + def ancestor_names | ||
16 | + self.class.parent_names(@name) | ||
17 | + end | ||
18 | +end |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +class Kalibro::ModuleNode < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :module, :child | ||
4 | + | ||
5 | + def module=(value) | ||
6 | + @module = Kalibro::Module.to_object value | ||
7 | + end | ||
8 | + | ||
9 | + def child=(value) | ||
10 | + @child = Kalibro::ModuleNode.to_objects_array value | ||
11 | + end | ||
12 | + | ||
13 | + def children | ||
14 | + @child | ||
15 | + end | ||
16 | + | ||
17 | + def children=(children) | ||
18 | + @child = children | ||
19 | + end | ||
20 | + | ||
21 | +end |
@@ -0,0 +1,63 @@ | @@ -0,0 +1,63 @@ | ||
1 | +class Kalibro::ModuleResult < Kalibro::Model | ||
2 | + | ||
3 | + attr_accessor :module, :date, :grade, :metric_result, :compound_metric_with_error | ||
4 | + | ||
5 | + def self.find_by_project_name_and_module_name_and_date(project_name, module_name, date) | ||
6 | + new request( | ||
7 | + 'ModuleResult', | ||
8 | + :get_module_result, | ||
9 | + { | ||
10 | + :project_name => project_name, | ||
11 | + :module_name => module_name, | ||
12 | + :date => date_with_milliseconds(date) | ||
13 | + })[:module_result] | ||
14 | + end | ||
15 | + | ||
16 | + def self.all_by_project_name_and_module_name(project_name, module_name) | ||
17 | + response = request( | ||
18 | + 'ModuleResult', | ||
19 | + :get_result_history, | ||
20 | + { | ||
21 | + :project_name => project_name, | ||
22 | + :module_name => module_name | ||
23 | + })[:module_result] | ||
24 | + Kalibro::ModuleResult.to_objects_array(response) | ||
25 | + end | ||
26 | + | ||
27 | + def module=(value) | ||
28 | + @module = Kalibro::Module.to_object value | ||
29 | + end | ||
30 | + | ||
31 | + def date=(value) | ||
32 | + @date = value.is_a?(String) ? DateTime.parse(value) : value | ||
33 | + end | ||
34 | + | ||
35 | + def grade=(value) | ||
36 | + @grade = value.to_f | ||
37 | + end | ||
38 | + | ||
39 | + def metric_result=(value) | ||
40 | + @metric_result = Kalibro::MetricResult.to_objects_array value | ||
41 | + end | ||
42 | + | ||
43 | + def metric_results | ||
44 | + @metric_result | ||
45 | + end | ||
46 | + | ||
47 | + def metric_results=(metric_results) | ||
48 | + @metric_result = metric_results | ||
49 | + end | ||
50 | + | ||
51 | + def compound_metric_with_error=(value) | ||
52 | + @compound_metric_with_error = Kalibro::CompoundMetricWithError.to_objects_array value | ||
53 | + end | ||
54 | + | ||
55 | + def compound_metrics_with_error | ||
56 | + @compound_metric_with_error | ||
57 | + end | ||
58 | + | ||
59 | + def compound_metrics_with_error=(compound_metrics_with_error) | ||
60 | + @compound_metric_with_error = compound_metrics_with_error | ||
61 | + end | ||
62 | + | ||
63 | +end |
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +class Kalibro::NativeMetric < Kalibro::Metric | ||
2 | + | ||
3 | + attr_accessor :origin, :language | ||
4 | + | ||
5 | + def languages | ||
6 | + @language | ||
7 | + end | ||
8 | + | ||
9 | + def languages=(languages) | ||
10 | + @language = languages | ||
11 | + end | ||
12 | + | ||
13 | + def language=(value) | ||
14 | + @language = Kalibro::Model.to_objects_array value | ||
15 | + end | ||
16 | + | ||
17 | +end |