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

now, users can like learning objects

parent 819dfc2c
No related branches found
No related tags found
No related merge requests found
......@@ -5,3 +5,11 @@ $ ->
$('#collections_list_popover').html()
return
# Rails creates this event, when the link_to(remote: true)
# successfully executes
$(document).on 'ajax:success', 'a.vote', (status, data, xhr)->
# the `data` parameter is the decoded JSON object
$(".votes-count[data-id=#{data.id}]").text data.count
return
\ No newline at end of file
class LearningObjectsController < ApplicationController
before_action :set_learning_object, only: [:show, :edit, :update, :destroy, :like]
after_action :increment_learning_object_views, only: [:show]
before_action :authenticate_user!, except: [:index, :show]
before_action :authenticate_user!, except: [:index, :show, :like]
# GET /learning_objects
# GET /learning_objects.json
......@@ -62,7 +62,10 @@ class LearningObjectsController < ApplicationController
# POST /learning_objects/1/like
def like
learning_object_repository.like current_user, @learning_object
redirect_to :back
if request.xhr?
render json: {count: @learning_object.likes, id: params[:id]}
end
end
private
......@@ -83,4 +86,4 @@ class LearningObjectsController < ApplicationController
end
end
end
end
\ No newline at end of file
class LearningObject
include ActiveModel::Model
include RepositoriesProxy
attr_accessor :id, :id_dspace, :rid, :name, :description,
:thumbnail, :created_at, :last_modified,
:type, :bitstreams, :metadata, :likes, :views,
......@@ -73,8 +75,4 @@ class LearningObject
}
end
def learning_object_repository
Portalmec::Application.repository.for :learning_object
end
end
......@@ -5,6 +5,7 @@ module OrientDb
def increment_views(user, learning_object)
create_edge "Views", user.rid, learning_object.id
learning_object.views = learning_object.views + 1
end
#
......@@ -13,6 +14,7 @@ module OrientDb
#
def like(user, learning_object)
create_edge "Likes", user.rid, learning_object.id
learning_object.likes = learning_object.likes + 1
end
# Example:
......@@ -58,7 +60,7 @@ module OrientDb
result = connection.command "INSERT INTO LearningObject CONTENT #{learning_object.to_json}"
end
def update_property(learning_object,property,value)
def update_property(learning_object, property, value)
if accepted_properties.include? property
connection.command "UPDATE LearningObject SET #{property}='#{value}' WHERE @rid = #{learning_object.id}"
end
......
......@@ -48,7 +48,7 @@ class UserRepositoryProxy
def update_user_refs(user)
rid = get_graph_id user
user.rid = rid
user.save!
save user
end
def check_references(user)
......
<div class="learning-object-actions">
<%= render 'learning_objects/like_button' %>
<%= render 'learning_objects/like_button', learning_object: learning_object %>
<%= render 'learning_objects/bookmarks_button' %>
<%= render 'learning_objects/collections_button' %>
</div>
\ No newline at end of file
......@@ -8,7 +8,7 @@
end %>
<% if user_signed_in? %>
<%= render 'learning_objects/actions_buttons' %>
<%= render 'learning_objects/actions_buttons', learning_object: learning_object %>
<% end %>
</div>
</div>
......
......@@ -5,14 +5,14 @@
learning_object_thumbnail learning_object
end %>
<% if user_signed_in? %>
<%= render 'learning_objects/actions_buttons' %>
<%= render 'learning_objects/actions_buttons', learning_object: learning_object %>
<% end %>
</div>
<div class="panel-body">
<h4 class="media-heading"><%= learning_object_title(learning_object) %></h4>
<span class="glyphicon glyphicon-eye-open"><%= learning_object.views %>&nbsp;</span>
<span class="glyphicon glyphicon-star"><%= learning_object.likes %>&nbsp;</span>
<span class="glyphicon glyphicon-eye-open"><%= learning_object.views %></span>
<span class="glyphicon glyphicon-star votes-count" data-id="<%= learning_object.id %>"><%= learning_object.likes %></span>
<span class="author-label">Por <%= learning_object.get_metadata_value_of("dc.contributor.author") %></span>
</div>
</div>
</div>
</div>
\ No newline at end of file
<button type="button" class="btn btn-primary btn-xs" data-toggle="button" aria-pressed="false" autocomplete="off" title="Gostei">
<span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span>
</button>
\ No newline at end of file
<%= 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>
<% end %>
\ No newline at end of file
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