From 8d4c86eaa2f89eccf9b2c9e3e457604688506aa8 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Tue, 24 Nov 2015 16:04:22 -0300 Subject: [PATCH] software-communities: refactoring namespaces --- src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb | 29 ----------------------------- src/noosfero-spb/software_communities/lib/categories_software_block.rb | 35 ----------------------------------- src/noosfero-spb/software_communities/lib/create_software.rb | 115 ------------------------------------------------------------------------------------------------------------------- src/noosfero-spb/software_communities/lib/database_description.rb | 15 --------------- src/noosfero-spb/software_communities/lib/database_helper.rb | 77 ----------------------------------------------------------------------------- src/noosfero-spb/software_communities/lib/download.rb | 51 --------------------------------------------------- src/noosfero-spb/software_communities/lib/download_block.rb | 36 ------------------------------------ src/noosfero-spb/software_communities/lib/dynamic_table_helper.rb | 153 --------------------------------------------------------------------------------------------------------------------------------------------------------- src/noosfero-spb/software_communities/lib/library.rb | 10 ---------- src/noosfero-spb/software_communities/lib/library_helper.rb | 57 --------------------------------------------------------- src/noosfero-spb/software_communities/lib/license_helper.rb | 9 --------- src/noosfero-spb/software_communities/lib/license_info.rb | 8 -------- src/noosfero-spb/software_communities/lib/operating_system.rb | 14 -------------- src/noosfero-spb/software_communities/lib/operating_system_helper.rb | 67 ------------------------------------------------------------------- src/noosfero-spb/software_communities/lib/operating_system_name.rb | 10 ---------- src/noosfero-spb/software_communities/lib/programming_language.rb | 15 --------------- src/noosfero-spb/software_communities/lib/repository_block.rb | 29 ----------------------------- src/noosfero-spb/software_communities/lib/search_catalog_block.rb | 29 ----------------------------- src/noosfero-spb/software_communities/lib/software_communities_plugin.rb | 26 +++++++++++++------------- src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_and_tags_block.rb | 29 +++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_software_block.rb | 35 +++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/database_description.rb | 15 +++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/database_helper.rb | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/download.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/download_block.rb | 36 ++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/dynamic_table_helper.rb | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/library.rb | 10 ++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/library_helper.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/license_helper.rb | 9 +++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/license_info.rb | 8 ++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system.rb | 14 ++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_helper.rb | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_name.rb | 10 ++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/programming_language.rb | 15 +++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/repository_block.rb | 29 +++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/search_catalog_block.rb | 29 +++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_database.rb | 20 ++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_helper.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_highlights_block.rb | 20 ++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_info.rb | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_information_block.rb | 37 +++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language.rb | 14 ++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language_helper.rb | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/software_tab_data_block.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/softwares_block.rb | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/statistic_block.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_communities_plugin/wiki_block.rb | 30 ++++++++++++++++++++++++++++++ src/noosfero-spb/software_communities/lib/software_database.rb | 20 -------------------- src/noosfero-spb/software_communities/lib/software_helper.rb | 43 ------------------------------------------- src/noosfero-spb/software_communities/lib/software_highlights_block.rb | 20 -------------------- src/noosfero-spb/software_communities/lib/software_info.rb | 263 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/noosfero-spb/software_communities/lib/software_information_block.rb | 37 ------------------------------------- src/noosfero-spb/software_communities/lib/software_language.rb | 14 -------------- src/noosfero-spb/software_communities/lib/software_language_helper.rb | 84 ------------------------------------------------------------------------------------ src/noosfero-spb/software_communities/lib/software_tab_data_block.rb | 48 ------------------------------------------------ src/noosfero-spb/software_communities/lib/softwares_block.rb | 105 --------------------------------------------------------------------------------------------------------- src/noosfero-spb/software_communities/lib/statistic_block.rb | 52 ---------------------------------------------------- src/noosfero-spb/software_communities/lib/wiki_block.rb | 30 ------------------------------ 59 files changed, 1491 insertions(+), 1488 deletions(-) delete mode 100644 src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/categories_software_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/create_software.rb delete mode 100644 src/noosfero-spb/software_communities/lib/database_description.rb delete mode 100644 src/noosfero-spb/software_communities/lib/database_helper.rb delete mode 100644 src/noosfero-spb/software_communities/lib/download.rb delete mode 100644 src/noosfero-spb/software_communities/lib/download_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/dynamic_table_helper.rb delete mode 100644 src/noosfero-spb/software_communities/lib/library.rb delete mode 100644 src/noosfero-spb/software_communities/lib/library_helper.rb delete mode 100644 src/noosfero-spb/software_communities/lib/license_helper.rb delete mode 100644 src/noosfero-spb/software_communities/lib/license_info.rb delete mode 100644 src/noosfero-spb/software_communities/lib/operating_system.rb delete mode 100644 src/noosfero-spb/software_communities/lib/operating_system_helper.rb delete mode 100644 src/noosfero-spb/software_communities/lib/operating_system_name.rb delete mode 100644 src/noosfero-spb/software_communities/lib/programming_language.rb delete mode 100644 src/noosfero-spb/software_communities/lib/repository_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/search_catalog_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_and_tags_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_software_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/database_description.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/database_helper.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/download.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/download_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/dynamic_table_helper.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/library.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/library_helper.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/license_helper.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/license_info.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_helper.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_name.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/programming_language.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/repository_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/search_catalog_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_database.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_helper.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_highlights_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_info.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_information_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language_helper.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/software_tab_data_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/softwares_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/statistic_block.rb create mode 100644 src/noosfero-spb/software_communities/lib/software_communities_plugin/wiki_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_database.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_helper.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_highlights_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_info.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_information_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_language.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_language_helper.rb delete mode 100644 src/noosfero-spb/software_communities/lib/software_tab_data_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/softwares_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/statistic_block.rb delete mode 100644 src/noosfero-spb/software_communities/lib/wiki_block.rb diff --git a/src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb b/src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb deleted file mode 100644 index e50f9c4..0000000 --- a/src/noosfero-spb/software_communities/lib/categories_and_tags_block.rb +++ /dev/null @@ -1,29 +0,0 @@ -class CategoriesAndTagsBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Categories and Tags') - end - - def help - _('This block displays the categories and tags of a software.') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/categories_and_tags', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/categories_software_block.rb b/src/noosfero-spb/software_communities/lib/categories_software_block.rb deleted file mode 100644 index 97e1fda..0000000 --- a/src/noosfero-spb/software_communities/lib/categories_software_block.rb +++ /dev/null @@ -1,35 +0,0 @@ -class CategoriesSoftwareBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Categories Softwares') - end - - def help - _('This block displays the categories and the amount of softwares for - each category.') - end - - def content(args={}) - block = self - s = show_name - - software_category = Category.find_by_name("Software") - categories = [] - categories = software_category.children.sort if software_category - - lambda do |object| - render( - :file => 'blocks/categories_software', - :locals => { :block => block, :show_name => s, :categories => categories } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/create_software.rb b/src/noosfero-spb/software_communities/lib/create_software.rb deleted file mode 100644 index d43a21b..0000000 --- a/src/noosfero-spb/software_communities/lib/create_software.rb +++ /dev/null @@ -1,115 +0,0 @@ -class CreateSoftware < Task - include Rails.application.routes.url_helpers - - validates_presence_of :requestor_id, :target_id - validates_presence_of :name, :finality - - attr_accessible :name, :finality, :repository_link, :requestor, :environment, - :reject_explanation, :license_info, :identifier, :target - - alias :environment :target - alias :environment= :target= - - DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link'] - DATA_FIELDS.each do |field| - settings_items field.to_sym - end - - def perform - software_template = SoftwareHelper.software_template - template_id = software_template.blank? ? nil : software_template.id - - identifier = self.identifier - identifier ||= self.name.to_slug - - community = Community.create!(:name => self.name, - :identifier => identifier, - :template_id => template_id) - - community.environment = self.environment - community.add_admin(self.requestor) - - software = SoftwareInfo.create!(:finality => self.finality, - :repository_link => self.repository_link, :community_id => community.id, - :license_info => self.license_info) - end - - def title - _("New software") - end - - def subject - name - end - - def information - message = _('%{requestor} wants to create software %{subject} with') - if finality.blank? - { :message => message + _(' no finality.') } - else - { :message => message + _(' this finality:

%{finality}

'), - :variables => {:finality => finality} } - end - end - - def reject_details - true - end - - # tells if this request was rejected - def rejected? - self.status == Task::Status::CANCELLED - end - - # tells if this request was appoved - def approved? - self.status == Task::Status::FINISHED - end - - def target_notification_description - _('%{requestor} wants to create software %{subject}') % - {:requestor => requestor.name, :subject => subject} - end - - def target_notification_message - _("User \"%{user}\" just requested to create software %{software}. - You have to approve or reject it through the \"Pending Validations\" - section in your control panel.\n") % - { :user => self.requestor.name, :software => self.name } - end - - def task_created_message - _("Your request for registering software %{software} at %{environment} was - just sent. Environment administrator will receive it and will approve or - reject your request according to his methods and criteria. - - You will be notified as soon as environment administrator has a position - about your request.") % - { :software => self.name, :environment => self.target } - end - - def task_cancelled_message - _("Your request for registering software %{software} at %{environment} was - not approved by the environment administrator. The following explanation - was given: \n\n%{explanation}") % - { :software => self.name, - :environment => self.environment, - :explanation => self.reject_explanation } - end - - def task_finished_message - _('Your request for registering the software "%{software}" was approved. - You can access %{url} and finish the registration of your software.') % - { :software => self.name, :url => mount_url } - end - - private - - def mount_url - identifier = Community.where(:name => self.name).first.identifier - # The use of url_for doesn't allow the /social within the Public Software - # portal. That's why the url is mounted so 'hard coded' - url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community" - end - -end diff --git a/src/noosfero-spb/software_communities/lib/database_description.rb b/src/noosfero-spb/software_communities/lib/database_description.rb deleted file mode 100644 index ff1e641..0000000 --- a/src/noosfero-spb/software_communities/lib/database_description.rb +++ /dev/null @@ -1,15 +0,0 @@ -class DatabaseDescription < ActiveRecord::Base - - SEARCHABLE_SOFTWARE_FIELDS = { - :name => 1 - } - - attr_accessible :name - - has_many :software_databases - has_many :software_infos, :through => :software_databases - - validates_presence_of :name - validates_uniqueness_of :name - -end diff --git a/src/noosfero-spb/software_communities/lib/database_helper.rb b/src/noosfero-spb/software_communities/lib/database_helper.rb deleted file mode 100644 index 94bf652..0000000 --- a/src/noosfero-spb/software_communities/lib/database_helper.rb +++ /dev/null @@ -1,77 +0,0 @@ -class DatabaseHelper < DynamicTableHelper - MODEL_NAME ="database" - FIELD_NAME = "database_description_id" - - def self.valid_database? database - return false if SoftwareHelper.all_table_is_empty?(database) - - database_description_id_list = DatabaseDescription.select(:id). - collect {|dd| dd.id} - - return database_description_id_list.include?( - database[:database_description_id].to_i - ) - end - - def self.list_database new_databases - return [] if new_databases.nil? or new_databases.length == 0 - list_databases = [] - - new_databases.each do |new_database| - if valid_database? new_database - database = SoftwareDatabase.new - - database.database_description_id = - new_database[:database_description_id] - - database.version = new_database[:version] - list_databases << database - end - end - - list_databases - end - - def self.valid_list_database? list_databases - return false if list_databases.nil? or list_databases.length == 0 - return !list_databases.any?{|database| !database.valid?} - end - - def self.database_as_tables(list_databases, disabled=false) - model_list = list_databases - model_list ||= [{:database_description_id => "", :version => ""}] - - models_as_tables model_list, "database_html_structure", disabled - end - - def self.database_html_structure(database_data, disabled) - database_id = database_data[:database_description_id] - database_name = database_id.blank? ? "" : DatabaseDescription.find( - database_data[:database_description_id], - :select=>"name" - ).name - - data = { - model_name: MODEL_NAME, - field_name: FIELD_NAME, - name: { - value: database_name, - id: database_id, - hidden: true, - autocomplete: true, - select_field: false - }, - version: { - value: database_data[:version], - hidden: true, - delete: true - } - } - DATA[:license].delete(:value) - table_html_structure(data, disabled) - end - - def self.add_dynamic_table - database_as_tables(nil).first.call - end -end diff --git a/src/noosfero-spb/software_communities/lib/download.rb b/src/noosfero-spb/software_communities/lib/download.rb deleted file mode 100644 index 0b63fed..0000000 --- a/src/noosfero-spb/software_communities/lib/download.rb +++ /dev/null @@ -1,51 +0,0 @@ -#FIX ME: Turn this into a proper model(next release) -class Download - def initialize data - @name = data[:name] - @link = data[:link] - @software_description = data[:software_description] - @minimum_requirements = data[:minimum_requirements] - @size = data[:size] - - @total_downloads = if data[:total_downloads] - data[:total_downloads] - else - 0 - end - end - - def self.validate_download_list download_list - download_list.select! do |download| - not download[:name].blank? - end - - download_list.map do |download| - Download.new(download).to_hash - end - end - - def to_hash - { - :name => @name, - :link => @link, - :software_description => @software_description, - :minimum_requirements => @minimum_requirements, - :size => @size, - :total_downloads => @total_downloads - } - end - - def total_downloads= value - if value.is_a? Integer - @total_downloads = value - end - end - - def total_downloads - @total_downloads - end - - def link - @link - end -end diff --git a/src/noosfero-spb/software_communities/lib/download_block.rb b/src/noosfero-spb/software_communities/lib/download_block.rb deleted file mode 100644 index 58048b7..0000000 --- a/src/noosfero-spb/software_communities/lib/download_block.rb +++ /dev/null @@ -1,36 +0,0 @@ -class DownloadBlock < Block - - attr_accessible :show_name, :downloads - - settings_items :show_name, :type => :boolean, :default => false - settings_items :downloads, :type => Array, :default => [] - - validate :download_values - - def download_values - self.downloads = Download.validate_download_list(self.downloads) - end - - def self.description - _('Download Stable Version') - end - - def help - _('This block displays the stable version of a software.') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/download', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/dynamic_table_helper.rb b/src/noosfero-spb/software_communities/lib/dynamic_table_helper.rb deleted file mode 100644 index 1c9265e..0000000 --- a/src/noosfero-spb/software_communities/lib/dynamic_table_helper.rb +++ /dev/null @@ -1,153 +0,0 @@ -class DynamicTableHelper - extend( - ActionView::Helpers::TagHelper, - ActionView::Helpers::FormTagHelper, - ActionView::Helpers::FormOptionsHelper, - ActionView::Helpers::UrlHelper, - ApplicationHelper - ) - - COLLUMN_NAME = { - name: "name", - version: "version", - license: "license" - } - - LABEL_TEXT = { - :name => _("Name"), - :version => _("Version"), - :license => _("License") - } - - DATA = { - name: { - label: LABEL_TEXT[:name], - name: COLLUMN_NAME[:name] - }, - version: { - label: LABEL_TEXT[:version], - name: COLLUMN_NAME[:version] - } , - license: { - label: LABEL_TEXT[:license], - name: COLLUMN_NAME[:license], - delete: true - } - } - @@disabled = false - - def self.table_html_structure data={}, disabled=false - @@disabled = disabled - Proc::new do - content_tag :table , generate_table_lines(data), :class => "dynamic-table" - end - end - - def self.generate_table_lines data={} - @@model = data[:model_name] - @@field_name = data[:field_name] - @@hidden_label = data[:name][:value] - @@hidden_id = data[:name][:id] - - row_data = prepare_row_data data - - table_line_data = [ - self.table_line(row_data[:name]), - self.table_line(row_data[:version]) - ] - - if row_data[:license].has_key?(:value) - table_line_data << self.table_line(row_data[:license]) - end - - table_line_data.join() - end - - def self.table_line row_data={} - unless row_data.blank? - content_tag :tr, [ - self.label_collumn(row_data[:label]), - self.value_collumn( - row_data[:value], - row_data[:name], - row_data[:autocomplete], - row_data[:select_field], - row_data[:options] - ), - self.hidden_collumn(row_data[:delete], row_data[:hidden]) - ].join() - end - end - - def self.label_collumn label="" - content_tag :td, label_tag(label) - end - - def self.value_collumn value="", name="", autocomplete=false, select_field=false, options=[] - html_options = - if autocomplete - { - :class => "#{@@model}_autocomplete", - :placeholder => _("Autocomplete field, type something") - } - else - {} - end - - html_options[:disabled] = @@disabled - - content = if select_field - select_tag("#{@@model}[][#{@@field_name}]", options, html_options) - elsif autocomplete - text_field_tag("#{@@model}_autocomplete", value, html_options) - else - text_field_tag("#{@@model}[][#{name}]", value, html_options) - end - - content_tag :td, content - end - - def self.hidden_collumn delete=false, hidden_data=false - value = - if @@disabled - nil - elsif delete - button_without_text( - :delete, _('Delete'), "#" , :class=>"delete-dynamic-table" - ) - elsif hidden_data - hidden_field_tag( - "#{@@model}[][#{@@field_name}]", - @@hidden_id, - :class => "#{@@field_name}", - :data => {:label => @@hidden_label } #check how to get the name of an object of the current model - ) - else - nil - end - - content_tag(:td, value, :align => 'right') - end - - def self.prepare_row_data data - row_data = { - name: DATA[:name], - version: DATA[:version], - license: DATA[:license] - } - - row_data[:name].merge! data[:name] - row_data[:version].merge! data[:version] - row_data[:license].merge! data[:license] if data.has_key? :license - - row_data - end - - def self.models_as_tables models, callback, disabled=false - lambdas_list = [] - - models.map do |model| - send(callback, model, disabled) - end - end -end \ No newline at end of file diff --git a/src/noosfero-spb/software_communities/lib/library.rb b/src/noosfero-spb/software_communities/lib/library.rb deleted file mode 100644 index d4b2b56..0000000 --- a/src/noosfero-spb/software_communities/lib/library.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Library < ActiveRecord::Base - attr_accessible :name, :version, :license, :software_info_id - - validates :name, :version, :license, - presence: { message: _("can't be blank") }, - length: { - maximum: 20, - too_long: _("Too long (maximum is 20 characters)") - } -end diff --git a/src/noosfero-spb/software_communities/lib/library_helper.rb b/src/noosfero-spb/software_communities/lib/library_helper.rb deleted file mode 100644 index 579ebb7..0000000 --- a/src/noosfero-spb/software_communities/lib/library_helper.rb +++ /dev/null @@ -1,57 +0,0 @@ -class LibraryHelper < DynamicTableHelper - MODEL_NAME = "library" - - def self.list_library new_libraries - return [] if new_libraries.nil? or new_libraries.length == 0 - list_libraries = [] - - new_libraries.each do |new_library| - unless SoftwareHelper.all_table_is_empty? new_library - library = Library.new - library.name = new_library[:name] - library.version = new_library[:version] - library.license = new_library[:license] - list_libraries << library - end - end - - list_libraries - end - - def self.valid_list_library? list_libraries - return true if list_libraries.nil? or list_libraries.length == 0 - return !list_libraries.any?{|library| !library.valid?} - end - - def self.libraries_as_tables list_libraries, disabled=false - model_list = list_libraries - model_list ||= [{:name=>"", :version=>"", :license=>""}] - - models_as_tables model_list, "library_html_structure", disabled - end - - def self.library_html_structure library_data, disabled - data = { - model_name: MODEL_NAME, - name: { - value: library_data[:name], - hidden: false, - autocomplete: false, - select_field: false - }, - version: { - value: library_data[:version], - delete: false - }, - license: { - value: library_data[:license] - } - } - - table_html_structure(data, disabled) - end - - def self.add_dynamic_table - libraries_as_tables(nil).first.call - end -end diff --git a/src/noosfero-spb/software_communities/lib/license_helper.rb b/src/noosfero-spb/software_communities/lib/license_helper.rb deleted file mode 100644 index 8a21a2b..0000000 --- a/src/noosfero-spb/software_communities/lib/license_helper.rb +++ /dev/null @@ -1,9 +0,0 @@ -module LicenseHelper - def self.find_licenses query - licenses = LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") - licenses.reject!{|license| license.version == "Another"} - license_another = LicenseInfo.find_by_version("Another") - licenses << license_another if license_another - licenses - end -end diff --git a/src/noosfero-spb/software_communities/lib/license_info.rb b/src/noosfero-spb/software_communities/lib/license_info.rb deleted file mode 100644 index 6f9bfe7..0000000 --- a/src/noosfero-spb/software_communities/lib/license_info.rb +++ /dev/null @@ -1,8 +0,0 @@ -class LicenseInfo < ActiveRecord::Base - attr_accessible :version, :link - - validates_presence_of :version - - has_many :software_info - -end diff --git a/src/noosfero-spb/software_communities/lib/operating_system.rb b/src/noosfero-spb/software_communities/lib/operating_system.rb deleted file mode 100644 index b2763e9..0000000 --- a/src/noosfero-spb/software_communities/lib/operating_system.rb +++ /dev/null @@ -1,14 +0,0 @@ -class OperatingSystem < ActiveRecord::Base - attr_accessible :version - - belongs_to :software_info - belongs_to :operating_system_name - - validates :operating_system_name, presence: true - validates :version, - presence: true, - length: { - maximum: 20, - too_long: _('too long (maximum is 20 characters)') - } -end diff --git a/src/noosfero-spb/software_communities/lib/operating_system_helper.rb b/src/noosfero-spb/software_communities/lib/operating_system_helper.rb deleted file mode 100644 index 201ac05..0000000 --- a/src/noosfero-spb/software_communities/lib/operating_system_helper.rb +++ /dev/null @@ -1,67 +0,0 @@ -class OperatingSystemHelper < DynamicTableHelper - MODEL_NAME = "operating_system" - FIELD_NAME = "operating_system_name_id" - - def self.list_operating_system new_operating_systems - return [] if new_operating_systems.nil? or new_operating_systems.length == 0 - list_operating_system = [] - - new_operating_systems.each do |new_operating_system| - unless SoftwareHelper.all_table_is_empty?( - new_operating_system, - ["operating_system_name_id"] - ) - - operating_system = OperatingSystem.new - operating_system.operating_system_name = OperatingSystemName.find( - new_operating_system[:operating_system_name_id] - ) - - operating_system.version = new_operating_system[:version] - list_operating_system << operating_system - end - end - list_operating_system - end - - def self.valid_list_operating_system? list_operating_system - return false if (list_operating_system.nil? || list_operating_system.length == 0) - return !list_operating_system.any?{|os| !os.valid?} - end - - def self.operating_system_as_tables(list_operating_system, disabled=false) - model_list = list_operating_system - model_list ||= [{:operating_system_name_id => "", :version => ""}] - - models_as_tables model_list, "operating_system_html_structure", disabled - end - - def self.operating_system_html_structure (operating_system_data, disabled) - select_options = options_for_select( - OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, - operating_system_data[:operating_system_name_id] - ) - - data = { - model_name: MODEL_NAME, - field_name: FIELD_NAME, - name: { - hidden: false, - autocomplete: false, - select_field: true, - options: select_options - }, - version: { - value: operating_system_data[:version], - hidden: true, - delete: true - } - } - DATA[:license].delete(:value) - table_html_structure(data, disabled) - end - - def self.add_dynamic_table - operating_system_as_tables(nil).first.call - end -end diff --git a/src/noosfero-spb/software_communities/lib/operating_system_name.rb b/src/noosfero-spb/software_communities/lib/operating_system_name.rb deleted file mode 100644 index cc59602..0000000 --- a/src/noosfero-spb/software_communities/lib/operating_system_name.rb +++ /dev/null @@ -1,10 +0,0 @@ -class OperatingSystemName < ActiveRecord::Base - attr_accessible :name - - validates_presence_of :name - validates_uniqueness_of :name - - has_many :operating_systems - has_many :software_infos, :through => :operating_systems - -end diff --git a/src/noosfero-spb/software_communities/lib/programming_language.rb b/src/noosfero-spb/software_communities/lib/programming_language.rb deleted file mode 100644 index 193225c..0000000 --- a/src/noosfero-spb/software_communities/lib/programming_language.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ProgrammingLanguage < ActiveRecord::Base - - SEARCHABLE_SOFTWARE_FIELDS = { - :name => 1 - } - - attr_accessible :name - - validates_presence_of :name - validates_uniqueness_of :name - - has_many :software_languages - has_many :software_infos, :through => :software_languages - -end diff --git a/src/noosfero-spb/software_communities/lib/repository_block.rb b/src/noosfero-spb/software_communities/lib/repository_block.rb deleted file mode 100644 index 483da7a..0000000 --- a/src/noosfero-spb/software_communities/lib/repository_block.rb +++ /dev/null @@ -1,29 +0,0 @@ -class RepositoryBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Repository Link') - end - - def help - _('This block displays the repository link of a software.') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/repository', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/search_catalog_block.rb b/src/noosfero-spb/software_communities/lib/search_catalog_block.rb deleted file mode 100644 index 4f7b517..0000000 --- a/src/noosfero-spb/software_communities/lib/search_catalog_block.rb +++ /dev/null @@ -1,29 +0,0 @@ -class SearchCatalogBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Search Softwares catalog') - end - - def help - _('This block displays the search categories field ') - end - - def content(args={}) - block = self - s = show_name - lambda do |object| - render( - :file => 'blocks/search_catalog', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - false - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb index b78d762..e2d2c2d 100644 --- a/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin.rb @@ -33,17 +33,17 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin def self.extra_blocks { - SoftwaresBlock => { :type => [Environment, Person] }, - SoftwareInformationBlock => { :type => [Community] }, - DownloadBlock => { :type => [Community] }, - RepositoryBlock => { :type => [Community] }, - CategoriesAndTagsBlock => { :type => [Community] }, - CategoriesSoftwareBlock => { :type => [Environment] }, - SearchCatalogBlock => { :type => [Environment] }, - SoftwareHighlightsBlock => { :type => [Environment] }, - SoftwareTabDataBlock => {:type => [Community], :position => 1}, - WikiBlock => {:type => [Community]}, - StatisticBlock => { :type => [Community] } + SoftwareCommunitiesPlugin::SoftwaresBlock => { :type => [Environment, Person] }, + SoftwareCommunitiesPlugin::SoftwareInformationBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::DownloadBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::RepositoryBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::CategoriesAndTagsBlock => { :type => [Community] }, + SoftwareCommunitiesPlugin::CategoriesSoftwareBlock => { :type => [Environment] }, + SoftwareCommunitiesPlugin::SearchCatalogBlock => { :type => [Environment] }, + SoftwareCommunitiesPlugin::SoftwareHighlightsBlock => { :type => [Environment] }, + SoftwareCommunitiesPlugin::SoftwareTabDataBlock => {:type => [Community], :position => 1}, + SoftwareCommunitiesPlugin::WikiBlock => {:type => [Community]}, + SoftwareCommunitiesPlugin::StatisticBlock => { :type => [Community] } } end @@ -117,7 +117,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin protected def software_info_transaction - SoftwareInfo.transaction do + SoftwareCommunitiesPlugin::SoftwareInfo.transaction do context.profile. software_info. update_attributes!(context.params[:software_info]) @@ -125,7 +125,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin end def license_transaction - license = LicenseInfo.find(context.params[:version]) + license = SoftwareCommunitiesPlugin::LicenseInfo.find(context.params[:version]) context.profile.software_info.license_info = license context.profile.software_info.save! end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_and_tags_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_and_tags_block.rb new file mode 100644 index 0000000..2b3f4e7 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_and_tags_block.rb @@ -0,0 +1,29 @@ +class SoftwareCommunitiesPlugin::CategoriesAndTagsBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Categories and Tags') + end + + def help + _('This block displays the categories and tags of a software.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/categories_and_tags', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_software_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_software_block.rb new file mode 100644 index 0000000..cf55556 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/categories_software_block.rb @@ -0,0 +1,35 @@ +class SoftwareCommunitiesPlugin::CategoriesSoftwareBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Categories Softwares') + end + + def help + _('This block displays the categories and the amount of softwares for + each category.') + end + + def content(args={}) + block = self + s = show_name + + software_category = Category.find_by_name("Software") + categories = [] + categories = software_category.children.sort if software_category + + lambda do |object| + render( + :file => 'blocks/categories_software', + :locals => { :block => block, :show_name => s, :categories => categories } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb new file mode 100644 index 0000000..8d32009 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/create_software.rb @@ -0,0 +1,115 @@ +class SoftwareCommunitiesPlugin::CreateSoftware < Task + include Rails.application.routes.url_helpers + + validates_presence_of :requestor_id, :target_id + validates_presence_of :name, :finality + + attr_accessible :name, :finality, :repository_link, :requestor, :environment, + :reject_explanation, :license_info, :identifier, :target + + alias :environment :target + alias :environment= :target= + + DATA_FIELDS = ['name', 'identifier', 'finality', 'license_info', 'repository_link'] + DATA_FIELDS.each do |field| + settings_items field.to_sym + end + + def perform + software_template = SoftwareCommunitiesPlugin::SoftwareHelper.software_template + template_id = software_template.blank? ? nil : software_template.id + + identifier = self.identifier + identifier ||= self.name.to_slug + + community = Community.create!(:name => self.name, + :identifier => identifier, + :template_id => template_id) + + community.environment = self.environment + community.add_admin(self.requestor) + + software = SoftwareCommunitiesPlugin::SoftwareInfo.create!(:finality => self.finality, + :repository_link => self.repository_link, :community_id => community.id, + :license_info => self.license_info) + end + + def title + _("New software") + end + + def subject + name + end + + def information + message = _('%{requestor} wants to create software %{subject} with') + if finality.blank? + { :message => message + _(' no finality.') } + else + { :message => message + _(' this finality:

%{finality}

'), + :variables => {:finality => finality} } + end + end + + def reject_details + true + end + + # tells if this request was rejected + def rejected? + self.status == Task::Status::CANCELLED + end + + # tells if this request was appoved + def approved? + self.status == Task::Status::FINISHED + end + + def target_notification_description + _('%{requestor} wants to create software %{subject}') % + {:requestor => requestor.name, :subject => subject} + end + + def target_notification_message + _("User \"%{user}\" just requested to create software %{software}. + You have to approve or reject it through the \"Pending Validations\" + section in your control panel.\n") % + { :user => self.requestor.name, :software => self.name } + end + + def task_created_message + _("Your request for registering software %{software} at %{environment} was + just sent. Environment administrator will receive it and will approve or + reject your request according to his methods and criteria. + + You will be notified as soon as environment administrator has a position + about your request.") % + { :software => self.name, :environment => self.target } + end + + def task_cancelled_message + _("Your request for registering software %{software} at %{environment} was + not approved by the environment administrator. The following explanation + was given: \n\n%{explanation}") % + { :software => self.name, + :environment => self.environment, + :explanation => self.reject_explanation } + end + + def task_finished_message + _('Your request for registering the software "%{software}" was approved. + You can access %{url} and finish the registration of your software.') % + { :software => self.name, :url => mount_url } + end + + private + + def mount_url + identifier = Community.where(:name => self.name).first.identifier + # The use of url_for doesn't allow the /social within the Public Software + # portal. That's why the url is mounted so 'hard coded' + url = "#{environment.top_url}/myprofile/#{identifier}/profile_editor/edit_software_community" + end + +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/database_description.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/database_description.rb new file mode 100644 index 0000000..90db0e7 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/database_description.rb @@ -0,0 +1,15 @@ +class SoftwareCommunitiesPlugin::DatabaseDescription < ActiveRecord::Base + + SEARCHABLE_SOFTWARE_FIELDS = { + :name => 1 + } + + attr_accessible :name + + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase' + has_many :software_infos, :through => :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + + validates_presence_of :name + validates_uniqueness_of :name + +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/database_helper.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/database_helper.rb new file mode 100644 index 0000000..2477989 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/database_helper.rb @@ -0,0 +1,77 @@ +class SoftwareCommunitiesPlugin::DatabaseHelper < SoftwareCommunitiesPlugin::DynamicTableHelper + MODEL_NAME ="database" + FIELD_NAME = "database_description_id" + + def self.valid_database? database + return false if SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty?(database) + + database_description_id_list = SoftwareCommunitiesPlugin::DatabaseDescription.select(:id). + collect {|dd| dd.id} + + return database_description_id_list.include?( + database[:database_description_id].to_i + ) + end + + def self.list_database new_databases + return [] if new_databases.nil? or new_databases.length == 0 + list_databases = [] + + new_databases.each do |new_database| + if valid_database? new_database + database = SoftwareCommunitiesPlugin::SoftwareDatabase.new + + database.database_description_id = + new_database[:database_description_id] + + database.version = new_database[:version] + list_databases << database + end + end + + list_databases + end + + def self.valid_list_database? list_databases + return false if list_databases.nil? or list_databases.length == 0 + return !list_databases.any?{|database| !database.valid?} + end + + def self.database_as_tables(list_databases, disabled=false) + model_list = list_databases + model_list ||= [{:database_description_id => "", :version => ""}] + + models_as_tables model_list, "database_html_structure", disabled + end + + def self.database_html_structure(database_data, disabled) + database_id = database_data[:database_description_id] + database_name = database_id.blank? ? "" : SoftwareCommunitiesPlugin::DatabaseDescription.find( + database_data[:database_description_id], + :select=>"name" + ).name + + data = { + model_name: MODEL_NAME, + field_name: FIELD_NAME, + name: { + value: database_name, + id: database_id, + hidden: true, + autocomplete: true, + select_field: false + }, + version: { + value: database_data[:version], + hidden: true, + delete: true + } + } + DATA[:license].delete(:value) + table_html_structure(data, disabled) + end + + def self.add_dynamic_table + database_as_tables(nil).first.call + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/download.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/download.rb new file mode 100644 index 0000000..de000d1 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/download.rb @@ -0,0 +1,51 @@ +#FIX ME: Turn this into a proper model(next release) +class SoftwareCommunitiesPlugin::Download + def initialize data + @name = data[:name] + @link = data[:link] + @software_description = data[:software_description] + @minimum_requirements = data[:minimum_requirements] + @size = data[:size] + + @total_downloads = if data[:total_downloads] + data[:total_downloads] + else + 0 + end + end + + def self.validate_download_list download_list + download_list.select! do |download| + not download[:name].blank? + end + + download_list.map do |download| + SoftwareCommunitiesPlugin::Download.new(download).to_hash + end + end + + def to_hash + { + :name => @name, + :link => @link, + :software_description => @software_description, + :minimum_requirements => @minimum_requirements, + :size => @size, + :total_downloads => @total_downloads + } + end + + def total_downloads= value + if value.is_a? Integer + @total_downloads = value + end + end + + def total_downloads + @total_downloads + end + + def link + @link + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/download_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/download_block.rb new file mode 100644 index 0000000..49f5239 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/download_block.rb @@ -0,0 +1,36 @@ +class SoftwareCommunitiesPlugin::DownloadBlock < Block + + attr_accessible :show_name, :downloads + + settings_items :show_name, :type => :boolean, :default => false + settings_items :downloads, :type => Array, :default => [] + + validate :download_values + + def download_values + self.downloads = SoftwareCommunitiesPlugin::Download.validate_download_list(self.downloads) + end + + def self.description + _('Download Stable Version') + end + + def help + _('This block displays the stable version of a software.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/download', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/dynamic_table_helper.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/dynamic_table_helper.rb new file mode 100644 index 0000000..90e38e3 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/dynamic_table_helper.rb @@ -0,0 +1,153 @@ +class SoftwareCommunitiesPlugin::DynamicTableHelper + extend( + ActionView::Helpers::TagHelper, + ActionView::Helpers::FormTagHelper, + ActionView::Helpers::FormOptionsHelper, + ActionView::Helpers::UrlHelper, + ApplicationHelper + ) + + COLLUMN_NAME = { + name: "name", + version: "version", + license: "license" + } + + LABEL_TEXT = { + :name => _("Name"), + :version => _("Version"), + :license => _("License") + } + + DATA = { + name: { + label: LABEL_TEXT[:name], + name: COLLUMN_NAME[:name] + }, + version: { + label: LABEL_TEXT[:version], + name: COLLUMN_NAME[:version] + } , + license: { + label: LABEL_TEXT[:license], + name: COLLUMN_NAME[:license], + delete: true + } + } + @@disabled = false + + def self.table_html_structure data={}, disabled=false + @@disabled = disabled + Proc::new do + content_tag :table , generate_table_lines(data), :class => "dynamic-table" + end + end + + def self.generate_table_lines data={} + @@model = data[:model_name] + @@field_name = data[:field_name] + @@hidden_label = data[:name][:value] + @@hidden_id = data[:name][:id] + + row_data = prepare_row_data data + + table_line_data = [ + self.table_line(row_data[:name]), + self.table_line(row_data[:version]) + ] + + if row_data[:license].has_key?(:value) + table_line_data << self.table_line(row_data[:license]) + end + + table_line_data.join() + end + + def self.table_line row_data={} + unless row_data.blank? + content_tag :tr, [ + self.label_collumn(row_data[:label]), + self.value_collumn( + row_data[:value], + row_data[:name], + row_data[:autocomplete], + row_data[:select_field], + row_data[:options] + ), + self.hidden_collumn(row_data[:delete], row_data[:hidden]) + ].join() + end + end + + def self.label_collumn label="" + content_tag :td, label_tag(label) + end + + def self.value_collumn value="", name="", autocomplete=false, select_field=false, options=[] + html_options = + if autocomplete + { + :class => "#{@@model}_autocomplete", + :placeholder => _("Autocomplete field, type something") + } + else + {} + end + + html_options[:disabled] = @@disabled + + content = if select_field + select_tag("#{@@model}[][#{@@field_name}]", options, html_options) + elsif autocomplete + text_field_tag("#{@@model}_autocomplete", value, html_options) + else + text_field_tag("#{@@model}[][#{name}]", value, html_options) + end + + content_tag :td, content + end + + def self.hidden_collumn delete=false, hidden_data=false + value = + if @@disabled + nil + elsif delete + button_without_text( + :delete, _('Delete'), "#" , :class=>"delete-dynamic-table" + ) + elsif hidden_data + hidden_field_tag( + "#{@@model}[][#{@@field_name}]", + @@hidden_id, + :class => "#{@@field_name}", + :data => {:label => @@hidden_label } #check how to get the name of an object of the current model + ) + else + nil + end + + content_tag(:td, value, :align => 'right') + end + + def self.prepare_row_data data + row_data = { + name: DATA[:name], + version: DATA[:version], + license: DATA[:license] + } + + row_data[:name].merge! data[:name] + row_data[:version].merge! data[:version] + row_data[:license].merge! data[:license] if data.has_key? :license + + row_data + end + + def self.models_as_tables models, callback, disabled=false + lambdas_list = [] + + models.map do |model| + send(callback, model, disabled) + end + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/library.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/library.rb new file mode 100644 index 0000000..126ea2a --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/library.rb @@ -0,0 +1,10 @@ +class SoftwareCommunitiesPlugin::Library < ActiveRecord::Base + attr_accessible :name, :version, :license, :software_info_id + + validates :name, :version, :license, + presence: { message: _("can't be blank") }, + length: { + maximum: 20, + too_long: _("Too long (maximum is 20 characters)") + } +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/library_helper.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/library_helper.rb new file mode 100644 index 0000000..b27c031 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/library_helper.rb @@ -0,0 +1,59 @@ +class SoftwareCommunitiesPlugin::LibraryHelper < SoftwareCommunitiesPlugin::DynamicTableHelper + #FIXME Verify this name. + MODEL_NAME = "software_communities_plugin/library" + + def self.list_library new_libraries + return [] if new_libraries.nil? or new_libraries.length == 0 + list_libraries = [] + + new_libraries.each do |new_library| + unless SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty? new_library + library = SoftwareCommunitiesPlugin::Library.new + library.name = new_library[:name] + library.version = new_library[:version] + library.license = new_library[:license] + list_libraries << library + end + end + + list_libraries + end + + def self.valid_list_library? list_libraries + return true if list_libraries.nil? or list_libraries.length == 0 + return !list_libraries.any?{|library| !library.valid?} + end + + def self.libraries_as_tables list_libraries, disabled=false + model_list = list_libraries + model_list ||= [{:name=>"", :version=>"", :license=>""}] + + models_as_tables model_list, "library_html_structure", disabled + end + + def self.library_html_structure library_data, disabled + data = { + #FIXME Verify MODEL_NAME + model_name: MODEL_NAME, + name: { + value: library_data[:name], + hidden: false, + autocomplete: false, + select_field: false + }, + version: { + value: library_data[:version], + delete: false + }, + license: { + value: library_data[:license] + } + } + + table_html_structure(data, disabled) + end + + def self.add_dynamic_table + libraries_as_tables(nil).first.call + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/license_helper.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/license_helper.rb new file mode 100644 index 0000000..ef9f27f --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/license_helper.rb @@ -0,0 +1,9 @@ +module SoftwareCommunitiesPlugin::LicenseHelper + def self.find_licenses query + licenses = SoftwareCommunitiesPlugin::LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") + licenses.reject!{|license| license.version == "Another"} + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") + licenses << license_another if license_another + licenses + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/license_info.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/license_info.rb new file mode 100644 index 0000000..2031603 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/license_info.rb @@ -0,0 +1,8 @@ +class SoftwareCommunitiesPlugin::LicenseInfo < ActiveRecord::Base + attr_accessible :version, :link + + validates_presence_of :version + + has_many :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system.rb new file mode 100644 index 0000000..ad28daa --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system.rb @@ -0,0 +1,14 @@ +class SoftwareCommunitiesPlugin::OperatingSystem < ActiveRecord::Base + attr_accessible :version + + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + belongs_to :operating_system_name, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName' + + validates :operating_system_name, presence: true + validates :version, + presence: true, + length: { + maximum: 20, + too_long: _('too long (maximum is 20 characters)') + } +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_helper.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_helper.rb new file mode 100644 index 0000000..84fcec6 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_helper.rb @@ -0,0 +1,69 @@ +class SoftwareCommunitiesPlugin::OperatingSystemHelper < SoftwareCommunitiesPlugin::DynamicTableHelper + #FIXME Verify model_name + MODEL_NAME = "software_communities_plugin/operating_system" + FIELD_NAME = "operating_system_name_id" + + def self.list_operating_system new_operating_systems + return [] if new_operating_systems.nil? or new_operating_systems.length == 0 + list_operating_system = [] + + new_operating_systems.each do |new_operating_system| + unless SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty?( + new_operating_system, + ["operating_system_name_id"] + ) + + operating_system = SoftwareCommunitiesPlugin::OperatingSystem.new + operating_system.operating_system_name = SoftwareCommunitiesPlugin::OperatingSystemName.find( + new_operating_system[:operating_system_name_id] + ) + + operating_system.version = new_operating_system[:version] + list_operating_system << operating_system + end + end + list_operating_system + end + + def self.valid_list_operating_system? list_operating_system + return false if (list_operating_system.nil? || list_operating_system.length == 0) + return !list_operating_system.any?{|os| !os.valid?} + end + + def self.operating_system_as_tables(list_operating_system, disabled=false) + model_list = list_operating_system + model_list ||= [{:operating_system_name_id => "", :version => ""}] + + models_as_tables model_list, "operating_system_html_structure", disabled + end + + def self.operating_system_html_structure (operating_system_data, disabled) + select_options = options_for_select( + SoftwareCommunitiesPlugin::OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, + operating_system_data[:operating_system_name_id] + ) + + data = { + #FIXME Verify model_name + model_name: MODEL_NAME, + field_name: FIELD_NAME, + name: { + hidden: false, + autocomplete: false, + select_field: true, + options: select_options + }, + version: { + value: operating_system_data[:version], + hidden: true, + delete: true + } + } + DATA[:license].delete(:value) + table_html_structure(data, disabled) + end + + def self.add_dynamic_table + operating_system_as_tables(nil).first.call + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_name.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_name.rb new file mode 100644 index 0000000..55e3a39 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/operating_system_name.rb @@ -0,0 +1,10 @@ +class SoftwareCommunitiesPlugin::OperatingSystemName < ActiveRecord::Base + attr_accessible :name + + validates_presence_of :name + validates_uniqueness_of :name + + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem' + has_many :software_infos, :through => :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/programming_language.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/programming_language.rb new file mode 100644 index 0000000..97dff7d --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/programming_language.rb @@ -0,0 +1,15 @@ +class SoftwareCommunitiesPlugin::ProgrammingLanguage < ActiveRecord::Base + + SEARCHABLE_SOFTWARE_FIELDS = { + :name => 1 + } + + attr_accessible :name + + validates_presence_of :name + validates_uniqueness_of :name + + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguage' + has_many :software_infos, :through => :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/repository_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/repository_block.rb new file mode 100644 index 0000000..5420e0e --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/repository_block.rb @@ -0,0 +1,29 @@ +class SoftwareCommunitiesPlugin::RepositoryBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Repository Link') + end + + def help + _('This block displays the repository link of a software.') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/repository', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/search_catalog_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/search_catalog_block.rb new file mode 100644 index 0000000..006cdf2 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/search_catalog_block.rb @@ -0,0 +1,29 @@ +class SoftwareCommunitiesPlugin::SearchCatalogBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Search Softwares catalog') + end + + def help + _('This block displays the search categories field ') + end + + def content(args={}) + block = self + s = show_name + lambda do |object| + render( + :file => 'blocks/search_catalog', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + false + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_database.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_database.rb new file mode 100644 index 0000000..a30c942 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_database.rb @@ -0,0 +1,20 @@ +class SoftwareCommunitiesPlugin::SoftwareDatabase < ActiveRecord::Base + attr_accessible :version + + belongs_to :software_info, :class_name => 'SoftwareCommunitiesPlugin::SoftwareInfo' + belongs_to :database_description, :class_name => 'SoftwareCommunitiesPlugin::DatabaseDescription' + + validates_presence_of :database_description_id, :version + + validates_length_of( + :version, + :maximum => 20, + :too_long => _("Software database is too long (maximum is 20 characters)") + ) + + validates( + :database_description_id, + :numericality => {:greater_than_or_equal_to => 1} + ) + +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_helper.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_helper.rb new file mode 100644 index 0000000..a882575 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_helper.rb @@ -0,0 +1,43 @@ +module SoftwareCommunitiesPlugin::SoftwareHelper + def self.select_options programming_languages, selected = 0 + value = "" + + programming_languages.each do |language| + selected = selected == language.id ? 'selected' : '' + value += "" + end + + value + end + + def self.create_list_with_file file_name, model + list_file = File.open file_name, "r" + + list_file.each_line do |line| + model.create(:name=>line.strip) + end + + list_file.close + end + + def self.all_table_is_empty? table, ignored_fields=[] + return !table.keys.any?{|key| ignored_fields.include?(key) ? false : !table[key].empty?} + end + + def self.software_template + identifier = SoftwareCommunitiesPlugin::SoftwareHelper.software_template_identifier + + software_template = Community[identifier] + if !software_template.blank? && software_template.is_template + software_template + else + nil + end + end + + def self.software_template_identifier + identifier = YAML::load(File.open(SoftwareCommunitiesPlugin.root_path + 'config.yml'))['software_template'] + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_highlights_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_highlights_block.rb new file mode 100644 index 0000000..749719f --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_highlights_block.rb @@ -0,0 +1,20 @@ +class SoftwareCommunitiesPlugin::SoftwareHighlightsBlock < HighlightsBlock + + def self.description + _('Software Highlights Block') + end + + def help + _('This block displays the softwares icon into a highlight') + end + + def content(args={}) + softwares = self.settings[:images].collect {|h| h[:address].split('/').last} + block = self + proc do + render :file => 'blocks/software_communities_plugin/software_highlights', :locals => { :block => block, :softwares => softwares} + end + end + + +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_info.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_info.rb new file mode 100644 index 0000000..1f361c6 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_info.rb @@ -0,0 +1,261 @@ +class SoftwareCommunitiesPlugin::SoftwareInfo < ActiveRecord::Base + acts_as_having_settings :field => :settings + + SEARCHABLE_SOFTWARE_FIELDS = { + :acronym => 1, + :finality => 2, + } + + SEARCHABLE_SOFTWARE_CLASSES = [ + SoftwareCommunitiesPlugin::SoftwareInfo, + SoftwareCommunitiesPlugin::Community, + SoftwareCommunitiesPlugin::ProgrammingLanguage, + SoftwareCommunitiesPlugin::DatabaseDescription + ] + + scope :search_by_query, lambda { |query = ""| + filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') + search_fields = SoftwareCommunitiesPlugin::SoftwareInfo.pg_search_plugin_fields + + if query.empty? + SoftwareInfo.joins(:community).where("profiles.visible = ?", true) + else + searchable_software_objects = SoftwareCommunitiesPlugin::SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) + includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) + end + } + + def self.transform_list_in_methods_list list + methods_list = [] + + list.each do |element| + if SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym) + methods_list << element.to_s.underscore.to_sym + elsif SoftwareCommunitiesPlugin::SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym) + methods_list << element.to_s.underscore.pluralize.to_sym + end + end + + methods_list + end + + def self.pg_search_plugin_fields + SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class| + self.get_searchable_fields(one_class) + }.join(" || ' ' || ") + end + + def self.get_searchable_fields one_class + searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ") + searchable_fields + end + + SEARCH_FILTERS = { + :order => %w[], + :display => %w[full] + } + + def self.default_search_display + 'full' + end + + attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, + :operating_platform + + attr_accessible :demonstration_url, :acronym, :objectives, :features, + :license_info + + attr_accessible :community_id, :finality, :repository_link, :public_software, + :first_edit + + has_many :libraries, :dependent => :destroy, :class_name => 'SoftwareCommunitiesPlugin::Library' + has_many :software_databases, :class_name => 'SoftwareCommunitiesPlugin::SoftwareDatabase' + has_many :database_descriptions, :through => :software_databases, :class_name => 'SoftwareCommunitiesPlugin::DatabaseDescription' + has_many :software_languages, :class_name => 'SoftwareCommunitiesPlugin::SoftwareLanguage' + has_many :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystem' + has_many :programming_languages, :through => :software_languages, :class_name => 'SoftwareCommunitiesPlugin::ProgrammingLanguage' + has_many :operating_system_names, :through => :operating_systems, :class_name => 'SoftwareCommunitiesPlugin::OperatingSystemName' + + belongs_to :community, :dependent => :destroy + belongs_to :license_info, :class_name => 'SoftwareCommunitiesPlugin::LicenseInfo' + + validates_length_of :finality, :maximum => 120 + validates_length_of :objectives, :maximum => 4000 + validates_length_of :features, :maximum => 4000 + validates_presence_of :finality, :community + + validate :validate_acronym + + settings_items :another_license_version, :another_license_link + + # used on find_by_contents + scope :like_search, lambda{ |name| + joins(:community).where( + "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", + "%#{name}%", "%#{name}%", "%#{name}%" + ) + } + + 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 = "", software_categories = "" | + + like_sql = "" + values = [] + + unless name.blank? + like_sql << "name ILIKE ? OR identifier ILIKE ? AND " + values << "%#{name}%" << "%#{name}%" + end + + like_sql = like_sql[0..like_sql.length-5] + + { + :joins => [:community], + :conditions=>[like_sql, *values] + } + } + + def license_info + license = SoftwareCommunitiesPlugin::LicenseInfo.find_by_id self.license_info_id + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") + + if license_another && license.id == license_another.id + LicenseInfo.new( + :version => self.another_license_version, + :link => self.another_license_link + ) + else + license + end + end + + def another_license(version, link) + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") + + if license_another + self.another_license_version = version + self.another_license_link = link + self.license_info = license_another + self.save! + end + end + + def validate_name_lenght + if self.community.name.size > 100 + self.errors.add( + :base, + _("Name is too long (maximum is %{count} characters)") + ) + false + end + true + end + + # if create_after_moderation receive a model object, would be possible to reuse core method + def self.create_after_moderation(requestor, attributes = {}) + environment = attributes.delete(:environment) + name = attributes.delete(:name) + identifier = attributes.delete(:identifier) + image_builder = attributes.delete(:image_builder) + license_info = attributes.delete(:license_info) + another_license_version = attributes.delete(:another_license_version) + another_license_link = attributes.delete(:another_license_link) + + software_info = SoftwareCommunitiesPlugin::SoftwareInfo.new(attributes) + unless environment.admins.include? requestor + SoftwareCommunitiesPlugin::CreateSoftware.create!( + attributes.merge( + :requestor => requestor, + :environment => environment, + :name => name, + :identifier => identifier, + :license_info => license_info + ) + ) + else + software_template = SoftwareCommunitiesPlugin::SoftwareHelper.software_template + + community_hash = {:name => name} + community_hash[:identifier] = identifier + community_hash[:image_builder] = image_builder if image_builder + + community = Community.new(community_hash) + community.environment = environment + + unless software_template.blank? + community.template_id = software_template.id + end + + community.save! + community.add_admin(requestor) + + software_info.community = community + software_info.license_info = license_info + software_info.save! + end + + software_info.verify_license_info(another_license_version, another_license_link) + software_info.save + software_info + end + + def verify_license_info another_license_version, another_license_link + license_another = SoftwareCommunitiesPlugin::LicenseInfo.find_by_version("Another") + + if license_another && self.license_info_id == license_another.id + version = another_license_version + link = another_license_link + + self.another_license(version, link) + end + end + + + def validate_acronym + self.acronym = "" if self.acronym.nil? + if self.acronym.length > 10 && self.errors.messages[:acronym].nil? + self.errors.add(:acronym, _("can't have more than 10 characteres")) + false + elsif self.acronym.match(/\s+/) + self.errors.add(:acronym, _("can't have whitespaces")) + false + end + true + end + + def valid_operating_systems + if self.operating_systems.empty? + self.errors.add(:operating_system, _(": at least one must be filled")) + end + end + + def valid_software_info + if self.software_languages.empty? + self.errors.add(:software_languages, _(": at least one must be filled")) + end + end + + def valid_databases + if self.software_databases.empty? + self.errors.add(:software_databases, _(": at least one must be filled")) + end + end + + def visible? + self.community.visible? + end + + def name + self.community.name + end + + def short_name + self.community.short_name + end + + def identifier + self.community.identifier + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_information_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_information_block.rb new file mode 100644 index 0000000..99f9982 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_information_block.rb @@ -0,0 +1,37 @@ +class SoftwareCommunitiesPlugin::SoftwareInformationBlock < Block + + attr_accessible :show_name + + settings_items :show_name, :type => :boolean, :default => false + + def self.description + _('Basic Software Information') + end + + def help + _('This block displays the basic information of a software profile.') + end + + def content(args={}) + block = self + s = show_name + + lambda do |object| + render( + :file => 'blocks/software_information', + :locals => { :block => block, :show_name => s} + ) + end + end + + def cacheable? + false + end + + private + + def owner_has_ratings? + ratings = OrganizationRating.where(community_id: block.owner.id) + !ratings.empty? + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language.rb new file mode 100644 index 0000000..72f0153 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language.rb @@ -0,0 +1,14 @@ +class SoftwareCommunitiesPlugin::SoftwareLanguage < ActiveRecord::Base + attr_accessible :version + + belongs_to :software_info, :class => "SoftwareCommunitiesPlugin::SoftwareInfo" + belongs_to :programming_language, :class => "SoftwareCommunitiesPlugin::ProgrammingLanguage" + + validates_length_of( + :version, + :maximum => 20, + :too_long => _("Software language is too long (maximum is 20 characters)") + ) + + validates_presence_of :version, :programming_language +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language_helper.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language_helper.rb new file mode 100644 index 0000000..f5af2cb --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_language_helper.rb @@ -0,0 +1,85 @@ +class SoftwareCommunitiesPlugin::SoftwareLanguageHelper < DynamicTableHelper + #FIX verify MODEL_NAME + MODEL_NAME = "language" + FIELD_NAME = "programming_language_id" + + def self.valid_language? language + return false if SoftwareCommunitiesPlugin::SoftwareHelper.all_table_is_empty?(language) + + programming_language_id_list = SoftwareCommunitiesPlugin::ProgrammingLanguage. + select(:id). + collect { |dd| dd.id } + + return programming_language_id_list.include?( + language[:programming_language_id].to_i + ) + end + + def self.list_language new_languages + return [] if new_languages.nil? or new_languages.length == 0 + list_languages = [] + + new_languages.each do |new_language| + if valid_language? new_language + language = SoftwareCommunitiesPlugin::SoftwareLanguage.new + language.programming_language = + SoftwareCommunitiesPlugin::ProgrammingLanguage.find(new_language[:programming_language_id]) + language.version = new_language[:version] + list_languages << language + end + end + + list_languages + end + + def self.valid_list_language? list_languages + return false if list_languages.nil? or list_languages.length == 0 + + list_languages.each do |language| + return false unless language.valid? + end + + true + end + + def self.language_as_tables(list_languages, disabled=false) + model_list = list_languages + model_list ||= [{:programming_language_id => "", :version => ""}] + + models_as_tables model_list, "language_html_structure", disabled + end + + def self.language_html_structure(language_data, disabled) + language_id = language_data[:programming_language_id] + language_name = "" + unless language_data[:programming_language_id].blank? + language_name = SoftwareCommunitiesPlugin::ProgrammingLanguage.find( + language_data[:programming_language_id], + :select=>"name" + ).name + end + + data = { + model_name: MODEL_NAME, + field_name: FIELD_NAME, + name: { + value: language_name, + id: language_id, + hidden: true, + autocomplete: true, + select_field: false + }, + version: { + value: language_data[:version], + hidden: true, + delete: true + } + } + DATA[:license].delete(:value) + table_html_structure(data, disabled) + end + + def self.add_dynamic_table + language_as_tables(nil).first.call + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_tab_data_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_tab_data_block.rb new file mode 100644 index 0000000..cc4eeb1 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/software_tab_data_block.rb @@ -0,0 +1,48 @@ +class SoftwareCommunitiesPlugin::SoftwareTabDataBlock < Block + attr_accessible :show_name, :displayed_blog + + settings_items :show_name, :type => :boolean, :default => false + settings_items :displayed_blog, :type => :integer, :default => 0 + + TOTAL_POSTS_DYSPLAYED = 5 + + def self.description + _('Software Tab Data') + end + + def help + _('This block is used by colab to insert data into Noosfero') + end + + def content(args={}) + block = self + + lambda do |object| + render( + :file => 'blocks/software_tab_data', + :locals => { + :block => block + } + ) + end + end + + def blogs + self.owner.blogs + end + + def actual_blog + # As :displayed_blog default value is 0, it falls to the first one + blogs.find_by_id(self.displayed_blog) || blogs.first + end + + def posts + blog = actual_blog + + if blog and (not blog.posts.empty?) + blog.posts.limit(TOTAL_POSTS_DYSPLAYED) + else + [] + end + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/softwares_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/softwares_block.rb new file mode 100644 index 0000000..0c0a910 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/softwares_block.rb @@ -0,0 +1,105 @@ +class SoftwareCommunitiesPlugin::SoftwaresBlock < CommunitiesBlock + + settings_items :software_type, :default => "All" + attr_accessible :accessor_id, :accessor_type, :role_id, + :resource_id, :resource_type, :software_type + + def self.description + _('Softwares') + end + + def default_title + if self.software_type == "Generic" + return n_('{#} generic software', '{#} generic softwares', profile_count) + elsif self.software_type == "Public" + return n_('{#} public software', '{#} public softwares', profile_count) + else + return n_('{#} software', '{#} softwares', profile_count) + end + end + + def help + _('This block displays the softwares in which the user is a member.') + end + + def footer + self.software_type ||= "All" + owner = self.owner + case owner + when Profile + lambda do |context| + link_to s_('softwares|View all'), :profile => owner.identifier, + :controller => 'profile', :action => 'communities', + :type => 'Software' + end + when Environment + lambda do |context| + link_to s_('softwares|View all'), :controller => 'search', + :action => 'software_infos' + end + else + '' + end + end + + def profile_count + profile_list.count + end + + def profiles + owner.communities + end + + def profile_list + profiles = get_visible_profiles + + software_profiles = profiles.select do |profile| + profile.class == Community && profile.software? + end + + block_softwares = if self.software_type == "Public" + software_profiles.select { |profile| profile.software_info.public_software? } + elsif self.software_type == "Generic" + software_profiles.select { |profile| !profile.software_info.public_software? } + else # All + software_profiles + end + + block_softwares.slice(0..get_limit-1) + end + + def content(arg={}) + if self.box.owner_type == "Environment" && self.box.position == 1 + block = self + + proc do + render :file => 'blocks/main_area_softwares', + :locals => {:profiles=> block.profile_list(), :block => block} + end + else + super(arg) + end + end + + protected + + def get_visible_profiles + profile_include_list = [:image, :domains, :preferred_domain, :environment] + visible_profiles = profiles.visible.includes(profile_include_list) + + if !prioritize_profiles_with_image + visible_profiles.all( :limit => get_limit, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + elsif profiles.visible.with_image.count >= get_limit + visible_profiles.with_image.all( :limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + else + visible_profiles.with_image.sort_by{ rand } + + visible_profiles.without_image.all( :limit => get_limit * 5, + :order => 'profiles.updated_at DESC' + ).sort_by{ rand } + end + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/statistic_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/statistic_block.rb new file mode 100644 index 0000000..73a0dcd --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/statistic_block.rb @@ -0,0 +1,52 @@ +class SoftwareCommunitiesPlugin::StatisticBlock < Block + + settings_items :benefited_people, :type => :integer, :default => 0 + settings_items :saved_resources, :type => :float, :default => 0.0 + + attr_accessible :benefited_people, :saved_resources + + def self.description + _('Software Statistics') + end + + def help + _('This block displays software statistics.') + end + + def content(args={}) + download_blocks = get_profile_download_blocks(self.owner) + downloads = download_blocks.map do |download_block| + get_downloads_from_block(download_block) + end + + block = self + + lambda do |object| + render( + :file => 'blocks/software_statistics', + :locals => { + :block => block, + :total_downloads => downloads.sum + } + ) + end + end + + def cacheable? + false + end + + private + + def get_profile_download_blocks profile + SoftwareCommunitiesPlugin::DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id) + end + + def get_downloads_from_block download_block + downloads = download_block.downloads.map do |download| + download[:total_downloads] unless download[:total_downloads].nil? + end + downloads.select! {|value| not value.nil? } + downloads.sum + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_communities_plugin/wiki_block.rb b/src/noosfero-spb/software_communities/lib/software_communities_plugin/wiki_block.rb new file mode 100644 index 0000000..9b55083 --- /dev/null +++ b/src/noosfero-spb/software_communities/lib/software_communities_plugin/wiki_block.rb @@ -0,0 +1,30 @@ +class SoftwareCommunitiesPlugin::WikiBlock < Block + + attr_accessible :show_name, :wiki_link + settings_items :show_name, :type => :boolean, :default => false + settings_items :wiki_link, :type => :string, :default => "" + + def self.description + _('Wiki Link') + end + + def help + _('This block displays a link to the software wiki.') + end + + def content(args={}) + block = self + s = show_name + + lambda do |object| + render( + :file => 'blocks/wiki', + :locals => { :block => block, :show_name => s } + ) + end + end + + def cacheable? + true + end +end diff --git a/src/noosfero-spb/software_communities/lib/software_database.rb b/src/noosfero-spb/software_communities/lib/software_database.rb deleted file mode 100644 index 6c7911f..0000000 --- a/src/noosfero-spb/software_communities/lib/software_database.rb +++ /dev/null @@ -1,20 +0,0 @@ -class SoftwareDatabase < ActiveRecord::Base - attr_accessible :version - - belongs_to :software_info - belongs_to :database_description - - validates_presence_of :database_description_id, :version - - validates_length_of( - :version, - :maximum => 20, - :too_long => _("Software database is too long (maximum is 20 characters)") - ) - - validates( - :database_description_id, - :numericality => {:greater_than_or_equal_to => 1} - ) - -end diff --git a/src/noosfero-spb/software_communities/lib/software_helper.rb b/src/noosfero-spb/software_communities/lib/software_helper.rb deleted file mode 100644 index 0809a2a..0000000 --- a/src/noosfero-spb/software_communities/lib/software_helper.rb +++ /dev/null @@ -1,43 +0,0 @@ -module SoftwareHelper - def self.select_options programming_languages, selected = 0 - value = "" - - programming_languages.each do |language| - selected = selected == language.id ? 'selected' : '' - value += "" - end - - value - end - - def self.create_list_with_file file_name, model - list_file = File.open file_name, "r" - - list_file.each_line do |line| - model.create(:name=>line.strip) - end - - list_file.close - end - - def self.all_table_is_empty? table, ignored_fields=[] - return !table.keys.any?{|key| ignored_fields.include?(key) ? false : !table[key].empty?} - end - - def self.software_template - identifier = SoftwareHelper.software_template_identifier - - software_template = Community[identifier] - if !software_template.blank? && software_template.is_template - software_template - else - nil - end - end - - def self.software_template_identifier - identifier = YAML::load(File.open(SoftwareCommunitiesPlugin.root_path + 'config.yml'))['software_template'] - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_highlights_block.rb b/src/noosfero-spb/software_communities/lib/software_highlights_block.rb deleted file mode 100644 index a8b2a1c..0000000 --- a/src/noosfero-spb/software_communities/lib/software_highlights_block.rb +++ /dev/null @@ -1,20 +0,0 @@ -class SoftwareHighlightsBlock < HighlightsBlock - - def self.description - _('Software Highlights Block') - end - - def help - _('This block displays the softwares icon into a highlight') - end - - def content(args={}) - softwares = self.settings[:images].collect {|h| h[:address].split('/').last} - block = self - proc do - render :file => 'blocks/software_highlights', :locals => { :block => block, :softwares => softwares} - end - end - - -end diff --git a/src/noosfero-spb/software_communities/lib/software_info.rb b/src/noosfero-spb/software_communities/lib/software_info.rb deleted file mode 100644 index fa82ccc..0000000 --- a/src/noosfero-spb/software_communities/lib/software_info.rb +++ /dev/null @@ -1,263 +0,0 @@ -class SoftwareInfo < ActiveRecord::Base - acts_as_having_settings :field => :settings - - SEARCHABLE_SOFTWARE_FIELDS = { - :acronym => 1, - :finality => 2, - } - - SEARCHABLE_SOFTWARE_CLASSES = [ - SoftwareInfo, - Community, - ProgrammingLanguage, - DatabaseDescription - ] - - scope :search_by_query, lambda { |query = ""| - filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') - search_fields = SoftwareInfo.pg_search_plugin_fields - - if query.empty? - SoftwareInfo.joins(:community).where("profiles.visible = ?", true) - else - searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) - end - } - - def self.transform_list_in_methods_list list - methods_list = [] - - list.each do |element| - if SoftwareInfo.instance_methods.include?(element.to_s.underscore.to_sym) - methods_list << element.to_s.underscore.to_sym - elsif SoftwareInfo.instance_methods.include?(element.to_s.underscore.pluralize.to_sym) - methods_list << element.to_s.underscore.pluralize.to_sym - end - end - - methods_list - end - - def self.pg_search_plugin_fields - SEARCHABLE_SOFTWARE_CLASSES.collect { |one_class| - self.get_searchable_fields(one_class) - }.join(" || ' ' || ") - end - - def self.get_searchable_fields one_class - searchable_fields = one_class::SEARCHABLE_SOFTWARE_FIELDS.keys.map(&:to_s).sort.map {|f| "coalesce(#{one_class.table_name}.#{f}, '')"}.join(" || ' ' || ") - searchable_fields - end - - SEARCH_FILTERS = { - :order => %w[], - :display => %w[full] - } - - def self.default_search_display - 'full' - end - - attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, - :operating_platform - - attr_accessible :demonstration_url, :acronym, :objectives, :features, - :license_info - - attr_accessible :community_id, :finality, :repository_link, :public_software, - :first_edit - - has_many :libraries, :dependent => :destroy - has_many :software_databases - has_many :database_descriptions, :through => :software_databases - has_many :software_languages - has_many :operating_systems - has_many :programming_languages, :through => :software_languages - has_many :operating_system_names, :through => :operating_systems - - belongs_to :community, :dependent => :destroy - belongs_to :license_info - - has_one :software_categories - - validates_length_of :finality, :maximum => 120 - validates_length_of :objectives, :maximum => 4000 - validates_length_of :features, :maximum => 4000 - validates_presence_of :finality, :community - - validate :validate_acronym - - settings_items :another_license_version, :another_license_link - - # used on find_by_contents - scope :like_search, lambda{ |name| - joins(:community).where( - "name ILIKE ? OR acronym ILIKE ? OR finality ILIKE ?", - "%#{name}%", "%#{name}%", "%#{name}%" - ) - } - - 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 = "", software_categories = "" | - - like_sql = "" - values = [] - - unless name.blank? - like_sql << "name ILIKE ? OR identifier ILIKE ? AND " - values << "%#{name}%" << "%#{name}%" - end - - like_sql = like_sql[0..like_sql.length-5] - - { - :joins => [:community], - :conditions=>[like_sql, *values] - } - } - - def license_info - license = LicenseInfo.find_by_id self.license_info_id - license_another = LicenseInfo.find_by_version("Another") - - if license_another && license.id == license_another.id - LicenseInfo.new( - :version => self.another_license_version, - :link => self.another_license_link - ) - else - license - end - end - - def another_license(version, link) - license_another = LicenseInfo.find_by_version("Another") - - if license_another - self.another_license_version = version - self.another_license_link = link - self.license_info = license_another - self.save! - end - end - - def validate_name_lenght - if self.community.name.size > 100 - self.errors.add( - :base, - _("Name is too long (maximum is %{count} characters)") - ) - false - end - true - end - - # if create_after_moderation receive a model object, would be possible to reuse core method - def self.create_after_moderation(requestor, attributes = {}) - environment = attributes.delete(:environment) - name = attributes.delete(:name) - identifier = attributes.delete(:identifier) - image_builder = attributes.delete(:image_builder) - license_info = attributes.delete(:license_info) - another_license_version = attributes.delete(:another_license_version) - another_license_link = attributes.delete(:another_license_link) - - software_info = SoftwareInfo.new(attributes) - unless environment.admins.include? requestor - CreateSoftware.create!( - attributes.merge( - :requestor => requestor, - :environment => environment, - :name => name, - :identifier => identifier, - :license_info => license_info - ) - ) - else - software_template = SoftwareHelper.software_template - - community_hash = {:name => name} - community_hash[:identifier] = identifier - community_hash[:image_builder] = image_builder if image_builder - - community = Community.new(community_hash) - community.environment = environment - - unless software_template.blank? - community.template_id = software_template.id - end - - community.save! - community.add_admin(requestor) - - software_info.community = community - software_info.license_info = license_info - software_info.save! - end - - software_info.verify_license_info(another_license_version, another_license_link) - software_info.save - software_info - end - - def verify_license_info another_license_version, another_license_link - license_another = LicenseInfo.find_by_version("Another") - - if license_another && self.license_info_id == license_another.id - version = another_license_version - link = another_license_link - - self.another_license(version, link) - end - end - - - def validate_acronym - self.acronym = "" if self.acronym.nil? - if self.acronym.length > 10 && self.errors.messages[:acronym].nil? - self.errors.add(:acronym, _("can't have more than 10 characteres")) - false - elsif self.acronym.match(/\s+/) - self.errors.add(:acronym, _("can't have whitespaces")) - false - end - true - end - - def valid_operating_systems - if self.operating_systems.empty? - self.errors.add(:operating_system, _(": at least one must be filled")) - end - end - - def valid_software_info - if self.software_languages.empty? - self.errors.add(:software_languages, _(": at least one must be filled")) - end - end - - def valid_databases - if self.software_databases.empty? - self.errors.add(:software_databases, _(": at least one must be filled")) - end - end - - def visible? - self.community.visible? - end - - def name - self.community.name - end - - def short_name - self.community.short_name - end - - def identifier - self.community.identifier - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_information_block.rb b/src/noosfero-spb/software_communities/lib/software_information_block.rb deleted file mode 100644 index a398c96..0000000 --- a/src/noosfero-spb/software_communities/lib/software_information_block.rb +++ /dev/null @@ -1,37 +0,0 @@ -class SoftwareInformationBlock < Block - - attr_accessible :show_name - - settings_items :show_name, :type => :boolean, :default => false - - def self.description - _('Basic Software Information') - end - - def help - _('This block displays the basic information of a software profile.') - end - - def content(args={}) - block = self - s = show_name - - lambda do |object| - render( - :file => 'blocks/software_information', - :locals => { :block => block, :show_name => s} - ) - end - end - - def cacheable? - false - end - - private - - def owner_has_ratings? - ratings = CommunityRating.where(community_id: block.owner.id) - !ratings.empty? - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_language.rb b/src/noosfero-spb/software_communities/lib/software_language.rb deleted file mode 100644 index 29f23c4..0000000 --- a/src/noosfero-spb/software_communities/lib/software_language.rb +++ /dev/null @@ -1,14 +0,0 @@ -class SoftwareLanguage < ActiveRecord::Base - attr_accessible :version - - belongs_to :software_info - belongs_to :programming_language - - validates_length_of( - :version, - :maximum => 20, - :too_long => _("Software language is too long (maximum is 20 characters)") - ) - - validates_presence_of :version,:programming_language -end diff --git a/src/noosfero-spb/software_communities/lib/software_language_helper.rb b/src/noosfero-spb/software_communities/lib/software_language_helper.rb deleted file mode 100644 index 38ba6e1..0000000 --- a/src/noosfero-spb/software_communities/lib/software_language_helper.rb +++ /dev/null @@ -1,84 +0,0 @@ -class SoftwareLanguageHelper < DynamicTableHelper - MODEL_NAME ="language" - FIELD_NAME = "programming_language_id" - - def self.valid_language? language - return false if SoftwareHelper.all_table_is_empty?(language) - - programming_language_id_list = ProgrammingLanguage. - select(:id). - collect { |dd| dd.id } - - return programming_language_id_list.include?( - language[:programming_language_id].to_i - ) - end - - def self.list_language new_languages - return [] if new_languages.nil? or new_languages.length == 0 - list_languages = [] - - new_languages.each do |new_language| - if valid_language? new_language - language = SoftwareLanguage.new - language.programming_language = - ProgrammingLanguage.find(new_language[:programming_language_id]) - language.version = new_language[:version] - list_languages << language - end - end - - list_languages - end - - def self.valid_list_language? list_languages - return false if list_languages.nil? or list_languages.length == 0 - - list_languages.each do |language| - return false unless language.valid? - end - - true - end - - def self.language_as_tables(list_languages, disabled=false) - model_list = list_languages - model_list ||= [{:programming_language_id => "", :version => ""}] - - models_as_tables model_list, "language_html_structure", disabled - end - - def self.language_html_structure(language_data, disabled) - language_id = language_data[:programming_language_id] - language_name = "" - unless language_data[:programming_language_id].blank? - language_name = ProgrammingLanguage.find( - language_data[:programming_language_id], - :select=>"name" - ).name - end - - data = { - model_name: MODEL_NAME, - field_name: FIELD_NAME, - name: { - value: language_name, - id: language_id, - hidden: true, - autocomplete: true, - select_field: false - }, - version: { - value: language_data[:version], - hidden: true, - delete: true - } - } - DATA[:license].delete(:value) - table_html_structure(data, disabled) - end - - def self.add_dynamic_table - language_as_tables(nil).first.call - end -end diff --git a/src/noosfero-spb/software_communities/lib/software_tab_data_block.rb b/src/noosfero-spb/software_communities/lib/software_tab_data_block.rb deleted file mode 100644 index b32eeb5..0000000 --- a/src/noosfero-spb/software_communities/lib/software_tab_data_block.rb +++ /dev/null @@ -1,48 +0,0 @@ -class SoftwareTabDataBlock < Block - attr_accessible :show_name, :displayed_blog - - settings_items :show_name, :type => :boolean, :default => false - settings_items :displayed_blog, :type => :integer, :default => 0 - - TOTAL_POSTS_DYSPLAYED = 5 - - def self.description - _('Software Tab Data') - end - - def help - _('This block is used by colab to insert data into Noosfero') - end - - def content(args={}) - block = self - - lambda do |object| - render( - :file => 'blocks/software_tab_data', - :locals => { - :block => block - } - ) - end - end - - def blogs - self.owner.blogs - end - - def actual_blog - # As :displayed_blog default value is 0, it falls to the first one - blogs.find_by_id(self.displayed_blog) || blogs.first - end - - def posts - blog = actual_blog - - if blog and (not blog.posts.empty?) - blog.posts.limit(TOTAL_POSTS_DYSPLAYED) - else - [] - end - end -end diff --git a/src/noosfero-spb/software_communities/lib/softwares_block.rb b/src/noosfero-spb/software_communities/lib/softwares_block.rb deleted file mode 100644 index 067345a..0000000 --- a/src/noosfero-spb/software_communities/lib/softwares_block.rb +++ /dev/null @@ -1,105 +0,0 @@ -class SoftwaresBlock < CommunitiesBlock - - settings_items :software_type, :default => "All" - attr_accessible :accessor_id, :accessor_type, :role_id, - :resource_id, :resource_type, :software_type - - def self.description - _('Softwares') - end - - def default_title - if self.software_type == "Generic" - return n_('{#} generic software', '{#} generic softwares', profile_count) - elsif self.software_type == "Public" - return n_('{#} public software', '{#} public softwares', profile_count) - else - return n_('{#} software', '{#} softwares', profile_count) - end - end - - def help - _('This block displays the softwares in which the user is a member.') - end - - def footer - self.software_type ||= "All" - owner = self.owner - case owner - when Profile - lambda do |context| - link_to s_('softwares|View all'), :profile => owner.identifier, - :controller => 'profile', :action => 'communities', - :type => 'Software' - end - when Environment - lambda do |context| - link_to s_('softwares|View all'), :controller => 'search', - :action => 'software_infos' - end - else - '' - end - end - - def profile_count - profile_list.count - end - - def profiles - owner.communities - end - - def profile_list - profiles = get_visible_profiles - - software_profiles = profiles.select do |profile| - profile.class == Community && profile.software? - end - - block_softwares = if self.software_type == "Public" - software_profiles.select { |profile| profile.software_info.public_software? } - elsif self.software_type == "Generic" - software_profiles.select { |profile| !profile.software_info.public_software? } - else # All - software_profiles - end - - block_softwares.slice(0..get_limit-1) - end - - def content(arg={}) - if self.box.owner_type == "Environment" && self.box.position == 1 - block = self - - proc do - render :file => 'blocks/main_area_softwares', - :locals => {:profiles=> block.profile_list(), :block => block} - end - else - super(arg) - end - end - - protected - - def get_visible_profiles - profile_include_list = [:image, :domains, :preferred_domain, :environment] - visible_profiles = profiles.visible.includes(profile_include_list) - - if !prioritize_profiles_with_image - visible_profiles.all( :limit => get_limit, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - elsif profiles.visible.with_image.count >= get_limit - visible_profiles.with_image.all( :limit => get_limit * 5, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - else - visible_profiles.with_image.sort_by{ rand } + - visible_profiles.without_image.all( :limit => get_limit * 5, - :order => 'profiles.updated_at DESC' - ).sort_by{ rand } - end - end -end diff --git a/src/noosfero-spb/software_communities/lib/statistic_block.rb b/src/noosfero-spb/software_communities/lib/statistic_block.rb deleted file mode 100644 index fd45f4f..0000000 --- a/src/noosfero-spb/software_communities/lib/statistic_block.rb +++ /dev/null @@ -1,52 +0,0 @@ -class StatisticBlock < Block - - settings_items :benefited_people, :type => :integer, :default => 0 - settings_items :saved_resources, :type => :float, :default => 0.0 - - attr_accessible :benefited_people, :saved_resources - - def self.description - _('Software Statistics') - end - - def help - _('This block displays software statistics.') - end - - def content(args={}) - download_blocks = get_profile_download_blocks(self.owner) - downloads = download_blocks.map do |download_block| - get_downloads_from_block(download_block) - end - - block = self - - lambda do |object| - render( - :file => 'blocks/software_statistics', - :locals => { - :block => block, - :total_downloads => downloads.sum - } - ) - end - end - - def cacheable? - false - end - - private - - def get_profile_download_blocks profile - DownloadBlock.joins(:box).where("boxes.owner_id = ?", profile.id) - end - - def get_downloads_from_block download_block - downloads = download_block.downloads.map do |download| - download[:total_downloads] unless download[:total_downloads].nil? - end - downloads.select! {|value| not value.nil? } - downloads.sum - end -end diff --git a/src/noosfero-spb/software_communities/lib/wiki_block.rb b/src/noosfero-spb/software_communities/lib/wiki_block.rb deleted file mode 100644 index 3d7da90..0000000 --- a/src/noosfero-spb/software_communities/lib/wiki_block.rb +++ /dev/null @@ -1,30 +0,0 @@ -class WikiBlock < Block - - attr_accessible :show_name, :wiki_link - settings_items :show_name, :type => :boolean, :default => false - settings_items :wiki_link, :type => :string, :default => "" - - def self.description - _('Wiki Link') - end - - def help - _('This block displays a link to the software wiki.') - end - - def content(args={}) - block = self - s = show_name - - lambda do |object| - render( - :file => 'blocks/wiki', - :locals => { :block => block, :show_name => s } - ) - end - end - - def cacheable? - true - end -end -- libgit2 0.21.2