diff --git a/controllers/mpog_software_plugin_myprofile_controller.rb b/controllers/mpog_software_plugin_myprofile_controller.rb index 4e62d33..52468bc 100644 --- a/controllers/mpog_software_plugin_myprofile_controller.rb +++ b/controllers/mpog_software_plugin_myprofile_controller.rb @@ -17,7 +17,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController @list_libraries = LibraryHelper.list_libraries(params[:library]) @list_languages = SoftwareLanguageHelper.list_language(params[:language]) @list_databases = DatabaseHelper.list_database(params[:database]) - @controlled_vocabulary = ControlledVocabulary::new params[:controlled_vocabulary] + @software_categories = SoftwareCategories::new params[:software_categories] @list_operating_systems = OperatingSystemHelper.list_operating_system(params[:operating_system]) @license_info = if params[:license_info].nil? LicenseInfo::new @@ -58,7 +58,8 @@ class MpogSoftwarePluginMyprofileController < MyProfileController valid_operating_system = OperatingSystemHelper.valid_list_operating_system?(@list_operating_systems) if valid_software_info && valid_community && valid_libraries && valid_license && valid_language && valid_database && valid_operating_system - @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]), @software_info, @license_info, @controlled_vocabulary) + + @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]), @software_info, @license_info, @software_categories) unless params[:q].nil? admins = params[:q].split(/,/).map{|n| environment.people.find n.to_i} diff --git a/db/migrate/20140909185547_rename_controlled_vocabulary_to_software_categories.rb b/db/migrate/20140909185547_rename_controlled_vocabulary_to_software_categories.rb new file mode 100644 index 0000000..0d9a7b1 --- /dev/null +++ b/db/migrate/20140909185547_rename_controlled_vocabulary_to_software_categories.rb @@ -0,0 +1,9 @@ +class RenameControlledVocabularyToSoftwareCategories < ActiveRecord::Migration + def up + rename_table :controlled_vocabulary, :software_categories + end + + def down + rename_table :software_categories, :controlled_vocabulary + end +end diff --git a/lib/controlled_vocabulary_helper.rb b/lib/controlled_vocabulary_helper.rb deleted file mode 100644 index 57f012c..0000000 --- a/lib/controlled_vocabulary_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -module ControlledVocabularyHelper - - def self.get_categories_as_options - categories = ["".html_safe] - value = 1 - - ControlledVocabulary.attribute_names.each do |attribute| - if attribute.to_s != "id" && attribute.to_s != "software_info_id" then - categories << "".html_safe - value+=1 - end - end - categories - end -end diff --git a/lib/ext/community.rb b/lib/ext/community.rb index acbdd6e..c24f659 100644 --- a/lib/ext/community.rb +++ b/lib/ext/community.rb @@ -7,17 +7,17 @@ class Community has_one :software_info, :dependent=>:delete has_one :institution, :dependent=>:delete - def self.create_after_moderation(requestor, attributes = {}, software_info = nil, license_info = nil, controlled_vocabulary = nil) + def self.create_after_moderation(requestor, attributes = {}, software_info = nil, license_info = nil, software_categories = nil) community = Community.new(attributes) if not software_info.nil? - if not license_info.nil? - software_info.license_info = license_info - end + if not license_info.nil? + software_info.license_info = license_info + end - if not controlled_vocabulary.nil? - software_info.controlled_vocabulary = controlled_vocabulary - end + if not software_categories.nil? + software_info.software_categories = software_categories + end software_info.save end diff --git a/lib/ext/controlled_vocabulary.rb b/lib/ext/controlled_vocabulary.rb deleted file mode 100644 index 3afc6f8..0000000 --- a/lib/ext/controlled_vocabulary.rb +++ /dev/null @@ -1,12 +0,0 @@ -class ControlledVocabulary < ActiveRecord::Base - self.table_name = "controlled_vocabulary" - - attr_accessible :administration , :agriculture , :business_and_services , :communication , - :culture , :national_defense , :economy_and_finances , :education , - :energy , :sports , :habitation , :industry , :environment , - :research_and_development , :social_security , :social_protection , - :international_relations , :sanitation , :health , - :security_public_order , :work , :transportation , :urbanism - - belongs_to :software_info -end \ No newline at end of file diff --git a/lib/mpog_software_plugin.rb b/lib/mpog_software_plugin.rb index bad9496..8a8a798 100644 --- a/lib/mpog_software_plugin.rb +++ b/lib/mpog_software_plugin.rb @@ -100,8 +100,8 @@ class MpogSoftwarePlugin < Noosfero::Plugin institution_transaction end - if context.params.has_key?(:controlled_vocabulary) - controlled_vocabulary_transaction + if context.params.has_key?(:software_categories) + software_categories_transaction end elsif context.profile.respond_to?(:user) if context.params.has_key?(:user) @@ -137,7 +137,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin softwares = SoftwareInfo.search(params[:name], params[:database_description][:id], params[:programming_language][:id], params[:operating_system][:id], params[:license_info][:id], params[:e_ping], params[:e_mag], params[:internacionalizable], - params[:icp_brasil], params[:e_arq], params[:controlled_vocabulary]) + params[:icp_brasil], params[:e_arq], params[:software_categories]) communities = [] softwares.each do |s| @@ -416,9 +416,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin end end - def controlled_vocabulary_transaction + def software_categories_transaction ControlledVocabulary.transaction do - context.profile.software_info.controlled_vocabulary.update_attributes!(context.params[:controlled_vocabulary]) + context.profile.software_info.software_categories.update_attributes!(context.params[:software_categories]) end end diff --git a/lib/software_categories.rb b/lib/software_categories.rb new file mode 100644 index 0000000..2ced887 --- /dev/null +++ b/lib/software_categories.rb @@ -0,0 +1,10 @@ +class SoftwareCategories < ActiveRecord::Base + attr_accessible :administration , :agriculture , :business_and_services , :communication , + :culture , :national_defense , :economy_and_finances , :education , + :energy , :sports , :habitation , :industry , :environment , + :research_and_development , :social_security , :social_protection , + :international_relations , :sanitation , :health , + :security_public_order , :work , :transportation , :urbanism + + belongs_to :software_info +end \ No newline at end of file diff --git a/lib/software_categories_helper.rb b/lib/software_categories_helper.rb new file mode 100644 index 0000000..4540847 --- /dev/null +++ b/lib/software_categories_helper.rb @@ -0,0 +1,15 @@ +module SoftwareCategoriesHelper + + def self.get_categories_as_options + categories = ["".html_safe] + value = 1 + + SoftwareCategories.attribute_names.each do |attribute| + if attribute.to_s != "id" && attribute.to_s != "software_info_id" then + categories << "".html_safe + value+=1 + end + end + categories + end +end diff --git a/lib/software_info.rb b/lib/software_info.rb index 3c4ba78..18384bf 100644 --- a/lib/software_info.rb +++ b/lib/software_info.rb @@ -12,7 +12,9 @@ class SoftwareInfo < ActiveRecord::Base belongs_to :community belongs_to :license_info - has_one :controlled_vocabulary + has_one :software_categories + + validates :software_categories, :presence=>true validates :features, :objectives, :presence=>true, @@ -31,7 +33,7 @@ class SoftwareInfo < ActiveRecord::Base scope :search, lambda { |name="", database_description_id = "", programming_language_id = "", operating_system_name_id = "", license_info_id = "", e_ping = "", e_mag = "", internacionalizable = "", - icp_brasil = "", e_arq = "", controlled_vocabulary = "" | + icp_brasil = "", e_arq = "", software_categories = "" | like_sql = "" values = [] @@ -86,9 +88,9 @@ class SoftwareInfo < ActiveRecord::Base values << "#{e_arq}" end - unless controlled_vocabulary.blank? - controlled_vocabulary = controlled_vocabulary.gsub(' ', '').underscore - like_sql << "controlled_vocabulary.#{controlled_vocabulary} = ? AND " + unless software_categories.blank? + software_categories = software_categories.gsub(' ', '').underscore + like_sql << "software_categories.#{software_categories} = ? AND " values << "true" end @@ -96,7 +98,7 @@ class SoftwareInfo < ActiveRecord::Base { :joins => [:community, :software_databases, :software_languages, - :operating_systems, :controlled_vocabulary], + :operating_systems, :software_categories], :conditions=>[like_sql, *values] } } diff --git a/test/unit/controlled_vocabulary_test.rb b/test/unit/controlled_vocabulary_test.rb deleted file mode 100644 index 753df0e..0000000 --- a/test/unit/controlled_vocabulary_test.rb +++ /dev/null @@ -1,59 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' - -class ControlledVocabularyTest < ActiveSupport::TestCase - - def setup - @community = fast_create(Community, :identifier => 'new-software', :name => 'New Software') - - @language = ProgrammingLanguage.new(:name => 'C++') - @language.save - @software_language = SoftwareLanguage.new(:version => '1', :operating_system => 'os') - @software_language.programming_language = @language - @software_language.save - - @database = DatabaseDescription.new(:name => 'Oracle') - @database.save - @software_database = SoftwareDatabase.new(:version => '2', :operating_system => 'os2') - @software_database.database_description = @database - @software_database.save - - @operating_system_name = OperatingSystemName.new(:name => 'Debian') - @operating_system_name.save - @operating_system = OperatingSystem.new(:version => '1.0') - @operating_system.operating_system_name = @operating_system_name - @operating_system.save - - @software_info = SoftwareInfo.new(:acronym => "SFTW", :e_mag => true,:icp_brasil => true,:intern => true,:e_ping => true, - :e_arq => true, :operating_platform => true, :objectives => "", :features => "") - @software_info.software_languages << @software_language - @software_info.software_databases << @software_database - @software_info.operating_systems << @operating_system - - @controlled_language = ControlledVocabulary.new() - @controlled_vocabulary = ControlledVocabulary.new(:administration => true, :agriculture => true, :business_and_services => true, :communication => true, - :culture => true, :national_defense => true, :economy_and_finances => true, :education => true, - :energy => true, :sports => false , :habitation => true, :industry => true, :environment => true, - :research_and_development => true, :social_security => false , :social_protection => true, - :international_relations => true, :sanitation => true, :health => false, - :security_public_order => true, :work => true, :transportation => true, :urbanism => true) - @software_info.controlled_vocabulary = @controlled_vocabulary - end - - should "save software correctly with ControlledVocabulary filds" do - assert @software_info.save - end - - should "set in software_info a reference to controlled_vocabulary" do - @software_info.save - @controlled_vocabulary.save - assert_equal SoftwareInfo.last.controlled_vocabulary, ControlledVocabulary.last - end - - should "return a valid value from database" do - @software_info.save - @controlled_vocabulary.save - software_info = SoftwareInfo.find(@software_info.id) - controlled_vocabulary = ControlledVocabulary.find(software_info.controlled_vocabulary) - assert_equal true, controlled_vocabulary.education - end -end diff --git a/test/unit/software_categories_test.rb b/test/unit/software_categories_test.rb new file mode 100644 index 0000000..ee75642 --- /dev/null +++ b/test/unit/software_categories_test.rb @@ -0,0 +1,61 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class SoftwareCategoriesTest < ActiveSupport::TestCase + + def setup + @community = fast_create(Community, :identifier => 'new-software', :name => 'New Software') + + @language = ProgrammingLanguage.new(:name => 'C++') + @language.save + @software_language = SoftwareLanguage.new(:version => '1', :operating_system => 'os') + @software_language.programming_language = @language + @software_language.save + + @database = DatabaseDescription.new(:name => 'Oracle') + @database.save + @software_database = SoftwareDatabase.new(:version => '2', :operating_system => 'os2') + @software_database.database_description = @database + @software_database.save + + @operating_system_name = OperatingSystemName.new(:name => 'Debian') + @operating_system_name.save + @operating_system = OperatingSystem.new(:version => '1.0') + @operating_system.operating_system_name = @operating_system_name + @operating_system.save + + @software_info = SoftwareInfo.new(:acronym => "SFTW", :e_mag => true,:icp_brasil => true,:intern => true,:e_ping => true, + :e_arq => true, :operating_platform => true, :objectives => "", :features => "") + @software_info.software_languages << @software_language + @software_info.software_databases << @software_database + @software_info.operating_systems << @operating_system + + @software_info.features = "Do a lot of things" + @software_info.objectives = "All tests should pass !" + + @software_categories = SoftwareCategories.new(:administration => true, :agriculture => true, :business_and_services => true, :communication => true, + :culture => true, :national_defense => true, :economy_and_finances => true, :education => true, + :energy => true, :sports => false , :habitation => true, :industry => true, :environment => true, + :research_and_development => true, :social_security => false , :social_protection => true, + :international_relations => true, :sanitation => true, :health => false, + :security_public_order => true, :work => true, :transportation => true, :urbanism => true) + @software_info.software_categories = @software_categories + end + + should "save software correctly with SoftwareCategories filds" do + assert @software_info.save + end + + should "set in software_info a reference to software_categories" do + @software_info.save + @software_categories.save + assert_equal SoftwareInfo.last.software_categories, SoftwareCategories.last + end + + should "return a valid value from database" do + @software_info.save + @software_categories.save + software_info = SoftwareInfo.find(@software_info.id) + software_categories = SoftwareCategories.find(software_info.software_categories) + assert_equal true, software_categories.education + end +end diff --git a/views/mpog_software_plugin_myprofile/new_software.html.erb b/views/mpog_software_plugin_myprofile/new_software.html.erb index 1d8819e..921fb77 100644 --- a/views/mpog_software_plugin_myprofile/new_software.html.erb +++ b/views/mpog_software_plugin_myprofile/new_software.html.erb @@ -151,9 +151,9 @@ offerers'), :pre_populate => @tokenized_children}) %> <%= render :partial => 'database_fields', :locals => { :f => f, :object_name => 'community', :profile => @community, :database => @list_databases } %> - <%= fields_for @controlled_vocabulary do |cv| %> -
-

