Commit 8d24d6f6e3d96ead5988c9e4ebfdc4f3bea69137

Authored by Gabriela Navarro
Committed by Álvaro Fernando Matos de Souza
1 parent e9757353
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Add new fields to comment

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
db/migrate/20150701134012_add_new_fields_to_comments.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class AddNewFieldsToComments < ActiveRecord::Migration
  2 + def self.up
  3 + change_table :comments do |t|
  4 + t.integer :people_benefited
  5 + t.decimal :saved_value
  6 + end
  7 + end
  8 +
  9 + def self.down
  10 + remove_column :comments, :people_benefited
  11 + remove_column :comments, :saved_value
  12 + end
  13 +end
... ...
lib/ext/comments.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency "comment"
  2 +
  3 +class Comment
  4 + attr_accessible :people_benefited, :saved_value
  5 +end
... ...
lib/software_communities_plugin.rb
... ... @@ -63,12 +63,21 @@ class SoftwareCommunitiesPlugin &lt; Noosfero::Plugin
63 63 views/search-software-catalog.js
64 64 views/profile-tabs-software.js
65 65 views/new-community.js
  66 + views/comments-software-extra-fields.js
66 67 blocks/software-download.js
67 68 initializer.js
68 69 app.js
69 70 )
70 71 end
71 72  
  73 + def communities_ratings_plugin_comments_extra_fields
  74 + Proc::new do render :file => 'comments_extra_fields' end
  75 + end
  76 +
  77 + def communities_ratings_plugin_star_message
  78 + Proc::new do _("Rate this software") end
  79 + end
  80 +
72 81 # FIXME - if in error log apears has_permission?, try to use this method
73 82 def has_permission?(person, permission, target)
74 83 person.has_permission_without_plugins?(permission, target)
... ...
public/initializer.js
... ... @@ -8,7 +8,8 @@
8 8 'SearchSoftwareCatalog',
9 9 'SoftwareDownload',
10 10 'ProfileTabsSoftware',
11   - 'NewCommunity'
  11 + 'NewCommunity',
  12 + 'CommentsSoftwareExtraFields'
12 13 ];
13 14  
14 15  
... ...
public/style.css
... ... @@ -162,3 +162,13 @@
162 162 display: block;
163 163 background-color:rgba(255, 255, 255, 0.9);
164 164 }
  165 +
  166 +/*===== Communities rate hotspot extra fields =====*/
  167 +.comments-software-extra-fields span {
  168 + cursor: pointer;
  169 +}
  170 +
  171 +.comments-software-extra-fields div {
  172 + display: none;
  173 +}
  174 +
... ...
public/views/comments-software-extra-fields.js 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +modulejs.define('CommentsSoftwareExtraFields', ['jquery'], function($) {
  2 + 'use strict';
  3 +
  4 + var DATA = {
  5 + information_display_state: "hidden"
  6 + }
  7 +
  8 + function set_show_aditional_information() {
  9 + $(".comments-software-extra-fields span").on("click", function() {
  10 + if (DATA.information_display_state === "hidden") {
  11 + DATA.information_display_state = "show";
  12 + $(this).parent().children("div").show();
  13 + } else {
  14 + DATA.information_display_state = "hidden";
  15 + $(this).parent().children("div").hide();
  16 + }
  17 + });
  18 + }
  19 +
  20 + return {
  21 + isCurrentPage: function() {
  22 + return $(".comments-software-extra-fields span").length === 1;
  23 + },
  24 +
  25 +
  26 + init: function() {
  27 + set_show_aditional_information();
  28 + }
  29 + }
  30 +});
... ...
test/unit/comments_test.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../lib/ext/comments.rb'
  3 +
  4 +class CommentsTest < ActiveSupport::TestCase
  5 +
  6 + def teardown
  7 + Comment.destroy_all
  8 + end
  9 +
  10 + should 'create comments with new fields' do
  11 + @person = fast_create(Person)
  12 + @article = Article.create(:profile => @person, :name => "Test")
  13 +
  14 + comment = Comment.new(:body => "Comment new", :author => @person, :people_benefited => 2, :saved_value => 38.5)
  15 + assert comment.save
  16 + end
  17 +end
... ...
views/comments_extra_fields.html.erb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +<div class="comments-software-extra-fields">
  2 + <span>
  3 + <%= _("Aditional informations") %>
  4 + </span>
  5 +
  6 + <div class="comments-software-people-benefited">
  7 + <%= label_tag "comments_people_benefited", _("Number of Beneficiaries")%>
  8 + <%= text_field_tag "comments[people_benefited]", "" %>
  9 + </div>
  10 + <div class="comments-software-saved-values">
  11 + <%= label_tag "comments_saved_value", _("Saved resources")%>
  12 + <%= text_field_tag "comments[saved_value]", ""%>
  13 + </div>
  14 +</div>
... ...