Skip to content
Snippets Groups Projects
Commit 332c698e authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec

parents 42ca43fe 79f1fdc7
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,8 @@ $(document).ready(function() { ...@@ -17,8 +17,8 @@ $(document).ready(function() {
} }
}).data("uiAutocomplete")._renderItem = function(ul, item) { }).data("uiAutocomplete")._renderItem = function(ul, item) {
return $("<li></li>") return $("<li></li>")
.append("<img class='autocomplete' src='" + item.thumbnail + "'>") .append(item.thumbnail)
.append("<a>"+ item.name +"</a>" ) .append(item.name)
.appendTo(ul); .appendTo(ul);
}; };
}); });
...@@ -3,10 +3,7 @@ ...@@ -3,10 +3,7 @@
} }
.autocomplete { .autocomplete {
width: 56px; margin-right: 5px;
height: 32px;
border: 0;
margin-right: 8px;
} }
.search-sidebar { .search-sidebar {
......
...@@ -10,8 +10,8 @@ class LearningObjectBuilder ...@@ -10,8 +10,8 @@ class LearningObjectBuilder
lo.author = lo.get_metadata_values_of('dc.contributor.author').join(', ') lo.author = lo.get_metadata_values_of('dc.contributor.author').join(', ')
lo.description = lo.get_metadata_value_of('dc.description') lo.description = lo.get_metadata_value_of('dc.description')
lo.object_type = lo.get_metadata_value_of('dc.type') lo.object_type = ObjectType.where(name: lo.get_metadata_value_of('dc.type')).first_or_create
lo.language = Language.first_or_create(code: lo.get_metadata_value_of('dc.language')) lo.language = Language.where(code: lo.get_metadata_value_of('dc.language')).first_or_create
date = lo.get_metadata_value_of('dc.date.issued') date = lo.get_metadata_value_of('dc.date.issued')
lo.published_at = Time.iso8601(date) unless date.nil? lo.published_at = Time.iso8601(date) unless date.nil?
lo lo
......
...@@ -4,7 +4,7 @@ class SearchController < ApplicationController ...@@ -4,7 +4,7 @@ class SearchController < ApplicationController
def index def index
@types = LearningObject.object_types @types = ObjectType.all
@topics = Topic.defaults @topics = Topic.defaults
...@@ -31,56 +31,45 @@ class SearchController < ApplicationController ...@@ -31,56 +31,45 @@ class SearchController < ApplicationController
end end
def autocomplete def autocomplete
response = [] params_hash = {}
get_thumbnail = nil
case params[:search_class] case params[:search_class]
when "LearningObject" when "LearningObject"
los = LearningObject.search(params[:query], { params_hash = { fields: ['name^10', 'description', 'author'] }
fields: ['name^5', 'description', 'author'], get_thumbnail = Proc.new { |obj| image_tag(learning_object_thumbnail(obj)) }
limit: 10,
misspellings: { below: 5 }
})
los.each do |lo|
hash = {}
hash["name"] = lo.name
hash["thumbnail"] = "/assets/"+learning_object_thumbnail(lo)
hash["url"] = url_for([lo, :only_path => false])
response << hash
end
when "Collection" when "Collection"
cols = Collection.search(params[:query], { params_hash = { where: {privacy: "public"},
where: {privacy: "public"}, fields: ['name^10', 'description', 'owner'] }
fields: ['name^5', 'description', 'owner'], get_thumbnail = Proc.new { |obj| image_tag("/assets/icons/collection") }
limit: 10,
misspellings: { below: 5 }
})
cols.each do |col|
hash = {}
hash["name"] = col.name
hash["thumbnail"] = "/assets/icons/collection"
hash["url"] = url_for([col, :only_path => false])
response << hash
end
when "User" when "User"
users = User.search(params[:query], { params_hash = { fields: ['name'] }
fields: ['name'], get_thumbnail = Proc.new { |obj| image_tag(obj.avatar.url(:thumb), 32) }
limit: 10,
misspellings: { below: 5 }
})
users.each do |user|
hash = {}
hash["name"] = user.name
hash["thumbnail"] = user.avatar.url(:thumb)
hash["url"] = url_for([user, :only_path => false])
response << hash
end
else else
raise "Wrong search class parameter" raise "Wrong search class parameter"
end end
render json: response render json: autocomplete_search(Object.const_get(params[:search_class]), params_hash, get_thumbnail)
end end
private private
def autocomplete_search(search_class, params_hash={}, get_thumbnail)
response = []
search_params = { limit: 10, misspellings: { below: 5 } }
objs = search_class.search(params[:query],search_params.merge(params_hash))
objs.each do |obj|
hash = {}
hash["name"] = obj.name
hash["thumbnail"] = get_thumbnail.call(obj)
hash["url"] = url_for([obj, :only_path => false])
response << hash
end
response
end
def image_tag(image, width=56, height=32)
ActionController::Base.helpers.image_tag image, width: width, height: height, class: "autocomplete"
end
def where_hash(params) def where_hash(params)
hash = {} hash = {}
......
...@@ -6,12 +6,12 @@ class View < ActiveRecord::Base ...@@ -6,12 +6,12 @@ class View < ActiveRecord::Base
before_create :current_time_greater_than_last before_create :current_time_greater_than_last
scope :created_last, ->(user) { where(user: user).order('created_at DESC').limit(1).first } scope :created_last, ->(user) { where(user: user).order('created_at DESC').limit(1) }
private private
def current_time_greater_than_last def current_time_greater_than_last
last_view = viewable.views.created_last(user) last_view = viewable.views.created_last(user).first
unless last_view.blank? unless last_view.blank?
return false if Time.now < (last_view.created_at + 1.days) return false if Time.now < (last_view.created_at + 1.days)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment