Skip to content
Snippets Groups Projects
Commit 89489913 authored by Matheus Agio Nerone's avatar Matheus Agio Nerone
Browse files

fix merge conflicts

parents e7ec5706 f811ca37
No related branches found
No related tags found
No related merge requests found
Showing
with 795 additions and 272 deletions
GEM
remote: https://rubygems.org/
specs:
abstract_type (0.0.7)
actionmailer (4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.0)
actionview (= 4.2.0)
activesupport (= 4.2.0)
rack (~> 1.6.0)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0)
activesupport (= 4.2.0)
globalid (>= 0.3.0)
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
arel (~> 6.0)
activesupport (4.2.0)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
adamantium (0.2.0)
ice_nine (~> 0.11.0)
memoizable (~> 0.4.0)
arel (6.0.3)
ast (2.1.0)
autoprefixer-rails (6.1.0.1)
execjs
json
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.10)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.5.1)
autoprefixer-rails (>= 5.0.0.1)
sass (>= 3.3.0)
builder (3.2.2)
bullet (4.14.10)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.9.0)
byebug (8.2.0)
chart-js-rails (0.0.9)
railties (> 3.1)
chronic (0.10.2)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.7)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.0)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
concord (0.1.5)
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
concurrent-ruby (1.0.0)
connection_pool (2.2.0)
curb (0.8.8)
dalli (2.7.4)
debug_inspector (0.0.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (3.5.2)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
devise_token_auth (0.1.36)
devise (~> 3.5.2)
rails (~> 4.2)
diff-lcs (1.2.5)
domain_name (0.5.25)
unf (>= 0.0.5, < 1.0.0)
dspace_rest_client (1.1.2)
curb (~> 0.8.6)
rest-client (>= 1.7, < 2)
equalizer (0.0.11)
erubis (2.7.0)
execjs (2.6.0)
fast_stack (0.1.0)
rake
rake-compiler
flamegraph (0.1.0)
fast_stack
flay (2.6.1)
ruby_parser (~> 3.0)
sexp_processor (~> 4.0)
flog (4.3.2)
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.4)
globalid (0.3.6)
activesupport (>= 4.1.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0)
ice_nine (0.11.1)
jbuilder (2.3.2)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (4.0.5)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-turbolinks (2.1.0)
railties (>= 3.1.0)
turbolinks
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.3)
kaminari (0.16.3)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
libarchive-static (1.0.5)
libv8 (3.16.14.13)
locastyle (0.0.2)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
mime-types (2.6.2)
mimemagic (0.3.0)
mina (0.3.7)
open4 (~> 1.3.4)
rake
mini_portile (0.6.2)
minitest (5.8.2)
multi_json (1.11.2)
netrc (0.11.0)
nokogiri (1.6.6.3)
mini_portile (~> 0.6.0)
open4 (1.3.4)
orientdb4r (0.5.1)
rest-client (~> 1.7)
orm_adapter (0.5.0)
paperclip (4.3.1)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (= 0.3.0)
parser (2.2.3.0)
ast (>= 1.1, < 3.0)
pg (0.18.4)
private_attr (1.1.0)
procto (0.0.2)
puma (2.15.3)
rack (1.6.4)
rack-cors (0.4.0)
rack-mini-profiler (0.9.7)
rack (>= 1.1.3)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.0)
actionmailer (= 4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
activemodel (= 4.2.0)
activerecord (= 4.2.0)
activesupport (= 4.2.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.0)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
rake (10.4.2)
rake-compiler (0.9.5)
rake
rdoc (4.2.0)
redis (3.2.2)
reek (3.6.0)
parser (~> 2.2, >= 2.2.2.5)
private_attr (~> 1.1)
rainbow (~> 2.0)
unparser (~> 0.2.2)
ref (2.0.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rmagick (2.15.4)
rsolr (1.0.13)
builder (>= 2.1.2)
ruby_parser (3.7.2)
sexp_processor (~> 4.1)
rubycritic (2.1.0)
flay (= 2.6.1)
flog (= 4.3.2)
parser (>= 2.2.0, < 3.0)
reek (= 3.6.0)
virtus (~> 1.0)
sass (3.4.19)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
select2-rails (4.0.0)
thor (~> 0.14)
sexp_processor (4.6.0)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-callback-matchers (1.1.3)
activesupport (>= 3)
shoulda-context (1.2.1)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
sidekiq (4.0.0)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
json (~> 1.0)
redis (~> 3.2, >= 3.2.1)
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
slim (3.0.6)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
spring (1.4.3)
sprockets (3.4.0)
rack (> 1, < 3)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.11)
stackprof (0.2.7)
streamio-ffmpeg (1.0.0)
temple (0.7.6)
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
execjs (>= 0.3.0)
json (>= 1.8.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
uniform_notifier (1.9.0)
unparser (0.2.4)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
concord (~> 0.1.5)
diff-lcs (~> 1.2.5)
equalizer (~> 0.0.9)
parser (~> 2.2.2)
procto (~> 0.0.2)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.3)
rack (>= 1.0)
web-console (2.2.1)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
whenever (0.9.4)
chronic (>= 0.6.3)
PLATFORMS
ruby
DEPENDENCIES
bcrypt (~> 3.1.7)
better_errors
bootstrap-sass
bullet
byebug
chart-js-rails
coffee-rails (~> 4.1.0)
curb (~> 0.8.8)
dalli
devise
devise_token_auth
dspace_rest_client (~> 1.1.0)
execjs
flamegraph
jbuilder (~> 2.0)
jquery-rails
jquery-turbolinks
jquery-ui-rails
kaminari
libarchive-static
locastyle
mina
orientdb4r
paperclip
pg
puma
rack-cors
rack-mini-profiler
rails (= 4.2.0)
rainbow
rdoc
rmagick
rsolr (~> 1.0.12)
rubycritic
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
select2-rails
shoulda
shoulda-callback-matchers (~> 1.1.1)
sidekiq
sinatra
slim
spring
sqlite3
stackprof
streamio-ffmpeg (~> 1.0.0)
therubyracer
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)
whenever
BUNDLED WITH
1.10.6
......@@ -11,13 +11,13 @@
// about supported directives.
//
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require bootstrap-sprockets
//= require select2
//= require select2_locale_pt-BR
//= require bootstrap-tagsinput
//= require jquery.turbolinks
//= require turbolinks
//= require_tree ./application
......
......@@ -6,98 +6,163 @@ $ ->
$('#create_collection_popover_content').html()
title: ->
$('#create_collection_popover_title').html()
return
# add/remove learning object to collection
$(document).on 'click', '.add-to-collection', ->
$(document).trigger('open_collections_modal', [learning_object: [$(this).data('loid')], type: 'add'])
# change collection privacy
$(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
$(document).on 'open_collections_modal', (evt, params) ->
id = if (params.collection == undefined) then "all" else encodeURIComponent(params.collection)
url = '/collections/' + id + '/list?type=' + params.type
url += '&learning_objects_ids=' + encodeURIComponent(params.learning_object) if params.learning_object != undefined
$.get url, (d) ->
$('#collections-modal').remove()
$('body').append d
$('#collections-modal').modal('show')
return
mount_modal_params = (e) ->
array = $(e).serializeArray()
object = {}
collection = ""
type = ""
collections = []
learning_objects = []
i = 0
length = array.length
while i < length
switch array[i].name
when 'collection' then collections.push(array[i].value)
when 'learning_object' then learning_objects.push(array[i].value)
when 'collection_id' then collection = array[i].value
when 'type' then type = array[i].value
++i
# add learning object to collection
$(document).on 'click', 'input[class=collection-element]', ->
url = '/collections/' + encodeURIComponent($(this).data('cid')) + '/learning_object/' + encodeURIComponent($(this).data('loid'))
if this.checked
$.ajax {method: "POST", url: url }, (d) ->
d
else
$.ajax {method: "DELETE", url: url }, (d) ->
d
# change collection privacy
$(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
$(document).on 'open_collections_modal', (evt, params) ->
url = '/collections/' + encodeURIComponent(params) + '/list'
$.get url, (d) ->
$('#collections-modal').remove()
$('body').append d
$('#collections-modal').modal('show')
return
object.collection_id = collection
object.collections_ids = collections if collections.length > 0
object.learning_objects_ids = learning_objects if learning_objects.length > 0
object.type = type
return object
$(document).on 'submit', '#collections-modal-form', (evt, params) ->
evt.preventDefault()
data = mount_modal_params(this)
return false if (data.learning_objects_ids.length < 1) || (data.collections_ids.length < 1) || (permitted_types.indexOf(data.type) < 0)
id = if (data.collections_ids == undefined) then data.collection_id else data.collections_ids
url = '/collections/' + encodeURIComponent(id) + '/learning_objects/' + encodeURIComponent(data.learning_objects_ids.join())
$.ajax {method: "POST", url: url, data: data }
.done () ->
if (data.type == "move")
url = '/collections/' + encodeURIComponent(data.collection_id) + '/learning_objects/' + encodeURIComponent(data.learning_objects_ids.join())
$.ajax {method: "DELETE", url: url, data: data }
.done ->
$(document).trigger('refresh_comments')
$(document).trigger 'flash_notice', {text: 'Operação efetuada com sucesso!', type: 'notice'}
$(document).trigger('clear_collections')
$('#collections-modal').modal('hide')
return
# manipulate collections in show page
# manipulate collections
# $(document).on 'ready page:load', ->
# if $('.collection-show-page').val() != undefined
# array with selected objects ids
selected_objects = []
$ ->
$(document).on 'ready page:load', ->
if $('.collection-show-page').val() != undefined
# array with selected collections ids
selected_collections = []
collection = $('.collection-show-page').data('cid')
# add selectors
$('.learning-object-vertical').each (e) ->
loid = $(this).data('loid')
$('.learning-object-thumbnail', this).append '<input class="collection-selector" type="checkbox" value="' + loid + '"></input>'
return
# add/remove collection to array when click checkbox
$(document).on 'click', '.collection-selector', ->
if this.checked
if selected_collections.indexOf(this.value) < 0
selected_collections.push this.value
$(document).trigger('check_selected_collection');
return
else
index = selected_collections.indexOf(this.value)
if !!(~index)
selected_collections.splice(index, 1)
$(document).trigger('check_selected_collection');
return
# clear selected collections
$(document).on 'clear_collections', ->
selected_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', ->
switch $(this).data('action')
when 'download' then
when 'copy' then $(document).trigger('open_collections_modal', [collection])
when 'move' then
when 'remove' then
# update interface when add/remove a collection
$(document).on 'check_selected_collection', (e) ->
length = selected_collections.length
if length == 0
return $('.collection-show-select-nav').slideUp('slow')
else if (length == 1)
html = "1 objeto selecionado"
else
html = length + " objetos selecionados"
$('.collection-show-select-nav .navbar-brand').html html
$('.collection-show-select-nav').slideDown('slow')
$(document).on 'submit', '#collections-modal-form', (evt) ->
evt.preventDefault()
url = '/collections/' + encodeURIComponent(collection) + '/copy'
collections = $(this).serializeArray()
$.ajax {method: "POST", url: url, data: {col: collections} }, (d) ->
console.log d
return
console.log collections
$('#collections-modal').modal('close')
return
return
selected_objects = []
# valid types of operations in collections
permitted_types = ['add', 'download', 'copy', 'move', 'remove']
$(document).on 'ready page:load', ->
if $('.collection-show-page').val() != undefined
$(document).trigger('add_collection_selector')
# add selectors to learning objects
$(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>'
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
$(document).trigger('check_selected_collection')
return
else
index = selected_objects.indexOf(this.value)
if !!(~index)
selected_objects.splice(index, 1)
$(document).trigger('check_selected_collection')
return
# select all objects
$(document).on 'mark_all_collections', ->
selected_objects = []
$('.collection-selector').each () ->
$(this).attr('checked', true) if !this.checked
selected_objects.push this.value
$(document).trigger('check_selected_collection')
$(document).on 'click', '.count-collections-objects', ->
$(document).trigger('mark_all_collections')
# clear selected objects
$(document).on 'clear_collections', ->
selected_objects = []
$('.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'))
if permitted_types[index] == 'remove'
url = '/collections/' + encodeURIComponent(collection) + '/learning_objects/' + encodeURIComponent(selected_objects.join())
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)
# refresh comments via ajax
$(document).on 'refresh_comments', (e) ->
selected_objects = []
$(document).trigger 'check_selected_collection'
$parent = $('.learning-object-columns')
url = window.location.pathname + '?list=true'
$parent.html('Carregando...')
$.get url, (data) ->
$parent.html('<br>' + data)
$(document).trigger 'create-learning-object-columns'
$(document).trigger 'add_collection_selector'
# update interface when add/remove an object
$(document).on 'check_selected_collection', (e) ->
length = selected_objects.length
if length == 0
return $('.collection-show-select-nav').slideUp('slow')
else if (length == 1)
html = "1 objeto selecionado"
else
html = length + " objetos selecionados"
$('.collection-show-select-nav .navbar-brand').html html
$('.collection-show-select-nav').slideDown('slow')
$(document).ready(function() {
$(".learning-object-columns").each(function() {
var html = '',
i = 1;
$(document).trigger('create-learning-object-columns');
});
$("> div", this).each(function () {
if (i == 2) {
html = '<div class="col-md-6"><div class="row"><div class="col-md-3">&nbsp;</div><div class="col-md-6">';
// TODO: find a way to not remove wrapper div
html += $(this).clone().wrap('<div>').parent().html();
html += '</div><div class="col-md-3">&nbsp;</div></div></div>';
$(this).replaceWith(html);
$(document).on('create-learning-object-columns', function() {
$parents = $(".learning-object-columns");
i = 0;
}
else {
$(this).wrap('<div class="col-md-3"></div>');
// small screen = 2 columns
if ($(window).width() < 1000) {
$parents.each(function() {
var html = '',
i = 1,
even = false;
i += 1;
}
$("> div", this).each(function () {
append = (even) ? ' style="text-align: -webkit-right; text-align: -moz-right;"' : '';
even = !(even);
$(this).wrap('<div class="col-sm-6"' + append +'></div>');
});
});
});
}
// bigger screen = 3 columns hack
else {
$parents.each(function() {
var html = '',
i = 1;
$("> div", this).each(function () {
if (i == 2) {
html = '<div class="col-md-6"><div class="row"><div class="col-md-3">&nbsp;</div><div class="col-md-6">';
// TODO: find a way to not remove wrapper div
html += $(this).clone().wrap('<div>').parent().html();
html += '</div><div class="col-md-3">&nbsp;</div></div></div>';
$(this).replaceWith(html);
i = 0;
}
else {
$(this).wrap('<div class="col-md-3"></div>');
i += 1;
}
});
});
}
});
$ ->
$('.default_btn').toggleClass 'active_btn'
$(document).on 'click', '*[data-poload]', ->
e = $(this)
e.popover({content: "Carregando..."}).popover('show')
all = undefined
objects = undefined
url = $(this).data('poload')
loid = $(this).data('loid')
$.get '/collections.json', (d) ->
all = d
$.get url, (d) ->
object = d
# generate a lookup table for object's collections id
lookup = {}
i = 0
len = object.length
while i < len
lookup[object[i].id] = object[i]
i++
# mark checked objects
i = 0
len = all.length
html = ''
while i < len
name = 'collection_' + all[i].id.split(':').slice(-1)[0]
html += '<input type="checkbox" class="collection-element" data-cid="' + all[i].id + '" data-loid="' + loid + '" id="' + name + '" value="' + all[i].id + '"'
if lookup[all[i].id] != undefined
html += " checked"
html += '>'
html += '<label for="' + name + '">' + all[i].name + '</label><br/>'
++i
html = 'Você não possui coleções.<br>É possível criá-las na sua página pessoal.' if html == ""
$('.popover-content').html(html)
return
return
return
$ ->
$(document).on 'click', '.add_to_collection', (e) ->
$('.add_to_collection').removeClass 'active'
$('.add_to_collection').not(this).popover 'hide'
return
$ ->
$(document).on 'ajax:success', 'a.vote', (status, data, xhr) ->
$('.votes-count[data-id=\'' + data.id + '\']').text data.count
......
# flash notice ()
$(document).on 'flash_notice', (e, params) ->
text = params.text
type = params.type
alert_type = if (type == 'alert') then 'alert-danger alert-dismissible' else 'alert-info'
html = '<div class="alert '+ alert_type + '" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Fechar">
<span aria-hidden="true">&times;</span></button>' + text + '</div>'
$('#content').prepend($(html))
......@@ -17,6 +17,7 @@ $checked_icon: 'icons/checked.png';
position: relative;
a > img {
background-image: url(image_path('learning-object-preview.png'));
width: 250px;
height: 141px;
border: 0;
......
......@@ -3,7 +3,9 @@ class Builder
protected
def self.cache_key(rid, last_modified)
last_modified = Time.at(0).to_s if last_modified.nil?
rid + '/' + last_modified
end
end
\ No newline at end of file
end
class ComplaintBuilder < Builder
extend RepositoriesProxy
##
# receive a list of ids and return a list of complaints
#
def self.build(complaints = [])
array = []
complaints = [complaints] if complaints.class == String
complaints.each do |complaint|
rid = complaint['@rid'] || complaint['rid']
unless rid.blank?
o = complaint_repository.find complaint['@rid'] #if o.nil?
array << o
end
end
array
end
def self.build_from_orientdb(args = {})
unless args.nil?
created = DateTime.now.strftime("%Y-%m-%d %H:%M:%S")
created = DateTime.strptime(args['created_at'], "%Y-%m-%d %H:%M:%S") unless args['created_at'].blank?
Complaint.new(
id: args['@rid'],
user: user_repository.get_by_rid(args['out']),
created_at: created,
object: learning_object_repository.find(args['in'].to_s),
message: ComplaintMessage.new(args['message']),
description: args['description'] || ''
)
end
end
end
......@@ -11,11 +11,7 @@ class LearningObjectBuilder < Builder
objects.each do |object|
unless object['rid'].blank?
o = Rails.cache.fetch(cache_key(object['rid'], object['last_modified'])) unless object['last_modified'].blank?
if o.nil?
o = learning_object_repository.find object['rid']
end
o = learning_object_repository.find object['rid'] if o.nil?
lo << o
end
end
......@@ -37,7 +33,7 @@ class LearningObjectBuilder < Builder
thumbnail: (args['thumbnail'] or ''),
id_dspace: args['id_dspace'],
type: args['type'],
bitstreams: args['bitstreams'],
attachment: LearningObject::Attachment.new(args['bitstreams']),
last_modified: args['last_modified'],
metadata: args['metadata']
)
......
class CollectionsController < ApplicationController
before_action :set_collection, only: [:show, :update, :destroy, :like, :list, :add_learning_object, :remove_learning_object, :move_learning_objects, :copy_learning_objects, :change_privacy]
before_action :authenticate_user!, only: [:update, :destroy, :like, :list, :add_learning_object, :remove_learning_object, :move_learning_objects, :copy_learning_objects, :change_privacy]
before_action :set_manipulation_params, only: [:move_learning_objects, :copy_learning_objects]
before_action :set_collection, only: [:show, :update, :destroy, :like, :change_privacy]
before_action :set_collections, only: [:list, :add_learning_object, :remove_learning_object]
before_action :authenticate_user!, only: [:update, :destroy, :like, :list, :add_learning_object, :remove_learning_object, :change_privacy]
# GET /collections
# GET /collections.json
......@@ -29,6 +29,8 @@ class CollectionsController < ApplicationController
@user = @collection.owner
@own = user_signed_in? ? @collection.owner?(current_user) : false
render partial: 'list' if params[:list] == "true"
end
# POST /collections/1/like
......@@ -39,7 +41,6 @@ class CollectionsController < ApplicationController
# POST /collections
# POST /collections.json
def create
authorize_create_collection!
@collection = Collection.new(collection_params)
@collection.owner = current_user if collection_params[:owner].blank?
......@@ -75,55 +76,61 @@ class CollectionsController < ApplicationController
end
def list
@learning_object = learning_object_repository.find params[:learning_object_id] unless params[:learning_object_id].blank?
@collection = @collections.first
@collections = collection_repository.all Collections::UserContext.new(current_user)
# list all
@collection = nil if @collection == 'all'
render layout: false
end
@collections = collection_repository.all(Collections::UserContext.new(current_user))
@collections.select! { |c| c.id != @collection.id } unless @collection.blank?
# POST /collections/1/learning_object/43
def add_learning_object
learning_object = learning_object_repository.find params[:learning_object_id]
@collection.add learning_object
unless params[:type].blank?
@type = params[:type]
if request.xhr? && collection_repository.save_learning_objects(@collection)
render json: {status: true}
@send = case @type
when 'add' then 'Adicionar'
when 'copy' then 'Copiar'
when 'move' then 'Mover'
else 'Enviar'
end
@title = (@send == 'Enviar') ? 'Coleções' : @send + ' objeto(s) às coleções'
end
render layout: false
end
# DELETE /collections/1/learning_object/43
def remove_learning_object
learning_object = learning_object_repository.find params[:learning_object_id]
@collection.remove learning_object
collection_repository.save_learning_objects @collection
# POST /collections/1/learning_object
def add_learning_object
@collections.each do |collection|
if collection.owner?(current_user)
@learning_objects.each do |learning_object|
collection.add learning_object
end
if request.xhr?
render json: {status: true}
collection_repository.save_learning_objects(collection)
end
end
end
def copy_learning_objects
response = learning_objects_to_collection(@learning_objects, @target_collection)
if request.xhr?
render json: {status: response}
render json: {status: true}
end
end
def move_learning_objects
response = learning_objects_to_collection(@learning_objects, @target_collection)
# DELETE /collections/1/learning_object
def remove_learning_object
@collections.each do |collection|
if collection.owner?(current_user)
@learning_objects.each do |learning_object|
collection.remove learning_object
end
if response
@learning_objects.each do |learning_object|
@collection.remove learning_object
collection_repository.save_learning_objects(collection)
end
response = collection_repository.save_learning_objects(@target_collection)
end
if request.xhr?
render json: {status: response}
render json: {status: true}
end
end
......@@ -137,20 +144,6 @@ class CollectionsController < ApplicationController
end
private
def authorize_create_collection!
end
def learning_objects_to_collection(learning_objects, collection)
if collection.owner?
learning_objects.each do |learning_object|
collection.add learning_object
end
return collection_repository.save_learning_objects(@target_collection)
end
end
def check_collection_privacy!(collection)
if collection.privacy == "private"
redirect_to :root, notice: 'Está é uma coleção privada.' unless collection.owner?(current_user)
......@@ -161,12 +154,21 @@ class CollectionsController < ApplicationController
@collection = collection_repository.find params[:id]
end
def set_manipulation_params
p "AQUI"
p JSON.stringify(params)
@target_collection = collection_repository.find params[:collection_id] unless params[:collection_id].empty?
def set_collections
if params[:id] == "all" || params[:id].blank?
@collections = ['all']
else
@collections = (params[:id].class == String) ? [collection_repository.find(params[:id])] : params[:id].map{|id| collection_repository.find id}
end
unless params[:learning_objects_ids].blank?
@learning_objects = []
@learning_objects = params[:learning_objects].map{|id| learning_object_repository.find id || false} unless params[:learning_objects].empty?
params[:learning_objects_ids].split(',').each do |id|
object = learning_object_repository.find id
@learning_objects << object unless object.blank?
end
end
end
# Never trust parameters from the scary internet, only allow the white list through.
......
class ComplaintsController < ApplicationController
before_action :authenticate_user!
include RepositoriesProxy
def create
@complaint = Complaint.new(complaint_params)
@complaint.user = current_user
@complaint.object = params[:complaint][:object_rid]
respond_to do |format|
if complaint_repository.report @complaint
format.html { redirect_to :back, notice: 'Denúncia realizada com sucesso.' }
format.html { redirect_to :back, notice: 'Denúncia realizada com sucesso.' }
else
format.html { redirect_to :back, alert: 'Objeto já foi denunciado por você.' }
end
......@@ -16,9 +16,9 @@ class ComplaintsController < ApplicationController
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def complaint_params
params.require(:complaint).permit(:object, :message, :description)
end
# Never trust parameters from the scary internet, only allow the white list through.
def complaint_params
params.require(:complaint).permit(:object, :message, :description)
end
end
class Management::ComplaintsController < ManagementController
include RepositoriesProxy
before_action :set_complaint, only: :destroy
def index
end
def show
@complaints = complaint_repository.get_complaints
@complaints.each do |c|
c.user = User.find_by(rid: c.user)
c.object = learning_object_repository.get_by_rid(c.object)
end
@complaints = complaint_repository.all
end
def destroy
object_rid = params["object_rid"]
user_rid = params["user_rid"]
complaint_repository.destroy(user_rid, object_rid)
complaint_repository.destroy @complaint
respond_to do |format|
format.html { redirect_to :back, notice: 'Denúncia excluída com sucesso.' }
end
end
private
def set_complaint
@complaint = complaint_repository.find params[:id]
end
# Never trust parameters from the scary internet, only allow the white list through.
def complaint_params
params.require(:complaint).permit(:id, :object, :message, :description)
end
end
......@@ -76,7 +76,9 @@ class Management::UsersController < ManagementController
@curators = Array.new
@users = User.includes(:roles).all
@users.all.each do |user|
@curators << user if user.roles[0].name == "curator"
if !user.roles[0].nil?
@curators << user if user.roles[0].name == "curator" || []
end
end
end
......@@ -84,7 +86,9 @@ class Management::UsersController < ManagementController
@admins = Array.new
@users = User.includes(:roles).all
@users.all.each do |user|
@admins << user if user.roles[0].name == "admin"
if !user.roles[0].nil?
@admins << user if user.roles[0].name == "admin" || []
end
end
end
......
class Attribute
include ActiveModel::Model
include OrientDbSerializable
attr_accessor :id, :key, :value
end
\ No newline at end of file
class Bookmarks < Collection
def initialize(params = {})
super(params)
@name = name
end
def name
'Bookmarks'
end
......
class Collection
include ActiveModel::Model
include OrientDbSerializable
include RepositoriesProxy
attr_accessor :id, :created_at, :last_modified, :name, :description, :privacy,
:owner, :learning_objects
......@@ -31,7 +32,7 @@ class Collection
# After remove some learning object to collection, you must use CollectionRepository to persist
# the changes.
def remove(learning_object)
learning_objects.delete_if{|x| x.id == learning_object.id}
learning_objects.delete_if { |x| x.id == learning_object.id }
end
def owner?(user)
......@@ -42,7 +43,11 @@ class Collection
!@name.blank?
end
private
protected
def excluded_orientdb_properties
['owner']
end
def defaults
{
......
class Complaint
include ActiveModel::Model
include OrientDbSerializable
attr_accessor :user,:object,:message,:description
validates_presence_of :user,:object,:message
attr_accessor :id, :user, :object, :message, :description, :created_at
validates_presence_of :user, :object, :message, :created_at
def initialize(params={})
super(params.merge(defaults))
end
def self.copyrights
ComplaintMessage.new("Objeto viola direitos autorais")
......@@ -19,4 +24,21 @@ class Complaint
def self.fake_user
ComplaintMessage.new "Usuário falso"
end
def to_orientdb_hash
super.merge("message" => @message.to_s)
end
private
def excluded_orientdb_properties
['user', 'object', '@class']
end
def defaults
{
created_at: DateTime.now.strftime("%Y-%m-%d %H:%M:%S")
}
end
end
module OrientDbSerializable
extend ActiveSupport::Concern
include OrientDb::Methods::SanitizableMethods
def to_orientdb_hash
hash = {'@class' => self.class.to_s}
self.instance_variables.each do |var|
var_name = sanitize_orientdb_vars(var)
hash[var_name] = sanitize_orientdb_values(self.instance_variable_get(var))
end
hash.delete('id')
excluded_orientdb_properties.each { |property| hash.delete(property.to_s) }
# TODO: find a better way to ignore variables from ActiveModel
hash.delete("validation_context")
hash.delete("errors")
hash
end
def excluded_orientdb_properties
[]
end
end
\ No newline at end of file
class LearningObject
include ActiveModel::Model
include RepositoriesProxy
include OrientDbSerializable
attr_accessor :id, :id_dspace, :rid, :name, :author, :description,
:published_at, :thumbnail, :created_at, :last_modified,
......@@ -8,10 +9,15 @@ class LearningObject
:downloads, :subjects, :attributes, :score, :publisher,
:school_level, :language, :source, :license, :copyright,
:country, :keywords, :file,
:grade_level, :attachment, :main_bitstream_id,
# Relation attrs
:likes, :views, :downloads, :subjects, :attributes, :publisher
validates_presence_of :name
validates_presence_of :name, :created_at, :type
delegate :get_retrievelink, to: :attachment
delegate :get_filename, to: :attachment
def initialize(params={})
super(params.merge(defaults))
......@@ -49,8 +55,10 @@ class LearningObject
def dislike(user)
learning_object_repository.dislike user, self
end
## end social actions
## metadata methods
def get_metadata_value_of key
get_metadata_values_of(key).first
end
......@@ -64,31 +72,7 @@ class LearningObject
values
end
#TODO: move for Bitstream model
def get_bitstream_retrievelink_of name
values = @bitstreams.select { |v| v["bundleName"] == name}
unless values.empty?
return Dspace::Config.rest_url + values.first["retrieveLink"]
end
end
#TODO: move for Bitstream model
def get_bitstream_filename_of name
values = @bitstreams.select { |v| v["bundleName"] == name }
unless values.empty?
return values.first["name"]
end
end
#TODO: move for Bitstream model
def get_retrievelink
get_bitstream_retrievelink_of "ORIGINAL"
end
#TODO: move for Bitstream model
def get_filename
get_bitstream_filename_of "ORIGINAL"
end
## end metadata methods
def likes
learning_object_repository.count_likes(self)
......@@ -98,16 +82,20 @@ class LearningObject
learning_object_repository.count_views(self)
end
def to_orientdb_hash
super.merge({'bitstreams' => attachment.bitstreams})
end
def excluded_orientdb_properties
['likes', 'views', 'downloads', 'subjects', 'attributes', 'publisher', 'attachment']
end
private
def defaults
{
likes: 0,
views: 0,
downloads: 0,
score: 0
# Setting this default value wont allow created_at to be set trough the constructor
# created_at: DateTime.new
}
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