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

add privacy selector in collection view

parent 68fdae02
No related branches found
No related tags found
No related merge requests found
...@@ -17,3 +17,11 @@ $ -> ...@@ -17,3 +17,11 @@ $ ->
$.ajax {method: "DELETE", url: url }, (d) -> $.ajax {method: "DELETE", url: url }, (d) ->
d d
return return
$ ->
$(document).on 'click', 'input[name=privacy]', ->
url = '/collections/' + encodeURIComponent($(this).data('cid')) + '/change_privacy'
value = $('input[name=privacy]:checked').val()
$.post url, {'privacy':value}, (d) ->
d
return
...@@ -3,4 +3,10 @@ ul.collection-header { ...@@ -3,4 +3,10 @@ ul.collection-header {
width: 100%; width: 100%;
margin-bottom: 10px; margin-bottom: 10px;
} }
} }
\ No newline at end of file
.collection-privacy {
text-align: center;
margin-top: 20px;
margin-right: 30px;
}
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
position: relative; position: relative;
min-height: 500px; min-height: 500px;
min-width: 350px; min-width: 350px;
margin-top: 30px;
background-color: #2178F5; background-color: #2178F5;
color: white; color: white;
} }
......
class CollectionsController < ApplicationController class CollectionsController < ApplicationController
before_action :set_collection, only: [:show, :update, :destroy, :like, :add_learning_object, :remove_learning_object] before_action :set_collection, only: [:show, :update, :destroy, :like, :add_learning_object, :remove_learning_object, :change_privacy]
before_action :authenticate_user!, only: [:update, :destroy, :like, :add_learning_object, :remove_learning_object] before_action :authenticate_user!, only: [:update, :destroy, :like, :add_learning_object, :remove_learning_object, :change_privacy]
# GET /collections # GET /collections
# GET /collections.json # GET /collections.json
...@@ -83,6 +83,15 @@ class CollectionsController < ApplicationController ...@@ -83,6 +83,15 @@ class CollectionsController < ApplicationController
end end
end end
# change collection privacy
def change_privacy
collection_repository.change_privacy(@collection, params[:privacy])
if request.xhr?
render json: {status: true}
end
end
private private
def set_collection def set_collection
......
...@@ -45,6 +45,12 @@ class OrientDb::Base ...@@ -45,6 +45,12 @@ class OrientDb::Base
objects objects
end end
def update_property(object, property, value)
if accepted_properties.include? property
connection.command "UPDATE #{odb_class} SET #{property}='#{value}', last_modified='#{Time.now()}' WHERE @rid = #{object.id}"
end
end
# Take the object and make a hash in the OrientDB format. # Take the object and make a hash in the OrientDB format.
# Used to create a document. # Used to create a document.
def build_hash(object) def build_hash(object)
...@@ -77,8 +83,12 @@ class OrientDb::Base ...@@ -77,8 +83,12 @@ class OrientDb::Base
protected protected
def odb_class def accepted_properties
raise NoMethodError, "You must implement this method" raise NoMethodError, "You must implement this method"
end end
def odb_class
raise NoMethodError, "You must implement this method"
end
end end
...@@ -100,8 +100,20 @@ module OrientDb ...@@ -100,8 +100,20 @@ module OrientDb
return [] return []
end end
def change_privacy(collection, privacy)
update_property(collection, 'privacy', privacy) if accepted_privacies(privacy)
end
private private
def accepted_properties
['privacy']
end
def accepted_privacies(privacy)
['private', 'public'].include? privacy
end
def owner_id(owner) def owner_id(owner)
(owner.class == User) ? owner.rid : owner.id (owner.class == User) ? owner.rid : owner.id
end end
......
...@@ -172,12 +172,6 @@ module OrientDb ...@@ -172,12 +172,6 @@ module OrientDb
end end
end end
def update_property(learning_object, property, value)
if accepted_properties.include? property
connection.command "UPDATE LearningObject SET #{property}='#{value}', last_modified='#{Time.now()}' WHERE @rid = #{learning_object.id}"
end
end
def types def types
Rails.cache.fetch("learning_object/types", expires_in: 1.days) do Rails.cache.fetch("learning_object/types", expires_in: 1.days) do
query = "select type from LearningObject GROUP BY type" query = "select type from LearningObject GROUP BY type"
......
<nav class="navigation navbar-default "><br/> <nav class="navigation navbar-default "><br/>
<div class="container-fluid"> <div class="container-fluid">
<div class="navbar-right"> <div class="navbar-right" style="text-align:right">
<%= link_to '#' do %> <%= link_to '#' do %>
<span style="margin-right: 30px;"><button class="btn btn-danger btn-remove">APAGAR</button></span> <span style="margin-right: 30px;"><button class="btn btn-danger btn-remove">APAGAR</button></span>
<% end %> <% end %>
<div class="collection-privacy">
<input type="radio" name="privacy" id="privacy_private" data-cid="<%= @collection.id %>" value="private" <%= "checked" if @collection.privacy == "private" %>><label for="privacy_private">Privada</label> |
<input type="radio" name="privacy" id="privacy_public" data-cid="<%= @collection.id %>" value="public" <%= "checked" if @collection.privacy == "public" %>><label for="privacy_public">Pública</label>
</div>
</div> </div>
<div class="navbar-header"> <div class="navbar-header">
<%= image_tag image_path("icons/collection.png"), class: "logo-image", size: "90x66" %> <%= image_tag image_path("icons/collection.png"), class: "logo-image", size: "90x66" %>
...@@ -45,4 +49,4 @@ ...@@ -45,4 +49,4 @@
<%= render learning_object, orientation: 'vertical' %> <%= render learning_object, orientation: 'vertical' %>
<% end %> <% end %>
</div> </div>
\ No newline at end of file
...@@ -68,6 +68,8 @@ Rails.application.routes.draw do ...@@ -68,6 +68,8 @@ Rails.application.routes.draw do
# remove a learning object for some collection # remove a learning object for some collection
delete '/learning_object/:learning_object_id', as: :destroy_learning_object, action: :remove_learning_object delete '/learning_object/:learning_object_id', as: :destroy_learning_object, action: :remove_learning_object
post :change_privacy
end end
end end
......
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