From c1d673ea1a0b7bb3f88c8734140bd1dd4e4cc5f8 Mon Sep 17 00:00:00 2001 From: Mateus Rambo Strey <mars11@inf.ufpr.br> Date: Wed, 28 Oct 2015 10:10:18 -0200 Subject: [PATCH] replace subjects by highlights in main page --- app/assets/stylesheets/application/welcome.scss | 4 ++-- app/controllers/search_controller.rb | 4 ++-- app/controllers/welcome_controller.rb | 4 +--- .../orient_db/learning_object_repository.rb | 7 ++++++- app/views/welcome/index.html.erb | 11 +++++------ 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/assets/stylesheets/application/welcome.scss b/app/assets/stylesheets/application/welcome.scss index beafcb4b5..c52bb26f7 100644 --- a/app/assets/stylesheets/application/welcome.scss +++ b/app/assets/stylesheets/application/welcome.scss @@ -7,7 +7,7 @@ color: white; } -.mainpage-subjects, .mainpage-highlights { +.mainpage-highlights { margin-top: 30px; h2 { @@ -15,7 +15,7 @@ } } -.mainpage-subject-element { +.mainpage-highlight-element { width: 250px; h4 { diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index c84caefc1..6bdd3cfb5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -37,11 +37,11 @@ class SearchController < ApplicationController def autocomplete begin auto = AutocompleteService.new - query = params["q"] || "" + query = params['q'] || '' json_data = auto.query(query) render text: json_data rescue - render text: "[]" + render text: '[]' end end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 9881ea47b..af71f7f55 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -11,9 +11,7 @@ class WelcomeController < ApplicationController learning_object_repository.find(id) end - @subjects = subject_repository.all_from_offset_to_limit 0, 10 - @subjects.reject!{|s| s.highlights.blank?} - @subjects = @subjects.take(6) + @highlights = learning_object_repository.all_by_score_from_offset_to_limit 0, 6 end def faq diff --git a/app/repositories/orient_db/learning_object_repository.rb b/app/repositories/orient_db/learning_object_repository.rb index 4c2ebfa26..611e35e4e 100644 --- a/app/repositories/orient_db/learning_object_repository.rb +++ b/app/repositories/orient_db/learning_object_repository.rb @@ -121,6 +121,11 @@ module OrientDb [] end + def all_by_score_from_offset_to_limit(offset, limit) + objects_hash = connection.query "SELECT FROM LearningObject ORDER BY score DESC LIMIT #{limit} SKIP #{offset}", limit: limit + objects = build_objects(objects_hash) || [] + end + def get_subjects(learning_object) result = get_edges_end("IsAbout", "out", learning_object.id) subject_repository.build_objects(result) @@ -290,4 +295,4 @@ module OrientDb end end -end \ No newline at end of file +end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 5fbbfea8f..55397cf96 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -66,15 +66,14 @@ <% end %> </div> -<div class="row mainpage-subjects"> +<div class="row mainpage-highlights"> <div class="col-md-12"> - <% unless @subjects.blank? %> + <% unless @highlights.blank? %> <div class="row learning-object-columns"> <h2>Destaque</h2> - <% @subjects.each do |subject| %> - <div class="row mainpage-subject-element"> - <h4><b><%= subject.name %></b></h4> - <%= render subject.highlights.first, orientation: 'vertical' unless subject.highlights.first.nil? %> + <% @highlights.each do |highlight| %> + <div class="row mainpage-highlight-element"> + <%= render highlight, orientation: 'vertical' %> <p class="more"> <a href="#">Ver Mais</a> </p> -- GitLab