<%= _("Controlled Vocabulary of E-government") %>

+ <%= fields_for @software_categories do |cv| %> +
+

<%= _("Software Categories:") %>

<%= cv.check_box :administration %> <%= cv.label :administration, _("Administration") %>
diff --git a/views/search/search_forms/_software_fields.html.erb b/views/search/search_forms/_software_fields.html.erb index 33854e0..51aff0c 100644 --- a/views/search/search_forms/_software_fields.html.erb +++ b/views/search/search_forms/_software_fields.html.erb @@ -26,9 +26,9 @@ - <%= _("Controlled Vocabulary") %> + <%= _("Software Categories") %> - <%= select_tag("controlled_vocabulary", (ControlledVocabularyHelper.get_categories_as_options)) %> + <%= select_tag("software_categories", (SoftwareCategoriesHelper.get_categories_as_options)) %> diff --git a/views/software_editor_extras.html.erb b/views/software_editor_extras.html.erb index fd43f15..d44352d 100644 --- a/views/software_editor_extras.html.erb +++ b/views/software_editor_extras.html.erb @@ -95,52 +95,52 @@ <%= link_to _('New Database'), "#", :class=>"button icon-add with-text new-dynamic-table dynamic-databases"%> -
-

<%= _("Controlled Vocabulary of E-government") %>

