Skip to content
Snippets Groups Projects
Commit 03e21ed7 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

Merge branch 'fix-bookmarks' into 'master'

Fix bookmarks



See merge request !197
parents 98264a9a cf887861
No related branches found
No related tags found
No related merge requests found
......@@ -91,20 +91,23 @@ $(document).on 'ready page:load', ->
$(document).on 'add_collection_selector', (e) ->
$('.learning-object-vertical').each (e) ->
loid = $(this).data('loid')
$('.learning-object-thumbnail', this).append '<input class="collection-selector" type="checkbox" value="' + loid + '"></input>'
type = $(this).data('type')
$('.learning-object-thumbnail', this).append '<input class="collection-selector" type="checkbox" value="' + loid + '" data-type="' + type + '" ></input>'
return
# add/remove object to array when click checkbox
$(document).on 'click', '.collection-selector', ->
if this.checked
if selected_objects.indexOf(this.value) < 0
selected_objects.push this.value
selected_objects.push { "class" : $(this).attr('data-type'), "value" : this.value}
$(document).trigger('check_selected_collection')
return
else
index = selected_objects.indexOf(this.value)
if !!(~index)
selected_objects.splice(index, 1)
i = 0
while i < selected_objects.length
if (selected_objects[i].value == this.value)
selected_objects.splice(i, 1)
i++
$(document).trigger('check_selected_collection')
return
......@@ -113,11 +116,16 @@ $(document).on 'mark_all_collections', ->
selected_objects = []
$('.collection-selector').prop('checked', true)
$('.collection-selector').each () ->
selected_objects.push this.value
selected_objects.push { "class" : $(this).attr('data-type'), "value" : this.value}
console.log(selected_objects)
$(document).trigger('check_selected_collection')
$(document).on 'click', '.count-collections-objects', ->
$(document).trigger('mark_all_collections')
$(document).on 'change', '.count-collections-objects', ->
if ($(this).prop('checked'))
$(document).trigger('mark_all_collections')
else
$(document).trigger('clear_collections')
# clear selected objects
$(document).on 'clear_collections', ->
......@@ -125,21 +133,33 @@ $(document).on 'clear_collections', ->
$('.collection-selector').attr('checked', false)
$(document).trigger('check_selected_collection')
$(document).on 'click', '.collection-show-select-nav .navbar-brand', ->
$(document).trigger('clear_collections')
# manipulation buttons
$(document).on 'click', '.collection-button', ->
collection = $('.collection-show-page').data('cid')
index = permitted_types.indexOf($(this).data('action'))
urls = []
learning_objects = []
if permitted_types[index] == 'remove'
url = '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(selected_objects.join())
if ($('.collection-button').data('class') == 'collections')
i = 0
while i < selected_objects.length
learning_objects.push selected_objects[i]["value"]
i++
urls.push '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(learning_objects.join(','))
else
i = 0
while i < selected_objects.length
urls.push '/bookmarks/' + encodeURIComponent(selected_objects[i]["class"]) + '/' + encodeURIComponent(selected_objects[i]["value"])
i++
if confirm('Você tem certeza?')
$.ajax { method: 'DELETE', url: url }
.done ->
$(document).trigger 'refresh_comments'
else
$(document).trigger('open_collections_modal', [collection: collection, type: permitted_types[index], learning_object: selected_objects ]) if !!(~index)
i = 0
while i < urls.length
$.ajax { method: 'DELETE', url: urls[i] }
.done ->
$(document).trigger 'refresh_comments'
i++
else
$(document).trigger('open_collections_modal', [collection: collection, type: permitted_types[index], learning_object: selected_objects ]) if !!(~index)
# refresh comments via ajax
$(document).on 'refresh_comments', (e) ->
......@@ -159,6 +179,7 @@ $(document).on 'refresh_comments', (e) ->
$(document).on 'check_selected_collection', (e) ->
length = selected_objects.length
if length == 0
$('.count-collections-objects').prop('checked',false)
return $('.collection-show-select-nav').slideUp('slow')
else if (length == 1)
html = "1 objeto selecionado"
......
......@@ -9,6 +9,7 @@ class BookmarksController < ApplicationController
# GET /bookmarks/1
# GET /bookmarks/1.json
def show
render partial: 'list' if params[:list] == 'true'
end
# POST /bookmarks/1/learning_object
......@@ -19,10 +20,14 @@ class BookmarksController < ApplicationController
render json: { status: true } if request.xhr?
end
def list
render layout: false
end
# DELETE /bookmarks/1/learning_object
def remove_object
authorize @object
Bookmark.destroy(user: @user, bookmarkable: @object)
Bookmark.destroy Bookmark.where(user: @user, bookmarkable: @object)
render json: { status: true } if request.xhr?
end
......
......@@ -118,10 +118,11 @@ class CollectionsController < ApplicationController
@new_collection = Collection.new
@publishers = publishers_for current_user
@bookmark = (current_user.bookmarks.nil? || current_user.bookmarks.first.nil?) ? [] : [current_user.bookmarks.first]
@groups = [
CollectionsGroup.new(title: 'Coleções Automáticas',
collections: [current_user.bookmarks.first]),
collections: @bookmark ),
CollectionsGroup.new(title: 'Coleções Adicionadas',
collections: current_user.collections.includes(:owner))
]
......
......@@ -13,8 +13,8 @@ class UsersController < ApplicationController
if @user == current_user
@publishers = @user.institutions
@bookmarks = @user.bookmarks.first
@groups.unshift(CollectionsGroup.new(title: 'Coleções Automáticas', collections: [@bookmarks]))
@bookmarks = (@user.bookmarks.nil? || @user.bookmarks.first.nil?) ? [] : [@user.bookmarks.first]
@groups.unshift(CollectionsGroup.new(title: 'Coleções Automáticas', collections: @bookmarks))
end
end
......
<% @user.bookmark_learning_objects.each do |object| %>
<%= render object, orientation: 'vertical' %>
<% end %>
......@@ -6,10 +6,8 @@
<ul class="nav navbar-nav navbar-right collection-header" style="margin-left: 30px;">
<li><h2>Favoritos</h2></li>
<li>
<a class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos">
<%= image_tag image_path("icons/square.png"), class: "logo-image", size: "20x20" %>
<input type="checkbox" class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos">
<%= bookmark_length @user %>
</a>
</li>
</ul>
</div>
......@@ -18,21 +16,21 @@
</nav>
<nav class="navigation navbar-inverse collection-show-select-nav" style="display:none;">
<div class="container-fluid">
<a class="navbar-brand" href="javascript:void(0);" data-toggle="tooltip" data-placement="bottom" title="Limpar seleção"></a>
<a class="navbar-brand" data-toggle="tooltip" data-placement="bottom" ></a>
<ul class="nav navbar-nav navbar-right">
<li class="set-align collection-button" data-action="download">
<li class="set-align collection-button" data-action="download" data-class="bookmarks">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Download_01.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Salvar no <br>computador</span></a>
</li>
<li class="set-align collection-button" data-action="copy">
<li class="set-align collection-button" data-action="copy" data-class="bookmarks">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Copiar_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Copiar <br>para</span></a>
</li>
<li class="set-align collection-button" data-action="move">
<li class="set-align collection-button" data-action="move" data-class="bookmarks">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Mover_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Mover <br>para</span></a>
</li>
<li class="set-align collection-button" data-action="remove">
<li class="set-align collection-button" data-action="remove" data-class="bookmarks">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Remover_da_Coleção_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Remover da <br>coleção</span></a>
</li>
......@@ -40,11 +38,9 @@
</div>
</nav>
<div class= "row">
<div class="row">
<div class="learning-object-columns">
<br/>
<% @user.bookmark_learning_objects.each do |object| %>
<%= render object, orientation: 'vertical' %>
<% end %>
<%= render partial: 'list' %>
</div>
</div>
......@@ -26,8 +26,7 @@
<ul class="nav navbar-nav navbar-right collection-header" style="margin-left: 30px;">
<li><h2><%= (@collection.class != Bookmark) ? @collection.name : "Favoritos" %></h2></li>
<li>
<a class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos">
<%= image_tag image_path("icons/square.png"), class: "logo-image", size: "20x20" %>
<input type="checkbox" class="count-collections-objects" data-toggle="tooltip" data-placement="bottom" title="Selecionar todos">
<%= collection_length @collection %>
</a>
</li>
......@@ -38,24 +37,24 @@
</nav>
<nav class="navigation navbar-inverse collection-show-select-nav" style="display:none;">
<div class="container-fluid">
<a class="navbar-brand" href="javascript:void(0);" data-toggle="tooltip" data-placement="bottom" title="Limpar seleção"></a>
<a class="navbar-brand" data-toggle="tooltip" data-placement="bottom" ></a>
<ul class="nav navbar-nav navbar-right">
<li class="set-align collection-button" data-action="download">
<li class="set-align collection-button" data-action="download" data-class="collections">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Download_01.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Salvar no <br>computador</span></a>
</li>
<% if user_signed_in? %>
<li class="set-align collection-button" data-action="copy">
<li class="set-align collection-button" data-action="copy" data-class="collections">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Copiar_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Copiar <br>para</span></a>
</li>
<% end %>
<% if @own %>
<li class="set-align collection-button" data-action="move">
<li class="set-align collection-button" data-action="move" data-class="collections">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Mover_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Mover <br>para</span></a>
</li>
<li class="set-align collection-button" data-action="remove">
<li class="set-align collection-button" data-action="remove" data-class="collections">
<a href="javascript:void(0);"><span class="left-edge1"><%= image_tag image_path("icons/Remover_da_Coleção_Seleção.png"), class: "logo-image", size: "35x35" %></span><span style="color: white">
Remover da <br>coleção</span></a>
</li>
......
......@@ -57,17 +57,17 @@
$('.Facebook-button').click(function(){
$('#social-modal-continue').empty();
$('#social-modal-continue').append('<button type="button" class="btn btn-danger" style="float:left;" data-dismiss="modal">Recusar</button>');
$('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:facebook), class: 'btn btn-primary' %>');
$('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:facebook), class: 'btn btn-success' %>');
});
$('.Google-button').click(function(){
$('#social-modal-continue').empty();
$('#social-modal-continue').append('<button type="button" class="btn btn-danger" style="float:left;" data-dismiss="modal">Recusar</button>');
$('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:google_oauth2), class: 'btn btn-primary' %>');
$('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:google_oauth2), class: 'btn btn-success' %>');
});
$('.Twitter-button').click(function(){
$('#social-modal-continue').empty();
$('#social-modal-continue').append('<button type="button" class="btn btn-danger" style="float:left;" data-dismiss="modal">Recusar</button>');
$('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:twitter), class: 'btn btn-primary' %>');
$('#social-modal-continue').append('<%= button_to "Aceitar", user_omniauth_authorize_path(:twitter), class: 'btn btn-success' %>');
});
</script>
<div class="learning-object-vertical" data-loid="<%= learning_object.id %>">
<div class="learning-object-vertical" data-loid="<%= learning_object.id %>" data-type="LearningObject" >
<div class="panel">
<div class="learning-object-thumbnail">
<%= link_to learning_object_path(id: learning_object.id) do
......
<div class="search-input">
<form action="/search" method="get">
<div class="input-group" id="search">
<input type="text" data-lo="<%=number_with_delimiter(LearningObject.count, delimiter: ".") %>" data-user="<%= number_with_delimiter(User.count, delimiter: ".") %>" data-collection="<%= number_with_delimiter(Collection.count, delimiter: ".") %>" placeholder="" class="form-control" name="query" id="main_search">
<input type="text" data-lo="<%=number_with_delimiter(LearningObject.count, delimiter: ".") %>" data-user="<%= number_with_delimiter(User.count, delimiter: ".") %>" data-collection="<%= number_with_delimiter(Collection.where(privacy: 'public').count, delimiter: ".") %>" placeholder="" class="form-control" name="query" id="main_search">
<select name="search_class" id="search_class" class="form-control">
<option value="LearningObject" selected>Conteúdos Educacionais</option>
<option value="Collection">Coleções</option>
......
......@@ -110,6 +110,7 @@ Rails.application.routes.draw do
end
get '/bookmarks' => 'bookmarks#show', as: 'bookmark'
get '/bookmarks/list' => 'bookmarks#list', as: 'list'
post '/bookmarks/:type/:id' => 'bookmarks#add_object', as: :bookmark_add
delete '/bookmarks/:type/:id' => 'bookmarks#remove_object', as: :bookmark_remove
......
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