Commit 3731d14fe303892ba4909ca050a07e941c3f4f94

Authored by Rodrigo Souto
1 parent 86be5aff

software-communities: extract category hardcoded extensions (checkpoint)

src/noosfero-spb/software_communities/lib/ext/category.rb
1 require_dependency 'category' 1 require_dependency 'category'
2 2
3 class Category 3 class Category
4 - SOFTWARE_CATEGORIES = [  
5 - _('Agriculture, Fisheries and Extraction'),  
6 - _('Science, Information and Communication'),  
7 - _('Economy and Finances'),  
8 - _('Public Administration'),  
9 - _('Habitation, Sanitation and Urbanism'),  
10 - _('Individual, Family and Society'),  
11 - _('Health'),  
12 - _('Social Welfare and Development'),  
13 - _('Defense and Security'),  
14 - _('Education'),  
15 - _('Government and Politics'),  
16 - _('Justice and Legislation'),  
17 - _('International Relationships'),  
18 - _('Transportation and Transit')  
19 - ]  
20 -  
21 - scope :software_categories, lambda {  
22 - software_category = Category.find_by_name("Software")  
23 - if software_category.nil?  
24 - []  
25 - else  
26 - software_category.children  
27 - end  
28 - }  
29 -  
30 def software_infos 4 def software_infos
31 software_list = self.communities 5 software_list = self.communities
32 software_list.collect { |x| software_list.delete(x) unless x.software? } 6 software_list.collect { |x| software_list.delete(x) unless x.software? }
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
@@ -151,12 +151,12 @@ class SearchController @@ -151,12 +151,12 @@ class SearchController
151 end 151 end
152 152
153 def prepare_software_infos_category_groups 153 def prepare_software_infos_category_groups
154 - @categories = Category.software_categories.sort{|a, b| a.name <=> b.name} 154 + @categories = SoftwareCommunitiesPlugin.software_categories.sort{|a, b| a.name <=> b.name}
155 end 155 end
156 156
157 def prepare_software_infos_category_enable 157 def prepare_software_infos_category_enable
158 @enabled_check_box = Hash.new 158 @enabled_check_box = Hash.new
159 - categories = Category.software_categories 159 + categories = SoftwareCommunitiesPlugin.software_categories
160 160
161 categories.each do |category| 161 categories.each do |category|
162 if category.software_infos.count > 0 162 if category.software_infos.count > 0
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
@@ -17,6 +17,23 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -17,6 +17,23 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
17 _('Add Public Software and MPOG features.') 17 _('Add Public Software and MPOG features.')
18 end 18 end
19 19
  20 + SOFTWARE_CATEGORIES = [
  21 + _('Agriculture, Fisheries and Extraction'),
  22 + _('Science, Information and Communication'),
  23 + _('Economy and Finances'),
  24 + _('Public Administration'),
  25 + _('Habitation, Sanitation and Urbanism'),
  26 + _('Individual, Family and Society'),
  27 + _('Health'),
  28 + _('Social Welfare and Development'),
  29 + _('Defense and Security'),
  30 + _('Education'),
  31 + _('Government and Politics'),
  32 + _('Justice and Legislation'),
  33 + _('International Relationships'),
  34 + _('Transportation and Transit')
  35 + ]
  36 +
20 def profile_tabs 37 def profile_tabs
21 if context.profile.community? && context.profile.software? 38 if context.profile.community? && context.profile.software?
22 return profile_tabs_software 39 return profile_tabs_software
@@ -47,6 +64,15 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin @@ -47,6 +64,15 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
47 } 64 }
48 end 65 end
49 66
  67 + def self.software_categories
  68 + software_category = Category.find_by_name("Software")
  69 + if software_category.nil?
  70 + []
  71 + else
  72 + software_category.children
  73 + end
  74 + end
  75 +
50 def stylesheet? 76 def stylesheet?
51 true 77 true
52 end 78 end
src/noosfero-spb/software_communities/lib/tasks/create_categories.rake
@@ -5,7 +5,7 @@ namespace :software do @@ -5,7 +5,7 @@ namespace :software do
5 if env.plugin_enabled?("SoftwareCommunitiesPlugin") or env.plugin_enabled?("SoftwareCommunities") 5 if env.plugin_enabled?("SoftwareCommunitiesPlugin") or env.plugin_enabled?("SoftwareCommunities")
6 print 'Creating categories: ' 6 print 'Creating categories: '
7 software = Category.create(:name => _("Software"), :environment => env) 7 software = Category.create(:name => _("Software"), :environment => env)
8 - Category::SOFTWARE_CATEGORIES.each do |category_name| 8 + SoftwareCommunitiesPlugin::SOFTWARE_CATEGORIES.each do |category_name|
9 unless Category.find_by_name(category_name) 9 unless Category.find_by_name(category_name)
10 print '.' 10 print '.'
11 Category.create(:name => category_name, :environment => env, :parent => software) 11 Category.create(:name => category_name, :environment => env, :parent => software)