From 8d24d6f6e3d96ead5988c9e4ebfdc4f3bea69137 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Tue, 7 Jul 2015 15:01:17 +0000 Subject: [PATCH] Add new fields to comment --- db/migrate/20150701134012_add_new_fields_to_comments.rb | 13 +++++++++++++ lib/ext/comments.rb | 5 +++++ lib/software_communities_plugin.rb | 9 +++++++++ public/initializer.js | 3 ++- public/style.css | 10 ++++++++++ public/views/comments-software-extra-fields.js | 30 ++++++++++++++++++++++++++++++ test/unit/comments_test.rb | 17 +++++++++++++++++ views/comments_extra_fields.html.erb | 14 ++++++++++++++ 8 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20150701134012_add_new_fields_to_comments.rb create mode 100644 lib/ext/comments.rb create mode 100644 public/views/comments-software-extra-fields.js create mode 100644 test/unit/comments_test.rb create mode 100644 views/comments_extra_fields.html.erb diff --git a/db/migrate/20150701134012_add_new_fields_to_comments.rb b/db/migrate/20150701134012_add_new_fields_to_comments.rb new file mode 100644 index 0000000..28c90e6 --- /dev/null +++ b/db/migrate/20150701134012_add_new_fields_to_comments.rb @@ -0,0 +1,13 @@ +class AddNewFieldsToComments < ActiveRecord::Migration + def self.up + change_table :comments do |t| + t.integer :people_benefited + t.decimal :saved_value + end + end + + def self.down + remove_column :comments, :people_benefited + remove_column :comments, :saved_value + end +end diff --git a/lib/ext/comments.rb b/lib/ext/comments.rb new file mode 100644 index 0000000..1d8d6b8 --- /dev/null +++ b/lib/ext/comments.rb @@ -0,0 +1,5 @@ +require_dependency "comment" + +class Comment + attr_accessible :people_benefited, :saved_value +end diff --git a/lib/software_communities_plugin.rb b/lib/software_communities_plugin.rb index f62caf9..a7dfd78 100644 --- a/lib/software_communities_plugin.rb +++ b/lib/software_communities_plugin.rb @@ -63,12 +63,21 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin views/search-software-catalog.js views/profile-tabs-software.js views/new-community.js + views/comments-software-extra-fields.js blocks/software-download.js initializer.js app.js ) end + def communities_ratings_plugin_comments_extra_fields + Proc::new do render :file => 'comments_extra_fields' end + end + + def communities_ratings_plugin_star_message + Proc::new do _("Rate this software") end + end + # FIXME - if in error log apears has_permission?, try to use this method def has_permission?(person, permission, target) person.has_permission_without_plugins?(permission, target) diff --git a/public/initializer.js b/public/initializer.js index b882e32..b0d3be6 100644 --- a/public/initializer.js +++ b/public/initializer.js @@ -8,7 +8,8 @@ 'SearchSoftwareCatalog', 'SoftwareDownload', 'ProfileTabsSoftware', - 'NewCommunity' + 'NewCommunity', + 'CommentsSoftwareExtraFields' ]; diff --git a/public/style.css b/public/style.css index 7d253b4..daea888 100644 --- a/public/style.css +++ b/public/style.css @@ -162,3 +162,13 @@ display: block; background-color:rgba(255, 255, 255, 0.9); } + +/*===== Communities rate hotspot extra fields =====*/ +.comments-software-extra-fields span { + cursor: pointer; +} + +.comments-software-extra-fields div { + display: none; +} + diff --git a/public/views/comments-software-extra-fields.js b/public/views/comments-software-extra-fields.js new file mode 100644 index 0000000..93967df --- /dev/null +++ b/public/views/comments-software-extra-fields.js @@ -0,0 +1,30 @@ +modulejs.define('CommentsSoftwareExtraFields', ['jquery'], function($) { + 'use strict'; + + var DATA = { + information_display_state: "hidden" + } + + function set_show_aditional_information() { + $(".comments-software-extra-fields span").on("click", function() { + if (DATA.information_display_state === "hidden") { + DATA.information_display_state = "show"; + $(this).parent().children("div").show(); + } else { + DATA.information_display_state = "hidden"; + $(this).parent().children("div").hide(); + } + }); + } + + return { + isCurrentPage: function() { + return $(".comments-software-extra-fields span").length === 1; + }, + + + init: function() { + set_show_aditional_information(); + } + } +}); diff --git a/test/unit/comments_test.rb b/test/unit/comments_test.rb new file mode 100644 index 0000000..e8a6b5a --- /dev/null +++ b/test/unit/comments_test.rb @@ -0,0 +1,17 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../lib/ext/comments.rb' + +class CommentsTest < ActiveSupport::TestCase + + def teardown + Comment.destroy_all + end + + should 'create comments with new fields' do + @person = fast_create(Person) + @article = Article.create(:profile => @person, :name => "Test") + + comment = Comment.new(:body => "Comment new", :author => @person, :people_benefited => 2, :saved_value => 38.5) + assert comment.save + end +end diff --git a/views/comments_extra_fields.html.erb b/views/comments_extra_fields.html.erb new file mode 100644 index 0000000..f0fdf7f --- /dev/null +++ b/views/comments_extra_fields.html.erb @@ -0,0 +1,14 @@ +
+ + <%= _("Aditional informations") %> + + +
+ <%= label_tag "comments_people_benefited", _("Number of Beneficiaries")%> + <%= text_field_tag "comments[people_benefited]", "" %> +
+
+ <%= label_tag "comments_saved_value", _("Saved resources")%> + <%= text_field_tag "comments[saved_value]", ""%> +
+
-- libgit2 0.21.2