Commit 8d4c86eaa2f89eccf9b2c9e3e457604688506aa8
Committed by
Luciano Prestes
1 parent
f73553ab
Exists in
refactor_software_communities
software-communities: refactoring namespaces
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Rodrigo Souto <rodrigo@colivre.coop.br>
Showing
59 changed files
with
1491 additions
and
1488 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -class CategoriesAndTagsBlock < Block | |
2 | - | |
3 | - attr_accessible :show_name | |
4 | - | |
5 | - settings_items :show_name, :type => :boolean, :default => false | |
6 | - | |
7 | - def self.description | |
8 | - _('Categories and Tags') | |
9 | - end | |
10 | - | |
11 | - def help | |
12 | - _('This block displays the categories and tags of a software.') | |
13 | - end | |
14 | - | |
15 | - def content(args={}) | |
16 | - block = self | |
17 | - s = show_name | |
18 | - lambda do |object| | |
19 | - render( | |
20 | - :file => 'blocks/categories_and_tags', | |
21 | - :locals => { :block => block, :show_name => s } | |
22 | - ) | |
23 | - end | |
24 | - end | |
25 | - | |
26 | - def cacheable? | |
27 | - false | |
28 | - end | |
29 | -end |
src/noosfero-spb/software_communities/lib/categories_software_block.rb
... | ... | @@ -1,35 +0,0 @@ |
1 | -class CategoriesSoftwareBlock < Block | |
2 | - | |
3 | - attr_accessible :show_name | |
4 | - | |
5 | - settings_items :show_name, :type => :boolean, :default => false | |
6 | - | |
7 | - def self.description | |
8 | - _('Categories Softwares') | |
9 | - end | |
10 | - | |
11 | - def help | |
12 | - _('This block displays the categories and the amount of softwares for | |
13 | - each category.') | |
14 | - end | |
15 | - | |
16 | - def content(args={}) | |
17 | - block = self | |
18 | - s = show_name | |
19 | - | |
20 | - software_category = Category.find_by_name("Software") | |
21 | - categories = [] | |
22 | - categories = software_category.children.sort if software_category | |
23 | - | |
24 | - lambda do |object| | |
25 | - render( | |
26 | - :file => 'blocks/categories_software', | |
27 | - :locals => { :block => block, :show_name => s, :categories => categories } | |
28 | - ) | |
29 | - end | |
30 | - end | |
31 | - | |
32 | - def cacheable? | |
33 | - false | |
34 | - end | |
35 | -end |
src/noosfero-spb/software_communities/lib/create_software.rb
... | ... | @@ -1,115 +0,0 @@ |
1 | -class CreateSoftware < Task | |
2 | - include Rails.application.routes.url_helpers | |
3 | - | |
4 | - validates_presence_of :requestor_id, :target_id | |
5 | - validates_presence_of :name, :finality | |
6 | - | |
7 | - attr_accessible :name, :finality, :repository_link, :requestor, :environment, | |
8 | - :reject_explanation, :license_info, :identifier, :target | |
9 | - | |
10 | - alias :environment :target | |
11 | - alias :environment= :target= | |
12 | - | |
13 | - DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link'] | |
14 | - DATA_FIELDS.each do |field| | |
15 | - settings_items field.to_sym | |
16 | - end | |
17 | - | |
18 | - def perform | |
19 | - software_template = SoftwareHelper.software_template | |
20 | - template_id = software_template.blank? ? nil : software_template.id | |
21 | - | |
22 | - identifier = self.identifier | |
23 | - identifier ||= self.name.to_slug | |
24 | - | |
25 | - community = Community.create!(:name => self.name, | |
26 | - :identifier => identifier, | |
27 | - :template_id => template_id) | |
28 | - | |
29 | - community.environment = self.environment | |
30 | - community.add_admin(self.requestor) | |
31 | - | |
32 | - software = SoftwareInfo.create!(:finality => self.finality, | |
33 | - :repository_link => self.repository_link, :community_id => community.id, | |
34 | - :license_info => self.license_info) | |
35 | - end | |
36 | - | |
37 | - def title | |
38 | - _("New software") | |
39 | - end | |
40 | - | |
41 | - def subject | |
42 | - name | |
43 | - end | |
44 | - | |
45 | - def information | |
46 | - message = _('%{requestor} wants to create software %{subject} with') | |
47 | - if finality.blank? | |
48 | - { :message => message + _(' no finality.') } | |
49 | - else | |
50 | - { :message => message + _(' this finality:<p><em>%{finality}</em></p>'), | |
51 | - :variables => {:finality => finality} } | |
52 | - end | |
53 | - end | |
54 | - | |
55 | - def reject_details | |
56 | - true | |
57 | - end | |
58 | - | |
59 | - # tells if this request was rejected | |
60 | - def rejected? | |
61 | - self.status == Task::Status::CANCELLED | |
62 | - end | |
63 | - | |
64 | - # tells if this request was appoved | |
65 | - def approved? | |
66 | - self.status == Task::Status::FINISHED | |
67 | - end | |
68 | - | |
69 | - def target_notification_description | |
70 | - _('%{requestor} wants to create software %{subject}') % | |
71 | - {:requestor => requestor.name, :subject => subject} | |
72 | - end | |
73 | - | |
74 | - def target_notification_message | |
75 | - _("User \"%{user}\" just requested to create software %{software}. | |
76 | - You have to approve or reject it through the \"Pending Validations\" | |
77 | - section in your control panel.\n") % | |
78 | - { :user => self.requestor.name, :software => self.name } | |
79 | - end | |
80 | - | |
81 | - def task_created_message | |
82 | - _("Your request for registering software %{software} at %{environment} was | |
83 | - just sent. Environment administrator will receive it and will approve or | |
84 | - reject your request according to his methods and criteria. | |
85 | - | |
86 | - You will be notified as soon as environment administrator has a position | |
87 | - about your request.") % | |
88 | - { :software => self.name, :environment => self.target } | |
89 | - end | |
90 | - | |
91 | - def task_cancelled_message | |
92 | - _("Your request for registering software %{software} at %{environment} was | |
93 | - not approved by the environment administrator. The following explanation | |
94 | - was given: \n\n%{explanation}") % | |
95 | - { :software => self.name, | |
96 | - :environment => self.environment, | |
97 | - :explanation => self.reject_explanation } | |
98 | - end | |
99 | - | |
100 | - def task_finished_message | |
101 | - _('Your request for registering the software "%{software}" was approved. | |
102 | - You can access %{url} and finish the registration of your software.') % | |
103 | - { :software => self.name, :url => mount_url } | |
104 | - end | |
105 | - | |
106 | - private | |
107 | - | |
108 | - def mount_url | |
109 | - identifier = Community.where(:name => self.name).first.identifier | |
110 | - # The use of url_for doesn't allow the /social within the Public Software | |
111 | - # portal. That's why the url is mounted so 'hard coded' | |
112 | - url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community" | |
113 | - end | |
114 | - | |
115 | -end |
src/noosfero-spb/software_communities/lib/database_description.rb
... | ... | @@ -1,15 +0,0 @@ |
1 | -class DatabaseDescription < ActiveRecord::Base | |
2 | - | |
3 | - SEARCHABLE_SOFTWARE_FIELDS = { | |
4 | - :name => 1 | |
5 | - } | |
6 | - | |
7 | - attr_accessible :name | |
8 | - | |
9 | - has_many :software_databases | |
10 | - has_many :software_infos, :through => :software_databases | |
11 | - | |
12 | - validates_presence_of :name | |
13 | - validates_uniqueness_of :name | |
14 | - | |
15 | -end |
src/noosfero-spb/software_communities/lib/database_helper.rb
... | ... | @@ -1,77 +0,0 @@ |
1 | -class DatabaseHelper < DynamicTableHelper | |
2 | - MODEL_NAME ="database" | |
3 | - FIELD_NAME = "database_description_id" | |
4 | - | |
5 | - def self.valid_database? database | |
6 | - return false if SoftwareHelper.all_table_is_empty?(database) | |
7 | - | |
8 | - database_description_id_list = DatabaseDescription.select(:id). | |
9 | - collect {|dd| dd.id} | |
10 | - | |
11 | - return database_description_id_list.include?( | |
12 | - database[:database_description_id].to_i | |
13 | - ) | |
14 | - end | |
15 | - | |
16 | - def self.list_database new_databases | |
17 | - return [] if new_databases.nil? or new_databases.length == 0 | |
18 | - list_databases = [] | |
19 | - | |
20 | - new_databases.each do |new_database| | |
21 | - if valid_database? new_database | |
22 | - database = SoftwareDatabase.new | |
23 | - | |
24 | - database.database_description_id = | |
25 | - new_database[:database_description_id] | |
26 | - | |
27 | - database.version = new_database[:version] | |
28 | - list_databases << database | |
29 | - end | |
30 | - end | |
31 | - | |
32 | - list_databases | |
33 | - end | |
34 | - | |
35 | - def self.valid_list_database? list_databases | |
36 | - return false if list_databases.nil? or list_databases.length == 0 | |
37 | - return !list_databases.any?{|database| !database.valid?} | |
38 | - end | |
39 | - | |
40 | - def self.database_as_tables(list_databases, disabled=false) | |
41 | - model_list = list_databases | |
42 | - model_list ||= [{:database_description_id => "", :version => ""}] | |
43 | - | |
44 | - models_as_tables model_list, "database_html_structure", disabled | |
45 | - end | |
46 | - | |
47 | - def self.database_html_structure(database_data, disabled) | |
48 | - database_id = database_data[:database_description_id] | |
49 | - database_name = database_id.blank? ? "" : DatabaseDescription.find( | |
50 | - database_data[:database_description_id], | |
51 | - :select=>"name" | |
52 | - ).name | |
53 | - | |
54 | - data = { | |
55 | - model_name: MODEL_NAME, | |
56 | - field_name: FIELD_NAME, | |
57 | - name: { | |
58 | - value: database_name, | |
59 | - id: database_id, | |
60 | - hidden: true, | |
61 | - autocomplete: true, | |
62 | - select_field: false | |
63 | - }, | |
64 | - version: { | |
65 | - value: database_data[:version], | |
66 | - hidden: true, | |
67 | - delete: true | |
68 | - } | |
69 | - } | |
70 | - DATA[:license].delete(:value) | |
71 | - table_html_structure(data, disabled) | |
72 | - end | |
73 | - | |
74 | - def self.add_dynamic_table | |
75 | - database_as_tables(nil).first.call | |
76 | - end | |
77 | -end |
src/noosfero-spb/software_communities/lib/download.rb
... | ... | @@ -1,51 +0,0 @@ |
1 | -#FIX ME: Turn this into a proper model(next release) | |
2 | -class Download | |
3 | - def initialize data | |
4 | - @name = data[:name] | |
5 | - @link = data[:link] | |
6 | - @software_description = data[:software_description] | |
7 | - @minimum_requirements = data[:minimum_requirements] | |
8 | - @size = data[:size] | |
9 | - | |
10 | - @total_downloads = if data[:total_downloads] | |
11 | - data[:total_downloads] | |
12 | - else | |
13 | - 0 | |
14 | - end | |
15 | - end | |
16 | - | |
17 | - def self.validate_download_list download_list | |
18 | - download_list.select! do |download| | |
19 | - not download[:name].blank? | |
20 | - end | |
21 | - | |
22 | - download_list.map do |download| | |
23 | - Download.new(download).to_hash | |
24 | - end | |
25 | - end | |
26 | - | |
27 | - def to_hash | |
28 | - { | |
29 | - :name => @name, | |
30 | - :link => @link, | |
31 | - :software_description => @software_description, | |
32 | - :minimum_requirements => @minimum_requirements, | |
33 | - :size => @size, | |
34 | - :total_downloads => @total_downloads | |
35 | - } | |
36 | - end | |
37 | - | |
38 | - def total_downloads= value | |
39 | - if value.is_a? Integer | |
40 | - @total_downloads = value | |
41 | - end | |
42 | - end | |
43 | - | |
44 | - def total_downloads | |
45 | - @total_downloads | |
46 | - end | |
47 | - | |
48 | - def link | |
49 | - @link | |
50 | - end | |
51 | -end |
src/noosfero-spb/software_communities/lib/download_block.rb
... | ... | @@ -1,36 +0,0 @@ |
1 | -class DownloadBlock < Block | |
2 | - | |
3 | - attr_accessible :show_name, :downloads | |
4 | - | |
5 | - settings_items :show_name, :type => :boolean, :default => false | |
6 | - settings_items :downloads, :type => Array, :default => [] | |
7 | - | |
8 | - validate :download_values | |
9 | - | |
10 | - def download_values | |
11 | - self.downloads = Download.validate_download_list(self.downloads) | |
12 | - end | |
13 | - | |
14 | - def self.description | |
15 | - _('Download Stable Version') | |
16 | - end | |
17 | - | |
18 | - def help | |
19 | - _('This block displays the stable version of a software.') | |
20 | - end | |
21 | - | |
22 | - def content(args={}) | |
23 | - block = self | |
24 | - s = show_name | |
25 | - lambda do |object| | |
26 | - render( | |
27 | - :file => 'blocks/download', | |
28 | - :locals => { :block => block, :show_name => s } | |
29 | - ) | |
30 | - end | |
31 | - end | |
32 | - | |
33 | - def cacheable? | |
34 | - false | |
35 | - end | |
36 | -end |
src/noosfero-spb/software_communities/lib/dynamic_table_helper.rb
... | ... | @@ -1,153 +0,0 @@ |
1 | -class DynamicTableHelper | |
2 | - extend( | |
3 | - ActionView::Helpers::TagHelper, | |
4 | - ActionView::Helpers::FormTagHelper, | |
5 | - ActionView::Helpers::FormOptionsHelper, | |
6 | - ActionView::Helpers::UrlHelper, | |
7 | - ApplicationHelper | |
8 | - ) | |
9 | - | |
10 | - COLLUMN_NAME = { | |
11 | - name: "name", | |
12 | - version: "version", | |
13 | - license: "license" | |
14 | - } | |
15 | - | |
16 | - LABEL_TEXT = { | |
17 | - :name => _("Name"), | |
18 | - :version => _("Version"), | |
19 | - :license => _("License") | |
20 | - } | |
21 | - | |
22 | - DATA = { | |
23 | - name: { | |
24 | - label: LABEL_TEXT[:name], | |
25 | - name: COLLUMN_NAME[:name] | |
26 | - }, | |
27 | - version: { | |
28 | - label: LABEL_TEXT[:version], | |
29 | - name: COLLUMN_NAME[:version] | |
30 | - } , | |
31 | - license: { | |
32 | - label: LABEL_TEXT[:license], | |
33 | - name: COLLUMN_NAME[:license], | |
34 | - delete: true | |
35 | - } | |
36 | - } | |
37 | - @@disabled = false | |
38 | - | |
39 | - def self.table_html_structure data={}, disabled=false | |
40 | - @@disabled = disabled | |
41 | - Proc::new do | |
42 | - content_tag :table , generate_table_lines(data), :class => "dynamic-table" | |
43 | - end | |
44 | - end | |
45 | - | |
46 | - def self.generate_table_lines data={} | |
47 | - @@model = data[:model_name] | |
48 | - @@field_name = data[:field_name] | |
49 | - @@hidden_label = data[:name][:value] | |
50 | - @@hidden_id = data[:name][:id] | |
51 | - | |
52 | - row_data = prepare_row_data data | |
53 | - | |
54 | - table_line_data = [ | |
55 | - self.table_line(row_data[:name]), | |
56 | - self.table_line(row_data[:version]) | |
57 | - ] | |
58 | - | |
59 | - if row_data[:license].has_key?(:value) | |
60 | - table_line_data << self.table_line(row_data[:license]) | |
61 | - end | |
62 | - | |
63 | - table_line_data.join() | |
64 | - end | |
65 | - | |
66 | - def self.table_line row_data={} | |
67 | - unless row_data.blank? | |
68 | - content_tag :tr, [ | |
69 | - self.label_collumn(row_data[:label]), | |
70 | - self.value_collumn( | |
71 | - row_data[:value], | |
72 | - row_data[:name], | |
73 | - row_data[:autocomplete], | |
74 | - row_data[:select_field], | |
75 | - row_data[:options] | |
76 | - ), | |
77 | - self.hidden_collumn(row_data[:delete], row_data[:hidden]) | |
78 | - ].join() | |
79 | - end | |
80 | - end | |
81 | - | |
82 | - def self.label_collumn label="" | |
83 | - content_tag :td, label_tag(label) | |
84 | - end | |
85 | - | |
86 | - def self.value_collumn value="", name="", autocomplete=false, select_field=false, options=[] | |
87 | - html_options = | |
88 | - if autocomplete | |
89 | - { | |
90 | - :class => "#{@@model}_autocomplete", | |
91 | - :placeholder => _("Autocomplete field, type something") | |
92 | - } | |
93 | - else | |
94 | - {} | |
95 | - end | |
96 | - | |
97 | - html_options[:disabled] = @@disabled | |
98 | - | |
99 | - content = if select_field | |
100 | - select_tag("#{@@model}[][#{@@field_name}]", options, html_options) | |
101 | - elsif autocomplete | |
102 | - text_field_tag("#{@@model}_autocomplete", value, html_options) | |
103 | - else | |
104 | - text_field_tag("#{@@model}[][#{name}]", value, html_options) | |
105 | - end | |
106 | - | |
107 | - content_tag :td, content | |
108 | - end | |
109 | - | |
110 | - def self.hidden_collumn delete=false, hidden_data=false | |
111 | - value = | |
112 | - if @@disabled | |
113 | - nil | |
114 | - elsif delete | |
115 | - button_without_text( | |
116 | - :delete, _('Delete'), "#" , :class=>"delete-dynamic-table" | |
117 | - ) | |
118 | - elsif hidden_data | |
119 | - hidden_field_tag( | |
120 | - "#{@@model}[][#{@@field_name}]", | |
121 | - @@hidden_id, | |
122 | - :class => "#{@@field_name}", | |
123 | - :data => {:label => @@hidden_label } #check how to get the name of an object of the current model | |
124 | - ) | |
125 | - else | |
126 | - nil | |
127 | - end | |
128 | - | |
129 | - content_tag(:td, value, :align => 'right') | |
130 | - end | |
131 | - | |
132 | - def self.prepare_row_data data | |
133 | - row_data = { | |
134 | - name: DATA[:name], | |
135 | - version: DATA[:version], | |
136 | - license: DATA[:license] | |
137 | - } | |
138 | - | |
139 | - row_data[:name].merge! data[:name] | |
140 | - row_data[:version].merge! data[:version] | |
141 | - row_data[:license].merge! data[:license] if data.has_key? :license | |
142 | - | |
143 | - row_data | |
144 | - end | |
145 | - | |
146 | - def self.models_as_tables models, callback, disabled=false | |
147 | - lambdas_list = [] | |
148 | - | |
149 | - models.map do |model| | |
150 | - send(callback, model, disabled) | |
151 | - end | |
152 | - end | |
153 | -end | |
154 | 0 | \ No newline at end of file |
src/noosfero-spb/software_communities/lib/library.rb
... | ... | @@ -1,10 +0,0 @@ |
1 | -class Library < ActiveRecord::Base | |
2 | - attr_accessible :name, :version, :license, :software_info_id | |
3 | - | |
4 | - validates :name, :version, :license, | |
5 | - presence: { message: _("can't be blank") }, | |
6 | - length: { | |
7 | - maximum: 20, | |
8 | - too_long: _("Too long (maximum is 20 characters)") | |
9 | - } | |
10 | -end |
src/noosfero-spb/software_communities/lib/library_helper.rb
... | ... | @@ -1,57 +0,0 @@ |
1 | -class LibraryHelper < DynamicTableHelper | |
2 | - MODEL_NAME = "library" | |
3 | - | |
4 | - def self.list_library new_libraries | |
5 | - return [] if new_libraries.nil? or new_libraries.length == 0 | |
6 | - list_libraries = [] | |
7 | - | |
8 | - new_libraries.each do |new_library| | |
9 | - unless SoftwareHelper.all_table_is_empty? new_library | |
10 | - library = Library.new | |
11 | - library.name = new_library[:name] | |
12 | - library.version = new_library[:version] | |
13 | - library.license = new_library[:license] | |
14 | - list_libraries << library | |
15 | - end | |
16 | - end | |
17 | - | |
18 | - list_libraries | |
19 | - end | |
20 | - | |
21 | - def self.valid_list_library? list_libraries | |
22 | - return true if list_libraries.nil? or list_libraries.length == 0 | |
23 | - return !list_libraries.any?{|library| !library.valid?} | |
24 | - end | |
25 | - | |
26 | - def self.libraries_as_tables list_libraries, disabled=false | |
27 | - model_list = list_libraries | |
28 | - model_list ||= [{:name=>"", :version=>"", :license=>""}] | |
29 | - | |
30 | - models_as_tables model_list, "library_html_structure", disabled | |
31 | - end | |
32 | - | |
33 | - def self.library_html_structure library_data, disabled | |
34 | - data = { | |
35 | - model_name: MODEL_NAME, | |
36 | - name: { | |
37 | - value: library_data[:name], | |
38 | - hidden: false, | |
39 | - autocomplete: false, | |
40 | - select_field: false | |
41 | - }, | |
42 | - version: { | |
43 | - value: library_data[:version], | |
44 | - delete: false | |
45 | - }, | |
46 | - license: { | |
47 | - value: library_data[:license] | |
48 | - } | |
49 | - } | |
50 | - | |
51 | - table_html_structure(data, disabled) | |
52 | - end | |
53 | - | |
54 | - def self.add_dynamic_table | |
55 | - libraries_as_tables(nil).first.call | |
56 | - end | |
57 | -end |
src/noosfero-spb/software_communities/lib/license_helper.rb
... | ... | @@ -1,9 +0,0 @@ |
1 | -module LicenseHelper | |
2 | - def self.find_licenses query | |
3 | - licenses = LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") | |
4 | - licenses.reject!{|license| license.version == "Another"} | |
5 | - license_another = LicenseInfo.find_by_version("Another") | |
6 | - licenses << license_another if license_another | |
7 | - licenses | |
8 | - end | |
9 | -end |
src/noosfero-spb/software_communities/lib/license_info.rb
src/noosfero-spb/software_communities/lib/operating_system.rb
... | ... | @@ -1,14 +0,0 @@ |
1 | -class OperatingSystem < ActiveRecord::Base | |
2 | - attr_accessible :version | |
3 | - | |
4 | - belongs_to :software_info | |
5 | - belongs_to :operating_system_name | |
6 | - | |
7 | - validates :operating_system_name, presence: true | |
8 | - validates :version, | |
9 | - presence: true, | |
10 | - length: { | |
11 | - maximum: 20, | |
12 | - too_long: _('too long (maximum is 20 characters)') | |
13 | - } | |
14 | -end |
src/noosfero-spb/software_communities/lib/operating_system_helper.rb
... | ... | @@ -1,67 +0,0 @@ |
1 | -class OperatingSystemHelper < DynamicTableHelper | |
2 | - MODEL_NAME = "operating_system" | |
3 | - FIELD_NAME = "operating_system_name_id" | |
4 | - | |
5 | - def self.list_operating_system new_operating_systems | |
6 | - return [] if new_operating_systems.nil? or new_operating_systems.length == 0 | |
7 | - list_operating_system = [] | |
8 | - | |
9 | - new_operating_systems.each do |new_operating_system| | |
10 | - unless SoftwareHelper.all_table_is_empty?( | |
11 | - new_operating_system, | |
12 | - ["operating_system_name_id"] | |
13 | - ) | |
14 | - | |
15 | - operating_system = OperatingSystem.new | |
16 | - operating_system.operating_system_name = OperatingSystemName.find( | |
17 | - new_operating_system[:operating_system_name_id] | |
18 | - ) | |
19 | - | |
20 | - operating_system.version = new_operating_system[:version] | |
21 | - list_operating_system << operating_system | |
22 | - end | |
23 | - end | |
24 | - list_operating_system | |
25 | - end | |
26 | - | |
27 | - def self.valid_list_operating_system? list_operating_system | |
28 | - return false if (list_operating_system.nil? || list_operating_system.length == 0) | |
29 | - return !list_operating_system.any?{|os| !os.valid?} | |
30 | - end | |
31 | - | |
32 | - def self.operating_system_as_tables(list_operating_system, disabled=false) | |
33 | - model_list = list_operating_system | |
34 | - model_list ||= [{:operating_system_name_id => "", :version => ""}] | |
35 | - | |
36 | - models_as_tables model_list, "operating_system_html_structure", disabled | |
37 | - end | |
38 | - | |
39 | - def self.operating_system_html_structure (operating_system_data, disabled) | |
40 | - select_options = options_for_select( | |
41 | - OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, | |
42 | - operating_system_data[:operating_system_name_id] | |
43 | - ) | |
44 | - | |
45 | - data = { | |
46 | - model_name: MODEL_NAME, | |
47 | - field_name: FIELD_NAME, | |
48 | - name: { | |
49 | - hidden: false, | |
50 | - autocomplete: false, | |
51 | - select_field: true, | |
52 | - options: select_options | |
53 | - }, | |
54 | - version: { | |
55 | - value: operating_system_data[:version], | |
56 | - hidden: true, | |
57 | - delete: true | |
58 | - } | |
59 | - } | |
60 | - DATA[:license].delete(:value) | |
61 | - table_html_structure(data, disabled) | |
62 | - end | |
63 | - | |
64 | - def self.add_dynamic_table | |
65 | - operating_system_as_tables(nil).first.call | |
66 | - end | |
67 | -end |
src/noosfero-spb/software_communities/lib/operating_system_name.rb
src/noosfero-spb/software_communities/lib/programming_language.rb
... | ... | @@ -1,15 +0,0 @@ |
1 | -class ProgrammingLanguage < ActiveRecord::Base | |
2 | - | |
3 | - SEARCHABLE_SOFTWARE_FIELDS = { | |
4 | - :name => 1 | |
5 | - } | |
6 | - | |
7 | - attr_accessible :name | |
8 | - | |
9 | - validates_presence_of :name | |
10 | - validates_uniqueness_of :name | |
11 | - | |
12 | - has_many :software_languages | |
13 | - has_many :software_infos, :through => :software_languages | |
14 | - | |
15 | -end |
src/noosfero-spb/software_communities/lib/repository_block.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -class RepositoryBlock < Block | |
2 | - | |
3 | - attr_accessible :show_name | |
4 | - | |
5 | - settings_items :show_name, :type => :boolean, :default => false | |
6 | - | |
7 | - def self.description | |
8 | - _('Repository Link') | |
9 | - end | |
10 | - | |
11 | - def help | |
12 | - _('This block displays the repository link of a software.') | |
13 | - end | |
14 | - | |
15 | - def content(args={}) | |
16 | - block = self | |
17 | - s = show_name | |
18 | - lambda do |object| | |
19 | - render( | |
20 | - :file => 'blocks/repository', | |
21 | - :locals => { :block => block, :show_name => s } | |
22 | - ) | |
23 | - end | |
24 | - end | |
25 | - | |
26 | - def cacheable? | |
27 | - false | |
28 | - end | |
29 | -end |
src/noosfero-spb/software_communities/lib/search_catalog_block.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -class SearchCatalogBlock < Block | |
2 | - | |
3 | - attr_accessible :show_name | |
4 | - | |
5 | - settings_items :show_name, :type => :boolean, :default => false | |
6 | - | |
7 | - def self.description | |
8 | - _('Search Softwares catalog') | |
9 | - end | |
10 | - | |
11 | - def help | |
12 | - _('This block displays the search categories field ') | |
13 | - end | |
14 | - | |
15 | - def content(args={}) | |
16 | - block = self | |
17 | - s = show_name | |
18 | - lambda do |object| | |
19 | - render( | |
20 | - :file => 'blocks/search_catalog', | |
21 | - :locals => { :block => block, :show_name => s } | |
22 | - ) | |
23 | - end | |
24 | - end | |
25 | - | |
26 | - def cacheable? | |
27 | - false | |
28 | - end | |
29 | -end |
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
... | ... | @@ -33,17 +33,17 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin |
33 | 33 | |
34 | 34 | def self.extra_blocks |
35 | 35 | { |
36 | - SoftwaresBlock => { :type => [Environment, Person] }, | |
37 | - SoftwareInformationBlock => { :type => [Community] }, | |
38 | - DownloadBlock => { :type => [Community] }, | |
39 | - RepositoryBlock => { :type => [Community] }, | |
40 | - CategoriesAndTagsBlock => { :type => [Community] }, | |
41 | - CategoriesSoftwareBlock => { :type => [Environment] }, | |
42 | - SearchCatalogBlock => { :type => [Environment] }, | |
43 | - SoftwareHighlightsBlock => { :type => [Environment] }, | |
44 | - SoftwareTabDataBlock => {:type => [Community], :position => 1}, | |
45 | - WikiBlock => {:type => [Community]}, | |
46 | - StatisticBlock => { :type => [Community] } | |
36 | + SoftwareCommunitiesPlugin::SoftwaresBlock => { :type => [Environment, Person] }, | |
37 | + SoftwareCommunitiesPlugin::SoftwareInformationBlock => { :type => [Community] }, | |
38 | + SoftwareCommunitiesPlugin::DownloadBlock => { :type => [Community] }, | |
39 | + SoftwareCommunitiesPlugin::RepositoryBlock => { :type => [Community] }, | |
40 | + SoftwareCommunitiesPlugin::CategoriesAndTagsBlock => { :type => [Community] }, | |
41 | + SoftwareCommunitiesPlugin::CategoriesSoftwareBlock => { :type => [Environment] }, | |
42 | + SoftwareCommunitiesPlugin::SearchCatalogBlock => { :type => [Environment] }, | |
43 | + SoftwareCommunitiesPlugin::SoftwareHighlightsBlock => { :type => [Environment] }, | |
44 | + SoftwareCommunitiesPlugin::SoftwareTabDataBlock => {:type => [Community], :position => 1}, | |
45 | + SoftwareCommunitiesPlugin::WikiBlock => {:type => [Community]}, | |
46 | + SoftwareCommunitiesPlugin::StatisticBlock => { :type => [Community] } | |
47 | 47 | } |
48 | 48 | end |
49 | 49 | |
... | ... | @@ -117,7 +117,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin |
117 | 117 | protected |
118 | 118 | |
119 | 119 | def software_info_transaction |
120 | - SoftwareInfo.transaction do | |
120 | + SoftwareCommunitiesPlugin::SoftwareInfo.transaction do | |
121 | 121 | context.profile. |
122 | 122 | software_info. |
123 | 123 | update_attributes!(context.params[:software_info]) |
... | ... | @@ -125,7 +125,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin |
125 | 125 | end |
126 | 126 | |
127 | 127 | def license_transaction |
128 | - license = LicenseInfo.find(context.params[:version]) | |
128 | + license = SoftwareCommunitiesPlugin::LicenseInfo.find(context.params[:version]) | |
129 | 129 | context.profile.software_info.license_info = license |
130 | 130 | context.profile.software_info.save! |
131 | 131 | end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_and_tags_block.rb
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +class SoftwareCommunitiesPlugin::CategoriesAndTagsBlock < Block | |
2 | + | |
3 | + attr_accessible :show_name | |
4 | + | |
5 | + settings_items :show_name, :type => :boolean, :default => false | |
6 | + | |
7 | + def self.description | |
8 | + _('Categories and Tags') | |
9 | + end | |
10 | + | |
11 | + def help | |
12 | + _('This block displays the categories and tags of a software.') | |
13 | + end | |
14 | + | |
15 | + def content(args={}) | |
16 | + block = self | |
17 | + s = show_name | |
18 | + lambda do |object| | |
19 | + render( | |
20 | + :file => 'blocks/categories_and_tags', | |
21 | + :locals => { :block => block, :show_name => s } | |
22 | + ) | |
23 | + end | |
24 | + end | |
25 | + | |
26 | + def cacheable? | |
27 | + false | |
28 | + end | |
29 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_software_block.rb
0 → 100644
... | ... | @@ -0,0 +1,35 @@ |
1 | +class SoftwareCommunitiesPlugin::CategoriesSoftwareBlock < Block | |
2 | + | |
3 | + attr_accessible :show_name | |
4 | + | |
5 | + settings_items :show_name, :type => :boolean, :default => false | |
6 | + | |
7 | + def self.description | |
8 | + _('Categories Softwares') | |
9 | + end | |
10 | + | |
11 | + def help | |
12 | + _('This block displays the categories and the amount of softwares for | |
13 | + each category.') | |
14 | + end | |
15 | + | |
16 | + def content(args={}) | |
17 | + block = self | |
18 | + s = show_name | |
19 | + | |
20 | + software_category = Category.find_by_name("Software") | |
21 | + categories = [] | |
22 | + categories = software_category.children.sort if software_category | |
23 | + | |
24 | + lambda do |object| | |
25 | + render( | |
26 | + :file => 'blocks/categories_software', | |
27 | + :locals => { :block => block, :show_name => s, :categories => categories } | |
28 | + ) | |
29 | + end | |
30 | + end | |
31 | + | |
32 | + def cacheable? | |
33 | + false | |
34 | + end | |
35 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb
0 → 100644
... | ... | @@ -0,0 +1,115 @@ |
1 | +class SoftwareCommunitiesPlugin::CreateSoftware < Task | |
2 | + include Rails.application.routes.url_helpers | |
3 | + | |
4 | + validates_presence_of :requestor_id, :target_id | |
5 | + validates_presence_of :name, :finality | |
6 | + | |
7 | + attr_accessible :name, :finality, :repository_link, :requestor, :environment, | |
8 | + :reject_explanation, :license_info, :identifier, :target | |
9 | + | |
10 | + alias :environment :target | |
11 | + alias :environment= :target= | |
12 | + | |
13 | + DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link'] | |
14 | + DATA_FIELDS.each do |field| | |
15 | + settings_items field.to_sym | |
16 | + end | |
17 | + | |
18 | + def perform | |
19 | + software_template = SoftwareCommunitiesPlugin::SoftwareHelper.software_template | |
20 | + template_id = software_template.blank? ? nil : software_template.id | |
21 | + | |
22 | + identifier = self.identifier | |
23 | + identifier ||= self.name.to_slug | |
24 | + | |
25 | + community = Community.create!(:name => self.name, | |
26 | + :identifier => identifier, | |
27 | + :template_id => template_id) | |
28 | + | |
29 | + community.environment = self.environment | |
30 | + community.add_admin(self.requestor) | |
31 | + | |
32 | + software = SoftwareCommunitiesPlugin::SoftwareInfo.create!(:finality => self.finality, | |
33 | + :repository_link => self.repository_link, :community_id => community.id, | |
34 | + :license_info => self.license_info) | |
35 | + end | |
36 | + | |
37 | + def title | |
38 | + _("New software") | |
39 | + end | |
40 | + | |
41 | + def subject | |
42 | + name | |
43 | + end | |
44 | + | |
45 | + def information | |
46 | + message = _('%{requestor} wants to create software %{subject} with') | |
47 | + if finality.blank? | |
48 | + { :message => message + _(' no finality.') } | |
49 | + else | |
50 | + { :message => message + _(' this finality:<p><em>%{finality}</em></p>'), | |
51 | + :variables => {:finality => finality} } | |
52 | + end | |
53 | + end | |
54 | + | |
55 | + def reject_details | |
56 | + true | |
57 | + end | |
58 | + | |
59 | + # tells if this request was rejected | |
60 | + def rejected? | |
61 | + self.status == Task::Status::CANCELLED | |
62 | + end | |
63 | + | |
64 | + # tells if this request was appoved | |
65 | + def approved? | |
66 | + self.status == Task::Status::FINISHED | |
67 | + end | |
68 | + | |
69 | + def target_notification_description | |
70 | + _('%{requestor} wants to create software %{subject}') % | |
71 | + {:requestor => requestor.name, :subject => subject} | |
72 | + end | |
73 | + | |
74 | + def target_notification_message | |
75 | + _("User \"%{user}\" just requested to create software %{software}. | |
76 | + You have to approve or reject it through the \"Pending Validations\" | |
77 | + section in your control panel.\n") % | |
78 | + { :user => self.requestor.name, :software => self.name } | |
79 | + end | |
80 | + | |
81 | + def task_created_message | |
82 | + _("Your request for registering software %{software} at %{environment} was | |
83 | + just sent. Environment administrator will receive it and will approve or | |
84 | + reject your request according to his methods and criteria. | |
85 | + | |
86 | + You will be notified as soon as environment administrator has a position | |
87 | + about your request.") % | |
88 | + { :software => self.name, :environment => self.target } | |
89 | + end | |
90 | + | |
91 | + def task_cancelled_message | |
92 | + _("Your request for registering software %{software} at %{environment} was | |
93 | + not approved by the environment administrator. The following explanation | |
94 | + was given: \n\n%{explanation}") % | |
95 | + { :software => self.name, | |
96 | + :environment => self.environment, | |
97 | + :explanation => self.reject_explanation } | |
98 | + end | |
99 | + | |
100 | + def task_finished_message | |
101 | + _('Your request for registering the software "%{software}" was approved. | |
102 | + You can access %{url} and finish the registration of your software.') % | |
103 | + { :software => self.name, :url => mount_url } | |
104 | + end | |
105 | + | |
106 | + private | |
107 | + | |
108 | + def mount_url | |
109 | + identifier = Community.where(:name => self.name).first.identifier | |
110 | + # The use of url_for doesn't allow the /social within the Public Software | |
111 | + # portal. That's why the url is mounted so 'hard coded' | |
112 | + url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community" | |
113 | + end | |
114 | + | |
115 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/database_description.rb
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +class SoftwareCommunitiesPlugin::DatabaseDescription < ActiveRecord::Base | |
2 | + | |
3 | + SEARCHABLE_SOFTWARE_FIELDS = { | |
4 | + :name => 1 | |
5 | + } | |
6 | + | |
7 | + attr_accessible :name | |
8 | + | |
9 | + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase' | |
10 | + has_many :software_infos, :through => :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' | |
11 | + | |
12 | + validates_presence_of :name | |
13 | + validates_uniqueness_of :name | |
14 | + | |
15 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/database_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,77 @@ |
1 | +class SoftwareCommunitiesPlugin::DatabaseHelper < SoftwareCommunitiesPlugin::DynamicTableHelper | |
2 | + MODEL_NAME ="database" | |
3 | + FIELD_NAME = "database_description_id" | |
4 | + | |
5 | + def self.valid_database? database | |
6 | + return false if SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty?(database) | |
7 | + | |
8 | + database_description_id_list = SoftwareCommunitiesPlugin::DatabaseDescription.select(:id). | |
9 | + collect {|dd| dd.id} | |
10 | + | |
11 | + return database_description_id_list.include?( | |
12 | + database[:database_description_id].to_i | |
13 | + ) | |
14 | + end | |
15 | + | |
16 | + def self.list_database new_databases | |
17 | + return [] if new_databases.nil? or new_databases.length == 0 | |
18 | + list_databases = [] | |
19 | + | |
20 | + new_databases.each do |new_database| | |
21 | + if valid_database? new_database | |
22 | + database = SoftwareCommunitiesPlugin::SoftwareDatabase.new | |
23 | + | |
24 | + database.database_description_id = | |
25 | + new_database[:database_description_id] | |
26 | + | |
27 | + database.version = new_database[:version] | |
28 | + list_databases << database | |
29 | + end | |
30 | + end | |
31 | + | |
32 | + list_databases | |
33 | + end | |
34 | + | |
35 | + def self.valid_list_database? list_databases | |
36 | + return false if list_databases.nil? or list_databases.length == 0 | |
37 | + return !list_databases.any?{|database| !database.valid?} | |
38 | + end | |
39 | + | |
40 | + def self.database_as_tables(list_databases, disabled=false) | |
41 | + model_list = list_databases | |
42 | + model_list ||= [{:database_description_id => "", :version => ""}] | |
43 | + | |
44 | + models_as_tables model_list, "database_html_structure", disabled | |
45 | + end | |
46 | + | |
47 | + def self.database_html_structure(database_data, disabled) | |
48 | + database_id = database_data[:database_description_id] | |
49 | + database_name = database_id.blank? ? "" : SoftwareCommunitiesPlugin::DatabaseDescription.find( | |
50 | + database_data[:database_description_id], | |
51 | + :select=>"name" | |
52 | + ).name | |
53 | + | |
54 | + data = { | |
55 | + model_name: MODEL_NAME, | |
56 | + field_name: FIELD_NAME, | |
57 | + name: { | |
58 | + value: database_name, | |
59 | + id: database_id, | |
60 | + hidden: true, | |
61 | + autocomplete: true, | |
62 | + select_field: false | |
63 | + }, | |
64 | + version: { | |
65 | + value: database_data[:version], | |
66 | + hidden: true, | |
67 | + delete: true | |
68 | + } | |
69 | + } | |
70 | + DATA[:license].delete(:value) | |
71 | + table_html_structure(data, disabled) | |
72 | + end | |
73 | + | |
74 | + def self.add_dynamic_table | |
75 | + database_as_tables(nil).first.call | |
76 | + end | |
77 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/download.rb
0 → 100644
... | ... | @@ -0,0 +1,51 @@ |
1 | +#FIX ME: Turn this into a proper model(next release) | |
2 | +class SoftwareCommunitiesPlugin::Download | |
3 | + def initialize data | |
4 | + @name = data[:name] | |
5 | + @link = data[:link] | |
6 | + @software_description = data[:software_description] | |
7 | + @minimum_requirements = data[:minimum_requirements] | |
8 | + @size = data[:size] | |
9 | + | |
10 | + @total_downloads = if data[:total_downloads] | |
11 | + data[:total_downloads] | |
12 | + else | |
13 | + 0 | |
14 | + end | |
15 | + end | |
16 | + | |
17 | + def self.validate_download_list download_list | |
18 | + download_list.select! do |download| | |
19 | + not download[:name].blank? | |
20 | + end | |
21 | + | |
22 | + download_list.map do |download| | |
23 | + SoftwareCommunitiesPlugin::Download.new(download).to_hash | |
24 | + end | |
25 | + end | |
26 | + | |
27 | + def to_hash | |
28 | + { | |
29 | + :name => @name, | |
30 | + :link => @link, | |
31 | + :software_description => @software_description, | |
32 | + :minimum_requirements => @minimum_requirements, | |
33 | + :size => @size, | |
34 | + :total_downloads => @total_downloads | |
35 | + } | |
36 | + end | |
37 | + | |
38 | + def total_downloads= value | |
39 | + if value.is_a? Integer | |
40 | + @total_downloads = value | |
41 | + end | |
42 | + end | |
43 | + | |
44 | + def total_downloads | |
45 | + @total_downloads | |
46 | + end | |
47 | + | |
48 | + def link | |
49 | + @link | |
50 | + end | |
51 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/download_block.rb
0 → 100644
... | ... | @@ -0,0 +1,36 @@ |
1 | +class SoftwareCommunitiesPlugin::DownloadBlock < Block | |
2 | + | |
3 | + attr_accessible :show_name, :downloads | |
4 | + | |
5 | + settings_items :show_name, :type => :boolean, :default => false | |
6 | + settings_items :downloads, :type => Array, :default => [] | |
7 | + | |
8 | + validate :download_values | |
9 | + | |
10 | + def download_values | |
11 | + self.downloads = SoftwareCommunitiesPlugin::Download.validate_download_list(self.downloads) | |
12 | + end | |
13 | + | |
14 | + def self.description | |
15 | + _('Download Stable Version') | |
16 | + end | |
17 | + | |
18 | + def help | |
19 | + _('This block displays the stable version of a software.') | |
20 | + end | |
21 | + | |
22 | + def content(args={}) | |
23 | + block = self | |
24 | + s = show_name | |
25 | + lambda do |object| | |
26 | + render( | |
27 | + :file => 'blocks/download', | |
28 | + :locals => { :block => block, :show_name => s } | |
29 | + ) | |
30 | + end | |
31 | + end | |
32 | + | |
33 | + def cacheable? | |
34 | + false | |
35 | + end | |
36 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/dynamic_table_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,153 @@ |
1 | +class SoftwareCommunitiesPlugin::DynamicTableHelper | |
2 | + extend( | |
3 | + ActionView::Helpers::TagHelper, | |
4 | + ActionView::Helpers::FormTagHelper, | |
5 | + ActionView::Helpers::FormOptionsHelper, | |
6 | + ActionView::Helpers::UrlHelper, | |
7 | + ApplicationHelper | |
8 | + ) | |
9 | + | |
10 | + COLLUMN_NAME = { | |
11 | + name: "name", | |
12 | + version: "version", | |
13 | + license: "license" | |
14 | + } | |
15 | + | |
16 | + LABEL_TEXT = { | |
17 | + :name => _("Name"), | |
18 | + :version => _("Version"), | |
19 | + :license => _("License") | |
20 | + } | |
21 | + | |
22 | + DATA = { | |
23 | + name: { | |
24 | + label: LABEL_TEXT[:name], | |
25 | + name: COLLUMN_NAME[:name] | |
26 | + }, | |
27 | + version: { | |
28 | + label: LABEL_TEXT[:version], | |
29 | + name: COLLUMN_NAME[:version] | |
30 | + } , | |
31 | + license: { | |
32 | + label: LABEL_TEXT[:license], | |
33 | + name: COLLUMN_NAME[:license], | |
34 | + delete: true | |
35 | + } | |
36 | + } | |
37 | + @@disabled = false | |
38 | + | |
39 | + def self.table_html_structure data={}, disabled=false | |
40 | + @@disabled = disabled | |
41 | + Proc::new do | |
42 | + content_tag :table , generate_table_lines(data), :class => "dynamic-table" | |
43 | + end | |
44 | + end | |
45 | + | |
46 | + def self.generate_table_lines data={} | |
47 | + @@model = data[:model_name] | |
48 | + @@field_name = data[:field_name] | |
49 | + @@hidden_label = data[:name][:value] | |
50 | + @@hidden_id = data[:name][:id] | |
51 | + | |
52 | + row_data = prepare_row_data data | |
53 | + | |
54 | + table_line_data = [ | |
55 | + self.table_line(row_data[:name]), | |
56 | + self.table_line(row_data[:version]) | |
57 | + ] | |
58 | + | |
59 | + if row_data[:license].has_key?(:value) | |
60 | + table_line_data << self.table_line(row_data[:license]) | |
61 | + end | |
62 | + | |
63 | + table_line_data.join() | |
64 | + end | |
65 | + | |
66 | + def self.table_line row_data={} | |
67 | + unless row_data.blank? | |
68 | + content_tag :tr, [ | |
69 | + self.label_collumn(row_data[:label]), | |
70 | + self.value_collumn( | |
71 | + row_data[:value], | |
72 | + row_data[:name], | |
73 | + row_data[:autocomplete], | |
74 | + row_data[:select_field], | |
75 | + row_data[:options] | |
76 | + ), | |
77 | + self.hidden_collumn(row_data[:delete], row_data[:hidden]) | |
78 | + ].join() | |
79 | + end | |
80 | + end | |
81 | + | |
82 | + def self.label_collumn label="" | |
83 | + content_tag :td, label_tag(label) | |
84 | + end | |
85 | + | |
86 | + def self.value_collumn value="", name="", autocomplete=false, select_field=false, options=[] | |
87 | + html_options = | |
88 | + if autocomplete | |
89 | + { | |
90 | + :class => "#{@@model}_autocomplete", | |
91 | + :placeholder => _("Autocomplete field, type something") | |
92 | + } | |
93 | + else | |
94 | + {} | |
95 | + end | |
96 | + | |
97 | + html_options[:disabled] = @@disabled | |
98 | + | |
99 | + content = if select_field | |
100 | + select_tag("#{@@model}[][#{@@field_name}]", options, html_options) | |
101 | + elsif autocomplete | |
102 | + text_field_tag("#{@@model}_autocomplete", value, html_options) | |
103 | + else | |
104 | + text_field_tag("#{@@model}[][#{name}]", value, html_options) | |
105 | + end | |
106 | + | |
107 | + content_tag :td, content | |
108 | + end | |
109 | + | |
110 | + def self.hidden_collumn delete=false, hidden_data=false | |
111 | + value = | |
112 | + if @@disabled | |
113 | + nil | |
114 | + elsif delete | |
115 | + button_without_text( | |
116 | + :delete, _('Delete'), "#" , :class=>"delete-dynamic-table" | |
117 | + ) | |
118 | + elsif hidden_data | |
119 | + hidden_field_tag( | |
120 | + "#{@@model}[][#{@@field_name}]", | |
121 | + @@hidden_id, | |
122 | + :class => "#{@@field_name}", | |
123 | + :data => {:label => @@hidden_label } #check how to get the name of an object of the current model | |
124 | + ) | |
125 | + else | |
126 | + nil | |
127 | + end | |
128 | + | |
129 | + content_tag(:td, value, :align => 'right') | |
130 | + end | |
131 | + | |
132 | + def self.prepare_row_data data | |
133 | + row_data = { | |
134 | + name: DATA[:name], | |
135 | + version: DATA[:version], | |
136 | + license: DATA[:license] | |
137 | + } | |
138 | + | |
139 | + row_data[:name].merge! data[:name] | |
140 | + row_data[:version].merge! data[:version] | |
141 | + row_data[:license].merge! data[:license] if data.has_key? :license | |
142 | + | |
143 | + row_data | |
144 | + end | |
145 | + | |
146 | + def self.models_as_tables models, callback, disabled=false | |
147 | + lambdas_list = [] | |
148 | + | |
149 | + models.map do |model| | |
150 | + send(callback, model, disabled) | |
151 | + end | |
152 | + end | |
153 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/library.rb
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +class SoftwareCommunitiesPlugin::Library < ActiveRecord::Base | |
2 | + attr_accessible :name, :version, :license, :software_info_id | |
3 | + | |
4 | + validates :name, :version, :license, | |
5 | + presence: { message: _("can't be blank") }, | |
6 | + length: { | |
7 | + maximum: 20, | |
8 | + too_long: _("Too long (maximum is 20 characters)") | |
9 | + } | |
10 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/library_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,59 @@ |
1 | +class SoftwareCommunitiesPlugin::LibraryHelper < SoftwareCommunitiesPlugin::DynamicTableHelper | |
2 | + #FIXME Verify this name. | |
3 | + MODEL_NAME = "software_communities_plugin/library" | |
4 | + | |
5 | + def self.list_library new_libraries | |
6 | + return [] if new_libraries.nil? or new_libraries.length == 0 | |
7 | + list_libraries = [] | |
8 | + | |
9 | + new_libraries.each do |new_library| | |
10 | + unless SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty? new_library | |
11 | + library = SoftwareCommunitiesPlugin::Library.new | |
12 | + library.name = new_library[:name] | |
13 | + library.version = new_library[:version] | |
14 | + library.license = new_library[:license] | |
15 | + list_libraries << library | |
16 | + end | |
17 | + end | |
18 | + | |
19 | + list_libraries | |
20 | + end | |
21 | + | |
22 | + def self.valid_list_library? list_libraries | |
23 | + return true if list_libraries.nil? or list_libraries.length == 0 | |
24 | + return !list_libraries.any?{|library| !library.valid?} | |
25 | + end | |
26 | + | |
27 | + def self.libraries_as_tables list_libraries, disabled=false | |
28 | + model_list = list_libraries | |
29 | + model_list ||= [{:name=>"", :version=>"", :license=>""}] | |
30 | + | |
31 | + models_as_tables model_list, "library_html_structure", disabled | |
32 | + end | |
33 | + | |
34 | + def self.library_html_structure library_data, disabled | |
35 | + data = { | |
36 | + #FIXME Verify MODEL_NAME | |
37 | + model_name: MODEL_NAME, | |
38 | + name: { | |
39 | + value: library_data[:name], | |
40 | + hidden: false, | |
41 | + autocomplete: false, | |
42 | + select_field: false | |
43 | + }, | |
44 | + version: { | |
45 | + value: library_data[:version], | |
46 | + delete: false | |
47 | + }, | |
48 | + license: { | |
49 | + value: library_data[:license] | |
50 | + } | |
51 | + } | |
52 | + | |
53 | + table_html_structure(data, disabled) | |
54 | + end | |
55 | + | |
56 | + def self.add_dynamic_table | |
57 | + libraries_as_tables(nil).first.call | |
58 | + end | |
59 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/license_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,9 @@ |
1 | +module SoftwareCommunitiesPlugin::LicenseHelper | |
2 | + def self.find_licenses query | |
3 | + licenses = SoftwareCommunitiesPlugin::LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") | |
4 | + licenses.reject!{|license| license.version == "Another"} | |
5 | + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") | |
6 | + licenses << license_another if license_another | |
7 | + licenses | |
8 | + end | |
9 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/license_info.rb
0 → 100644
src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system.rb
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +class SoftwareCommunitiesPlugin::OperatingSystem < ActiveRecord::Base | |
2 | + attr_accessible :version | |
3 | + | |
4 | + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' | |
5 | + belongs_to :operating_system_name, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName' | |
6 | + | |
7 | + validates :operating_system_name, presence: true | |
8 | + validates :version, | |
9 | + presence: true, | |
10 | + length: { | |
11 | + maximum: 20, | |
12 | + too_long: _('too long (maximum is 20 characters)') | |
13 | + } | |
14 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,69 @@ |
1 | +class SoftwareCommunitiesPlugin::OperatingSystemHelper < SoftwareCommunitiesPlugin::DynamicTableHelper | |
2 | + #FIXME Verify model_name | |
3 | + MODEL_NAME = "software_communities_plugin/operating_system" | |
4 | + FIELD_NAME = "operating_system_name_id" | |
5 | + | |
6 | + def self.list_operating_system new_operating_systems | |
7 | + return [] if new_operating_systems.nil? or new_operating_systems.length == 0 | |
8 | + list_operating_system = [] | |
9 | + | |
10 | + new_operating_systems.each do |new_operating_system| | |
11 | + unless SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty?( | |
12 | + new_operating_system, | |
13 | + ["operating_system_name_id"] | |
14 | + ) | |
15 | + | |
16 | + operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new | |
17 | + operating_system.operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName.find( | |
18 | + new_operating_system[:operating_system_name_id] | |
19 | + ) | |
20 | + | |
21 | + operating_system.version = new_operating_system[:version] | |
22 | + list_operating_system << operating_system | |
23 | + end | |
24 | + end | |
25 | + list_operating_system | |
26 | + end | |
27 | + | |
28 | + def self.valid_list_operating_system? list_operating_system | |
29 | + return false if (list_operating_system.nil? || list_operating_system.length == 0) | |
30 | + return !list_operating_system.any?{|os| !os.valid?} | |
31 | + end | |
32 | + | |
33 | + def self.operating_system_as_tables(list_operating_system, disabled=false) | |
34 | + model_list = list_operating_system | |
35 | + model_list ||= [{:operating_system_name_id => "", :version => ""}] | |
36 | + | |
37 | + models_as_tables model_list, "operating_system_html_structure", disabled | |
38 | + end | |
39 | + | |
40 | + def self.operating_system_html_structure (operating_system_data, disabled) | |
41 | + select_options = options_for_select( | |
42 | + SoftwareCommunitiesPlugin::OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, | |
43 | + operating_system_data[:operating_system_name_id] | |
44 | + ) | |
45 | + | |
46 | + data = { | |
47 | + #FIXME Verify model_name | |
48 | + model_name: MODEL_NAME, | |
49 | + field_name: FIELD_NAME, | |
50 | + name: { | |
51 | + hidden: false, | |
52 | + autocomplete: false, | |
53 | + select_field: true, | |
54 | + options: select_options | |
55 | + }, | |
56 | + version: { | |
57 | + value: operating_system_data[:version], | |
58 | + hidden: true, | |
59 | + delete: true | |
60 | + } | |
61 | + } | |
62 | + DATA[:license].delete(:value) | |
63 | + table_html_structure(data, disabled) | |
64 | + end | |
65 | + | |
66 | + def self.add_dynamic_table | |
67 | + operating_system_as_tables(nil).first.call | |
68 | + end | |
69 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_name.rb
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +class SoftwareCommunitiesPlugin::OperatingSystemName < ActiveRecord::Base | |
2 | + attr_accessible :name | |
3 | + | |
4 | + validates_presence_of :name | |
5 | + validates_uniqueness_of :name | |
6 | + | |
7 | + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem' | |
8 | + has_many :software_infos, :through => :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' | |
9 | + | |
10 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/programming_language.rb
0 → 100644
... | ... | @@ -0,0 +1,15 @@ |
1 | +class SoftwareCommunitiesPlugin::ProgrammingLanguage < ActiveRecord::Base | |
2 | + | |
3 | + SEARCHABLE_SOFTWARE_FIELDS = { | |
4 | + :name => 1 | |
5 | + } | |
6 | + | |
7 | + attr_accessible :name | |
8 | + | |
9 | + validates_presence_of :name | |
10 | + validates_uniqueness_of :name | |
11 | + | |
12 | + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguage' | |
13 | + has_many :software_infos, :through => :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' | |
14 | + | |
15 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/repository_block.rb
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +class SoftwareCommunitiesPlugin::RepositoryBlock < Block | |
2 | + | |
3 | + attr_accessible :show_name | |
4 | + | |
5 | + settings_items :show_name, :type => :boolean, :default => false | |
6 | + | |
7 | + def self.description | |
8 | + _('Repository Link') | |
9 | + end | |
10 | + | |
11 | + def help | |
12 | + _('This block displays the repository link of a software.') | |
13 | + end | |
14 | + | |
15 | + def content(args={}) | |
16 | + block = self | |
17 | + s = show_name | |
18 | + lambda do |object| | |
19 | + render( | |
20 | + :file => 'blocks/repository', | |
21 | + :locals => { :block => block, :show_name => s } | |
22 | + ) | |
23 | + end | |
24 | + end | |
25 | + | |
26 | + def cacheable? | |
27 | + false | |
28 | + end | |
29 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/search_catalog_block.rb
0 → 100644
... | ... | @@ -0,0 +1,29 @@ |
1 | +class SoftwareCommunitiesPlugin::SearchCatalogBlock < Block | |
2 | + | |
3 | + attr_accessible :show_name | |
4 | + | |
5 | + settings_items :show_name, :type => :boolean, :default => false | |
6 | + | |
7 | + def self.description | |
8 | + _('Search Softwares catalog') | |
9 | + end | |
10 | + | |
11 | + def help | |
12 | + _('This block displays the search categories field ') | |
13 | + end | |
14 | + | |
15 | + def content(args={}) | |
16 | + block = self | |
17 | + s = show_name | |
18 | + lambda do |object| | |
19 | + render( | |
20 | + :file => 'blocks/search_catalog', | |
21 | + :locals => { :block => block, :show_name => s } | |
22 | + ) | |
23 | + end | |
24 | + end | |
25 | + | |
26 | + def cacheable? | |
27 | + false | |
28 | + end | |
29 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_database.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwareDatabase < ActiveRecord::Base | |
2 | + attr_accessible :version | |
3 | + | |
4 | + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' | |
5 | + belongs_to :database_description, :class_name => 'SoftwareCommunitiesPlugin::DatabaseDescription' | |
6 | + | |
7 | + validates_presence_of :database_description_id, :version | |
8 | + | |
9 | + validates_length_of( | |
10 | + :version, | |
11 | + :maximum => 20, | |
12 | + :too_long => _("Software database is too long (maximum is 20 characters)") | |
13 | + ) | |
14 | + | |
15 | + validates( | |
16 | + :database_description_id, | |
17 | + :numericality => {:greater_than_or_equal_to => 1} | |
18 | + ) | |
19 | + | |
20 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,43 @@ |
1 | +module SoftwareCommunitiesPlugin::SoftwareHelper | |
2 | + def self.select_options programming_languages, selected = 0 | |
3 | + value = "" | |
4 | + | |
5 | + programming_languages.each do |language| | |
6 | + selected = selected == language.id ? 'selected' : '' | |
7 | + value += "<option value=#{language.id} #{selected}> | |
8 | + #{language.name} | |
9 | + </option>" | |
10 | + end | |
11 | + | |
12 | + value | |
13 | + end | |
14 | + | |
15 | + def self.create_list_with_file file_name, model | |
16 | + list_file = File.open file_name, "r" | |
17 | + | |
18 | + list_file.each_line do |line| | |
19 | + model.create(:name=>line.strip) | |
20 | + end | |
21 | + | |
22 | + list_file.close | |
23 | + end | |
24 | + | |
25 | + def self.all_table_is_empty? table, ignored_fields=[] | |
26 | + return !table.keys.any?{|key| ignored_fields.include?(key) ? false : !table[key].empty?} | |
27 | + end | |
28 | + | |
29 | + def self.software_template | |
30 | + identifier = SoftwareCommunitiesPlugin::SoftwareHelper.software_template_identifier | |
31 | + | |
32 | + software_template = Community[identifier] | |
33 | + if !software_template.blank? && software_template.is_template | |
34 | + software_template | |
35 | + else | |
36 | + nil | |
37 | + end | |
38 | + end | |
39 | + | |
40 | + def self.software_template_identifier | |
41 | + identifier = YAML::load(File.open(SoftwareCommunitiesPlugin.root_path + 'config.yml'))['software_template'] | |
42 | + end | |
43 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_highlights_block.rb
0 → 100644
... | ... | @@ -0,0 +1,20 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwareHighlightsBlock < HighlightsBlock | |
2 | + | |
3 | + def self.description | |
4 | + _('Software Highlights Block') | |
5 | + end | |
6 | + | |
7 | + def help | |
8 | + _('This block displays the softwares icon into a highlight') | |
9 | + end | |
10 | + | |
11 | + def content(args={}) | |
12 | + softwares = self.settings[:images].collect {|h| h[:address].split('/').last} | |
13 | + block = self | |
14 | + proc do | |
15 | + render :file => 'blocks/software_communities_plugin/software_highlights', :locals => { :block => block, :softwares => softwares} | |
16 | + end | |
17 | + end | |
18 | + | |
19 | + | |
20 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_info.rb
0 → 100644
... | ... | @@ -0,0 +1,261 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwareInfo < ActiveRecord::Base | |
2 | + acts_as_having_settings :field => :settings | |
3 | + | |
4 | + SEARCHABLE_SOFTWARE_FIELDS = { | |
5 | + :acronym => 1, | |
6 | + :finality => 2, | |
7 | + } | |
8 | + | |
9 | + SEARCHABLE_SOFTWARE_CLASSES = [ | |
10 | + SoftwareCommunitiesPlugin::SoftwareInfo, | |
11 | + SoftwareCommunitiesPlugin::Community, | |
12 | + SoftwareCommunitiesPlugin::ProgrammingLanguage, | |
13 | + SoftwareCommunitiesPlugin::DatabaseDescription | |
14 | + ] | |
15 | + | |
16 | + scope :search_by_query, lambda { |query = ""| | |
17 | + filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') | |
18 | + search_fields = SoftwareCommunitiesPlugin::SoftwareInfo.pg_search_plugin_fields | |
19 | + | |
20 | + if query.empty? | |
21 | + SoftwareInfo.joins(:community).where("profiles.visible = ?", true) | |
22 | + else | |
23 | + searchable_software_objects = SoftwareCommunitiesPlugin::SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) | |
24 | + includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) | |
25 | + end | |
26 | + } | |
27 | + | |
28 | + def self.transform_list_in_methods_list list | |
29 | + methods_list = [] | |
30 | + | |
31 | + list.each do |element| | |
32 | + if SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym) | |
33 | + methods_list << element.to_s.underscore.to_sym | |
34 | + elsif SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym) | |
35 | + methods_list << element.to_s.underscore.pluralize.to_sym | |
36 | + end | |
37 | + end | |
38 | + | |
39 | + methods_list | |
40 | + end | |
41 | + | |
42 | + def self.pg_search_plugin_fields | |
43 | + SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class| | |
44 | + self.get_searchable_fields(one_class) | |
45 | + }.join(" || ' ' || ") | |
46 | + end | |
47 | + | |
48 | + def self.get_searchable_fields one_class | |
49 | + searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ") | |
50 | + searchable_fields | |
51 | + end | |
52 | + | |
53 | + SEARCH_FILTERS = { | |
54 | + :order => %w[], | |
55 | + :display => %w[full] | |
56 | + } | |
57 | + | |
58 | + def self.default_search_display | |
59 | + 'full' | |
60 | + end | |
61 | + | |
62 | + attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, | |
63 | + :operating_platform | |
64 | + | |
65 | + attr_accessible :demonstration_url, :acronym, :objectives, :features, | |
66 | + :license_info | |
67 | + | |
68 | + attr_accessible :community_id, :finality, :repository_link, :public_software, | |
69 | + :first_edit | |
70 | + | |
71 | + has_many :libraries, :dependent => :destroy, :class_name => 'SoftwareCommunitiesPlugin::Library' | |
72 | + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase' | |
73 | + has_many :database_descriptions, :through => :software_databases, :class_name => 'SoftwareCommunitiesPlugin::DatabaseDescription' | |
74 | + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguage' | |
75 | + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem' | |
76 | + has_many :programming_languages, :through => :software_languages, :class_name => 'SoftwareCommunitiesPlugin::ProgrammingLanguage' | |
77 | + has_many :operating_system_names, :through => :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName' | |
78 | + | |
79 | + belongs_to :community, :dependent => :destroy | |
80 | + belongs_to :license_info, :class_name => 'SoftwareCommunitiesPlugin::LicenseInfo' | |
81 | + | |
82 | + validates_length_of :finality, :maximum => 120 | |
83 | + validates_length_of :objectives, :maximum => 4000 | |
84 | + validates_length_of :features, :maximum => 4000 | |
85 | + validates_presence_of :finality, :community | |
86 | + | |
87 | + validate :validate_acronym | |
88 | + | |
89 | + settings_items :another_license_version, :another_license_link | |
90 | + | |
91 | + # used on find_by_contents | |
92 | + scope :like_search, lambda{ |name| | |
93 | + joins(:community).where( | |
94 | + "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", | |
95 | + "%#{name}%", "%#{name}%", "%#{name}%" | |
96 | + ) | |
97 | + } | |
98 | + | |
99 | + scope :search, lambda { |name="", database_description_id = "", | |
100 | + programming_language_id = "", operating_system_name_id = "", | |
101 | + license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "", | |
102 | + icp_brasil = "", e_arq = "", software_categories = "" | | |
103 | + | |
104 | + like_sql = "" | |
105 | + values = [] | |
106 | + | |
107 | + unless name.blank? | |
108 | + like_sql << "name ILIKE ? OR identifier ILIKE ? AND " | |
109 | + values << "%#{name}%" << "%#{name}%" | |
110 | + end | |
111 | + | |
112 | + like_sql = like_sql[0..like_sql.length-5] | |
113 | + | |
114 | + { | |
115 | + :joins => [:community], | |
116 | + :conditions=>[like_sql, *values] | |
117 | + } | |
118 | + } | |
119 | + | |
120 | + def license_info | |
121 | + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_id self.license_info_id | |
122 | + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") | |
123 | + | |
124 | + if license_another && license.id == license_another.id | |
125 | + LicenseInfo.new( | |
126 | + :version => self.another_license_version, | |
127 | + :link => self.another_license_link | |
128 | + ) | |
129 | + else | |
130 | + license | |
131 | + end | |
132 | + end | |
133 | + | |
134 | + def another_license(version, link) | |
135 | + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") | |
136 | + | |
137 | + if license_another | |
138 | + self.another_license_version = version | |
139 | + self.another_license_link = link | |
140 | + self.license_info = license_another | |
141 | + self.save! | |
142 | + end | |
143 | + end | |
144 | + | |
145 | + def validate_name_lenght | |
146 | + if self.community.name.size > 100 | |
147 | + self.errors.add( | |
148 | + :base, | |
149 | + _("Name is too long (maximum is %{count} characters)") | |
150 | + ) | |
151 | + false | |
152 | + end | |
153 | + true | |
154 | + end | |
155 | + | |
156 | + # if create_after_moderation receive a model object, would be possible to reuse core method | |
157 | + def self.create_after_moderation(requestor, attributes = {}) | |
158 | + environment = attributes.delete(:environment) | |
159 | + name = attributes.delete(:name) | |
160 | + identifier = attributes.delete(:identifier) | |
161 | + image_builder = attributes.delete(:image_builder) | |
162 | + license_info = attributes.delete(:license_info) | |
163 | + another_license_version = attributes.delete(:another_license_version) | |
164 | + another_license_link = attributes.delete(:another_license_link) | |
165 | + | |
166 | + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(attributes) | |
167 | + unless environment.admins.include? requestor | |
168 | + SoftwareCommunitiesPlugin::CreateSoftware.create!( | |
169 | + attributes.merge( | |
170 | + :requestor => requestor, | |
171 | + :environment => environment, | |
172 | + :name => name, | |
173 | + :identifier => identifier, | |
174 | + :license_info => license_info | |
175 | + ) | |
176 | + ) | |
177 | + else | |
178 | + software_template = SoftwareCommunitiesPlugin::SoftwareHelper.software_template | |
179 | + | |
180 | + community_hash = {:name => name} | |
181 | + community_hash[:identifier] = identifier | |
182 | + community_hash[:image_builder] = image_builder if image_builder | |
183 | + | |
184 | + community = Community.new(community_hash) | |
185 | + community.environment = environment | |
186 | + | |
187 | + unless software_template.blank? | |
188 | + community.template_id = software_template.id | |
189 | + end | |
190 | + | |
191 | + community.save! | |
192 | + community.add_admin(requestor) | |
193 | + | |
194 | + software_info.community = community | |
195 | + software_info.license_info = license_info | |
196 | + software_info.save! | |
197 | + end | |
198 | + | |
199 | + software_info.verify_license_info(another_license_version, another_license_link) | |
200 | + software_info.save | |
201 | + software_info | |
202 | + end | |
203 | + | |
204 | + def verify_license_info another_license_version, another_license_link | |
205 | + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") | |
206 | + | |
207 | + if license_another && self.license_info_id == license_another.id | |
208 | + version = another_license_version | |
209 | + link = another_license_link | |
210 | + | |
211 | + self.another_license(version, link) | |
212 | + end | |
213 | + end | |
214 | + | |
215 | + | |
216 | + def validate_acronym | |
217 | + self.acronym = "" if self.acronym.nil? | |
218 | + if self.acronym.length > 10 && self.errors.messages[:acronym].nil? | |
219 | + self.errors.add(:acronym, _("can't have more than 10 characteres")) | |
220 | + false | |
221 | + elsif self.acronym.match(/\s+/) | |
222 | + self.errors.add(:acronym, _("can't have whitespaces")) | |
223 | + false | |
224 | + end | |
225 | + true | |
226 | + end | |
227 | + | |
228 | + def valid_operating_systems | |
229 | + if self.operating_systems.empty? | |
230 | + self.errors.add(:operating_system, _(": at least one must be filled")) | |
231 | + end | |
232 | + end | |
233 | + | |
234 | + def valid_software_info | |
235 | + if self.software_languages.empty? | |
236 | + self.errors.add(:software_languages, _(": at least one must be filled")) | |
237 | + end | |
238 | + end | |
239 | + | |
240 | + def valid_databases | |
241 | + if self.software_databases.empty? | |
242 | + self.errors.add(:software_databases, _(": at least one must be filled")) | |
243 | + end | |
244 | + end | |
245 | + | |
246 | + def visible? | |
247 | + self.community.visible? | |
248 | + end | |
249 | + | |
250 | + def name | |
251 | + self.community.name | |
252 | + end | |
253 | + | |
254 | + def short_name | |
255 | + self.community.short_name | |
256 | + end | |
257 | + | |
258 | + def identifier | |
259 | + self.community.identifier | |
260 | + end | |
261 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_information_block.rb
0 → 100644
... | ... | @@ -0,0 +1,37 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwareInformationBlock < Block | |
2 | + | |
3 | + attr_accessible :show_name | |
4 | + | |
5 | + settings_items :show_name, :type => :boolean, :default => false | |
6 | + | |
7 | + def self.description | |
8 | + _('Basic Software Information') | |
9 | + end | |
10 | + | |
11 | + def help | |
12 | + _('This block displays the basic information of a software profile.') | |
13 | + end | |
14 | + | |
15 | + def content(args={}) | |
16 | + block = self | |
17 | + s = show_name | |
18 | + | |
19 | + lambda do |object| | |
20 | + render( | |
21 | + :file => 'blocks/software_information', | |
22 | + :locals => { :block => block, :show_name => s} | |
23 | + ) | |
24 | + end | |
25 | + end | |
26 | + | |
27 | + def cacheable? | |
28 | + false | |
29 | + end | |
30 | + | |
31 | + private | |
32 | + | |
33 | + def owner_has_ratings? | |
34 | + ratings = OrganizationRating.where(community_id: block.owner.id) | |
35 | + !ratings.empty? | |
36 | + end | |
37 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language.rb
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwareLanguage < ActiveRecord::Base | |
2 | + attr_accessible :version | |
3 | + | |
4 | + belongs_to :software_info, :class => "SoftwareCommunitiesPlugin::SoftwareInfo" | |
5 | + belongs_to :programming_language, :class => "SoftwareCommunitiesPlugin::ProgrammingLanguage" | |
6 | + | |
7 | + validates_length_of( | |
8 | + :version, | |
9 | + :maximum => 20, | |
10 | + :too_long => _("Software language is too long (maximum is 20 characters)") | |
11 | + ) | |
12 | + | |
13 | + validates_presence_of :version, :programming_language | |
14 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language_helper.rb
0 → 100644
... | ... | @@ -0,0 +1,85 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwareLanguageHelper < DynamicTableHelper | |
2 | + #FIX verify MODEL_NAME | |
3 | + MODEL_NAME = "language" | |
4 | + FIELD_NAME = "programming_language_id" | |
5 | + | |
6 | + def self.valid_language? language | |
7 | + return false if SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty?(language) | |
8 | + | |
9 | + programming_language_id_list = SoftwareCommunitiesPlugin::ProgrammingLanguage. | |
10 | + select(:id). | |
11 | + collect { |dd| dd.id } | |
12 | + | |
13 | + return programming_language_id_list.include?( | |
14 | + language[:programming_language_id].to_i | |
15 | + ) | |
16 | + end | |
17 | + | |
18 | + def self.list_language new_languages | |
19 | + return [] if new_languages.nil? or new_languages.length == 0 | |
20 | + list_languages = [] | |
21 | + | |
22 | + new_languages.each do |new_language| | |
23 | + if valid_language? new_language | |
24 | + language = SoftwareCommunitiesPlugin::SoftwareLanguage.new | |
25 | + language.programming_language = | |
26 | + SoftwareCommunitiesPlugin::ProgrammingLanguage.find(new_language[:programming_language_id]) | |
27 | + language.version = new_language[:version] | |
28 | + list_languages << language | |
29 | + end | |
30 | + end | |
31 | + | |
32 | + list_languages | |
33 | + end | |
34 | + | |
35 | + def self.valid_list_language? list_languages | |
36 | + return false if list_languages.nil? or list_languages.length == 0 | |
37 | + | |
38 | + list_languages.each do |language| | |
39 | + return false unless language.valid? | |
40 | + end | |
41 | + | |
42 | + true | |
43 | + end | |
44 | + | |
45 | + def self.language_as_tables(list_languages, disabled=false) | |
46 | + model_list = list_languages | |
47 | + model_list ||= [{:programming_language_id => "", :version => ""}] | |
48 | + | |
49 | + models_as_tables model_list, "language_html_structure", disabled | |
50 | + end | |
51 | + | |
52 | + def self.language_html_structure(language_data, disabled) | |
53 | + language_id = language_data[:programming_language_id] | |
54 | + language_name = "" | |
55 | + unless language_data[:programming_language_id].blank? | |
56 | + language_name = SoftwareCommunitiesPlugin::ProgrammingLanguage.find( | |
57 | + language_data[:programming_language_id], | |
58 | + :select=>"name" | |
59 | + ).name | |
60 | + end | |
61 | + | |
62 | + data = { | |
63 | + model_name: MODEL_NAME, | |
64 | + field_name: FIELD_NAME, | |
65 | + name: { | |
66 | + value: language_name, | |
67 | + id: language_id, | |
68 | + hidden: true, | |
69 | + autocomplete: true, | |
70 | + select_field: false | |
71 | + }, | |
72 | + version: { | |
73 | + value: language_data[:version], | |
74 | + hidden: true, | |
75 | + delete: true | |
76 | + } | |
77 | + } | |
78 | + DATA[:license].delete(:value) | |
79 | + table_html_structure(data, disabled) | |
80 | + end | |
81 | + | |
82 | + def self.add_dynamic_table | |
83 | + language_as_tables(nil).first.call | |
84 | + end | |
85 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/software_tab_data_block.rb
0 → 100644
... | ... | @@ -0,0 +1,48 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwareTabDataBlock < Block | |
2 | + attr_accessible :show_name, :displayed_blog | |
3 | + | |
4 | + settings_items :show_name, :type => :boolean, :default => false | |
5 | + settings_items :displayed_blog, :type => :integer, :default => 0 | |
6 | + | |
7 | + TOTAL_POSTS_DYSPLAYED = 5 | |
8 | + | |
9 | + def self.description | |
10 | + _('Software Tab Data') | |
11 | + end | |
12 | + | |
13 | + def help | |
14 | + _('This block is used by colab to insert data into Noosfero') | |
15 | + end | |
16 | + | |
17 | + def content(args={}) | |
18 | + block = self | |
19 | + | |
20 | + lambda do |object| | |
21 | + render( | |
22 | + :file => 'blocks/software_tab_data', | |
23 | + :locals => { | |
24 | + :block => block | |
25 | + } | |
26 | + ) | |
27 | + end | |
28 | + end | |
29 | + | |
30 | + def blogs | |
31 | + self.owner.blogs | |
32 | + end | |
33 | + | |
34 | + def actual_blog | |
35 | + # As :displayed_blog default value is 0, it falls to the first one | |
36 | + blogs.find_by_id(self.displayed_blog) || blogs.first | |
37 | + end | |
38 | + | |
39 | + def posts | |
40 | + blog = actual_blog | |
41 | + | |
42 | + if blog and (not blog.posts.empty?) | |
43 | + blog.posts.limit(TOTAL_POSTS_DYSPLAYED) | |
44 | + else | |
45 | + [] | |
46 | + end | |
47 | + end | |
48 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/softwares_block.rb
0 → 100644
... | ... | @@ -0,0 +1,105 @@ |
1 | +class SoftwareCommunitiesPlugin::SoftwaresBlock < CommunitiesBlock | |
2 | + | |
3 | + settings_items :software_type, :default => "All" | |
4 | + attr_accessible :accessor_id, :accessor_type, :role_id, | |
5 | + :resource_id, :resource_type, :software_type | |
6 | + | |
7 | + def self.description | |
8 | + _('Softwares') | |
9 | + end | |
10 | + | |
11 | + def default_title | |
12 | + if self.software_type == "Generic" | |
13 | + return n_('{#} generic software', '{#} generic softwares', profile_count) | |
14 | + elsif self.software_type == "Public" | |
15 | + return n_('{#} public software', '{#} public softwares', profile_count) | |
16 | + else | |
17 | + return n_('{#} software', '{#} softwares', profile_count) | |
18 | + end | |
19 | + end | |
20 | + | |
21 | + def help | |
22 | + _('This block displays the softwares in which the user is a member.') | |
23 | + end | |
24 | + | |
25 | + def footer | |
26 | + self.software_type ||= "All" | |
27 | + owner = self.owner | |
28 | + case owner | |
29 | + when Profile | |
30 | + lambda do |context| | |
31 | + link_to s_('softwares|View all'), :profile => owner.identifier, | |
32 | + :controller => 'profile', :action => 'communities', | |
33 | + :type => 'Software' | |
34 | + end | |
35 | + when Environment | |
36 | + lambda do |context| | |
37 | + link_to s_('softwares|View all'), :controller => 'search', | |
38 | + :action => 'software_infos' | |
39 | + end | |
40 | + else | |
41 | + '' | |
42 | + end | |
43 | + end | |
44 | + | |
45 | + def profile_count | |
46 | + profile_list.count | |
47 | + end | |
48 | + | |
49 | + def profiles | |
50 | + owner.communities | |
51 | + end | |
52 | + | |
53 | + def profile_list | |
54 | + profiles = get_visible_profiles | |
55 | + | |
56 | + software_profiles = profiles.select do |profile| | |
57 | + profile.class == Community && profile.software? | |
58 | + end | |
59 | + | |
60 | + block_softwares = if self.software_type == "Public" | |
61 | + software_profiles.select { |profile| profile.software_info.public_software? } | |
62 | + elsif self.software_type == "Generic" | |
63 | + software_profiles.select { |profile| !profile.software_info.public_software? } | |
64 | + else # All | |
65 | + software_profiles | |
66 | + end | |
67 | + | |
68 | + block_softwares.slice(0..get_limit-1) | |
69 | + end | |
70 | + | |
71 | + def content(arg={}) | |
72 | + if self.box.owner_type == "Environment" && self.box.position == 1 | |
73 | + block = self | |
74 | + | |
75 | + proc do | |
76 | + render :file => 'blocks/main_area_softwares', | |
77 | + :locals => {:profiles=> block.profile_list(), :block => block} | |
78 | + end | |
79 | + else | |
80 | + super(arg) | |
81 | + end | |
82 | + end | |
83 | + | |
84 | + protected | |
85 | + | |
86 | + def get_visible_profiles | |
87 | + profile_include_list = [:image, :domains, :preferred_domain, :environment] | |
88 | + visible_profiles = profiles.visible.includes(profile_include_list) | |
89 | + | |
90 | + if !prioritize_profiles_with_image | |
91 | + visible_profiles.all( :limit => get_limit, | |
92 | + :order => 'profiles.updated_at DESC' | |
93 | + ).sort_by{ rand } | |
94 | + elsif profiles.visible.with_image.count >= get_limit | |
95 | + visible_profiles.with_image.all( :limit => get_limit * 5, | |
96 | + :order => 'profiles.updated_at DESC' | |
97 | + ).sort_by{ rand } | |
98 | + else | |
99 | + visible_profiles.with_image.sort_by{ rand } + | |
100 | + visible_profiles.without_image.all( :limit => get_limit * 5, | |
101 | + :order => 'profiles.updated_at DESC' | |
102 | + ).sort_by{ rand } | |
103 | + end | |
104 | + end | |
105 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/statistic_block.rb
0 → 100644
... | ... | @@ -0,0 +1,52 @@ |
1 | +class SoftwareCommunitiesPlugin::StatisticBlock < Block | |
2 | + | |
3 | + settings_items :benefited_people, :type => :integer, :default => 0 | |
4 | + settings_items :saved_resources, :type => :float, :default => 0.0 | |
5 | + | |
6 | + attr_accessible :benefited_people, :saved_resources | |
7 | + | |
8 | + def self.description | |
9 | + _('Software Statistics') | |
10 | + end | |
11 | + | |
12 | + def help | |
13 | + _('This block displays software statistics.') | |
14 | + end | |
15 | + | |
16 | + def content(args={}) | |
17 | + download_blocks = get_profile_download_blocks(self.owner) | |
18 | + downloads = download_blocks.map do |download_block| | |
19 | + get_downloads_from_block(download_block) | |
20 | + end | |
21 | + | |
22 | + block = self | |
23 | + | |
24 | + lambda do |object| | |
25 | + render( | |
26 | + :file => 'blocks/software_statistics', | |
27 | + :locals => { | |
28 | + :block => block, | |
29 | + :total_downloads => downloads.sum | |
30 | + } | |
31 | + ) | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + def cacheable? | |
36 | + false | |
37 | + end | |
38 | + | |
39 | + private | |
40 | + | |
41 | + def get_profile_download_blocks profile | |
42 | + SoftwareCommunitiesPlugin::DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id) | |
43 | + end | |
44 | + | |
45 | + def get_downloads_from_block download_block | |
46 | + downloads = download_block.downloads.map do |download| | |
47 | + download[:total_downloads] unless download[:total_downloads].nil? | |
48 | + end | |
49 | + downloads.select! {|value| not value.nil? } | |
50 | + downloads.sum | |
51 | + end | |
52 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin/wiki_block.rb
0 → 100644
... | ... | @@ -0,0 +1,30 @@ |
1 | +class SoftwareCommunitiesPlugin::WikiBlock < Block | |
2 | + | |
3 | + attr_accessible :show_name, :wiki_link | |
4 | + settings_items :show_name, :type => :boolean, :default => false | |
5 | + settings_items :wiki_link, :type => :string, :default => "" | |
6 | + | |
7 | + def self.description | |
8 | + _('Wiki Link') | |
9 | + end | |
10 | + | |
11 | + def help | |
12 | + _('This block displays a link to the software wiki.') | |
13 | + end | |
14 | + | |
15 | + def content(args={}) | |
16 | + block = self | |
17 | + s = show_name | |
18 | + | |
19 | + lambda do |object| | |
20 | + render( | |
21 | + :file => 'blocks/wiki', | |
22 | + :locals => { :block => block, :show_name => s } | |
23 | + ) | |
24 | + end | |
25 | + end | |
26 | + | |
27 | + def cacheable? | |
28 | + true | |
29 | + end | |
30 | +end | ... | ... |
src/noosfero-spb/software_communities/lib/software_database.rb
... | ... | @@ -1,20 +0,0 @@ |
1 | -class SoftwareDatabase < ActiveRecord::Base | |
2 | - attr_accessible :version | |
3 | - | |
4 | - belongs_to :software_info | |
5 | - belongs_to :database_description | |
6 | - | |
7 | - validates_presence_of :database_description_id, :version | |
8 | - | |
9 | - validates_length_of( | |
10 | - :version, | |
11 | - :maximum => 20, | |
12 | - :too_long => _("Software database is too long (maximum is 20 characters)") | |
13 | - ) | |
14 | - | |
15 | - validates( | |
16 | - :database_description_id, | |
17 | - :numericality => {:greater_than_or_equal_to => 1} | |
18 | - ) | |
19 | - | |
20 | -end |
src/noosfero-spb/software_communities/lib/software_helper.rb
... | ... | @@ -1,43 +0,0 @@ |
1 | -module SoftwareHelper | |
2 | - def self.select_options programming_languages, selected = 0 | |
3 | - value = "" | |
4 | - | |
5 | - programming_languages.each do |language| | |
6 | - selected = selected == language.id ? 'selected' : '' | |
7 | - value += "<option value=#{language.id} #{selected}> | |
8 | - #{language.name} | |
9 | - </option>" | |
10 | - end | |
11 | - | |
12 | - value | |
13 | - end | |
14 | - | |
15 | - def self.create_list_with_file file_name, model | |
16 | - list_file = File.open file_name, "r" | |
17 | - | |
18 | - list_file.each_line do |line| | |
19 | - model.create(:name=>line.strip) | |
20 | - end | |
21 | - | |
22 | - list_file.close | |
23 | - end | |
24 | - | |
25 | - def self.all_table_is_empty? table, ignored_fields=[] | |
26 | - return !table.keys.any?{|key| ignored_fields.include?(key) ? false : !table[key].empty?} | |
27 | - end | |
28 | - | |
29 | - def self.software_template | |
30 | - identifier = SoftwareHelper.software_template_identifier | |
31 | - | |
32 | - software_template = Community[identifier] | |
33 | - if !software_template.blank? && software_template.is_template | |
34 | - software_template | |
35 | - else | |
36 | - nil | |
37 | - end | |
38 | - end | |
39 | - | |
40 | - def self.software_template_identifier | |
41 | - identifier = YAML::load(File.open(SoftwareCommunitiesPlugin.root_path + 'config.yml'))['software_template'] | |
42 | - end | |
43 | -end |
src/noosfero-spb/software_communities/lib/software_highlights_block.rb
... | ... | @@ -1,20 +0,0 @@ |
1 | -class SoftwareHighlightsBlock < HighlightsBlock | |
2 | - | |
3 | - def self.description | |
4 | - _('Software Highlights Block') | |
5 | - end | |
6 | - | |
7 | - def help | |
8 | - _('This block displays the softwares icon into a highlight') | |
9 | - end | |
10 | - | |
11 | - def content(args={}) | |
12 | - softwares = self.settings[:images].collect {|h| h[:address].split('/').last} | |
13 | - block = self | |
14 | - proc do | |
15 | - render :file => 'blocks/software_highlights', :locals => { :block => block, :softwares => softwares} | |
16 | - end | |
17 | - end | |
18 | - | |
19 | - | |
20 | -end |
src/noosfero-spb/software_communities/lib/software_info.rb
... | ... | @@ -1,263 +0,0 @@ |
1 | -class SoftwareInfo < ActiveRecord::Base | |
2 | - acts_as_having_settings :field => :settings | |
3 | - | |
4 | - SEARCHABLE_SOFTWARE_FIELDS = { | |
5 | - :acronym => 1, | |
6 | - :finality => 2, | |
7 | - } | |
8 | - | |
9 | - SEARCHABLE_SOFTWARE_CLASSES = [ | |
10 | - SoftwareInfo, | |
11 | - Community, | |
12 | - ProgrammingLanguage, | |
13 | - DatabaseDescription | |
14 | - ] | |
15 | - | |
16 | - scope :search_by_query, lambda { |query = ""| | |
17 | - filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') | |
18 | - search_fields = SoftwareInfo.pg_search_plugin_fields | |
19 | - | |
20 | - if query.empty? | |
21 | - SoftwareInfo.joins(:community).where("profiles.visible = ?", true) | |
22 | - else | |
23 | - searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) | |
24 | - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) | |
25 | - end | |
26 | - } | |
27 | - | |
28 | - def self.transform_list_in_methods_list list | |
29 | - methods_list = [] | |
30 | - | |
31 | - list.each do |element| | |
32 | - if SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym) | |
33 | - methods_list << element.to_s.underscore.to_sym | |
34 | - elsif SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym) | |
35 | - methods_list << element.to_s.underscore.pluralize.to_sym | |
36 | - end | |
37 | - end | |
38 | - | |
39 | - methods_list | |
40 | - end | |
41 | - | |
42 | - def self.pg_search_plugin_fields | |
43 | - SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class| | |
44 | - self.get_searchable_fields(one_class) | |
45 | - }.join(" || ' ' || ") | |
46 | - end | |
47 | - | |
48 | - def self.get_searchable_fields one_class | |
49 | - searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ") | |
50 | - searchable_fields | |
51 | - end | |
52 | - | |
53 | - SEARCH_FILTERS = { | |
54 | - :order => %w[], | |
55 | - :display => %w[full] | |
56 | - } | |
57 | - | |
58 | - def self.default_search_display | |
59 | - 'full' | |
60 | - end | |
61 | - | |
62 | - attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, | |
63 | - :operating_platform | |
64 | - | |
65 | - attr_accessible :demonstration_url, :acronym, :objectives, :features, | |
66 | - :license_info | |
67 | - | |
68 | - attr_accessible :community_id, :finality, :repository_link, :public_software, | |
69 | - :first_edit | |
70 | - | |
71 | - has_many :libraries, :dependent => :destroy | |
72 | - has_many :software_databases | |
73 | - has_many :database_descriptions, :through => :software_databases | |
74 | - has_many :software_languages | |
75 | - has_many :operating_systems | |
76 | - has_many :programming_languages, :through => :software_languages | |
77 | - has_many :operating_system_names, :through => :operating_systems | |
78 | - | |
79 | - belongs_to :community, :dependent => :destroy | |
80 | - belongs_to :license_info | |
81 | - | |
82 | - has_one :software_categories | |
83 | - | |
84 | - validates_length_of :finality, :maximum => 120 | |
85 | - validates_length_of :objectives, :maximum => 4000 | |
86 | - validates_length_of :features, :maximum => 4000 | |
87 | - validates_presence_of :finality, :community | |
88 | - | |
89 | - validate :validate_acronym | |
90 | - | |
91 | - settings_items :another_license_version, :another_license_link | |
92 | - | |
93 | - # used on find_by_contents | |
94 | - scope :like_search, lambda{ |name| | |
95 | - joins(:community).where( | |
96 | - "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", | |
97 | - "%#{name}%", "%#{name}%", "%#{name}%" | |
98 | - ) | |
99 | - } | |
100 | - | |
101 | - scope :search, lambda { |name="", database_description_id = "", | |
102 | - programming_language_id = "", operating_system_name_id = "", | |
103 | - license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "", | |
104 | - icp_brasil = "", e_arq = "", software_categories = "" | | |
105 | - | |
106 | - like_sql = "" | |
107 | - values = [] | |
108 | - | |
109 | - unless name.blank? | |
110 | - like_sql << "name ILIKE ? OR identifier ILIKE ? AND " | |
111 | - values << "%#{name}%" << "%#{name}%" | |
112 | - end | |
113 | - | |
114 | - like_sql = like_sql[0..like_sql.length-5] | |
115 | - | |
116 | - { | |
117 | - :joins => [:community], | |
118 | - :conditions=>[like_sql, *values] | |
119 | - } | |
120 | - } | |
121 | - | |
122 | - def license_info | |
123 | - license = LicenseInfo.find_by_id self.license_info_id | |
124 | - license_another = LicenseInfo.find_by_version("Another") | |
125 | - | |
126 | - if license_another && license.id == license_another.id | |
127 | - LicenseInfo.new( | |
128 | - :version => self.another_license_version, | |
129 | - :link => self.another_license_link | |
130 | - ) | |
131 | - else | |
132 | - license | |
133 | - end | |
134 | - end | |
135 | - | |
136 | - def another_license(version, link) | |
137 | - license_another = LicenseInfo.find_by_version("Another") | |
138 | - | |
139 | - if license_another | |
140 | - self.another_license_version = version | |
141 | - self.another_license_link = link | |
142 | - self.license_info = license_another | |
143 | - self.save! | |
144 | - end | |
145 | - end | |
146 | - | |
147 | - def validate_name_lenght | |
148 | - if self.community.name.size > 100 | |
149 | - self.errors.add( | |
150 | - :base, | |
151 | - _("Name is too long (maximum is %{count} characters)") | |
152 | - ) | |
153 | - false | |
154 | - end | |
155 | - true | |
156 | - end | |
157 | - | |
158 | - # if create_after_moderation receive a model object, would be possible to reuse core method | |
159 | - def self.create_after_moderation(requestor, attributes = {}) | |
160 | - environment = attributes.delete(:environment) | |
161 | - name = attributes.delete(:name) | |
162 | - identifier = attributes.delete(:identifier) | |
163 | - image_builder = attributes.delete(:image_builder) | |
164 | - license_info = attributes.delete(:license_info) | |
165 | - another_license_version = attributes.delete(:another_license_version) | |
166 | - another_license_link = attributes.delete(:another_license_link) | |
167 | - | |
168 | - software_info = SoftwareInfo.new(attributes) | |
169 | - unless environment.admins.include? requestor | |
170 | - CreateSoftware.create!( | |
171 | - attributes.merge( | |
172 | - :requestor => requestor, | |
173 | - :environment => environment, | |
174 | - :name => name, | |
175 | - :identifier => identifier, | |
176 | - :license_info => license_info | |
177 | - ) | |
178 | - ) | |
179 | - else | |
180 | - software_template = SoftwareHelper.software_template | |
181 | - | |
182 | - community_hash = {:name => name} | |
183 | - community_hash[:identifier] = identifier | |
184 | - community_hash[:image_builder] = image_builder if image_builder | |
185 | - | |
186 | - community = Community.new(community_hash) | |
187 | - community.environment = environment | |
188 | - | |
189 | - unless software_template.blank? | |
190 | - community.template_id = software_template.id | |
191 | - end | |
192 | - | |
193 | - community.save! | |
194 | - community.add_admin(requestor) | |
195 | - | |
196 | - software_info.community = community | |
197 | - software_info.license_info = license_info | |
198 | - software_info.save! | |
199 | - end | |
200 | - | |
201 | - software_info.verify_license_info(another_license_version, another_license_link) | |
202 | - software_info.save | |
203 | - software_info | |
204 | - end | |
205 | - | |
206 | - def verify_license_info another_license_version, another_license_link | |
207 | - license_another = LicenseInfo.find_by_version("Another") | |
208 | - | |
209 | - if license_another && self.license_info_id == license_another.id | |
210 | - version = another_license_version | |
211 | - link = another_license_link | |
212 | - | |
213 | - self.another_license(version, link) | |
214 | - end | |
215 | - end | |
216 | - | |
217 | - | |
218 | - def validate_acronym | |
219 | - self.acronym = "" if self.acronym.nil? | |
220 | - if self.acronym.length > 10 && self.errors.messages[:acronym].nil? | |
221 | - self.errors.add(:acronym, _("can't have more than 10 characteres")) | |
222 | - false | |
223 | - elsif self.acronym.match(/\s+/) | |
224 | - self.errors.add(:acronym, _("can't have whitespaces")) | |
225 | - false | |
226 | - end | |
227 | - true | |
228 | - end | |
229 | - | |
230 | - def valid_operating_systems | |
231 | - if self.operating_systems.empty? | |
232 | - self.errors.add(:operating_system, _(": at least one must be filled")) | |
233 | - end | |
234 | - end | |
235 | - | |
236 | - def valid_software_info | |
237 | - if self.software_languages.empty? | |
238 | - self.errors.add(:software_languages, _(": at least one must be filled")) | |
239 | - end | |
240 | - end | |
241 | - | |
242 | - def valid_databases | |
243 | - if self.software_databases.empty? | |
244 | - self.errors.add(:software_databases, _(": at least one must be filled")) | |
245 | - end | |
246 | - end | |
247 | - | |
248 | - def visible? | |
249 | - self.community.visible? | |
250 | - end | |
251 | - | |
252 | - def name | |
253 | - self.community.name | |
254 | - end | |
255 | - | |
256 | - def short_name | |
257 | - self.community.short_name | |
258 | - end | |
259 | - | |
260 | - def identifier | |
261 | - self.community.identifier | |
262 | - end | |
263 | -end |
src/noosfero-spb/software_communities/lib/software_information_block.rb
... | ... | @@ -1,37 +0,0 @@ |
1 | -class SoftwareInformationBlock < Block | |
2 | - | |
3 | - attr_accessible :show_name | |
4 | - | |
5 | - settings_items :show_name, :type => :boolean, :default => false | |
6 | - | |
7 | - def self.description | |
8 | - _('Basic Software Information') | |
9 | - end | |
10 | - | |
11 | - def help | |
12 | - _('This block displays the basic information of a software profile.') | |
13 | - end | |
14 | - | |
15 | - def content(args={}) | |
16 | - block = self | |
17 | - s = show_name | |
18 | - | |
19 | - lambda do |object| | |
20 | - render( | |
21 | - :file => 'blocks/software_information', | |
22 | - :locals => { :block => block, :show_name => s} | |
23 | - ) | |
24 | - end | |
25 | - end | |
26 | - | |
27 | - def cacheable? | |
28 | - false | |
29 | - end | |
30 | - | |
31 | - private | |
32 | - | |
33 | - def owner_has_ratings? | |
34 | - ratings = CommunityRating.where(community_id: block.owner.id) | |
35 | - !ratings.empty? | |
36 | - end | |
37 | -end |
src/noosfero-spb/software_communities/lib/software_language.rb
... | ... | @@ -1,14 +0,0 @@ |
1 | -class SoftwareLanguage < ActiveRecord::Base | |
2 | - attr_accessible :version | |
3 | - | |
4 | - belongs_to :software_info | |
5 | - belongs_to :programming_language | |
6 | - | |
7 | - validates_length_of( | |
8 | - :version, | |
9 | - :maximum => 20, | |
10 | - :too_long => _("Software language is too long (maximum is 20 characters)") | |
11 | - ) | |
12 | - | |
13 | - validates_presence_of :version,:programming_language | |
14 | -end |
src/noosfero-spb/software_communities/lib/software_language_helper.rb
... | ... | @@ -1,84 +0,0 @@ |
1 | -class SoftwareLanguageHelper < DynamicTableHelper | |
2 | - MODEL_NAME ="language" | |
3 | - FIELD_NAME = "programming_language_id" | |
4 | - | |
5 | - def self.valid_language? language | |
6 | - return false if SoftwareHelper.all_table_is_empty?(language) | |
7 | - | |
8 | - programming_language_id_list = ProgrammingLanguage. | |
9 | - select(:id). | |
10 | - collect { |dd| dd.id } | |
11 | - | |
12 | - return programming_language_id_list.include?( | |
13 | - language[:programming_language_id].to_i | |
14 | - ) | |
15 | - end | |
16 | - | |
17 | - def self.list_language new_languages | |
18 | - return [] if new_languages.nil? or new_languages.length == 0 | |
19 | - list_languages = [] | |
20 | - | |
21 | - new_languages.each do |new_language| | |
22 | - if valid_language? new_language | |
23 | - language = SoftwareLanguage.new | |
24 | - language.programming_language = | |
25 | - ProgrammingLanguage.find(new_language[:programming_language_id]) | |
26 | - language.version = new_language[:version] | |
27 | - list_languages << language | |
28 | - end | |
29 | - end | |
30 | - | |
31 | - list_languages | |
32 | - end | |
33 | - | |
34 | - def self.valid_list_language? list_languages | |
35 | - return false if list_languages.nil? or list_languages.length == 0 | |
36 | - | |
37 | - list_languages.each do |language| | |
38 | - return false unless language.valid? | |
39 | - end | |
40 | - | |
41 | - true | |
42 | - end | |
43 | - | |
44 | - def self.language_as_tables(list_languages, disabled=false) | |
45 | - model_list = list_languages | |
46 | - model_list ||= [{:programming_language_id => "", :version => ""}] | |
47 | - | |
48 | - models_as_tables model_list, "language_html_structure", disabled | |
49 | - end | |
50 | - | |
51 | - def self.language_html_structure(language_data, disabled) | |
52 | - language_id = language_data[:programming_language_id] | |
53 | - language_name = "" | |
54 | - unless language_data[:programming_language_id].blank? | |
55 | - language_name = ProgrammingLanguage.find( | |
56 | - language_data[:programming_language_id], | |
57 | - :select=>"name" | |
58 | - ).name | |
59 | - end | |
60 | - | |
61 | - data = { | |
62 | - model_name: MODEL_NAME, | |
63 | - field_name: FIELD_NAME, | |
64 | - name: { | |
65 | - value: language_name, | |
66 | - id: language_id, | |
67 | - hidden: true, | |
68 | - autocomplete: true, | |
69 | - select_field: false | |
70 | - }, | |
71 | - version: { | |
72 | - value: language_data[:version], | |
73 | - hidden: true, | |
74 | - delete: true | |
75 | - } | |
76 | - } | |
77 | - DATA[:license].delete(:value) | |
78 | - table_html_structure(data, disabled) | |
79 | - end | |
80 | - | |
81 | - def self.add_dynamic_table | |
82 | - language_as_tables(nil).first.call | |
83 | - end | |
84 | -end |
src/noosfero-spb/software_communities/lib/software_tab_data_block.rb
... | ... | @@ -1,48 +0,0 @@ |
1 | -class SoftwareTabDataBlock < Block | |
2 | - attr_accessible :show_name, :displayed_blog | |
3 | - | |
4 | - settings_items :show_name, :type => :boolean, :default => false | |
5 | - settings_items :displayed_blog, :type => :integer, :default => 0 | |
6 | - | |
7 | - TOTAL_POSTS_DYSPLAYED = 5 | |
8 | - | |
9 | - def self.description | |
10 | - _('Software Tab Data') | |
11 | - end | |
12 | - | |
13 | - def help | |
14 | - _('This block is used by colab to insert data into Noosfero') | |
15 | - end | |
16 | - | |
17 | - def content(args={}) | |
18 | - block = self | |
19 | - | |
20 | - lambda do |object| | |
21 | - render( | |
22 | - :file => 'blocks/software_tab_data', | |
23 | - :locals => { | |
24 | - :block => block | |
25 | - } | |
26 | - ) | |
27 | - end | |
28 | - end | |
29 | - | |
30 | - def blogs | |
31 | - self.owner.blogs | |
32 | - end | |
33 | - | |
34 | - def actual_blog | |
35 | - # As :displayed_blog default value is 0, it falls to the first one | |
36 | - blogs.find_by_id(self.displayed_blog) || blogs.first | |
37 | - end | |
38 | - | |
39 | - def posts | |
40 | - blog = actual_blog | |
41 | - | |
42 | - if blog and (not blog.posts.empty?) | |
43 | - blog.posts.limit(TOTAL_POSTS_DYSPLAYED) | |
44 | - else | |
45 | - [] | |
46 | - end | |
47 | - end | |
48 | -end |
src/noosfero-spb/software_communities/lib/softwares_block.rb
... | ... | @@ -1,105 +0,0 @@ |
1 | -class SoftwaresBlock < CommunitiesBlock | |
2 | - | |
3 | - settings_items :software_type, :default => "All" | |
4 | - attr_accessible :accessor_id, :accessor_type, :role_id, | |
5 | - :resource_id, :resource_type, :software_type | |
6 | - | |
7 | - def self.description | |
8 | - _('Softwares') | |
9 | - end | |
10 | - | |
11 | - def default_title | |
12 | - if self.software_type == "Generic" | |
13 | - return n_('{#} generic software', '{#} generic softwares', profile_count) | |
14 | - elsif self.software_type == "Public" | |
15 | - return n_('{#} public software', '{#} public softwares', profile_count) | |
16 | - else | |
17 | - return n_('{#} software', '{#} softwares', profile_count) | |
18 | - end | |
19 | - end | |
20 | - | |
21 | - def help | |
22 | - _('This block displays the softwares in which the user is a member.') | |
23 | - end | |
24 | - | |
25 | - def footer | |
26 | - self.software_type ||= "All" | |
27 | - owner = self.owner | |
28 | - case owner | |
29 | - when Profile | |
30 | - lambda do |context| | |
31 | - link_to s_('softwares|View all'), :profile => owner.identifier, | |
32 | - :controller => 'profile', :action => 'communities', | |
33 | - :type => 'Software' | |
34 | - end | |
35 | - when Environment | |
36 | - lambda do |context| | |
37 | - link_to s_('softwares|View all'), :controller => 'search', | |
38 | - :action => 'software_infos' | |
39 | - end | |
40 | - else | |
41 | - '' | |
42 | - end | |
43 | - end | |
44 | - | |
45 | - def profile_count | |
46 | - profile_list.count | |
47 | - end | |
48 | - | |
49 | - def profiles | |
50 | - owner.communities | |
51 | - end | |
52 | - | |
53 | - def profile_list | |
54 | - profiles = get_visible_profiles | |
55 | - | |
56 | - software_profiles = profiles.select do |profile| | |
57 | - profile.class == Community && profile.software? | |
58 | - end | |
59 | - | |
60 | - block_softwares = if self.software_type == "Public" | |
61 | - software_profiles.select { |profile| profile.software_info.public_software? } | |
62 | - elsif self.software_type == "Generic" | |
63 | - software_profiles.select { |profile| !profile.software_info.public_software? } | |
64 | - else # All | |
65 | - software_profiles | |
66 | - end | |
67 | - | |
68 | - block_softwares.slice(0..get_limit-1) | |
69 | - end | |
70 | - | |
71 | - def content(arg={}) | |
72 | - if self.box.owner_type == "Environment" && self.box.position == 1 | |
73 | - block = self | |
74 | - | |
75 | - proc do | |
76 | - render :file => 'blocks/main_area_softwares', | |
77 | - :locals => {:profiles=> block.profile_list(), :block => block} | |
78 | - end | |
79 | - else | |
80 | - super(arg) | |
81 | - end | |
82 | - end | |
83 | - | |
84 | - protected | |
85 | - | |
86 | - def get_visible_profiles | |
87 | - profile_include_list = [:image, :domains, :preferred_domain, :environment] | |
88 | - visible_profiles = profiles.visible.includes(profile_include_list) | |
89 | - | |
90 | - if !prioritize_profiles_with_image | |
91 | - visible_profiles.all( :limit => get_limit, | |
92 | - :order => 'profiles.updated_at DESC' | |
93 | - ).sort_by{ rand } | |
94 | - elsif profiles.visible.with_image.count >= get_limit | |
95 | - visible_profiles.with_image.all( :limit => get_limit * 5, | |
96 | - :order => 'profiles.updated_at DESC' | |
97 | - ).sort_by{ rand } | |
98 | - else | |
99 | - visible_profiles.with_image.sort_by{ rand } + | |
100 | - visible_profiles.without_image.all( :limit => get_limit * 5, | |
101 | - :order => 'profiles.updated_at DESC' | |
102 | - ).sort_by{ rand } | |
103 | - end | |
104 | - end | |
105 | -end |
src/noosfero-spb/software_communities/lib/statistic_block.rb
... | ... | @@ -1,52 +0,0 @@ |
1 | -class StatisticBlock < Block | |
2 | - | |
3 | - settings_items :benefited_people, :type => :integer, :default => 0 | |
4 | - settings_items :saved_resources, :type => :float, :default => 0.0 | |
5 | - | |
6 | - attr_accessible :benefited_people, :saved_resources | |
7 | - | |
8 | - def self.description | |
9 | - _('Software Statistics') | |
10 | - end | |
11 | - | |
12 | - def help | |
13 | - _('This block displays software statistics.') | |
14 | - end | |
15 | - | |
16 | - def content(args={}) | |
17 | - download_blocks = get_profile_download_blocks(self.owner) | |
18 | - downloads = download_blocks.map do |download_block| | |
19 | - get_downloads_from_block(download_block) | |
20 | - end | |
21 | - | |
22 | - block = self | |
23 | - | |
24 | - lambda do |object| | |
25 | - render( | |
26 | - :file => 'blocks/software_statistics', | |
27 | - :locals => { | |
28 | - :block => block, | |
29 | - :total_downloads => downloads.sum | |
30 | - } | |
31 | - ) | |
32 | - end | |
33 | - end | |
34 | - | |
35 | - def cacheable? | |
36 | - false | |
37 | - end | |
38 | - | |
39 | - private | |
40 | - | |
41 | - def get_profile_download_blocks profile | |
42 | - DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id) | |
43 | - end | |
44 | - | |
45 | - def get_downloads_from_block download_block | |
46 | - downloads = download_block.downloads.map do |download| | |
47 | - download[:total_downloads] unless download[:total_downloads].nil? | |
48 | - end | |
49 | - downloads.select! {|value| not value.nil? } | |
50 | - downloads.sum | |
51 | - end | |
52 | -end |
src/noosfero-spb/software_communities/lib/wiki_block.rb
... | ... | @@ -1,30 +0,0 @@ |
1 | -class WikiBlock < Block | |
2 | - | |
3 | - attr_accessible :show_name, :wiki_link | |
4 | - settings_items :show_name, :type => :boolean, :default => false | |
5 | - settings_items :wiki_link, :type => :string, :default => "" | |
6 | - | |
7 | - def self.description | |
8 | - _('Wiki Link') | |
9 | - end | |
10 | - | |
11 | - def help | |
12 | - _('This block displays a link to the software wiki.') | |
13 | - end | |
14 | - | |
15 | - def content(args={}) | |
16 | - block = self | |
17 | - s = show_name | |
18 | - | |
19 | - lambda do |object| | |
20 | - render( | |
21 | - :file => 'blocks/wiki', | |
22 | - :locals => { :block => block, :show_name => s } | |
23 | - ) | |
24 | - end | |
25 | - end | |
26 | - | |
27 | - def cacheable? | |
28 | - true | |
29 | - end | |
30 | -end |