diff --git a/Gemfile b/Gemfile index d79c7ba801aa092cafa7b71e77b0724ea66d65f1..a6fa0de089f789f45d9838095fdfd419296b05e7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '4.2.0' +gem 'rails', '4.2.5.1' # Use postgresql as the database for Active Record gem 'pg' # Use SCSS for stylesheets @@ -91,6 +91,9 @@ gem 'rubycritic', require: false gem 'rdoc' gem 'stackprof' +#Awesome font icons +gem "font-awesome-rails" + group :development, :test do # profiler gem 'rack-mini-profiler' @@ -152,3 +155,9 @@ gem 'feature' # mass insert in ActiveRecord gem 'activerecord-import' + +gem 'social-share-button' +gem 'meta-tags' +gem 'omniauth-facebook' +gem 'omniauth-twitter' +gem "omniauth-google-oauth2" diff --git a/Gemfile.lock b/Gemfile.lock index c9cd9063eb705677f81d8827a175bbb2c27cbad8..ddaacbbc8411285d00befa927ec44717fa0e1313 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,38 +1,38 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.0) - actionpack (= 4.2.0) - actionview (= 4.2.0) - activejob (= 4.2.0) + actionmailer (4.2.5.1) + actionpack (= 4.2.5.1) + actionview (= 4.2.5.1) + activejob (= 4.2.5.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.0) - actionview (= 4.2.0) - activesupport (= 4.2.0) - rack (~> 1.6.0) + actionpack (4.2.5.1) + actionview (= 4.2.5.1) + activesupport (= 4.2.5.1) + rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - actionview (4.2.0) - activesupport (= 4.2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.5.1) + activesupport (= 4.2.5.1) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) - rails-html-sanitizer (~> 1.0, >= 1.0.1) - activejob (4.2.0) - activesupport (= 4.2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.5.1) + activesupport (= 4.2.5.1) globalid (>= 0.3.0) - activemodel (4.2.0) - activesupport (= 4.2.0) + activemodel (4.2.5.1) + activesupport (= 4.2.5.1) builder (~> 3.1) - activerecord (4.2.0) - activemodel (= 4.2.0) - activesupport (= 4.2.0) + activerecord (4.2.5.1) + activemodel (= 4.2.5.1) + activesupport (= 4.2.5.1) arel (~> 6.0) activerecord-import (0.11.0) activerecord (>= 3.0) - activesupport (4.2.0) + activesupport (4.2.5.1) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -130,6 +130,8 @@ GEM flog (4.3.2) ruby_parser (~> 3.1, > 3.1.0) sexp_processor (~> 4.4) + font-awesome-rails (4.5.0.1) + railties (>= 3.2, < 5.1) gitlab (3.6.1) httparty terminal-table @@ -154,6 +156,7 @@ GEM jquery-ui-rails (5.0.5) railties (>= 3.2.16) json (1.8.3) + jwt (1.5.1) kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -166,6 +169,8 @@ GEM nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) + meta-tags (2.1.0) + actionpack (>= 3.0.0) mime-types (2.99.1) mimemagic (0.3.0) mina (0.3.8) @@ -179,6 +184,32 @@ GEM net-http-persistent (2.9.4) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) + oauth (0.5.0) + oauth2 (1.1.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0, < 1.5.2) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) + omniauth (1.3.1) + hashie (>= 1.2, < 4) + rack (>= 1.0, < 3) + omniauth-facebook (3.0.0) + omniauth-oauth2 (~> 1.2) + omniauth-google-oauth2 (0.3.1) + jwt (~> 1.0) + multi_json (~> 1.3) + omniauth (>= 1.1.1) + omniauth-oauth2 (>= 1.3.1) + omniauth-oauth (1.1.0) + oauth + omniauth (~> 1.0) + omniauth-oauth2 (1.4.0) + oauth2 (~> 1.0) + omniauth (~> 1.2) + omniauth-twitter (1.2.1) + json (~> 1.3) + omniauth-oauth (~> 1.1) open4 (1.3.4) orm_adapter (0.5.0) paperclip (4.3.5) @@ -202,16 +233,16 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.0) - actionmailer (= 4.2.0) - actionpack (= 4.2.0) - actionview (= 4.2.0) - activejob (= 4.2.0) - activemodel (= 4.2.0) - activerecord (= 4.2.0) - activesupport (= 4.2.0) + rails (4.2.5.1) + actionmailer (= 4.2.5.1) + actionpack (= 4.2.5.1) + actionview (= 4.2.5.1) + activejob (= 4.2.5.1) + activemodel (= 4.2.5.1) + activerecord (= 4.2.5.1) + activesupport (= 4.2.5.1) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.0) + railties (= 4.2.5.1) sprockets-rails rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) @@ -221,9 +252,9 @@ GEM rails-deprecated_sanitizer (>= 1.0.1) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (4.2.0) - actionpack (= 4.2.0) - activesupport (= 4.2.0) + railties (4.2.5.1) + actionpack (= 4.2.5.1) + activesupport (= 4.2.5.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.1.0) @@ -294,11 +325,14 @@ GEM slim (3.0.6) temple (~> 0.7.3) tilt (>= 1.3.3, < 2.1) + social-share-button (0.1.10) + coffee-rails + sass-rails spring (1.6.3) sprockets (3.5.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.0.1) + sprockets-rails (3.0.3) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) @@ -356,6 +390,7 @@ DEPENDENCIES execjs feature flamegraph + font-awesome-rails gitlab jbuilder (~> 2.0) jquery-rails @@ -364,14 +399,18 @@ DEPENDENCIES kaminari libarchive-static locastyle + meta-tags mina + omniauth-facebook + omniauth-google-oauth2 + omniauth-twitter paperclip pg puma pundit rack-cors rack-mini-profiler - rails (= 4.2.0) + rails (= 4.2.5.1) rainbow rdoc resumablejs-rails @@ -387,6 +426,7 @@ DEPENDENCIES sidekiq sinatra slim + social-share-button spring sqlite3 stackprof diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index aaa8724e8ebe8d9714f84d0abecdab1a8883efca..8cf3388e68a2c7dd24495d5cd6546a2a0277e9cb 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -19,6 +19,7 @@ //= require select2_locale_pt-BR //= require bootstrap-tagsinput //= require turbolinks +//= require social-share-button //= require resumable //= require_tree ./application diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 6cf1cdbc65d4ad3bf94a57c1cecf8c4dc5b27655..afa50ef96c718e4fb8fd5d2f23817093764651d9 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -15,13 +15,17 @@ *= require jquery-ui/core *= require jquery-ui/theme *= require jquery-ui/autocomplete + *= require font-awesome */ + @import "bootstrap-sprockets"; @import "bootstrap"; @import "select2"; @import "select2-bootstrap"; @import "bootstrap-tagsinput"; @import "spinners"; +@import "font-awesome"; +@import "social-share-button"; $header-blue: #1676bc; $link-grey: #343D3E; diff --git a/app/builders/learning_object_builder.rb b/app/builders/learning_object_builder.rb index b52982a639393e97c4c99485df83bb5d2a29e66d..7613fc6e676eb13a1f29ec9a5dfabc07ebf433be 100644 --- a/app/builders/learning_object_builder.rb +++ b/app/builders/learning_object_builder.rb @@ -2,10 +2,10 @@ class LearningObjectBuilder def self.build_from_dspace(item) lo = LearningObject.new( - name: item.name, - id_dspace: item.id, - thumbnail: nil, - metadata: item.metadata.to_json + name: item.name, + id_dspace: item.id, + thumbnail: nil, + metadata: item.metadata.map { |m| m.to_h} ) lo.author = lo.get_metadata_values_of('dc.contributor.author').join(', ') diff --git a/app/controllers/callbacks_controller.rb b/app/controllers/callbacks_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..56360cbdf6051b7efc7f63ef43d5512a7b08fa0e --- /dev/null +++ b/app/controllers/callbacks_controller.rb @@ -0,0 +1,33 @@ +class CallbacksController < Devise::OmniauthCallbacksController + + def facebook + request_data("Facebook","devise.facebook_data") + end + + def twitter + request_data("Twitter","devise.twitter_data") + end + + def google_oauth2 + request_data("Google","devise.google_oauth2_data") + end + + private + + def request_data(provider,provider_session) + @user = User.from_omniauth(request.env["omniauth.auth"]) + + if @user.persisted? + sign_in_and_redirect @user, :event => :authentication + flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => provider + else + session[provider_session] = request.env["omniauth.auth"] + redirect_to new_user_registration_url + end + + def failure + redirect_to root_path + end + end + +end diff --git a/app/helpers/learning_objects_helper.rb b/app/helpers/learning_objects_helper.rb index 4dfa144645e250f21132b62d805478ab5a3faa95..280296fcb6514e9776ba518879e90c7d0d96ff86 100644 --- a/app/helpers/learning_objects_helper.rb +++ b/app/helpers/learning_objects_helper.rb @@ -70,4 +70,19 @@ module LearningObjectsHelper collections = @collections.diff(learning_object_collections(learning_object)) end + def social_share(learning_object) + set_meta_tags og: { + title: @learning_object.name, + type: 'website', + description: @learning_object.description, + image: @learning_object.thumbnail + } + + set_meta_tags fb: { + app_id: '745857965514514' + } + + end + + end diff --git a/app/models/concerns/reviewable.rb b/app/models/concerns/reviewable.rb index 31a9580847d997fa6f6111cc62ddc281a3c92752..82d9391d3b9d2b14387de5874986e740cd986946 100644 --- a/app/models/concerns/reviewable.rb +++ b/app/models/concerns/reviewable.rb @@ -5,4 +5,8 @@ module Reviewable has_many :reviews, as: :reviewable, dependent: :destroy end + def review_ratings_average + array_average(reviews.map { |review| review.rating_average }) + end + end diff --git a/app/models/score.rb b/app/models/score.rb new file mode 100644 index 0000000000000000000000000000000000000000..508061b5f69f50f05b38a3c2f3f11d5cf8c14d79 --- /dev/null +++ b/app/models/score.rb @@ -0,0 +1,16 @@ +class Score < ActiveRecord::Base + has_many :score_user_categories, dependent: :destroy + has_many :user_categories, through: :score_user_categories + + validates_presence_of :name, :code, :weight + validates_uniqueness_of :code + + def max_value + score_user_categories.maximum(:value) + end + + def category_value(category) + score = score_user_categories.where(score: self, user_category: category).first + (score.nil?) ? nil : score.value + end +end diff --git a/app/models/score_user_category.rb b/app/models/score_user_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..1ff802069cdccaf1e0c52dec1628f9a01d308f21 --- /dev/null +++ b/app/models/score_user_category.rb @@ -0,0 +1,34 @@ +class ScoreUserCategory < ActiveRecord::Base + belongs_to :score + belongs_to :user_category + + validates_presence_of :score, :user_category, :value + validates_uniqueness_of :user_category, scope: :score + + after_commit :calculate_reference + + private + + def calculate_reference + return 0 if Score.count < 9 || !reputation_hash.values.all? { |x| !x.nil? } + + reference = ScoreCalculatorService.new(self).reputation(reputation_hash) + + user_category.update(reference: reference) if reference.is_a? Float + end + + def reputation_hash + { + 'reputation_submitted': Score.where(code: 'reputation_submitted').first.category_value(user_category), + 'reputation_reviews_average_score': Score.where(code: 'reputation_reviews_average_score').first.category_value(user_category), + 'reputation_added_in_best_collections': Score.where(code: 'reputation_added_in_best_collections').first.category_value(user_category), + 'reputation_best_score': Score.where(code: 'reputation_best_score').first.category_value(user_category), + 'reputation_average_score': Score.where(code: 'reputation_average_score').first.category_value(user_category), + 'reputation_reviews_rate': Score.where(code: 'reputation_reviews_rate').first.category_value(user_category), + # 'reputation_confirmed_complaints': Score.where(code: 'reputation_confirmed_complaints').first.category_value(user_category), + 'reputation_followers': Score.where(code: 'reputation_followers').first.category_value(user_category), + 'reputation_submitted_recently': Score.where(code: 'reputation_submitted_recently').first.category_value(user_category), + 'reputation_collection_score': Score.where(code: 'reputation_collection_score').first.category_value(user_category) + } + end +end diff --git a/app/models/topic_relationship.rb b/app/models/topic_relationship.rb index 5dd3f84bb5ab5e127c95f4725304d88af5059f71..c5007d12988ade58cc2cd036f90fcd1aabed0b71 100644 --- a/app/models/topic_relationship.rb +++ b/app/models/topic_relationship.rb @@ -3,4 +3,5 @@ class TopicRelationship < ActiveRecord::Base belongs_to :child, class_name: 'Topic' validates_presence_of :parent, :child + validates_uniqueness_of :child, scope: :parent end diff --git a/app/models/user.rb b/app/models/user.rb index 301f842067bf3edb30a0a34fdd4abc77acf1cc96..acd962419950fc12c4a5838cdcea2ed3a09a70bc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,8 @@ class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :validatable + :recoverable, :rememberable, :trackable, :validatable, + :omniauthable has_and_belongs_to_many :roles has_and_belongs_to_many :institutions @@ -44,10 +45,46 @@ class User < ActiveRecord::Base false end + def review_approval_average + array = reviews.map(&:rates_percentage) + array.inject(0.0) { |sum, el| sum + el } / array.size + end + + def learning_objects_in_best_collections + average = Collection.average(:score) + collections.where(:score > average).count + end + + def learning_objects_submitted_recently + learning_objects.where(:created_at > (Time.now - 2.months)).count + end + private def default_role roles << Role.find_by_name("teacher") end + def self.from_omniauth(access_token) + data = access_token.info + + if access_token.provider == "twitter" + user_email = access_token.uid + "@twitter.com" + else + user_email = data["email"] + end + + user = User.where(:email => user_email).first + + unless user + user = User.create(name: data["name"], + email: user_email, + provider: access_token.provider, + uid: access_token.uid, + password: Devise.friendly_token[0,20] + ) + end + user + end + end diff --git a/app/models/user_category.rb b/app/models/user_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..dec0e310c6de38e1cf8f8c5bad8bad87895fe2a9 --- /dev/null +++ b/app/models/user_category.rb @@ -0,0 +1,7 @@ +class UserCategory < ActiveRecord::Base + has_many :score_user_categories, dependent: :destroy + has_many :scores, through: :score_user_categories + + validates_presence_of :name + validates_uniqueness_of :name +end diff --git a/app/services/score_calculator_service.rb b/app/services/score_calculator_service.rb new file mode 100644 index 0000000000000000000000000000000000000000..e238c19363f5e733f10419c9bd72af8acc4ae88e --- /dev/null +++ b/app/services/score_calculator_service.rb @@ -0,0 +1,49 @@ +class ScoreCalculatorService + + def initialize(object) + @object = object + @class = @object.class.name + end + + def calculate + case @class + when 'User' then reputation + end + end + + def reputation(values = nil) + values = reputation_hash if values.nil? + + sum = 0 + + Score.all.find_each do |score| + next if score.max_value.to_f == 0 + + sum += (values[score.code.to_sym].to_f / score.max_value.to_f) * score.weight.to_f + end + + sum.to_f / sum_weights.to_f + end + + private + + def reputation_hash + { + 'reputation_submitted': @object.learning_objects.count, + 'reputation_reviews_average_score': @object.learning_objects.review_ratings_average, + 'reputation_added_in_best_collections': @object.learning_objects_in_best_collections, + 'reputation_best_score': @object.learning_objects.maximum(:score), + 'reputation_average_score': @object.learning_objects.average(:score), + 'reputation_reviews_rate': @object.review_approval_average, + # 'reputation_confirmed_complaints': , + 'reputation_followers': @object.followers.count, + 'reputation_submitted_recently': @object.learning_objects_submitted_recently, + 'reputation_collection_score': @object.where(privacy: 'public').average(:score) + } + end + + def sum_weights + Score.pluck(:weight).inject(0.0) { |a, e| a + e } + end + +end diff --git a/app/services/topics_importer.rb b/app/services/topics_importer.rb index 1acf80432b5c40bc85c4ab2b7efd91db22467fd2..0180f3e3182c545117aa15a1f628b3df453f8066 100644 --- a/app/services/topics_importer.rb +++ b/app/services/topics_importer.rb @@ -9,26 +9,33 @@ class TopicsImporter def import - relations = [] + learning_objects = [] @items.each do |learning_object| lo_topics = parse_topics ( learning_object.get_metadata_values_of "dc.subject.category" ) - lo_topics.each_with_index do |topic_name, i| + lo_topics.each do |topic_name| + topic = @@topics[topic_name] + + if !topic_exists? topic_name + topic = Topic.where(name: topic_name).new + elsif @@topics[topic_name].nil? + topic = Topic.find_by_name topic_name + end - next if topic_exists? topic_name - topic = Topic.where(name: topic_name).new - topic.learning_objects << learning_object - create_relations(lo_topics[i - 1], topic_name) unless i == 0 + create_relations(topic_name) + learning_object.topics << topic @@topics[topic_name] = topic end + learning_objects << learning_object separate_relations() end Topic.import @@topics.values + LearningObject.import learning_objects import_topics_relations() end @@ -36,9 +43,8 @@ class TopicsImporter private - def create_relations parent_name, child_name - @@topics_relations.push(parent_name) - @@topics_relations.push(child_name) + def create_relations topic_name + @@topics_relations << topic_name end def separate_relations @@ -53,7 +59,7 @@ class TopicsImporter unless relation.nil? || @@topics_relations[i - 1].nil? parent_id = Topic.find_by_name(@@topics_relations[i - 1]).id child_id = Topic.find_by_name(relation).id - unless TopicRelationship.exists?(parent_id: parent_id, child_id: child_id) || i == 0 + unless TopicRelationship.exists?(parent_id: parent_id, child_id: child_id) relations.push TopicRelationship.where(parent_id: parent_id, child_id: child_id ).new end end diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 6ec13f7f999921b0986c6655c90c79066e4d6135..293b439c25b3254173503abe642ca1308419f0e0 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -3,60 +3,67 @@ <div class="row"> <div class=" col-md-12"> <div class="white-input"> - <div class="grey-panel"> - <h2>Entrar</h2> - <br/> - <%= image_tag image_path('user-anon.png'), class: "logo" %><br/><br/> + <div class="grey-panel"> + <h2>Entrar</h2> + <br/> + <%= image_tag image_path('user-anon.png'), class: "logo" %><br/><br/> - <form action="" method=""> - <table style="margin: 20px auto;"> - <tr> - <td>Email:</td><td> </td> - <td style=" padding: 10px;"> - <%= f.email_field :email, autofocus: true , style:"width:375px;"%> - </td> - </tr> + <form action="" method=""> + <table style="margin: 20px auto;"> + <tr> + <td>Email:</td> + <td> </td> + <td style=" padding: 10px;"> + <%= f.email_field :email, autofocus: true, style: "width:375px;" %> + </td> + </tr> - <tr> - <td>Senha:</td><td> </td> - <td><%= f.password_field :password, autocomplete: "off", style:"width:375px;" %></td> - </tr> - <tr> - <td></td><td></td> - <td> - <span class="pull-right"> - <% if devise_mapping.rememberable? -%> - <div class="field"> - <%= f.check_box :remember_me %> - <%= f.label :remember_me %> + <tr> + <td>Senha:</td> + <td> </td> + <td><%= f.password_field :password, autocomplete: "off", style: "width:375px;" %></td> + </tr> + <tr> + <td></td> + <td></td> + <td> + <span class="pull-right"> + <% if devise_mapping.rememberable? -%> + <div class="field"> + <%= f.check_box :remember_me %> + <%= f.label :remember_me %> + </div> + <% end -%> + <%= link_to "Esqueceu sua senha?", new_password_path(resource_name), class: 'link-setup-2' %> + </span> + </td> + </tr> + </table> + </form> + <br/> + <br/> + <div class="container-fluid"> + <div class="col-md-offset-3 col-md-4"> + <div class="col-md-7"> + <span class="pull-right">Não possui conta?</span><br/> + <span class="pull-right"> + <%= link_to "Cadastre-se", new_registration_path(resource_name), class: 'link-setup' %> + <span class="pull-right"><%= link_to "Entre com o Facebook", user_omniauth_authorize_path(:facebook), class: 'link-setup' %></span> + <span class="pull-right"><%= link_to "Entre com o Twitter", user_omniauth_authorize_path(:twitter), class: 'link-setup' %></span> + <span class="pull-right"><%= link_to "Entre com o Google", user_omniauth_authorize_path(:google_oauth2), class: 'link-setup' %></span> + </span> </div> - <% end -%> - <%= link_to "Esqueceu sua senha?", new_password_path(resource_name) , class:'link-setup-2' %> - </span></td> - </tr> - </table> - </form> - <br/> - <br/> - <div class="container-fluid"> - <div class="col-md-offset-3 col-md-4"> - <div class="col-md-7"> - <span class="pull-right">Não possui conta?</span><br/> - <span class="pull-right"> - <%= link_to "Cadastre-se", new_registration_path(resource_name),class:'link-setup' %> - </span> - </div> - <div class=" col-md-3"> - <span class="pull-left"> - <%= f.submit "Entrar", class: "btn-singin btn " %> - </span> - <br/> - </div> - </div> - </div> + <div class=" col-md-3"> + <span class="pull-left"> + <%= f.submit "Entrar", class: "btn-singin btn " %> + </span> + <br/> + </div> + </div> + </div> + </div> </div> </div> - </div> </div> </div> <% end %> diff --git a/app/views/devise/shared/_links.html.erb b/app/views/devise/shared/_links.html.erb index cbc179c84ad016e18170e998c6dec8907626ab74..1d470b08592071eeb164066b38583c8007eb2994 100644 --- a/app/views/devise/shared/_links.html.erb +++ b/app/views/devise/shared/_links.html.erb @@ -20,6 +20,10 @@ <%- if devise_mapping.omniauthable? %> <%- resource_class.omniauth_providers.each do |provider| %> - <%= link_to "Entre com #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br /> - <% end -%> + <%- if provider.to_s.titleize == "Google Oauth2" %> + <%= link_to "Entre com Google", omniauth_authorize_path(resource_name, provider), {:class=>'add-picture'} %><br /> + <%- else %> + <%= link_to "Entre com #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider), {:class=>'add-picture'} %><br /> + <% end -%> + <%- end %> <% end -%> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e7768cf49bf3bf6fab30019863674d941f90099a..27d72e6dad8e1a5447d5de6863de445484f73a39 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,6 +2,7 @@ <html> <head> <title>PortalMEC</title> + <%= display_meta_tags %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700' rel='stylesheet' type='text/css'> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> diff --git a/app/views/learning_objects/_bookmarks_button.html.erb b/app/views/learning_objects/_bookmarks_button.html.erb index f5aaa1ab7eb253c16099de9f8e64120c86036204..cd793b493cdb908b8340e07df36dee094dbb20de 100644 --- a/app/views/learning_objects/_bookmarks_button.html.erb +++ b/app/views/learning_objects/_bookmarks_button.html.erb @@ -1,3 +1,3 @@ <%= link_to bookmark_add_path(id: learning_object.id, type: learning_object.class.to_s), class: 'btn btn-default btn-xs', title: "Adicionar aos favoritos", method: :post, remote: true do %> - <span class="glyphicon glyphicon-bookmark" aria-hidden="true"></span> + <i class="fa fa-bookmark" aria-hidden="true"></i> <% end %> diff --git a/app/views/learning_objects/_collections_button.html.erb b/app/views/learning_objects/_collections_button.html.erb index 1f2b4f7802cf33b365f73a207f3e9620a0124aad..41373e128d9a06117b8ba26be6da5caf85d69258 100644 --- a/app/views/learning_objects/_collections_button.html.erb +++ b/app/views/learning_objects/_collections_button.html.erb @@ -1,3 +1,3 @@ <a tabindex="0" class="add-to-collection btn btn-default btn-xs" role="button" title="Adicionar as coleções" data-loid="<%= learning_object.id %>"> - <span class="glyphicon glyphicon-list" aria-hidden="true"></span> + <i class="fa fa-list" aria-hidden="true"></i> </a> diff --git a/app/views/learning_objects/_learning_object_horizontal.erb b/app/views/learning_objects/_learning_object_horizontal.erb index 6538596f77807cc636867b04e0d45c400a518539..134f597c6e652ff6319623ab7c046487f6584773 100644 --- a/app/views/learning_objects/_learning_object_horizontal.erb +++ b/app/views/learning_objects/_learning_object_horizontal.erb @@ -18,8 +18,8 @@ <% end %> <span class="author-label">Por <%= learning_object.get_metadata_value_of("dc.contributor.author") %></span><br/> - <span class="glyphicon glyphicon-eye-open" data-toggle="tooltip" data-placement="bottom" title="Visualizações"><%= learning_object.views.count %></span> - <span class="glyphicon glyphicon-star votes-count" data-id="<%= learning_object.id %>" data-toggle="tooltip" data-placement="bottom" title="Curtidas"><%= learning_object.likes.count %></span><br> + <i class="fa fa-eye" data-toggle="tooltip" data-placement="bottom" title="Visualizações"><%= learning_object.views.count %></i> + <i class="fa fa-star votes-count" data-id="<%= learning_object.id %>" data-toggle="tooltip" data-placement="bottom" title="Curtidas"><%= learning_object.likes.count %></i><br> <% unless learning_object.description.nil? %> <div class="learning-object-text"> diff --git a/app/views/learning_objects/_learning_object_vertical.erb b/app/views/learning_objects/_learning_object_vertical.erb index 0e22d59fb5bad7cd65ea3d632fdd7f209ffac1f6..61282aeb66ada3527eb238c766b1bb4a49eb97dd 100644 --- a/app/views/learning_objects/_learning_object_vertical.erb +++ b/app/views/learning_objects/_learning_object_vertical.erb @@ -10,8 +10,8 @@ </div> <div class="panel-body"> <h4 class="media-heading"><%= learning_object_title(learning_object) %></h4> - <span class="glyphicon glyphicon-eye-open" data-toggle="tooltip" data-placement="bottom" title="Visualizações"><%= learning_object.views.size %></span> - <span class="glyphicon glyphicon-star votes-count" data-id="<%= learning_object.id %>" data-toggle="tooltip" data-placement="bottom" title="Curtidas"><%= learning_object.likes.size %></span> + <i class="fa fa-eye" data-toggle="tooltip" data-placement="bottom" title="Visualizações"><%= learning_object.views.size %></i> + <i class="fa fa-star votes-count" data-id="<%= learning_object.id %>" data-toggle="tooltip" data-placement="bottom" title="Curtidas"><%= learning_object.likes.size %></i> <span class="author-label">Por <%= learning_object.get_metadata_value_of("dc.contributor.author") %></span> </div> </div> diff --git a/app/views/learning_objects/_like_button.html.erb b/app/views/learning_objects/_like_button.html.erb index 45a5e00594c3d1309068f409a1fa4466f28321af..9b85fb4ea0979597f21588020819de5775e62911 100644 --- a/app/views/learning_objects/_like_button.html.erb +++ b/app/views/learning_objects/_like_button.html.erb @@ -1,3 +1,3 @@ <%= link_to like_learning_object_path(id: learning_object.id), class: 'btn btn-primary btn-xs vote', method: :post, remote: true do %> - <span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span> + <i class="fa fa-thumbs-up" aria-hidden="true"></i> <% end %> \ No newline at end of file diff --git a/app/views/learning_objects/_share_modal.html.erb b/app/views/learning_objects/_share_modal.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a4ec9f8f11696bf52378b06f4452fa23d8ac2c23 --- /dev/null +++ b/app/views/learning_objects/_share_modal.html.erb @@ -0,0 +1,18 @@ +<div class="modal fade" id="share_modal" tabindex="-1" role="dialog" aria-labelledby="sahre_modal_label"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-label="Fechar"><span aria-hidden="true">×</span></button> + <h4 class="modal-title" id="share_modal_label">Redes Sociais</h4> + </div> + <div class="modal-body" style="text-align:justify"> + + <% social_share(@learning_object) %> + <%= social_share_button_tag(@learning_object.name) %> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button> + </div> + </div> + </div> +</div> diff --git a/app/views/learning_objects/show.html.erb b/app/views/learning_objects/show.html.erb index 4b14f459f571c08c8dce4f77e276da9130b82434..384a3bea5bdbeb84f507af860203fa19d8b20bf5 100644 --- a/app/views/learning_objects/show.html.erb +++ b/app/views/learning_objects/show.html.erb @@ -5,8 +5,9 @@ <%= display_object_type @learning_object %> </div> <div class="pull-right" style="padding-right:122px"> - <span class="glyphicon glyphicon-eye-open"><%= @learning_object.views.size %> </span> - <span class="glyphicon glyphicon-star votes-count" data-id="<%= @learning_object.id %>" data-toggle="tooltip" data-placement="bottom" title="Curtidas"><%= @learning_object.likes.size %></span> + <i class="fa fa-eye"><%= @learning_object.views.size %> </i> + <i class="fa fa-thumbs-up votes-count" data-id="<%= @learning_object.id %>" data-toggle="tooltip" data-placement="bottom" title="Curtidas"><%= @learning_object.likes.size %></i> + </div> <br/><br/> <h2 class="title"><%= @learning_object.name %></h2> @@ -54,22 +55,29 @@ <h6>curtir objeto</h6> <% end %> </div> - <div class="col-sm-3 action"> + <div class="col-sm-2 action"> <%= link_to download_learning_object_path, target: "_blank" do %> <%#= @learning_object.retrieve_link %> <%= image_tag "icons/download.png", alt: "Download do objeto" %> <h6>salvar no computador</h6> <%end%> </div> - <div class="col-sm-3 action"> + <div class="col-sm-2 action"> <a tabindex="0" class="add-to-collection" role="button" title="Adicionar as coleções" data-loid="<%= @learning_object.id %>"> <%= image_tag "icons/collection-add.png", alt: "Adicionar à coleção" %> <h6>adicionar à coleção</h6> </a> </div> - <div class="col-sm-3 action"> + <div class="col-sm-2 action"> <%= render 'complaints/complaints_button' %> </div> + <div class="col-sm-3 action"> + <a tabindex="1" role="button" title="Compartilhar" data-toggle="modal" data-target="#share_modal"> + <%= image_tag "icons/collection-add.png", alt: "Compartilhar" %> + <h6>Compartilhar</h6> + </a> + <%= render 'share_modal' %> + </div> </div> <% else %> <br/> diff --git a/app/views/reviews/_review.html.erb b/app/views/reviews/_review.html.erb index fd549f0dbfd37772bfe972526babd3955ce2f15f..04e71e70676786c6b67521dfdaabec804db00d63 100644 --- a/app/views/reviews/_review.html.erb +++ b/app/views/reviews/_review.html.erb @@ -33,7 +33,7 @@ <div class="col-md-1"> <%= link_to rate_review_path(id: review.id, approves: true), class: 'btn btn-default btn-lg', method: :post, remote: true do %> - <span class="glyphicon glyphicon-menu-up" aria-hidden="true"></span> + <i class="fa fa-caret-up" aria-hidden="true"></i> <% end %> </br> </br> @@ -42,7 +42,7 @@ </br> <%= link_to rate_review_path(id: review.id, approves: false), class: 'btn btn-default btn-lg', method: :post, remote: true do %> - <span class="glyphicon glyphicon-menu-down" aria-hidden="true"></span> + <i class="fa fa-caret-down" aria-hidden="true"></i> <% end %> </br> </div> diff --git a/app/views/users/_header.html.erb b/app/views/users/_header.html.erb index 1cd36cbf616e57365878f8a05962e82776f4ccb0..4ee08ee937a127bd819211437cb65ffad1c618b0 100644 --- a/app/views/users/_header.html.erb +++ b/app/views/users/_header.html.erb @@ -2,7 +2,7 @@ <div class="col-md-6"> <div class="media"> <div class="media-left"> - <% if current_user.id == user.id %> + <% if current_user.id == user.id and current_user.provider == "email" %> <%= link_to edit_user_registration_path do image_tag user.avatar.url(:thumb), class: 'user-image' end %> @@ -29,7 +29,9 @@ </div> <div class="col-md-6 right-column"> <% if current_user_page? user %> + <% if current_user.provider == "email" %> <%= link_to 'Editar perfil', edit_user_registration_path, class: 'btn btn-default' %> + <% end %> <% else %> <button type="button" class="btn btn-default">Seguir</button> <% end %> diff --git a/app/workers/score_calculator_worker.rb b/app/workers/score_calculator_worker.rb index 5654058c0f0821fbfb03dee191c446945a2d97b5..5a0e9b820fd7f907d2337a7af81a4f780166b84c 100644 --- a/app/workers/score_calculator_worker.rb +++ b/app/workers/score_calculator_worker.rb @@ -2,59 +2,13 @@ class ScoreCalculatorWorker include Sidekiq::Worker sidekiq_options queue: :score - def perform(rid) - object = LearningObject.find(rid) + def perform(id, object_class) + return false unless %w(User LearningObject Collection).include? object_class - unless object.blank? - # Weights to score. Sum must be 1000 - weights = { - "thumbnail": 250, - "description": 150, - "likes": 250, - "views": 150, - "downloads":200 - } + object = object_class.constantize.find(id) - score = 0 + score = ScoreCalculatorService.new(object).calculate - # 250 points if it has thumbnail - score += weights[:thumbnail] unless object.thumbnail.blank? - - # 150 points if it has description - score += weights[:description] unless object.description.blank? - - # range to 250 points, for normalized likes ( maxLikes/actualLike => [0..1] ) - score += divide_by_max( - LearningObject.count('Likes', object), - LearningObject.max('Likes'), - weights[:likes] - ) - - # range to 200 points, for normalized views ( maxLikes/actualLike => [0..1] ) - score += divide_by_max( - LearningObject.count('Views', object), - LearningObject.max('Views'), - weights[:views] - ) - - # downloads - score += divide_by_max( - LearningObject.count('Downloads', object), - LearningObject.max('Downloads'), - weights[:downloads] - ) - - LearningObject.update_property(object, 'score', score) - end - end - - private - - def divide_by_max(i, max, weight) - if (i > 0 && max > 0) && (i <= max) - (i / max) * weight - else - 0 - end + object.update(score: score) end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index f29fa86c004f7f24b8365a0c2ed71f97b3f5f364..e977629bb3e78e073f9190c136529ed5ea3481c7 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,4 +1,4 @@ -# Use this hook to configure devise mailer, warden hooks and so forth. +''# Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| # The secret key used by Devise. Devise uses this key to generate @@ -236,6 +236,9 @@ Devise.setup do |config| # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + config.omniauth :facebook, "745857965514514", "eb465ec961022087f56204e3b86a63ee" + config.omniauth :twitter, "pGD4B2uPuDv07yYqshlwDmdeM", "zt2PHrfIhHjk8lRCqlc47BanKrBghjxYyh8XOzaSnPF27rTnNS" + config.omniauth :google_oauth2, "314037571286-v3in875omm5vn56uhg77j06vtuic223f.apps.googleusercontent.com", "cJN0MTZisPqkkCLg3kSQDWIx", { } # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/initializers/social_share_button.rb b/config/initializers/social_share_button.rb new file mode 100644 index 0000000000000000000000000000000000000000..d8b6e52546ae594d848f011ed7c2dfbd95738227 --- /dev/null +++ b/config/initializers/social_share_button.rb @@ -0,0 +1,3 @@ +SocialShareButton.configure do |config| + config.allow_sites = %w(twitter facebook google_plus) +end diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 783f03dc6d622195238cc581483f63e697cee4c2..48712eff5805b6669cb284525bed04a5ee83c6a5 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -155,4 +155,23 @@ pt-BR: less_than: "precisa ser menor do que {{count}}" less_than_or_equal_to: "precisa ser menor ou igual a {{count}}" odd: "precisa ser Ãmpar" - even: "precisa ser par" \ No newline at end of file + even: "precisa ser par" + + social_share_button: + share_to: Compartilhar com %{name} + weibo: Sina Weibo + twitter: Twitter + facebook: Facebook + douban: Douban + qq: Qzone + tqq: Tqq + delicious: Delicious + baidu: Baidu.com + kaixin001: Kaixin001.com + renren: Renren.com + google_plus: Google+ + google_bookmark: Google Bookmark + tumblr: Tumblr + plurk: Plurk + pinterest: Pinterest + email: Email diff --git a/config/routes.rb b/config/routes.rb index 2e9c1277c332704df8da47da50f88fe8fc0a4a15..1f50f0827da28aaf323bf7ab014a2d8b602c7ae1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do require 'sidekiq/web' - devise_for :users + devise_for :users,:controllers => { :omniauth_callbacks => "callbacks" } namespace :auth do mount_devise_token_auth_for 'User', skip: [:omniauth_callbacks] diff --git a/db/migrate/20160222144157_create_scores.rb b/db/migrate/20160222144157_create_scores.rb new file mode 100644 index 0000000000000000000000000000000000000000..736b07385090b4ba4b9e17dcf253ffa30f4b9f1e --- /dev/null +++ b/db/migrate/20160222144157_create_scores.rb @@ -0,0 +1,12 @@ +class CreateScores < ActiveRecord::Migration + def change + create_table :scores do |t| + t.string :name + t.string :code + t.float :weight + t.boolean :active, default: true + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160222144216_create_user_categories.rb b/db/migrate/20160222144216_create_user_categories.rb new file mode 100644 index 0000000000000000000000000000000000000000..fa97c78f2e6ecf4b0313d6b1725323426995236e --- /dev/null +++ b/db/migrate/20160222144216_create_user_categories.rb @@ -0,0 +1,10 @@ +class CreateUserCategories < ActiveRecord::Migration + def change + create_table :user_categories do |t| + t.string :name + t.float :reference + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20160222144259_create_score_user_categories.rb b/db/migrate/20160222144259_create_score_user_categories.rb new file mode 100644 index 0000000000000000000000000000000000000000..b41e57f2e627d5d53ded3c2f86b4cab0a4d64e6b --- /dev/null +++ b/db/migrate/20160222144259_create_score_user_categories.rb @@ -0,0 +1,13 @@ +class CreateScoreUserCategories < ActiveRecord::Migration + def change + create_table :score_user_categories do |t| + t.references :score, index: true + t.references :user_category, index: true + t.float :value + + t.timestamps null: false + end + add_foreign_key :score_user_categories, :scores + add_foreign_key :score_user_categories, :user_categories + end +end diff --git a/db/migrate/20160225101700_change_users_add_score.rb b/db/migrate/20160225101700_change_users_add_score.rb new file mode 100644 index 0000000000000000000000000000000000000000..ac9d75bb8b448bb7600890339b737e73138db8fe --- /dev/null +++ b/db/migrate/20160225101700_change_users_add_score.rb @@ -0,0 +1,6 @@ +class ChangeUsersAddScore < ActiveRecord::Migration + def change + add_reference :users, :user_category, index: true + add_column :users, :score, :float, default: 0 + end +end diff --git a/db/seeds.rb b/db/seeds.rb index 6de731e6b8f0c6cc3e49d9545d035885e470f8c5..ef2acb24fd81c05dfad076712fb71a6c9b7136cb 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -18,8 +18,9 @@ User.create( ) # data for portalmec -require_relative "seeds/complaints" -require_relative "seeds/institutions" -require_relative "seeds/languages" -require_relative "seeds/ratings" -require_relative "seeds/object_types" +require_relative 'seeds/complaints' +require_relative 'seeds/institutions' +require_relative 'seeds/languages' +require_relative 'seeds/object_types' +require_relative 'seeds/ratings' +require_relative 'seeds/scores' diff --git a/db/seeds/scores.rb b/db/seeds/scores.rb new file mode 100644 index 0000000000000000000000000000000000000000..7d97c0ec00582e1dbbed64a19714be32156ea0d9 --- /dev/null +++ b/db/seeds/scores.rb @@ -0,0 +1,41 @@ +# objects + +# reputation categories +categories = [ + { name: 'Iniciante' }, + { name: 'Novato' }, + { name: 'Amador' }, + { name: 'Profissional' }, + { name: 'Expert' } +].reverse + +# reputation +reputations = [ + { name: 'Quantidade de envio de objetos', code: 'reputation_submitted', weight: 4, active: true }, + { name: 'Avaliação média dos seus objetos', code: 'reputation_reviews_average_score', weight: 9, active: true }, + { name: 'Adições a coleções bem avaliadas', code: 'reputation_added_in_best_collections', weight: 7, active: true }, + { name: 'Melhor score', code: 'reputation_best_score', weight: 3, active: true }, + { name: 'Score médio', code: 'reputation_average_score', weight: 7, active: true }, + { name: 'Aprovação das avaliações em objetos de terceiros (% de sim)', code: 'reputation_reviews_rate', weight: 10, active: true }, + # { name: 'Denúncias confirmadas', code: 'reputation_confirmed_complaints', weight: 0, active: true }, + { name: 'Quantidade de seguidores', code: 'reputation_followers', weight: 6, active: true }, + { name: 'Submissões recentes', code: 'reputation_submitted_recently', weight: 4, active: true }, + { name: 'Score das coleções públicas', code: 'reputation_collection_score', weight: 3, active: true } +] + +values = [ + [ 0, 0, 0, 0, 0, 0, 0, 0, 0], # Iniciante + [ 25, 3.0, 10, 500, 250, 70, 50, 5, 400], # Novato + [ 50, 3.8, 20, 550, 350, 85, 250, 15, 600], # Amador + [ 100, 4.2, 40, 600, 450, 90, 1000, 25, 750], # Profissional + [ 250, 4.9, 80, 680, 550, 95, 5000, 35, 800] # Expert +].reverse + +# iterate to make associations +categories.each_with_index do |c, i| + category = UserCategory.where(c).first_or_create + reputations.each_with_index do |r, j| + reputation = Score.where(r).first_or_create + ScoreUserCategory.create(user_category: category, score: reputation, value: values[i][j]) + end +end diff --git a/test/fixtures/bookmarks.yml b/test/fixtures/bookmarks.yml index d9098d9934714fbe4ea20f4003a7c8beacfb73c6..eb518fa5279ce269f068a328b0516cb134e29af9 100644 --- a/test/fixtures/bookmarks.yml +++ b/test/fixtures/bookmarks.yml @@ -1,7 +1,13 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - user_id: +<% 1.upto(5000) do |i| %> +bookmark_top_<%= i %>: + user: user_<%= i %> + bookmarkable: lo_top (LearningObject) +<% end %> -two: - user_id: +<% 1.upto(3000) do |i| %> +bookmark_joao_<%= i %>: + user: joao + bookmarkable: lo_test_<%= i %> (LearningObject) +<% end %> diff --git a/test/fixtures/collections.yml b/test/fixtures/collections.yml index be5d2e5138faca1e2c1b2c1a69b6fd2db1c3422a..8accfb840e1d7249d47eb7e203d52128725019e9 100644 --- a/test/fixtures/collections.yml +++ b/test/fixtures/collections.yml @@ -1,11 +1,12 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - name: MyString - description: MyText - privacy: MyString - -two: - name: MyString - description: MyText - privacy: MyString +<% 1.upto(20000) do |i| %> +collection_test_<%= i %>: + name: 'lo_test_<%= i %>' + description: 'hue hue hue test <%= i %>' + created_at: 2016-01-28 09:51:07 + views: <% 1.upto(9999) do |i| %>view_<%= i %>,<% end %>view_10000 + likes: <% 1.upto(2799) do |i| %>like_<%= i %>,<% end %>like_2800 + downloads: <% 1.upto(5999) do |i| %>download_<%= i %>,<% end %>download_6000 + shares: <% 1.upto(2999) do |i| %>share_<%= i %>,<% end %>share_3000 +<% end %> diff --git a/test/fixtures/downloads.yml b/test/fixtures/downloads.yml index 1afd2aa2c6cc5e33cf90cf2d48fe9b3f20b3a653..4a4858e7054582501099cfb8c4747f458005412e 100644 --- a/test/fixtures/downloads.yml +++ b/test/fixtures/downloads.yml @@ -1,7 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - date: 2016-01-28 09:54:28 - -two: - date: 2016-01-28 09:54:28 +<% 1.upto(10000) do |i| %> +download_<%= i %>: + date: 2016-01-28 09:51:07 +<% end %> diff --git a/test/fixtures/follows.yml b/test/fixtures/follows.yml index 937a0c002e426861e33bb25a2a8ce2b20b3efaa3..a11b3da63d835635e3f39e50d823db8f7ba240c9 100644 --- a/test/fixtures/follows.yml +++ b/test/fixtures/follows.yml @@ -1,11 +1,7 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value +<% 1.upto(20000) do |i| %> +follow_<%= i %>: + user: + followable: +<% end %> diff --git a/test/fixtures/learning_objects.yml b/test/fixtures/learning_objects.yml index 7c75fb6710d6fc594b31b98a3a5d720bf587e0ff..7a482571fa9d54bd09faaaa99c303bfada0ba219 100644 --- a/test/fixtures/learning_objects.yml +++ b/test/fixtures/learning_objects.yml @@ -1,25 +1,37 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - id_dspace: 1 - name: MyString - author: MyString - description: MyText - published_at: 2016-01-25 10:09:28 - type: - score: 1 - school_level: 1 - language: MyString - keywords: MyText +lo1: + name: 'lo1' + description: 'hue hue hue 1' + reviews: + thumbnail: '' + score: 0.0 + created_at: 2016-01-28 09:51:07 + views: <% 1.upto(9999) do |i| %>view_<%= i %>,<% end %>view_10000 + likes: <% 1.upto(2799) do |i| %>like_<%= i %>,<% end %>like_2800 + downloads: <% 1.upto(5999) do |i| %>download_<%= i %>,<% end %>download_6000 + shares: <% 1.upto(2999) do |i| %>share_<%= i %>,<% end %>share_3000 -two: - id_dspace: 1 - name: MyString - author: MyString - description: MyText - published_at: 2016-01-25 10:09:28 - type: - score: 1 - school_level: 1 - language: MyString - keywords: MyText +lo_top: + name: 'lo_top' + description: 'hue hue hue top' + reviews: + thumbnail: '' + score: 0.0 + created_at: 2016-01-28 09:51:07 + views: <% 1.upto(19999) do |i| %>view_<%= i %>,<% end %>view_20000 + likes: <% 1.upto(3499) do |i| %>like_<%= i %>,<% end %>like_3500 + downloads: <% 1.upto(7999) do |i| %>download_<%= i %>,<% end %>download_8000 + shares: <% 1.upto(3999) do |i| %>share_<%= i %>,<% end %>share_4000 + +<% 1.upto(10000) do |i| %> +lo_test_<%= i %>: + name: 'lo_test_<%= i %>' + description: 'hue hue hue test <%= i %>' + thumbnail: '' + created_at: 2016-01-28 09:51:07 + views: <% 1.upto(9999) do |i| %>view_<%= i %>,<% end %>view_10000 + likes: <% 1.upto(2799) do |i| %>like_<%= i %>,<% end %>like_2800 + downloads: <% 1.upto(5999) do |i| %>download_<%= i %>,<% end %>download_6000 + shares: <% 1.upto(2999) do |i| %>share_<%= i %>,<% end %>share_3000 +<% end %> diff --git a/test/fixtures/likes.yml b/test/fixtures/likes.yml index 9dc57b68dd5ad1d883dda1bc093a8900ef1e745e..dba27447649804f1c471041d4940b86ba975b616 100644 --- a/test/fixtures/likes.yml +++ b/test/fixtures/likes.yml @@ -1,7 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - date: 2016-01-28 09:55:55 - -two: - date: 2016-01-28 09:55:55 +<% 1.upto(10000) do |i| %> +like_<%= i %>: + date: 2016-01-28 09:51:07 +<% end %> diff --git a/test/fixtures/score_user_categories.yml b/test/fixtures/score_user_categories.yml new file mode 100644 index 0000000000000000000000000000000000000000..8b48ec7eac837b9208529a5480b336b045e3a0a0 --- /dev/null +++ b/test/fixtures/score_user_categories.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + score_id: + user_category_id: + value: 1 + +two: + score_id: + user_category_id: + value: 1 diff --git a/test/fixtures/scores.yml b/test/fixtures/scores.yml new file mode 100644 index 0000000000000000000000000000000000000000..bd103ffc7b605d6340700a90e69a8e3750ad9d49 --- /dev/null +++ b/test/fixtures/scores.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + code: MyString + weight: 1 + active: false + +two: + name: MyString + code: MyString + weight: 1 + active: false diff --git a/test/fixtures/shares.yml b/test/fixtures/shares.yml index 18c323239a0eec3362ec5b1f64da298702dc123a..44c28365e12f4099444fc2f7155d4becc19efb98 100644 --- a/test/fixtures/shares.yml +++ b/test/fixtures/shares.yml @@ -1,7 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - date: 2016-01-28 09:57:21 - -two: - date: 2016-01-28 09:57:21 +<% 1.upto(10000) do |i| %> +share_<%= i %>: + date: 2016-01-28 09:51:07 +<% end %> diff --git a/test/fixtures/user_categories.yml b/test/fixtures/user_categories.yml new file mode 100644 index 0000000000000000000000000000000000000000..56066c68af42f307f5780e9ac146e3651cea3979 --- /dev/null +++ b/test/fixtures/user_categories.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index e7c2ceefe67d37c925d3243bfb4110b900ec03a8..8d6fe0462c36c286c3493fd9879a0c8890642e2e 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,7 +1,11 @@ -one: - email: 'mgg12@inf.ufpr.br' - provider: 'email' +joao: + name: 'João' + email: 'joao@teste.br' + score: '0.0' + learning_objects: lo1, lo2, lo3 -two: - email: 'test@c3sl.ufpr.br' - provider: 'email' \ No newline at end of file +<% 1.upto(10000) do |i| %> +user_<%= i %>: + name: 'user test <%= i %>' + email: 'user_test_<%= i %>@test.com' +<% end %> diff --git a/test/fixtures/views.yml b/test/fixtures/views.yml index 2450a5d83c100365f3b24912a5ba086970603d0a..fd91cd03e4eb035d1a3f5d1df6c54f8cf4496bf1 100644 --- a/test/fixtures/views.yml +++ b/test/fixtures/views.yml @@ -1,7 +1,6 @@ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - date: 2016-01-28 09:51:07 - -two: +<% 1.upto(20000) do |i| %> +view_<%= i %>: date: 2016-01-28 09:51:07 +<% end %> diff --git a/test/models/score_test.rb b/test/models/score_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..d38cb0a3c55492dad6707691aa49fa19fb9b7987 --- /dev/null +++ b/test/models/score_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ScoreTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/score_user_category_test.rb b/test/models/score_user_category_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..bd5bf9f3167904855c052af49b181f97a25019aa --- /dev/null +++ b/test/models/score_user_category_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ScoreUserCategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/user_category_test.rb b/test/models/user_category_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..4cdbac46363829d8f97cff9140dd589eb4ba466b --- /dev/null +++ b/test/models/user_category_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserCategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/services/score_calculator_service_test.rb b/test/services/score_calculator_service_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391