+
+

<%= _("Software Categories") %>

- <%= labelled_check_box _("Administration"), "controlled_vocabulary[administration]", "1", context.profile.software_info.controlled_vocabulary.administration %>
+ <%= labelled_check_box _("Administration"), "software_categories[administration]", "1", context.profile.software_info.software_categories.administration %>
- <%= labelled_check_box _("Agriculture"), "controlled_vocabulary[agriculture]", "1", context.profile.software_info.controlled_vocabulary.agriculture %>
+ <%= labelled_check_box _("Agriculture"), "software_categories[agriculture]", "1", context.profile.software_info.software_categories.agriculture %>
- <%= labelled_check_box _("Business_and Services"), "controlled_vocabulary[business_and_services]", "1", context.profile.software_info.controlled_vocabulary.business_and_services %>
+ <%= labelled_check_box _("Business_and Services"), "software_categories[business_and_services]", "1", context.profile.software_info.software_categories.business_and_services %>
- <%= labelled_check_box _("Communication"), "controlled_vocabulary[communication]", "1", context.profile.software_info.controlled_vocabulary.communication %>
+ <%= labelled_check_box _("Communication"), "software_categories[communication]", "1", context.profile.software_info.software_categories.communication %>
- <%= labelled_check_box _("Culture"), "controlled_vocabulary[culture]", "1", context.profile.software_info.controlled_vocabulary.culture %>
+ <%= labelled_check_box _("Culture"), "software_categories[culture]", "1", context.profile.software_info.software_categories.culture %>
- <%= labelled_check_box _("National Defense"), "controlled_vocabulary[national_defense]", "1", context.profile.software_info.controlled_vocabulary.national_defense %>
+ <%= labelled_check_box _("National Defense"), "software_categories[national_defense]", "1", context.profile.software_info.software_categories.national_defense %>
- <%= labelled_check_box _("Economy and Finances"), "controlled_vocabulary[economy_and_finances]", "1", context.profile.software_info.controlled_vocabulary.economy_and_finances %>
+ <%= labelled_check_box _("Economy and Finances"), "software_categories[economy_and_finances]", "1", context.profile.software_info.software_categories.economy_and_finances %>
- <%= labelled_check_box _("Education"), "controlled_vocabulary[education]", "1", context.profile.software_info.controlled_vocabulary.education %>
+ <%= labelled_check_box _("Education"), "software_categories[education]", "1", context.profile.software_info.software_categories.education %>
- <%= labelled_check_box _("Energy"), "controlled_vocabulary[energy]", "1", context.profile.software_info.controlled_vocabulary.energy %>
+ <%= labelled_check_box _("Energy"), "software_categories[energy]", "1", context.profile.software_info.software_categories.energy %>
- <%= labelled_check_box _("Sports"), "controlled_vocabulary[sports]", "1", context.profile.software_info.controlled_vocabulary.sports %>
+ <%= labelled_check_box _("Sports"), "software_categories[sports]", "1", context.profile.software_info.software_categories.sports %>
- <%= labelled_check_box _("Habitation"), "controlled_vocabulary[habitation]", "1", context.profile.software_info.controlled_vocabulary.habitation %>
+ <%= labelled_check_box _("Habitation"), "software_categories[habitation]", "1", context.profile.software_info.software_categories.habitation %>
- <%= labelled_check_box _("Industry"), "controlled_vocabulary[industry]", "1", context.profile.software_info.controlled_vocabulary.industry %>
+ <%= labelled_check_box _("Industry"), "software_categories[industry]", "1", context.profile.software_info.software_categories.industry %>
- <%= labelled_check_box _("Environment"), "controlled_vocabulary[environment]", "1", context.profile.software_info.controlled_vocabulary.environment %>
+ <%= labelled_check_box _("Environment"), "software_categories[environment]", "1", context.profile.software_info.software_categories.environment %>
- <%= labelled_check_box _("Research and Development"), "controlled_vocabulary[research_and_development]", "1", context.profile.software_info.controlled_vocabulary.research_and_development %>
+ <%= labelled_check_box _("Research and Development"), "software_categories[research_and_development]", "1", context.profile.software_info.software_categories.research_and_development %>
- <%= labelled_check_box _("Social Security"), "controlled_vocabulary[social_security]", "1", context.profile.software_info.controlled_vocabulary.social_security %>
+ <%= labelled_check_box _("Social Security"), "software_categories[social_security]", "1", context.profile.software_info.software_categories.social_security %>
- <%= labelled_check_box _("Social Protection"), "controlled_vocabulary[social_protection]", "1", context.profile.software_info.controlled_vocabulary.social_protection %>
+ <%= labelled_check_box _("Social Protection"), "software_categories[social_protection]", "1", context.profile.software_info.software_categories.social_protection %>
- <%= labelled_check_box _("Sanitation"), "controlled_vocabulary[sanitation]", "1", context.profile.software_info.controlled_vocabulary.sanitation %>
+ <%= labelled_check_box _("Sanitation"), "software_categories[sanitation]", "1", context.profile.software_info.software_categories.sanitation %>
- <%= labelled_check_box _("Health"), "controlled_vocabulary[health]", "1", context.profile.software_info.controlled_vocabulary.health %>
+ <%= labelled_check_box _("Health"), "software_categories[health]", "1", context.profile.software_info.software_categories.health %>
- <%= labelled_check_box _("Security and Public Order"), "controlled_vocabulary[security_public_order]", "1", context.profile.software_info.controlled_vocabulary.security_public_order %>
+ <%= labelled_check_box _("Security and Public Order"), "software_categories[security_public_order]", "1", context.profile.software_info.software_categories.security_public_order %>
- <%= labelled_check_box _("Work"), "controlled_vocabulary[work]", "1", context.profile.software_info.controlled_vocabulary.work %>
+ <%= labelled_check_box _("Work"), "software_categories[work]", "1", context.profile.software_info.software_categories.work %>
- <%= labelled_check_box _("Transportation"), "controlled_vocabulary[transportation]", "1", context.profile.software_info.controlled_vocabulary.transportation %>
+ <%= labelled_check_box _("Transportation"), "software_categories[transportation]", "1", context.profile.software_info.software_categories.transportation %>
- <%= labelled_check_box _("Urbanism"), "controlled_vocabulary[urbanism]", "1", context.profile.software_info.controlled_vocabulary.urbanism %>
+ <%= labelled_check_box _("Urbanism"), "software_categories[urbanism]", "1", context.profile.software_info.software_categories.urbanism %>

<%= _("Operating System") %>

-- libgit2 0.21.2