diff --git a/Gemfile.lock b/Gemfile.lock index bbf6710d5645846de56383e0da1cba7ecca5605c..c9cd9063eb705677f81d8827a175bbb2c27cbad8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,9 +41,8 @@ GEM addressable (2.3.8) arel (6.0.3) ast (2.2.0) - autoprefixer-rails (6.3.1) + autoprefixer-rails (6.3.3.1) execjs - json axiom-types (0.1.1) descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) @@ -62,7 +61,7 @@ GEM bullet (5.0.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.9.0) - byebug (8.2.1) + byebug (8.2.2) chart-js-rails (0.0.9) railties (> 3.1) chronic (0.10.2) @@ -70,9 +69,9 @@ GEM activesupport (>= 3.0) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) - codeclimate-engine-rb (0.1.0) + codeclimate-engine-rb (0.3.1) virtus (~> 1.0) - coderay (1.1.0) + coderay (1.1.1) coercible (1.0.0) descendants_tracker (~> 0.0.1) coffee-rails (4.1.1) @@ -86,7 +85,7 @@ GEM concurrent-ruby (1.0.0) connection_pool (2.2.0) curb (0.8.8) - dalli (2.7.5) + dalli (2.7.6) debug_inspector (0.0.2) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) @@ -100,7 +99,7 @@ GEM devise_token_auth (0.1.37) devise (> 3.5.2, < 4.1) rails (< 6) - dspace_rest_client (2.2.2) + dspace_rest_client (2.2.4) activesupport (~> 4.2, >= 4.2.0) faraday (~> 0.9.2) json (~> 1.8, >= 1.8.3) @@ -142,7 +141,7 @@ GEM multi_xml (>= 0.5.2) i18n (0.7.0) ice_nine (0.11.2) - jbuilder (2.4.0) + jbuilder (2.4.1) activesupport (>= 3.0.0, < 5.1) multi_json (~> 1.2) jquery-rails (4.1.0) @@ -167,7 +166,7 @@ GEM nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) - mime-types (2.99) + mime-types (2.99.1) mimemagic (0.3.0) mina (0.3.8) open4 (~> 1.3.4) @@ -182,13 +181,13 @@ GEM mini_portile2 (~> 2.0.0.rc2) open4 (1.3.4) orm_adapter (0.5.0) - paperclip (4.3.3) + paperclip (4.3.5) activemodel (>= 3.2.0) activesupport (>= 3.2.0) cocaine (~> 0.5.5) mime-types mimemagic (= 0.3.0) - parser (2.3.0.2) + parser (2.3.0.6) ast (~> 2.2) pg (0.18.4) private_attr (1.1.0) @@ -231,11 +230,11 @@ GEM rake (10.5.0) rake-compiler (0.9.5) rake - rdoc (4.2.1) + rdoc (4.2.2) json (~> 1.4) redis (3.2.2) - reek (3.9.1) - codeclimate-engine-rb (~> 0.1.0) + reek (3.10.1) + codeclimate-engine-rb (~> 0.3.1) parser (~> 2.3) private_attr (~> 1.1) rainbow (~> 2.0) @@ -249,15 +248,15 @@ GEM rmagick (2.15.4) rsolr (1.0.13) builder (>= 2.1.2) - ruby_parser (3.7.3) + ruby_parser (3.8.1) sexp_processor (~> 4.1) - rubycritic (2.7.0) + rubycritic (2.7.1) colorize flay (= 2.6.1) flog (= 4.3.2) launchy (= 2.4.3) parser (~> 2.3) - reek (= 3.9.1) + reek (= 3.10.1) virtus (~> 1.0) sass (3.4.21) sass-rails (5.0.4) @@ -269,13 +268,13 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) - searchkick (1.1.2) + searchkick (1.2.1) activemodel elasticsearch (>= 1) hashie select2-rails (4.0.1) thor (~> 0.14) - sexp_processor (4.6.1) + sexp_processor (4.7.0) shoulda (3.5.0) shoulda-context (~> 1.0, >= 1.0.1) shoulda-matchers (>= 1.4.1, < 3.0) @@ -295,7 +294,7 @@ GEM slim (3.0.6) temple (~> 0.7.3) tilt (>= 1.3.3, < 2.1) - spring (1.6.2) + spring (1.6.3) sprockets (3.5.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) diff --git a/app/assets/javascripts/management.js b/app/assets/javascripts/management.js index 47fb767729d14615bbb80b9a64985b852b94e531..d6599d4ff51f5649c6c1eab9f427e63a47250a9b 100644 --- a/app/assets/javascripts/management.js +++ b/app/assets/javascripts/management.js @@ -19,8 +19,14 @@ //= require locastyle //= require turbolinks //= require_tree ./management + + var teachers, curators, admins; var visualised,non_visualised; +var n_complaints; +var complaints = []; +var complaints_names = []; + $(document).ready(function(){ if (document.getElementById("lobject") !== null) { visualised = document.getElementById("lobject").value; @@ -35,13 +41,16 @@ $(document).ready(function(){ var data_users = dataUsers(teachers,curators,admins); } - if(document.getElementById("lcomplaints") != null) { + if(document.getElementById("n_complaints") != null) { + + n_complaints = document.getElementById("n_complaints").value; + + for (i = 0; i < n_complaints; i++) { + complaints[i] = document.getElementById("complaints[" + i + "]").value; + complaints_names[i] = document.getElementById("complaints_names[" + i + "]").value; + } - false_user = document.getElementById("lcomplaints").value; - agressive_user = document.getElementById("lcomplaints_false").value; - offensive_object = document.getElementById("lcomplaints_offensive").value; - violates_copyright = document.getElementById("lcomplaints_violates").value; - var data_complaints = dataComplaints(false_user,agressive_user,offensive_object,violates_copyright); + var data_complaints = dataComplaints(complaints, complaints_names, n_complaints); } if (document.getElementById("lcollection") !== null) { diff --git a/app/assets/javascripts/management/complaints.js b/app/assets/javascripts/management/complaints.js index c86edd8190206abdae0a338a3a79534d81c798c9..987961aefd83b59d35d78266cfd58f031d72667f 100644 --- a/app/assets/javascripts/management/complaints.js +++ b/app/assets/javascripts/management/complaints.js @@ -3,38 +3,37 @@ //confurações dos gráficos de linha //mais infos: www.chartjs.org/docs/ +function increase_brightness(hex, percent){ + // strip the leading # if it's there + hex = hex.replace(/^\s*#|\s*$/g, ''); + + // convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF` + if(hex.length == 3){ + hex = hex.replace(/(.)/g, '$1$1'); + } + + var r = parseInt(hex.substr(0, 2), 16), + g = parseInt(hex.substr(2, 2), 16), + b = parseInt(hex.substr(4, 2), 16); + + return '#' + + ((0|(1<<8) + r + (256 - r) * percent / 100).toString(16)).substr(1) + + ((0|(1<<8) + g + (256 - g) * percent / 100).toString(16)).substr(1) + + ((0|(1<<8) + b + (256 - b) * percent / 100).toString(16)).substr(1); +} //var visual = document.getElementById("object").value; //alert(visual); -function dataComplaints(false_user,agressive_user,offensive_object,violates_copyright) { - var data = [ - { - value: false_user, - color:"#68F000", - highlight: "#a9ff67", - label: "Usuários Falsos" - }, - { - value: agressive_user, - color: "#F55858", - highlight: "#FC8787", - label: "Usuários Ofensivos/Agressivos" - }, - { - value: offensive_object, - color: "#F9D60A", - highlight: "#fbe357", - label: "Objetos contém conteúdo Ofensivo/Abusivo" - }, - { - value: violates_copyright, - color: "#46BFBD", - highlight: "#5AD3D1", - label: "Objeto viola direitos Autorais" - }, - - ]; +function dataComplaints(complaints,complaints_names, n) { + + var data = []; + + for(i = 0; i < n; i++) { + var color = "#"+((1<<24)*Math.random()|0).toString(16); + var color_highlight = increase_brightness(color,20); + data[i] = {value: complaints[i], color: color, highlight: color_highlight, label: complaints_names[i]}; + } return data; } diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index 016b91af4101f0baa9989041473261052bee4d9a..b2874b35e7367955e8bc326c01e715dd92b0ca8b 100644 --- a/app/controllers/learning_objects_controller.rb +++ b/app/controllers/learning_objects_controller.rb @@ -12,8 +12,8 @@ class LearningObjectsController < ApplicationController # GET /learning_objects/1 # GET /learning_objects/1.json def show - @liked = !@learning_object.likes.where(user: current_user).blank? if user_signed_in? - @reviews = Review.includes(:user).where(reviewable: @learning_object) + @liked = !@learning_object.liked?(current_user) if user_signed_in? + @reviews = Review.where(reviewable: @learning_object) end # GET /learning_objects/new @@ -21,7 +21,7 @@ class LearningObjectsController < ApplicationController @learning_object = LearningObject.new @school_levels = ['Educação Infantil', 'Ensino Fundamental', 'Ensino Médio'] @topics = Topic.defaults - @types = LearningObject.object_types + @types = ObjectType.all @languages = Language.all end @@ -74,7 +74,7 @@ class LearningObjectsController < ApplicationController def like if @learning_object.liked? current_user @learning_object.dislike current_user - else + elseg @learning_object.like current_user end diff --git a/app/controllers/management/complaint_reasons_controller.rb b/app/controllers/management/complaint_reasons_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..36d6c89f52849910ba6faad486d42455f032b876 --- /dev/null +++ b/app/controllers/management/complaint_reasons_controller.rb @@ -0,0 +1,65 @@ +class Management::ComplaintReasonsController < ManagementController + + before_action :set_complaint_reason, only: [:destroy, :update, :edit] + + def show + end + + def index + @complaint_reasons = ComplaintReason.all + end + + + def new + @complaint_reason = ComplaintReason.new + end + + def create + @complaint_reason = ComplaintReason.new(complaint_reason_params) + + respond_to do |format| + if @complaint_reason.save + format.html { redirect_to management_complaint_reasons_path } + else + format.html { render :new } + end + end + end + + + def destroy + ComplaintReason.destroy @complaint_reason + + respond_to do |format| + format.html { redirect_to :back, notice: 'Razão de denúncia excluÃda com sucesso.' } + end + + end + + def edit + end + + + def update + respond_to do |format| + if @complaint_reason.save + format.html { redirect_to management_complaint_reasons_path } + else + format.html { render :new } + end + end + end + + + + private + + def set_complaint_reason + @complaint_reason = ComplaintReason.find params[:id] + end + + def complaint_reason_params + params.require(:complaint_reason).permit(:reason) + end + +end diff --git a/app/controllers/management/complaints_controller.rb b/app/controllers/management/complaints_controller.rb index cbfeefcd732eb8db0361ccb6debf23e79857e9c5..25f54e9b58a37b721136fe292e49336487c85223 100644 --- a/app/controllers/management/complaints_controller.rb +++ b/app/controllers/management/complaints_controller.rb @@ -1,7 +1,7 @@ class Management::ComplaintsController < ManagementController before_action :set_complaint, only: :destroy def index - @complaints = Complaint.all + @complaints = Complaint.includes(:complaint_reason, :complaintable, :user) @date = params[:period] @date_limit = case @date.to_i @@ -21,7 +21,9 @@ class Management::ComplaintsController < ManagementController -DateTime::Infinity.new end @complaints_in_period = @complaints.select{ |complaint| complaint.created_at >= @date_limit} + @n_complaints_in_period = @complaints_in_period.size @complaints_objs = @complaints_in_period.uniq{|x| x.complaintable.name}.size + @complaints_in_period = Kaminari.paginate_array(@complaints_in_period).page(params[:page]).per(25) end def suspend_object diff --git a/app/controllers/management/statistics_controller.rb b/app/controllers/management/statistics_controller.rb index 09e45aa093263bbc27b98370c37418554c570f8e..8695e54f39307c5e525f51cdf81e192b515e423a 100644 --- a/app/controllers/management/statistics_controller.rb +++ b/app/controllers/management/statistics_controller.rb @@ -39,7 +39,7 @@ class Management::StatisticsController < ManagementController @complaints = Complaint.all @n_complaints = Complaint.count @complaints_objs = @complaints.map{|complaint| complaint.complaintable.name}.inject(Hash.new(0)) { |h,e| h[e] += 1; h } - @complaints_per_message = Complaint.group(:complaint_reason_id).count + @complaints_per_message = Complaint.group(:complaint_reason).count.reduce({}){ |hash, (k, v)| hash.merge( k.reason => v ) } end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 3b374228aab799a0fd298d23d90e8f780c152742..0ebc1032e2b3e8ddef500ab88cbd26c5da225ce4 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -3,7 +3,7 @@ class WelcomeController < ApplicationController def index @carousel = Carousel.all || [] - @highlights = LearningObject.order(:score).limit(6) + @highlights = LearningObject.limit(6) end def faq diff --git a/app/models/complaint_reason.rb b/app/models/complaint_reason.rb index 52fcbab028babde99c0b5ad2b127cc6fcdf489dc..90fd5d0f19af50e6f947fe89ef29153f2569c94d 100644 --- a/app/models/complaint_reason.rb +++ b/app/models/complaint_reason.rb @@ -1,5 +1,6 @@ class ComplaintReason < ActiveRecord::Base - has_many :complaints + has_many :complaints, dependent: :destroy validates_presence_of :reason + end diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index 00f79988219c5bb3d431505aee32b5feee6025ab..65f009aa4309ecbdb4dce118c0ae8942f1d16601 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -13,23 +13,23 @@ class LearningObject < ActiveRecord::Base belongs_to :publisher, polymorphic: true belongs_to :language + belongs_to :object_type validates_presence_of :name, :id_dspace validates_uniqueness_of :id_dspace - scope :object_types, -> { group(:object_type).count.reject { |type, frequency| type.blank? }.map { |type, frequency| type } } - searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author, :object_type] + default_scope { includes(:object_type).order(:score) } + def search_data { name: name, description: description, author: author, - object_type: object_type, + object_type: object_type.name, score: score, published_at: published_at, - # publisher_id: publisher.id, topics_name: topics.map(&:name) } end diff --git a/app/models/object_type.rb b/app/models/object_type.rb new file mode 100644 index 0000000000000000000000000000000000000000..7121494df78e71446136fce7a03f4d9b9c578af8 --- /dev/null +++ b/app/models/object_type.rb @@ -0,0 +1,5 @@ +class ObjectType < ActiveRecord::Base + has_many :learning_objects + + validates :name, presence: true +end \ No newline at end of file diff --git a/app/models/review.rb b/app/models/review.rb index ee50b70933e1d486cd18c0023cca2ccd2fec0cc5..5c656973ebb39b6dc1e9143c4e5cbab4a30e4421 100644 --- a/app/models/review.rb +++ b/app/models/review.rb @@ -1,18 +1,18 @@ class Review < ActiveRecord::Base belongs_to :reviewable, polymorphic: true - belongs_to :user has_many :review_ratings, dependent: :destroy has_many :ratings, through: :review_ratings - has_many :rates, dependent: :destroy validates_presence_of :user, :reviewable - validates :reviewable_type, inclusion: { in: %w(LearningObject Collection), message: '%{value} is not a valid reviewable type!' } + validates :reviewable_type, inclusion: {in: %w(LearningObject Collection), message: '%{value} is not a valid reviewable type!'} + + default_scope { includes(:user) } def rating_values - review_ratings.includes(:rating).map { |r| { rating: r.rating, value: r.value } } + review_ratings.includes(:rating).map { |r| {rating: r.rating, value: r.value} } end def rating_average @@ -21,9 +21,7 @@ class Review < ActiveRecord::Base def rates_percentage return false if rates.count < 5 - approved = rates.where(approves: true).count - (approved.to_f / rates.count.to_f) * 100 end diff --git a/app/services/autocomplete_service.rb b/app/services/autocomplete_service.rb deleted file mode 100644 index 8aefd38cceaa328dd24dd495bacc76bfeb86b5f5..0000000000000000000000000000000000000000 --- a/app/services/autocomplete_service.rb +++ /dev/null @@ -1,11 +0,0 @@ -class AutocompleteService - - def initialize(url="http://localhost",port=4242) - @url = url - @port = port - end - - def query(query) - return open( "#{@url}:#{@port}?q=#{query.downcase}" ).read - end -end diff --git a/app/services/institutions_importer.rb b/app/services/institutions_importer.rb new file mode 100644 index 0000000000000000000000000000000000000000..2dc9a2fe5e90af8791d0745a204b91c46fee2214 --- /dev/null +++ b/app/services/institutions_importer.rb @@ -0,0 +1,29 @@ +class InstitutionsImporter + + + def initialize items + @items = items + @@institutions = {} + end + + + def import + + + @items.each do |learning_object| + institution_name = learning_object.get_metadata_values_of("dc.creator").first + next if institution_exist? institution_name || institution_name.nil? + @@institutions[institution_name] = Institution.where(name: institution_name).new + end + + Institution.import @@institutions.values + + end + + private + + def institution_exist? institution_name + Institution.exists? name: institution_name || !@@institutions[institution_name].nil? + end + +end diff --git a/app/services/learning_object_relations.rb b/app/services/learning_object_relations.rb deleted file mode 100644 index 4e1976cdeca9821660a51ba7212d8500cdceceeb..0000000000000000000000000000000000000000 --- a/app/services/learning_object_relations.rb +++ /dev/null @@ -1,13 +0,0 @@ -class LearningObjectRelations - - def parse_topics values - topics = [] - values.compact! - values.each do |value| - topics = value.split('::') - end - topics - end - - -end diff --git a/app/services/topics_importer.rb b/app/services/topics_importer.rb new file mode 100644 index 0000000000000000000000000000000000000000..1acf80432b5c40bc85c4ab2b7efd91db22467fd2 --- /dev/null +++ b/app/services/topics_importer.rb @@ -0,0 +1,79 @@ +class TopicsImporter + + + def initialize items + @items = items + @@topics = {} + @@topics_relations = [] + end + + def import + + relations = [] + + @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| + + 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 + @@topics[topic_name] = topic + + end + separate_relations() + end + + Topic.import @@topics.values + import_topics_relations() + + end + + + private + + def create_relations parent_name, child_name + @@topics_relations.push(parent_name) + @@topics_relations.push(child_name) + end + + def separate_relations + @@topics_relations.push nil + end + + def import_topics_relations + + relations = [] + + @@topics_relations.each_with_index do |relation, i| + 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 + relations.push TopicRelationship.where(parent_id: parent_id, child_id: child_id ).new + end + end + end + + TopicRelationship.import relations + + end + + def parse_topics values + topics = [] + values.compact! + values.each do |value| + topics = value.split('::') + end + topics.map{|topic| topic.strip} + end + + def topic_exists? (topic_name) + Topic.exists? name: topic_name || !@@topics[topic_name].nil? + end + +end diff --git a/app/views/management/complaint_reasons/_form.html.erb b/app/views/management/complaint_reasons/_form.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..07a08e4ec563ec28e36df56967ef6e5f656b169e --- /dev/null +++ b/app/views/management/complaint_reasons/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_for([:management, @complaint_reason], html: {class: 'ls-form row'}) do |f| %> + + <% if @complaint_reason.errors.any? %> + <div class="ls-alert-danger"> + <h2><%= pluralize(@complaint_reason.errors.count, "erro") %> <%= "happened".pluralize(@complaint_reason.errors.count) %>:</h2> + <ul> + <% @complaint_reason.errors.full_messages.each do |message| %> + <li><%= message %></li> + <% end %> + </ul> + </div> + <% end %> + + <fieldset> + <label class="ls-label col-md-3"> + <b class="ls-label-text">Razão</b> + <p>Digite a razão</p> + <%= f.text_field :reason, {required: true} %> + </label> + </fieldset> + + <div class="ls-actions-btn"> + <button class="ls-btn">Salvar</button> + <%= link_to "Cancelar", management_complaint_reasons_path,class: "ls-btn-danger"%> + </div> + +<% end %> diff --git a/app/views/management/complaint_reasons/edit.html.erb b/app/views/management/complaint_reasons/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..58e8ac702172633a5d1ca36512c73a221ea311e5 --- /dev/null +++ b/app/views/management/complaint_reasons/edit.html.erb @@ -0,0 +1,7 @@ +<h1 class="ls-title-intro ls-ico-star">Razões</h1> + +<ol class="ls-breadcrumb"> + <li><%= link_to 'Razões', management_complaint_reason_path %></li> +</ol> + +<%= render 'form' %> diff --git a/app/views/management/complaint_reasons/index.html.erb b/app/views/management/complaint_reasons/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..ccd43ae15366b0ca8930b0941dc11c613baefbfe --- /dev/null +++ b/app/views/management/complaint_reasons/index.html.erb @@ -0,0 +1,26 @@ +<h1 class="ls-title-intro ls-ico-bullhorn">Denúncias</h1> + +<h2 class="ls-title-4">Razões das Denúncias</h2> + + +<div class="ls-clearfix"></div> + +<% @complaint_reasons.each do |complaint| %> +<div class="ls-list"> + <header class="ls-list-header"> + <div class="ls-list-title col-md-9"> + <a href="#" ><%= complaint.reason %></a> + </div> + <div class="col-md-3 ls-txt-right"> + <%= link_to 'Modificar', edit_management_complaint_reason_path(complaint), class:'ls-btn-primary ls-ico-cog' %> + <%= link_to 'Excluir', management_complaint_reason_path(id: complaint.id), {method: :delete, data: {confirm: 'Tem certeza que deseja excluir esta razão de denúncia?'}, title: 'Excluir', class: 'ls-btn ls-btn-sm', role: 'button'} %> + </div> + </header> +</div> +<% end %> + +<%= link_to 'Nova Razão', new_management_complaint_reason_path, title: 'Excluir', class: 'ls-btn ls-btn-sm', role: 'button' %> + + + +</div> diff --git a/app/views/management/complaint_reasons/new.html.erb b/app/views/management/complaint_reasons/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..db339872fa0efaf2b92dbbbcf678d033e1e710bb --- /dev/null +++ b/app/views/management/complaint_reasons/new.html.erb @@ -0,0 +1,6 @@ +<h1 class="ls-title-intro ls-ico-star">Razão</h1> + +<ol class="ls-breadcrumb"> +</ol> + +<%= render 'form' %> diff --git a/app/views/management/complaints/index.html.erb b/app/views/management/complaints/index.html.erb index c7cbec1e814de115bdb55c82e49241a1d774b129..a2d9d0069dfec0d52c350396764acc1d3083aba2 100644 --- a/app/views/management/complaints/index.html.erb +++ b/app/views/management/complaints/index.html.erb @@ -32,7 +32,7 @@ <div class="row"> <div class="col-md-6 col-sm-6"><p>Número de vezes que os usuários marcaram objetos educacionais como spam.</p></div> <div class="col-md-6 col-sm-6"> - <p class="ls-float-right ls-float-none-xs">PerÃodo selecionado: <strong>últimos 30 dias</strong></p></div> + <p class="ls-float-right ls-float-none-xs">PerÃodo selecionado: <strong><%= @date_limit %></strong></p></div> </div> <div class="ls-clearfix"></div> @@ -46,7 +46,7 @@ <h6 class="ls-title-4">Total de denúncias</h6> </div> <div class="ls-box-body"> - <strong><%= @complaints_in_period.size %></strong> + <strong><%= @n_complaints_in_period %></strong> </div> </div> </div> @@ -67,7 +67,7 @@ <div class="ls-tabs-container" id="awesome-tab-content"> <div id="infoAll" class="ls-tab-content" role="tabpanel" style="display: block;"> - <% (@complaints.sort{|x,y| x.created_at <=> y.created_at}.reverse.uniq{ |x| x.complaintable.name}).each do |complaint| %> + <% (@complaints_in_period.sort{|x,y| x.created_at <=> y.created_at}.reverse.uniq{ |x| x.complaintable.name}).each do |complaint| %> <% if Date.parse(complaint.created_at.to_s) >= @date_limit %> <div class="ls-list"> <header class="ls-list-header"> @@ -76,12 +76,12 @@ <% if complaint.complaintable.state == 'suspended' %> <a href="#" class="ls-tag-danger">Objeto Suspenso</a> <% end %> - <small><%= @complaints.select{ |x| x.complaintable.name == complaint.complaintable.name}.map{|x| x.reason }.each_with_object(Hash.new(0)){ |frequency,message| message[frequency] += 1 }.sort_by{ |k,v| v }.reverse.each{|x| x}.map{ |k,v| "#{k}(#{v})"}.join(",")%></small> + <small><%= @complaints_in_period.select{ |x| x.complaintable.name == complaint.complaintable.name}.map{|x| x.reason }.each_with_object(Hash.new(0)){ |frequency,message| message[frequency] += 1 }.sort_by{ |k,v| v }.reverse.each{|x| x}.map{ |k,v| "#{k}(#{v})"}.join(",")%></small> <div data-ls-module="collapse" data-target="#<%= complaint.complaintable.id %>" class="ls-collapse "> <a href="#" class="ls-collapse-header"><h5 class="ls-collapse-title"><strong>Descrições</strong></h5></a> <div class="ls-collapse-body" id="<%= complaint.complaintable.id %>"> - <% @complaints.sort {|left, right| left.description.length <=> right.description.length}.reverse.select{ |x| x.complaintable.name == complaint.complaintable.name }.each do |complaint_description| %> + <% @complaints_in_period.sort {|left, right| left.description.length <=> right.description.length}.reverse.select{ |x| x.complaintable.name == complaint.complaintable.name }.each do |complaint_description| %> <table class="ls-table ls-no-hover ls-table-striped"> <thead> <tr> @@ -146,4 +146,8 @@ </div> +<div class="ls-pagination-filter"> + <%= paginate @complaints_in_period, :theme => 'management_theme', :window => 2 %> +</div> + </div> diff --git a/app/views/management/statistics/complaints.html.erb b/app/views/management/statistics/complaints.html.erb index 5542a96994f179a70b0df5432b7865aaf67c0797..cff40f44d4a74f771b42cb2af2513d78890d6c51 100644 --- a/app/views/management/statistics/complaints.html.erb +++ b/app/views/management/statistics/complaints.html.erb @@ -27,7 +27,7 @@ <div class="col-sm-6 col-md-6"> <div class="ls-box"> <h6 class="ls-title-4"><%= complaint.reason %></h6> - <strong class="ls-color-theme"><%= @complaints_per_message[complaint.complaint_reason_id] %></strong> + <strong class="ls-color-theme"><%= @complaints_per_message[complaint.reason] %></strong> </div> </div> @@ -37,10 +37,14 @@ </div> </div> -<input type="hidden" id="lcomplaints" value="<%= @complaints_per_message[1] %>"/> -<input type="hidden" id="lcomplaints_false" value="<%= @complaints_per_message[2] %>"/> -<input type="hidden" id="lcomplaints_offensive" value="<%= @complaints_per_message[3] %>"/> -<input type="hidden" id="lcomplaints_violates" value="<%= @complaints_per_message[4] %>"/> + +<input type="hidden" id=<%= "n_complaints" %> value="<%= @complaints_per_message.keys.size %>"/> +<% @complaints.each_with_index do |complaint,i| %> + <input type="hidden" id=<%= "complaints[#{i}]" %> value="<%= @complaints_per_message[complaint.reason] %>"/> + <input type="hidden" id=<%= "complaints_names[#{i}]" %> value="<%= complaint.reason %>"/> +<% end %> + + <div align="right" > </div> diff --git a/app/views/management/users/admins.html.erb b/app/views/management/users/admins.html.erb index 8a6b2a1e5ed2567552b9dbb08ce54208d33d643d..a5a4f104bd0482a8700434bcffd01835ff6437be 100644 --- a/app/views/management/users/admins.html.erb +++ b/app/views/management/users/admins.html.erb @@ -64,10 +64,10 @@ <%= c.email %> </td> <td class="ls-txt-right ls-regroup"> - <%= link_to 'Administrar', edit_management_user_path(c), {class: 'ls-btn-primary ls-ico-cog', aria: {expanded: false}, role: 'combobox'} %> - <%= link_to 'Excluir', management_user_path(c), {method: :delete, data: {confirm: 'Tem certeza que deseja excluir?'}, title: 'Apagar usuário', class: 'ls-btn-danger ls-ico-close', role: 'option'} %> + <%= link_to 'Administrar', edit_management_user_path(c), {class: 'ls-btn-primary', aria: {expanded: false}, role: 'combobox'} %> + <%= link_to 'Excluir', management_user_path(c), {method: :delete, data: {confirm: 'Tem certeza que deseja excluir?'}, title: 'Apagar usuário', class: 'ls-btn-danger', role: 'option'} %> <div data-ls-module="dropdown" class="ls-dropdown ls-pos-right"> - <a href="#" class="ls-btn ls-ico-list" aria-expanded="false" role="combobox">NÃvel</a> + <a href="#" class="ls-btn" aria-expanded="false" role="combobox">NÃvel</a> <ul class="ls-dropdown-nav" aria-hidden="true"> <% Role.all.each do |r| %> <% nome = translate_role(r.name) %> diff --git a/app/views/management/users/curators.html.erb b/app/views/management/users/curators.html.erb index 46bd8c0e99bda6721f0232240617c424a13e874b..c0d0b5d24b3c4111eb3796dab4c0e0fc097b5911 100644 --- a/app/views/management/users/curators.html.erb +++ b/app/views/management/users/curators.html.erb @@ -64,10 +64,10 @@ <%= c.email %> </td> <td class="ls-txt-right ls-regroup"> - <%= link_to 'Administrar', edit_management_user_path(c), {class: 'ls-btn-primary ls-ico-cog', aria: {expanded: false}, role: 'combobox'} %> - <%= link_to 'Excluir', management_user_path(c), {method: :delete, data: {confirm: 'Tem certeza que deseja excluir?'}, title: 'Apagar usuário', class: 'ls-btn-danger ls-ico-close', role: 'option'} %> + <%= link_to 'Administrar', edit_management_user_path(c), {class: 'ls-btn-primary', aria: {expanded: false}, role: 'combobox'} %> + <%= link_to 'Excluir', management_user_path(c), {method: :delete, data: {confirm: 'Tem certeza que deseja excluir?'}, title: 'Apagar usuário', class: 'ls-btn-danger', role: 'option'} %> <div data-ls-module="dropdown" class="ls-dropdown ls-pos-right"> - <a href="#" class="ls-btn ls-ico-list" aria-expanded="false" role="combobox">NÃvel</a> + <a href="#" class="ls-btn" aria-expanded="false" role="combobox">NÃvel</a> <ul class="ls-dropdown-nav" aria-hidden="true"> <% Role.all.each do |r| %> <% nome = translate_role(r.name) %> diff --git a/app/views/management/users/index.html.erb b/app/views/management/users/index.html.erb index 14d53767fbf23e56b9fef5f6652d7a74e880dad8..a2d275d8d85fac0371f2c2a2439e0240d486b07e 100644 --- a/app/views/management/users/index.html.erb +++ b/app/views/management/users/index.html.erb @@ -66,10 +66,10 @@ </td> <td class="ls-txt-right ls-regroup"> - <%= link_to 'Administrar', edit_management_user_path(u), {class: 'ls-btn-primary ls-ico-cog', aria: {expanded: false}, role: 'combobox'} %> - <%= link_to 'Excluir', management_user_path(u), {method: :delete, data: {confirm: 'Tem certeza que deseja excluir?'}, title: 'Apagar usuário', class: 'ls-btn-danger ls-ico-close', role: 'option'} %> + <%= link_to 'Administrar', edit_management_user_path(u), {class: 'ls-btn-primary', aria: {expanded: false}, role: 'combobox'} %> + <%= link_to 'Excluir', management_user_path(u), {method: :delete, data: {confirm: 'Tem certeza que deseja excluir?'}, title: 'Apagar usuário', class: 'ls-btn-danger', role: 'option'} %> <div data-ls-module="dropdown" class="ls-dropdown ls-pos-right"> - <a href="#" class="ls-btn ls-ico-list" aria-expanded="false" role="combobox">NÃvel</a> + <a href="#" class="ls-btn" aria-expanded="false" role="combobox">NÃvel</a> <ul class="ls-dropdown-nav"> <% @user = u %> <% Role.all.each do |r| %> diff --git a/app/views/reviews/_rating.html.erb b/app/views/reviews/_rating.html.erb index fcfd9cc1a01d844d12b10a5417339c6b20f48257..f2a4b9bc4778070517d2f2700168b0335a7077e4 100644 --- a/app/views/reviews/_rating.html.erb +++ b/app/views/reviews/_rating.html.erb @@ -7,7 +7,7 @@ <i data-toggle="tooltip" data-placement="right" title="<%= rate.description %>"><%= rate.name %></i> </div> - <div class="col-md-6"> + <div class="col-md-6" style="width:180px"> <fieldset class="rating"> <% Array(1..5).reverse_each do |index| %> <% checked = (value == index) ? true : false %> diff --git a/app/views/reviews/_review.html.erb b/app/views/reviews/_review.html.erb index ef5ece7f251370cca7bb14527beac0e6665c716a..fd549f0dbfd37772bfe972526babd3955ce2f15f 100644 --- a/app/views/reviews/_review.html.erb +++ b/app/views/reviews/_review.html.erb @@ -1,45 +1,87 @@ -<div class="row"> - <div class="col-md-4"> - <%= link_to rate_review_path(id: review.id, approves: true), class: 'btn btn-default', method: :post, remote: true do %> - <span class="glyphicon glyphicon-menu-up" aria-hidden="true"></span> - <% end %> +<div class="container well"> + <div class="row"> + + <div class="col-md-12"> + + + + <div class="media-left"> + <img class="user-image-small" src="<%= review.user.avatar.url(:thumb) %>"/> + <%= review.user.name %> + </div> + + <div class="media-right"> + <% if review.user == current_user %> + <%= link_to 'excluir avaliação', review_path(review), method: :delete, data: { confirm: 'Você tem certeza?' }, class: 'btn btn-danger' %> + <% end %> + + <span class="text-right"> + <% if review.rates_percentage %> + <%= review.rates_percentage %>% aprovam esta avaliação (de <%= review.rates.count %> votos) + <% else %> + Esta avaliação não possui votos suficientes. + <% end %> + </span> + </div> + </br> + </div> - <%= link_to rate_review_path(id: review.id, approves: false), class: 'btn btn-default', method: :post, remote: true do %> - <span class="glyphicon glyphicon-menu-down" aria-hidden="true"></span> + + + </div> + + <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> <% end %> + </br> + </br> - <% if review.rates_percentage %> - <span><%= review.rates_percentage %>% aprovam esta avaliação (de <%= review.rates.count %> votos)</span> - <% else %> - <span>Esta avaliação não possui votos suficientes.</span> + <h1><%= review.rating_average %></h1> + </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> <% end %> - <br/><br/> + </br> + </div> + + <div class="col-md-4"> - <div class="media-left"> - <img class="user-image-small" src="<%= review.user.avatar.url(:thumb) %>"/> - <%= review.user.name %> - <% if review.user == current_user %> - <%= link_to 'excluir avaliação', review_path(review), method: :delete, data: { confirm: 'Você tem certeza?' }, class: 'btn btn-danger' %> - <% end %> - </div> <span> <% review.rating_values.each do |r| %> - <!-- <%#= rate[:name] %>: <%#= rate[:value] %> estrelas <br> --> <%= render 'reviews/rating', rate: r[:rating], value: r[:value], review_id: review.id %> <% end %> </span> - <span>Média das avaliações: <%= review.rating_average %></span> </div> - <div class="col-md-8"> - <b><%= review.name %></b><br> - <b>Comentário</b><br> - <%= review.description %><br> - <br> - <b>Pros</b><br> - <%= review.pros %><br> - <br> - <b>Contras</b><br> - <%= review.cons %><br><br/><br/> + <div class="col-md-7"> + + <div class="col-md-12"> + <b><%= review.name %></b> + </div> + + </br> + </br> + + <div class="col-md-12"> + <b>Comentário</b><br> + <%= review.description %> + </div> + + <div class="col-md-6"> + <b>Pros</b><br> + <%= review.pros %> + </div> + + + <div class="col-md-6"> + <b>Contras</b><br> + <%= review.cons %> + </div> + + + </div> </div> diff --git a/app/views/shared/management/_nav_menu.html.erb b/app/views/shared/management/_nav_menu.html.erb index da5517392b150b7b541e95184c36153c5530dd6d..142c107193eb73cc4d6695a40544fa343f5c0150 100644 --- a/app/views/shared/management/_nav_menu.html.erb +++ b/app/views/shared/management/_nav_menu.html.erb @@ -11,6 +11,7 @@ <li><%= link_to "Coleções", collections_management_statistics_path, class: 'ls-submenu-item' %></li> <li><%= link_to "Objetos", learning_objects_management_statistics_path, class: 'ls-submenu-item' %></li> <li><%= link_to "Acessos", accesses_management_statistics_path, class: 'ls-submenu-item' %></li> + <li><%= link_to "Denúncias", complaints_management_statistics_path, class: 'ls-submenu-item' %></li> </ul> </li> <li><%= link_to "Instituições", management_institutions_path, class: 'ls-ico-list2' %></li> @@ -22,7 +23,15 @@ <li><%= link_to "Administradores", admins_management_users_path, class: 'ls-submenu-item' %></li> </ul> </li> - <li><%= link_to "Denúncias", management_complaints_path, class: 'ls-ico-bullhorn' %> + + <li class="ls-submenu"> + <a href="#" class="ls-ico-bullhorn">Denúncias</a> + <ul role="menu"> + <li><%= link_to "Denúncias", management_complaints_path, class: 'ls-submenu-item' %> + <li><%= link_to "Razões", management_complaint_reasons_path, class: 'ls-submenu-item' %> + </ul> + </li> + <li> <%= link_to "Voltar ao Portal", root_path, class: 'ls-ico-chevron-left' %> </li> </ul> diff --git a/config/routes.rb b/config/routes.rb index 9c7b79d700469e89df8bab48ded3c51bb18f9c0e..668389642b64b537cd5763cf68e0d656330d2b94 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,8 @@ Rails.application.routes.draw do delete '/user/:user_id', as: :remove_user, action: :remove_user end end + + resources :complaint_reasons resources :highlights resources :carousels diff --git a/db/migrate/20160222145100_create_object_types.rb b/db/migrate/20160222145100_create_object_types.rb new file mode 100644 index 0000000000000000000000000000000000000000..74917748b4aa98e279ece1006f585a2e2c9d3db8 --- /dev/null +++ b/db/migrate/20160222145100_create_object_types.rb @@ -0,0 +1,7 @@ +class CreateObjectTypes < ActiveRecord::Migration + def change + create_table :object_types do |t| + t.string :name + end + end +end diff --git a/db/migrate/20160223123901_change_column_object_type_of_learning_objects.rb b/db/migrate/20160223123901_change_column_object_type_of_learning_objects.rb new file mode 100644 index 0000000000000000000000000000000000000000..9db85d2c171bf395d98011f9af85ca907f07d610 --- /dev/null +++ b/db/migrate/20160223123901_change_column_object_type_of_learning_objects.rb @@ -0,0 +1,6 @@ +class ChangeColumnObjectTypeOfLearningObjects < ActiveRecord::Migration + def change + remove_column :learning_objects, :object_type, :string + add_reference :learning_objects, :object_type + end +end diff --git a/db/seeds.rb b/db/seeds.rb index ee558cb63cf5a8044867d9f75b5f6fa2fe02e358..6de731e6b8f0c6cc3e49d9545d035885e470f8c5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -22,3 +22,4 @@ require_relative "seeds/complaints" require_relative "seeds/institutions" require_relative "seeds/languages" require_relative "seeds/ratings" +require_relative "seeds/object_types" diff --git a/db/seeds/object_types.rb b/db/seeds/object_types.rb new file mode 100644 index 0000000000000000000000000000000000000000..d1c6f89f31f1c591a8b7d0574fcda7b38f465e16 --- /dev/null +++ b/db/seeds/object_types.rb @@ -0,0 +1,9 @@ +ObjectType.create(name: 'Imagem') +ObjectType.create(name: 'Mapa') +ObjectType.create(name: 'Software Educacional') +ObjectType.create(name: 'Experimento prático') +ObjectType.create(name: 'Animação/simulação') +ObjectType.create(name: 'Texto') +ObjectType.create(name: 'Ãudio') +ObjectType.create(name: 'PDF') +ObjectType.create(name: 'Website externo') \ No newline at end of file diff --git a/lib/tasks/create_relations.rake b/lib/tasks/create_relations.rake deleted file mode 100644 index 33160b9ce2d2ee97070232f80d0b091d44efacc7..0000000000000000000000000000000000000000 --- a/lib/tasks/create_relations.rake +++ /dev/null @@ -1,80 +0,0 @@ -namespace :create_relations do - desc "Create relations" - - task :learning_object, [:log] => [:environment] do |t, args| - desc "Create LearningObject relations based on its metadata" - include Log::Logging - - args.with_defaults(:log => STDOUT) - - Log::Logging.logger = Log::DatabaseLogger.new(args.log) - logger.level = Log::DatabaseLogger::CREATE - - new_topics = {} - new_institutions = {} - relations = [] - relations_order = [] - - limit = 500 - offset = 0 - helper = LearningObjectRelations.new - - loop do - logger.info " --> Creating LearningObjects relations from #{offset} to #{offset+limit}" - - begin - learning_objects = LearningObject.limit(limit).offset(offset) - - rescue => e - logger.warn "Database error, going to sleep" - logger.error e - sleep(10.seconds) - next - else - break if learning_objects.empty? - - learning_objects.each do |learning_object| - lo_topics = helper.parse_topics ( learning_object.get_metadata_values_of "dc.subject.category" ) - institution_name = learning_object.get_metadata_values_of("dc.creator").first - - lo_topics.each do |topic_name| - unless Topic.exists?(name: topic_name) - new_topics[topic_name] ||= Topic.where(name: topic_name).new - new_topics[topic_name].learning_objects << learning_object - relations_order.push(topic_name) - end - end - - unless institution_name.nil? || Institution.exists?(name:institution_name) - new_institutions[institution_name] ||= Institution.where(name: institution_name).new - end - - relations_order.push nil - - end - end - offset += limit - end - - Institution.import new_institutions.values - logger.info " --> Institutions imported" - Topic.import new_topics.values - logger.info " --> Topics imported" - - relations_order.each_with_index do |relation, i| - unless relation.nil? || relations_order[i - 1].nil? - parent_id = Topic.find_by_name(relations_order[i - 1]).id - child_id = Topic.find_by_name(relation).id - unless TopicRelationship.exists?(parent_id: parent_id, child_id: child_id) || i == 0 - relations.push TopicRelationship.where(parent_id: parent_id, child_id: child_id ).new - end - end - end - - TopicRelationship.import relations - logger.info " --> TopicsRelations created" - logger.close - end - - -end diff --git a/lib/tasks/dbInfo.rake b/lib/tasks/dbInfo.rake deleted file mode 100644 index d72a12733a1ad713dee5af4b4354502e69c0d67a..0000000000000000000000000000000000000000 --- a/lib/tasks/dbInfo.rake +++ /dev/null @@ -1,203 +0,0 @@ -namespace :dbinfo do - desc "Database Information Tasks" - - task bitstreams_formats: :environment do - desc "List bitstreams formats" - - include Thumbnail::AcceptedFormats - - # Quantity of LearningObjects fetched on each iteration - limit = 1000 - # Starting point from where LearningObjects will be fetched - offset = 0 - - bitstreams_formats_hash = Hash.new - thumbnails_per_format_hash = Hash.new - - loop do - print "\r -> Analysing LearningObjects from #{offset} to #{offset+limit}" - - begin - # Get LearningObjects from OrientDB (from offset to offset+limit) - learning_objects = learning_object_repository.all_from_offset_to_limit(offset,limit) - rescue - # Sleeps for a while to wait database's recovery - sleep(30.seconds) - # Goes to next iteration to retry - next - else - # Terminate loop if there are no more LearningObjects - break if learning_objects.empty? - - learning_objects.each do |lo| - bitstream_filename = lo.get_bitstream_filename_of "ORIGINAL" - unless bitstream_filename.nil? - bitstream_format = File.extname(bitstream_filename) - - unless bitstreams_formats_hash[bitstream_format].nil? - bitstreams_formats_hash[bitstream_format] += 1 - else - bitstreams_formats_hash[bitstream_format] = 1 - end - - unless lo.thumbnail.empty? - unless thumbnails_per_format_hash[bitstream_format].nil? - thumbnails_per_format_hash[bitstream_format] += 1 - else - thumbnails_per_format_hash[bitstream_format] = 1 - end - end - - end - end - - offset += limit - end - end - - bitstreams_formats = bitstreams_formats_hash.sort_by {|key, value| value} - - puts "\n\n" - puts "---------------------------------------------------" - puts "------------- BITSTREAMS FORMATS LIST -------------" - puts "---------------------------------------------------" - puts "Format\t\tTotal\tAccepts?\tThumbnails" - puts "---------------------------------------------------" - bitstreams_formats.each do |key,value| - accepts_thumbnail = (accepted_formats.include? key or accepted_archive_formats.include? key) - total_thumbnails = (thumbnails_per_format_hash[key] or '-') - puts "#{key}\t\t#{value}\t#{accepts_thumbnail}\t\t#{total_thumbnails}" - end - puts "---------------------------------------------------" - puts "Format\t\tTotal\tAccepts?\tThumbnails" - puts "---------------------------------------------------" - - end - - task verify_duplicated_items: :environment do - desc "Verify duplicated items" - - # Quantity of LearningObjects fetched on each iteration - limit = 1000 - # Starting point from where LearningObjects will be fetched - offset = 0 - - lo_hash = Hash.new - - loop do - print "\r -> Analysing LearningObjects from #{offset} to #{offset+limit}" - - begin - # Get LearningObjects from OrientDB (from offset to offset+limit) - learning_objects = learning_object_repository.all_from_offset_to_limit(offset,limit) - rescue - # Sleeps for a while to wait database's recovery - sleep(30.seconds) - # Goes to next iteration to retry - next - else - # Terminate loop if there are no more LearningObjects - break if learning_objects.empty? - - learning_objects.each do |lo| - # Verify duplicity using LO's unique attributes - lo_key = encode_hash_from learning_object_unique_attributes(lo) - if lo_hash[lo_key].nil? - lo_hash[lo_key] = Array.new - end - lo_hash[lo_key] << lo.id - end - - offset += limit - end - end - - duplicated_lo = lo_hash.select {|key,value| value.length > 1} - - puts "\n\n" - puts "---------------------------------" - puts "----- DUPLICATED ITEMS LIST -----" - puts "---------------------------------" - puts "TOTAL CASES: #{duplicated_lo.length}" - puts "---------------------------------" - duplicated_lo.each do |key, value| - puts "#{value.to_s}" - end - puts "---------------------------------" - - end - - task verify_dead_bitstreams: :environment do - desc "Verify dead bitstreams" - - # Quantity of LearningObjects fetched on each iteration - limit = 1000 - # Starting point from where LearningObjects will be fetched - offset = 0 - - dead_bitstreams = Array.new - - loop do - print "\r -> Analysing LearningObjects from #{offset} to #{offset+limit}" - - begin - # Get LearningObjects from OrientDB (from offset to offset+limit) - learning_objects = learning_object_repository.all_from_offset_to_limit(offset,limit) - rescue - # Sleeps for a while to wait database's recovery - sleep(30.seconds) - # Goes to next iteration to retry - next - else - # Terminate loop if there are no more LearningObjects - break if learning_objects.empty? - - learning_objects.each do |lo| - bitstream_url = lo.get_bitstream_retrievelink_of "ORIGINAL" - unless bitstream_url.nil? - unless bitstream_url_is_alive bitstream_url - dead_bitstreams << {id: lo.id, url: bitstream_url} - end - end - end - - offset += limit - end - end - - puts "\n\n" - puts "---------------------------------" - puts "------ DEAD BITSTREAMS LIST -----" - puts "---------------------------------" - puts "TOTAL CASES: #{dead_bitstreams.length}" - puts "---------------------------------" - dead_bitstreams.each do |dead_bitstream| - puts "#{dead_bitstream[:id]} -> #{dead_bitstream[:url]}" - end - puts "---------------------------------" - - end - - private - - def bitstream_url_is_alive(url) - c = Curl::Easy.http_head(url){ |easy| - easy.follow_location = true - easy.ssl_verify_peer = false - easy.ssl_verify_host = false - } - c.status.eql? "200 OK" - end - - def learning_object_unique_attributes(lo) - unique_attributes = Array.new - unique_attributes << lo.metadata - unique_attributes << lo.bitstreams - unique_attributes.to_s - end - - def encode_hash_from(object) - Digest::SHA1.hexdigest object - end - -end diff --git a/lib/tasks/dspace.rake b/lib/tasks/dspace.rake deleted file mode 100644 index fbbd55194009fc82f8cef93d5ac89d680b83ac38..0000000000000000000000000000000000000000 --- a/lib/tasks/dspace.rake +++ /dev/null @@ -1,70 +0,0 @@ -require 'rainbow' - -namespace :dspace do - desc "Dspace tasks" - - task :import_items, [:log] => [:environment] do |t, args| - desc "Import DSpace items to LearningObject Repository" - - args.with_defaults(:log => STDOUT) - logger = Log::DatabaseLogger.new(args.log) - logger.level = Log::DatabaseLogger::CREATE - - # Quantity of items fetched on each iteration - limit = 500 - - # Start point from where items will be fetched - offset = 0 - - loop do - - logger.info " --> importing items from #{offset} to #{offset+limit}" - - begin - # Get items from dspace (from offset to offset+limit) - dspace_items = get_items_from_dspace(limit, offset, ['metadata', 'bitstreams']) - rescue => e - logger.warn "Database error, going to sleep" - logger.error e - # Sleeps for a while to wait database's recovery - sleep(10.seconds) - # Goes to next iteration to retry - next - else - # Terminate loop if there are no more items to import - break if dspace_items.empty? - - # continue if receive an error string - if dspace_items.is_a? String - logger.warn "Received a string instead of items: #{dspace_items}" - next - end - - # Increment offset, to get new items on next iteration - offset = offset + limit - - # Iterates through items - # Verifies if item is already on repository - # Initializes new LearningObjects - # and saves them on LearningObjects's repository - importer = Dspace::LearningObjectImporter.new(dspace_items) - importer.import - end - end - logger.close - end - - private - - def dspace_repository - DspaceService.create_client - end - - def get_items_from_dspace(limit, offset, expand=[]) - dspace_repository.items.all( - expand: expand.join(','), - limit: limit, offset: offset - ) - end - -end diff --git a/lib/tasks/fakeData.rake b/lib/tasks/fakeData.rake deleted file mode 100644 index 07f90f587c7cc4d7c781eb0b039ca14ca40a26be..0000000000000000000000000000000000000000 --- a/lib/tasks/fakeData.rake +++ /dev/null @@ -1,89 +0,0 @@ -namespace :fakedata do - desc "Fake data generation tasks" - - task generate_users: :environment do - desc "Generate fake Users" - - include RepositoriesProxy - - total_new_users = 50 - - (1..total_new_users).each do |i| - user = User.new( - :name => "User#{i}", - :email => "user#{i}@inf.ufpr.br", - :password => "1234567890", - :password_confirmation => "1234567890" - ) - user.save - end - end - - task generate_data: :environment do - desc "Generate fake user Likes/Views data" - - include RepositoriesProxy - - # Quantity of items fetched on each iteration - limit = 100 - - # Start point from where items will be fetched - offset = 0 - - users = User.all - - loop do - - begin - # Get items from dspace (from offset to offset+limit) - learning_objects = learning_object_repository.all_from_offset_to_limit(limit,offset) - rescue - # Sleeps for a while to wait database's recovery - sleep(30.seconds) - # Goes to next iteration to retry - next - else - # Terminate loop if there are no more items to import - break if learning_objects.empty? - - # Increment offset, to get new items on next iteration - offset = offset + limit - - learning_objects.each do |lo| - - users_views = [] - users_likes = [] - - users.each do |user| - # Randomize "Views" - if random_check(30) - users_views << user. id - # Randomize "Likes" - if random_check(70) - users_likes << user.id - end - end - end - - MassiveViewsCreatorWorker.perform_async(lo.id, users_views) - MassiveLikesCreatorWorker.perform_async(lo.id, users_likes) - - end - - end - - end - - end - - private - - def random_check(threshold) - if rand(1..100) <= threshold - return true - else - return false - end - end - -end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake new file mode 100644 index 0000000000000000000000000000000000000000..bd379c8b7d08b96c8e3cd1731dca01d4373c3a63 --- /dev/null +++ b/lib/tasks/import.rake @@ -0,0 +1,147 @@ +require 'rainbow' + +namespace :import do + desc "Portal MEC data importer" + + task :topics, [:log] => [:environment] do |t, args| + desc "Create Topics relations based on its metadata" + include Log::Logging + + args.with_defaults(:log => STDOUT) + + Log::Logging.logger = Log::DatabaseLogger.new(args.log) + logger.level = Log::DatabaseLogger::CREATE + + + # Quantity of items fetched on each iteration + limit = 500 + # Start point from where items will be fetched + offset = 0 + + loop do + logger.info " --> Creating Topics relations from #{offset} to #{offset+limit}" + + begin + # Get learning_objects (from offset to offset+limit) + learning_objects = LearningObject.limit(limit).offset(offset) + + rescue => e + logger.warn "Database error, going to sleep" + logger.error e + # Sleeps for a while to wait database's recovery + sleep(10.seconds) + # Goes to next iteration to retry + next + else + # Terminate loop if there are no more learning_objects to import + break if learning_objects.empty? + + importer = TopicsImporter.new (learning_objects) + importer.import + + end + offset += limit + end + logger.close + end + + + task :institutions, [:log] => [:environment] do |t, args| + desc "Create Institutions based on its metadata" + include Log::Logging + + args.with_defaults(:log => STDOUT) + + Log::Logging.logger = Log::DatabaseLogger.new(args.log) + logger.level = Log::DatabaseLogger::CREATE + + limit = 500 + offset = 0 + + loop do + logger.info " --> Creating Institutions from #{offset} to #{offset+limit}" + + begin + learning_objects = LearningObject.limit(limit).offset(offset) + + rescue => e + logger.warn "Database error, going to sleep" + logger.error e + sleep(10.seconds) + next + else + break if learning_objects.empty? + + importer = InstitutionsImporter.new (learning_objects) + importer.import + + end + offset += limit + end + + logger.info " --> Institutions imported" + logger.close + end + + task :learning_objects, [:log] => [:environment] do |t, args| + desc "Importing Learning Objects from Dspace items" + + args.with_defaults(:log => STDOUT) + logger = Log::DatabaseLogger.new(args.log) + logger.level = Log::DatabaseLogger::CREATE + + # Quantity of items fetched on each iteration + limit = 500 + + # Start point from where items will be fetched + offset = 0 + + loop do + + logger.info " --> importing items from #{offset} to #{offset+limit}" + + begin + # Get items from dspace (from offset to offset+limit) + dspace_items = get_items_from_dspace(limit, offset, ['metadata', 'bitstreams']) + rescue => e + logger.warn "Database error, going to sleep" + logger.error e + # Sleeps for a while to wait database's recovery + sleep(10.seconds) + # Goes to next iteration to retry + next + else + # Terminate loop if there are no more items to import + break if dspace_items.empty? + + # continue if receive an error string + if dspace_items.is_a? String + logger.warn "Received a string instead of items: #{dspace_items}" + next + end + + # Increment offset, to get new items on next iteration + offset = offset + limit + + # Iterates through items + # Verifies if item is already on repository + # Initializes new LearningObjects + # and saves them on LearningObjects's repository + importer = Dspace::LearningObjectImporter.new(dspace_items) + importer.import + end + end + logger.close + end + + private + + def get_items_from_dspace(limit, offset, expand=[]) + client = DspaceService.create_client + client.items.all( + expand: expand.join(','), + limit: limit, offset: offset + ) + end + +end diff --git a/lib/tasks/portalmec.rake b/lib/tasks/portalmec.rake new file mode 100644 index 0000000000000000000000000000000000000000..0e78ef764b2e7e2e59502231f2cd2522ea3905d5 --- /dev/null +++ b/lib/tasks/portalmec.rake @@ -0,0 +1,12 @@ +namespace :portalmec do + + desc 'setup initial environment' + task :setup do + Rake::Task['db:migrate:reset'].invoke + Rake::Task['db:seed'].invoke + Rake::Task['import:learning_objects'].invoke + Rake::Task['import:topics'].invoke + Rake::Task['import:institutions'].invoke + end + +end diff --git a/lib/tasks/thumbnail.rake b/lib/tasks/thumbnail.rake deleted file mode 100644 index 2381eb6ee51c94821bfeb001fdbceb429a66a560..0000000000000000000000000000000000000000 --- a/lib/tasks/thumbnail.rake +++ /dev/null @@ -1,49 +0,0 @@ -namespace :thumbnail do - - desc "Generate Thumbnails" - task :generate => :environment do - generate - end - - namespace :generate do - task :force => :environment do - generate(true) - end - end - - private - - def generate(force = false) - include RepositoriesProxy - - # Quantity of items fetched on each iteration - limit = 500 - - # Start point from where items will be fetched - offset = 0 - - loop do - - begin - # Get items from dspace (from offset to offset+limit) - items = learning_object_repository.all_from_offset_to_limit(offset,limit) - rescue - # Sleeps for a while to wait database's recovery - sleep(30.seconds) - # Goes to next iteration to retry - next - else - # Terminate loop if there are no more items to import - break if items.empty? - - items.each do |item| - ThumbnailGeneratorWorker.perform_async(item.id) if (item.thumbnail.blank? || force) - end - - # Increment offset, to get new items on next iteration - offset += limit - end - end - end - -end