diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000000000000000000000000000000000..99f7e706f38a24719b0fa5b6b60f5189f74c0d69 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,384 @@ +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 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9758003e54505227ecf1dbc2099a49d0bbd424cd..e492735487a1459230de4b867ccdd1ec5316254e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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 diff --git a/app/assets/javascripts/application/collections.coffee b/app/assets/javascripts/application/collections.coffee index 682a2f9738788679eeba61af6a293331f381e937..186298ef90ed4cb63ec34d9fa08614040d2184ef 100644 --- a/app/assets/javascripts/application/collections.coffee +++ b/app/assets/javascripts/application/collections.coffee @@ -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') diff --git a/app/assets/javascripts/application/columns.js b/app/assets/javascripts/application/columns.js index 9a24c897df0bacefd95b1242da0fa49b05f05403..4a5ec01014bdf8bde0a5d3959bf5f9e3d8dc78ad 100644 --- a/app/assets/javascripts/application/columns.js +++ b/app/assets/javascripts/application/columns.js @@ -1,24 +1,46 @@ $(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"> </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"> </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"> </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"> </div></div></div>'; + $(this).replaceWith(html); + i = 0; + } + else { + $(this).wrap('<div class="col-md-3"></div>'); + + i += 1; + } + }); + }); + } }); diff --git a/app/assets/javascripts/application/learning_objects.coffee.erb b/app/assets/javascripts/application/learning_objects.coffee.erb index c3e5b23ed56cb7d97727085261fe8bd4aa91be2f..aff6150bc575ba8429c9df41023542d815781089 100644 --- a/app/assets/javascripts/application/learning_objects.coffee.erb +++ b/app/assets/javascripts/application/learning_objects.coffee.erb @@ -1,50 +1,3 @@ -$ -> - $('.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 diff --git a/app/assets/javascripts/application/notice.coffee b/app/assets/javascripts/application/notice.coffee new file mode 100644 index 0000000000000000000000000000000000000000..1049f85e4ca15be3f61745bd4530dbad8116ef62 --- /dev/null +++ b/app/assets/javascripts/application/notice.coffee @@ -0,0 +1,11 @@ +# 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">×</span></button>' + text + '</div>' + + $('#content').prepend($(html)) diff --git a/app/assets/stylesheets/application/learning_objects.scss b/app/assets/stylesheets/application/learning_objects.scss index 2089a8e3504cece3dc1b922f0bc6ef8431260a06..2ab9b79f03abba8aa643dfd408a02b813aec8a55 100644 --- a/app/assets/stylesheets/application/learning_objects.scss +++ b/app/assets/stylesheets/application/learning_objects.scss @@ -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; diff --git a/app/builders/builder.rb b/app/builders/builder.rb index 00973be93271e30449ed922505f78ba80a388da8..2235e8b8dfc591a1f91f9eff0c9831c67b57fb50 100644 --- a/app/builders/builder.rb +++ b/app/builders/builder.rb @@ -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 diff --git a/app/builders/complaint_builder.rb b/app/builders/complaint_builder.rb new file mode 100644 index 0000000000000000000000000000000000000000..2b977bc8bf1e55f4e74ca4f2a6b7a55d3e8545c2 --- /dev/null +++ b/app/builders/complaint_builder.rb @@ -0,0 +1,36 @@ +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 diff --git a/app/builders/learning_object_builder.rb b/app/builders/learning_object_builder.rb index f5619b41f1594b714d53fb26f5eedf8497f694d9..4cdcf9a75438b195a5891987b055b2377483e338 100644 --- a/app/builders/learning_object_builder.rb +++ b/app/builders/learning_object_builder.rb @@ -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'] ) diff --git a/app/controllers/collections_controller.rb b/app/controllers/collections_controller.rb index d36cf9dcfb3a829302a4772f96d0008a1479c6f6..02db8f0ee93c100a2b3e78fc89ae1aa6b8f5496b 100644 --- a/app/controllers/collections_controller.rb +++ b/app/controllers/collections_controller.rb @@ -1,7 +1,7 @@ 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. diff --git a/app/controllers/complaints_controller.rb b/app/controllers/complaints_controller.rb index 54c2daf26282fc5f14dbc602ff9143346b9db54a..b4b2039369b8612f96ffa64b447397bfd29e6be0 100644 --- a/app/controllers/complaints_controller.rb +++ b/app/controllers/complaints_controller.rb @@ -1,14 +1,14 @@ 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 diff --git a/app/controllers/management/complaints_controller.rb b/app/controllers/management/complaints_controller.rb index 6db8a8aeb8376868b6061f58ccb67e814f5b93f0..fdcaa4775291b38b7e7e0af753db8a999304dbb7 100644 --- a/app/controllers/management/complaints_controller.rb +++ b/app/controllers/management/complaints_controller.rb @@ -1,25 +1,27 @@ 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 diff --git a/app/controllers/management/users_controller.rb b/app/controllers/management/users_controller.rb index 8419c88f8c9c85c0801ae385ed8472acca5e4e93..d223f2f71cba133a87bd1d3a1207b1b5dda04bb3 100644 --- a/app/controllers/management/users_controller.rb +++ b/app/controllers/management/users_controller.rb @@ -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 diff --git a/app/models/attribute.rb b/app/models/attribute.rb index af0710be3bf389b3fec994e82629afaccbc4e199..403de827e79c89db129ffb655cd0e36587ad9c0b 100644 --- a/app/models/attribute.rb +++ b/app/models/attribute.rb @@ -1,6 +1,6 @@ class Attribute include ActiveModel::Model + include OrientDbSerializable attr_accessor :id, :key, :value - end \ No newline at end of file diff --git a/app/models/bookmarks.rb b/app/models/bookmarks.rb index da16e2d62eed65afb4858820e62bd1409f2bb849..baf0dd1afa66deed5cfc73d587b6520fec1ff9d8 100644 --- a/app/models/bookmarks.rb +++ b/app/models/bookmarks.rb @@ -1,5 +1,10 @@ class Bookmarks < Collection + def initialize(params = {}) + super(params) + @name = name + end + def name 'Bookmarks' end diff --git a/app/models/collection.rb b/app/models/collection.rb index 015116ae819cd999ad898526fd766e2b5fc868ee..a39ca74c501250bda6cccc9421a479b274034b28 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -1,5 +1,6 @@ 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 { diff --git a/app/models/complaint.rb b/app/models/complaint.rb index f5815c162ac3840058331a5ef4c82d971da2b9f8..83ae4172ac55d6be0709eb7aa170ca546952be57 100644 --- a/app/models/complaint.rb +++ b/app/models/complaint.rb @@ -1,8 +1,13 @@ 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 diff --git a/app/models/concerns/orient_db_serializable.rb b/app/models/concerns/orient_db_serializable.rb new file mode 100644 index 0000000000000000000000000000000000000000..4d0daeeca520a6ad9fbbbdd55747b0d07290d422 --- /dev/null +++ b/app/models/concerns/orient_db_serializable.rb @@ -0,0 +1,25 @@ +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 diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index bd937e37a55ff5550de0f146ab68e2dca2bacb74..98c24eecbf6eeba71112759b5be83e48a9404577 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -1,6 +1,7 @@ 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 diff --git a/app/models/learning_object/attachment.rb b/app/models/learning_object/attachment.rb new file mode 100644 index 0000000000000000000000000000000000000000..ddf7b9c4910ff207638f6de7d228564609a46445 --- /dev/null +++ b/app/models/learning_object/attachment.rb @@ -0,0 +1,32 @@ +class LearningObject::Attachment + attr_accessor :bitstreams + + def initialize(bitstreams) + @bitstreams = bitstreams + end + + def get_retrievelink + get_bitstream_retrievelink_of "ORIGINAL" + end + + def get_filename + get_bitstream_filename_of "ORIGINAL" + end + + private + + 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 + + def get_bitstream_filename_of name + values = @bitstreams.select { |v| v["bundleName"] == name } + unless values.empty? + return values.first["name"] + end + end + +end \ No newline at end of file diff --git a/app/repositories/orient_db/attribute_repository.rb b/app/repositories/orient_db/attribute_repository.rb index a0283b36a4f8bd77f59550110429e634ba30b732..6d05df8a8d3a94746306c105d8acc2d21329c356 100644 --- a/app/repositories/orient_db/attribute_repository.rb +++ b/app/repositories/orient_db/attribute_repository.rb @@ -13,6 +13,8 @@ module OrientDb build_objects get_edges_end("HasAttr", "out", learning_object.id) end + protected + def build_object(args={}) AttributeBuilder.build_from_orientdb args end diff --git a/app/repositories/orient_db/base.rb b/app/repositories/orient_db/base.rb index 394b8857567e0a0a087f01914908b96fc914bd3e..4d1016f39cd08a4f9bc39e69b3933bc80d02435a 100644 --- a/app/repositories/orient_db/base.rb +++ b/app/repositories/orient_db/base.rb @@ -44,19 +44,12 @@ class OrientDb::Base end end + protected + # Take the object and make a hash in the OrientDB format. # Used to create a document. def build_hash(object) - hash = {'@class' => odb_class} - object.instance_variables.each do |var| - var_name = sanitize_orientdb_vars(var) - hash[var_name] = sanitize_orientdb_values(object.instance_variable_get(var)) - end - hash.delete('id') - # TODO: find a better way to ignore variables from ActiveModel - hash.delete("validation_context") - hash.delete("errors") - hash + object.to_orientdb_hash end def build_objects(hash=[]) @@ -71,8 +64,6 @@ class OrientDb::Base raise NoMethodError, "You must implement this method" end - protected - def accepted_properties raise NoMethodError, "You must implement this method" end diff --git a/app/repositories/orient_db/collection_repository.rb b/app/repositories/orient_db/collection_repository.rb index 67836427b5b9ced2367491455f3287bfdf326605..064b5c0108ba3ab17ea141c6ef801e8283dc6cf5 100644 --- a/app/repositories/orient_db/collection_repository.rb +++ b/app/repositories/orient_db/collection_repository.rb @@ -4,10 +4,6 @@ module OrientDb include OrientDb::Methods::FinderMethods include RepositoriesProxy - def build_object(args={}) - CollectionBuilder.build_from_orientdb args - end - def save_learning_objects(collection = Collection.new) if collection.id.to_s.empty? raise NotPersistedRecordError, 'Before save learning objects to collection, you must persist using CollectionRepository::create method' @@ -116,7 +112,11 @@ module OrientDb update_property(collection, 'privacy', privacy) if privacy_accepted?(privacy) end - private + protected + + def build_object(args={}) + CollectionBuilder.build_from_orientdb args + end def accepted_properties ['privacy'] diff --git a/app/repositories/orient_db/complaint_repository.rb b/app/repositories/orient_db/complaint_repository.rb index f0419fe6d8ecc5347dadf84ae020c503698e66d4..678a91bc2c28fd205d7ee04853feb1d4ebe556f4 100644 --- a/app/repositories/orient_db/complaint_repository.rb +++ b/app/repositories/orient_db/complaint_repository.rb @@ -4,11 +4,7 @@ module OrientDb include RepositoriesProxy def report(complaint) - if edge_exists?(odb_class, complaint.user.rid, complaint.object) - false - else - connection.command "CREATE EDGE Complaint FROM #{complaint.user.rid} TO #{complaint.object} SET message = '#{complaint.message}', description = '#{complaint.description}'" - end + create(complaint) if can_report? complaint end def destroy(user_rid, object_rid) @@ -16,27 +12,30 @@ module OrientDb raise "The object has not been reported by you yet." end - connection.command "DELETE EDGE Complaint FROM #{user_rid} TO #{object_rid}" + destroy_edge 'Complaint', user_rid, object_rid end - def build_object(args={}) - Complaint.new(args) + ## + #checks if user can report a object + #returns bool + def can_report?(complaint) + !edge_exists?(odb_class, complaint.user.rid, complaint.object) end - def get_complaints - result = connection.command "SELECT FROM Complaint" - build_complaint result + ## + #overwriting OrientDb::Base#create method + def create(complaint) + if complaint.valid? + create_and_set_edge('Complaint', complaint.user.rid, complaint.object.id, complaint.to_orientdb_hash) + return true + end + false end + protected - def build_complaint(args) - complaint = Array.new - for i in 0..args["result"].length-1 - unless args.nil? - complaint[i] = Complaint.new(:user => args["result"][i]["out"], :object => args["result"][i]["in"], :message => args["result"][i]["message"], :description => args["result"][i]["description"]) - end - end - complaint + def build_object(args={}) + ComplaintBuilder.build_from_orientdb args end end diff --git a/app/repositories/user_repository_proxy.rb b/app/repositories/user_repository_proxy.rb index 88cbdfbf1d40d7b415ff08d7349d0b68455f150d..4fa3f253aef1c082fb4ab50aa18b29d81298f773 100644 --- a/app/repositories/user_repository_proxy.rb +++ b/app/repositories/user_repository_proxy.rb @@ -17,7 +17,7 @@ class UserRepositoryProxy end def get_by_rid(rid) - orientdb_user_repository.get_by_rid(rid) + User.find_by_rid rid end def get_graph_id(user) diff --git a/app/services/autocomplete_service.rb b/app/services/autocomplete_service.rb index 086c1ff114b70a3e50b613e09c5a2e70fe0e504a..8aefd38cceaa328dd24dd495bacc76bfeb86b5f5 100644 --- a/app/services/autocomplete_service.rb +++ b/app/services/autocomplete_service.rb @@ -6,6 +6,6 @@ class AutocompleteService end def query(query) - return open( "#{@url}:#{@port}?q=#{query}" ).read + return open( "#{@url}:#{@port}?q=#{query.downcase}" ).read end end diff --git a/app/views/collections/_list.html.erb b/app/views/collections/_list.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..4eb2767808042bd7d8f7e8d1478cd16aa356cc0a --- /dev/null +++ b/app/views/collections/_list.html.erb @@ -0,0 +1,3 @@ +<% @collection.learning_objects.each do |learning_object| %> + <%= render learning_object, orientation: 'vertical' %> +<% end %> diff --git a/app/views/collections/list.html.erb b/app/views/collections/list.html.erb index 15f03b62ff298d2bf2242d86fd582c4143f78710..3c2f0c010bed078ab48e9a645629b4848375864d 100644 --- a/app/views/collections/list.html.erb +++ b/app/views/collections/list.html.erb @@ -3,22 +3,27 @@ <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title">Coleções</h4> + <h4 class="modal-title"><%= @title %></h4> </div> <form id="collections-modal-form"> <div class="modal-body"> - <% if @learning_object.blank? %> - <% @collections.each do |collection| %> - <% unless collection.id == @collection.id %> - <input type="checkbox" class="collection-element" id="<%= collection.id %>" name="collections" value="<%= collection.id %>"> - <label for="<%= collection.id %>"><%= collection.name %></label><br/> - <% end %> + <%= hidden_field_tag 'collection_id', @collection.id unless @collection.blank? %> + <%= hidden_field_tag 'type', @type unless @type.blank? %> + <% unless @learning_objects.blank? %> + <% @learning_objects.each do |object| %> + <%= hidden_field_tag 'learning_object', object.id %> <% end %> <% end %> + + <% @collections.each do |collection| %> + <input type="checkbox" class="collection-element" id="<%= collection.id %>" name="collection" value="<%= collection.id %>"> + <label for="<%= collection.id %>"><%= collection.name %></label><br/> + <% end %> + <%= 'Nenhuma coleção disponÃvel. Crie novas no seu perfil de usuário.' if @collections.blank? %> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button> - <button type="submit" class="btn btn-primary">Enviar</button> + <button type="submit" class="btn btn-primary"><%= @send %></button> </div> </form> </div> diff --git a/app/views/collections/show.html.erb b/app/views/collections/show.html.erb index 17b645d8fd4d9ca70a283969e0a7abe52b1d2ab6..6c6bdeead1c2b851dc14236c879dd95fbbf61772 100644 --- a/app/views/collections/show.html.erb +++ b/app/views/collections/show.html.erb @@ -2,17 +2,19 @@ <br/> <div class="container-fluid"> <div class="navbar-right" style="text-align:right"> - <% if @own && @collection.class != Bookmarks %> + <% if @own %> + <% if @collection.class != Bookmarks %> <%= link_to '#' do %> - <%= link_to 'APAGAR', collection_path(@collection.id), method: :delete, class: 'btn btn-danger btn-remove', style: 'margin-right: 30px', data: {confirm: 'Não será possÃvel recuperá-la, você tem certeza?'} %></span> + <%= link_to 'APAGAR', collection_path(@collection.id), method: :delete, class: 'btn btn-danger btn-remove', style: 'margin-right: 30px', data: {confirm: 'Não será possÃvel recuperá-la, você tem certeza?'} %></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> <% 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 class="navbar-header"> @@ -24,8 +26,10 @@ <ul class="nav navbar-nav navbar-right collection-header" style="margin-left: 30px;"> <li><h2><%= (@collection.class != Bookmarks) ? @collection.name : "Favoritos" %></h2></li> <li> - <%= image_tag image_path("icons/square.png"), class: "logo-image", size: "20x20" %> - <%= collection_length @collection %> + <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" %> + <%= collection_length @collection %> + </a> </li> </ul> </div> @@ -40,10 +44,12 @@ <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"> <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"> <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"> @@ -58,11 +64,9 @@ </div> </nav> -<div class="row learning-object-columns"> - <br/> - - <% @collection.learning_objects.each do |learning_object| %> - <%= render learning_object, orientation: 'vertical' %> - <% end %> - +<div class= "row"> + <div class="learning-object-columns"> + <br/> + <%= render partial: 'list' %> + </div> </div> diff --git a/app/views/complaints/_form.html.erb b/app/views/complaints/_form.html.erb index fd89e3e83c024f372647a24f51b9e1ccfcd31f3d..d2b53c9655a9539dce3f54f8a2bc7069b63c4793 100644 --- a/app/views/complaints/_form.html.erb +++ b/app/views/complaints/_form.html.erb @@ -2,29 +2,31 @@ <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title" id="myModalLabel">Denunciar objeto</h4> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">×</span></button> + <h4 class="modal-title" id="myModalLabel">Ajude-nos a entender o que está acontecendo</h4> </div> <%= form_for @complaint do |f| %> - <div class="modal-body" style="text-align:justify"> - <fieldset> - <div class="ls-label"> - <%= f.collection_radio_buttons :message, @messages, :message, :message do |m| %> - <div class="radio"> - <%= f.radio_button :message, m.text %> - <%= f.label :message, m.text %> - </div> - <% end %> - <br> - <%= f.text_area :description, placeholder: "mais informações", rows: "10", style: "width:100%" %> - </div> - <%= f.hidden_field :object_rid, value: @learning_object.id %> - </fieldset> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button> - <%= f.submit "Denunciar", class:"btn btn-danger submit_button" %> - </div> + <div class="modal-body" style=" text-align:justify"> + <h5>Por que você está denunciando este objeto?</h5> + <fieldset> + <div class="ls-label"> + <%= f.collection_radio_buttons :message, @messages, :message, :message do |m| %> + <div class="radio"> + <%= f.radio_button :message, m.text %> + <%= f.label :message, m.text %> + </div> + <% end %> + <br> + <%= f.text_area :description, placeholder: "Fale mais sobre o problema...", rows: "10", style: "width:100%" %> + </div> + <%= f.hidden_field :object, value: @learning_object.id %> + </fieldset> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button> + <%= f.submit "Denunciar", class: "btn btn-danger submit_button" %> + </div> <% end %> </div> </div> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 72ee6642ab35f9b70022629ac42abfabb25dd7ea..e978812d1ecdb3c7bb0d72e11ec698f9153cb484 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,7 +28,9 @@ </div> <% end %> - <%= yield %> + <div id="content"> + <%= yield %> + </div> </div> <%= render 'shared/application/footer' %> diff --git a/app/views/learning_objects/_collections_button.html.erb b/app/views/learning_objects/_collections_button.html.erb index 159378255504aaad28d4cbb487cb61de78ab0857..1f2b4f7802cf33b365f73a207f3e9620a0124aad 100644 --- a/app/views/learning_objects/_collections_button.html.erb +++ b/app/views/learning_objects/_collections_button.html.erb @@ -1,3 +1,3 @@ -<a tabindex="0" data-container="body" class="btn btn-default btn-xs add_to_collection" role="button" data-toggle="popover" data-placement="left" title="Adicionar as coleções" data-loid="<%= learning_object.id %>" data-poload="/learning_objects/<%= ERB::Util.url_encode(learning_object.id) %>/collections.json"> +<a tabindex="0" class="add-to-collection btn btn-default btn-xs" role="button" title="Adicionar as coleções" data-loid="<%= learning_object.id %>"> <span class="glyphicon glyphicon-list" aria-hidden="true"></span> </a> diff --git a/app/views/learning_objects/show.html.erb b/app/views/learning_objects/show.html.erb index d19b273e1fa18b977bb6221bb5deddfa4e090fdb..b563888f8da704e7e064e11efb9424b8fcfcbebc 100644 --- a/app/views/learning_objects/show.html.erb +++ b/app/views/learning_objects/show.html.erb @@ -35,7 +35,7 @@ <div class="rating-panel"> <% if user_signed_in? %> <div class="actions"> - <div class="col-md-3 action"> + <div class="col-sm-3 action"> <%= link_to like_learning_object_path(id: @learning_object.id), class: 'vote',method: :post, remote: true do %> <% if @liked %> <%= image_tag "icons/Curtir_02.png", alt: "Descurtir" %> @@ -45,19 +45,19 @@ <h6>curtir objeto</h6> <% end %> </div> - <div class="col-md-3 action"> + <div class="col-sm-3 action"> <a href="<%= @learning_object.get_retrievelink %>"> <%= image_tag "icons/download.png", alt: "Download do objeto" %> <h6>salvar no computador</h6> </a> </div> - <div class="col-md-3 action"> - <a tabindex="0" class="add_to_collection" role="button" data-toggle="popover" data-placement="left" title="Adicionar as coleções" data-loid="<%= @learning_object.id %>" data-poload="/learning_objects/<%= ERB::Util.url_encode(@learning_object.id) %>/collections.json"> + <div class="col-sm-3 action"> + <a tabindex="0" class="add-to-collection" role="button" title="Adicionar as coleções" data-loid="<%= @learning_object.id %>"> <%= image_tag "icons/collection-add.png", alt: "Adicionar à coleção" %> <h6>adicionar à coleção</h6> </a> </div> - <div class="col-md-3 action"> + <div class="col-sm-3 action"> <%= render 'complaints/complaints_button' %> </div> </div> diff --git a/app/views/management/complaints/index.html.erb b/app/views/management/complaints/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..85938c556159b61535d77f92aab99ff9419903f6 --- /dev/null +++ b/app/views/management/complaints/index.html.erb @@ -0,0 +1,124 @@ +<h1 class="ls-title-intro ls-ico-stats">Denúncias</h1> + +<div class="ls-box-filter"> + + <form action="" class="ls-form ls-form-inline"> + + <input type="hidden" name="status" value=""> + + <label class="ls-label col-lg-3 col-md-6 col-sm-12"> + <b class="ls-label-text">PerÃodo</b> + + <div class="ls-custom-select"> + <select name="period" id="select_period" class="ls-select"> + <option>Hoje</option> + <option>Ontem</option> + <option>Última semana</option> + <option>Últimos 30 dias</option> + <option>Últimos 6 meses</option> + <option>Últimos 12 meses</option> + </select> + </div> + </label> + + <input type="submit" class="ls-btn-primary" value="Filtrar" aria-expanded="false"> + </form> + +</div> + + +<h2 class="ls-title-4">Relatório de Denúncias</h2> + +<div class="row"> + <div class="col-md-6 col-sm-6"><p>Número de vezes que os usuários marcaram objetos educacionais como spam.</p></div> + <div class="col-md-6 col-sm-6"> + <p class="ls-float-right ls-float-none-xs">PerÃodo selecionado: <strong>últimos 30 dias</strong></p></div> +</div> + +<div class="ls-clearfix"></div> + +<div class="ls-board-box"> + + <div id="sending-stats" class="row ls-box-group"> + <div class="col-sm-12 col-lg-5"> + <div class="ls-box"> + <div class="ls-box-head"> + <h6 class="ls-title-4">Total de denúncias</h6> + </div> + <div class="ls-box-body"> + <strong>80</strong> + <small>spam</small> + </div> + </div> + </div> + + <div class="col-sm-12 col-lg-7"> + <div class="ls-box"> + <div class="ls-box-head"> + <h6 class="ls-title-4">Percentual comparado ao último mês</h6> + </div> + <div class="ls-box-body"> + <div class="col-lg-offset-3 col-lg-3 col-xs-6"> + <strong class="ls-color-theme" data-prefix="%">-3,60</strong> + <small>usuário falso</small> + </div> + <div class="col-lg-3 col-xs-6"> + <strong class="ls-color-danger" data-prefix="%">+0,90</strong> + <small>direitos autorais</small> + </div> + <div class="col-lg-3 col-xs-6"> + <strong class="ls-color-danger" data-prefix="%">+32</strong> + <small>conteúdo ofensivo</small> + </div> + </div> + </div> + </div> + </div> + + + <div class="ls-tabs-container" id="awesome-tab-content"> + <div id="infoAll" class="ls-tab-content" role="tabpanel" style="display: block;"> + <% @complaints.each do |complaint| %> + + <div class="ls-list"> + <header class="ls-list-header"> + <div class="ls-list-title col-md-9"> + <strong><%= complaint.object.name %></strong> + <small><%= complaint.message %></small> + + <% if !complaint.description.blank? %> + <p><%= complaint.description %></p> + <% end %> + + </div> + <div class="col-md-3 ls-txt-right"> + <div data-ls-module="dropdown" class="ls-dropdown ls-pos-right"> + <a href="#" class="ls-btn-primary" aria-expanded="false" role="combobox">Administrar</a> + <ul class="ls-dropdown-nav" aria-hidden="true"> + <li><a href="#" role="option" title="Funcionalidade em desenvolvimento!">Suspender conteúdo</a></li> + <li> + <%= link_to 'Ignorar denúncia', management_complaint_path(id: complaint.id), {method: :delete, data: {confirm: 'Tem certeza que deseja ignorar esta denúncia?'}, title: 'Ignorar denúncia', class: 'ls-btn ls-btn-sm', role: 'option'} %> + </li> + </ul> + </div> + </div> + </header> + <div class="ls-list-content "> + <div class="col-xs-12 col-md-6"> + <span class="ls-list-label">Denunciado por</span> + <strong><%= complaint.user.name %></strong> + </div> + <div class="col-xs-12 col-md-6"> + <span class="ls-list-label">Data</span> + <strong><%= complaint.created_at %></strong> + </div> + </div> + </div> + + <% end %> + </div> + </div> + +</div> + +</div> \ No newline at end of file diff --git a/app/views/management/complaints/show.html.erb b/app/views/management/complaints/show.html.erb index 240766be7a33a97e0d6272c4530ec540c2532e0c..4a706713209327af4adebe76f2c2e9165a0247ec 100644 --- a/app/views/management/complaints/show.html.erb +++ b/app/views/management/complaints/show.html.erb @@ -1,28 +1,126 @@ -<ol class="ls-breadcrumb"> - <li><%= link_to "InÃcio", management_root_path %></li> - <li>Denúncias</li> -</ol> -<br><br> +<h1 class="ls-title-intro ls-ico-stats">Denúncias</h1> +<div class="ls-box-filter"> -<h3><b>Total de denúncias: <%= @complaints.count %></b></h3> <BR><BR> + <form action="" class="ls-form ls-form-inline"> + <input type="hidden" name="status" value=""> + <label class="ls-label col-lg-3 col-md-6 col-sm-12"> + <b class="ls-label-text">PerÃodo</b> -<% @complaints.each do |c| %> - <div class="ls-box-filter"> - Denúncia de <b><%= c.user.name %></b> para o objeto <%= link_to c.object["name"], learning_object_path(c.object["@rid"]) %><BR> - <BR> - <b>Mensagem:</b> <%= c.message %><BR> - <BR> - <b>Descrição:</b> <%= c.description == "" ? "--" : c.description %><BR> + <div class="ls-custom-select"> + <select name="period" id="select_period" class="ls-select"> + <option>Hoje</option> + <option>Ontem</option> + <option>Última semana</option> + <option>Últimos 30 dias</option> + <option>Últimos 6 meses</option> + <option>Últimos 12 meses</option> + </select> + </div> + </label> - <div id="suspend", class="ls-btn ls-float-right"> - <%= link_to 'Cancelar Denúncia', management_complaints_path(:object_rid => c.object["@rid"], :user_rid => c.user.rid), {method: :delete, data: { confirm: 'Tem certeza que deseja excluir?'}, title: 'Apagar usuário', class: 'ls-color-danger', role: 'option'} %> + <input type="submit" class="ls-btn-primary" value="Filtrar" aria-expanded="false"> + </form> + +</div> + + +<h2 class="ls-title-4">Relatório de Denúncias</h2> + +<div class="row"> + <div class="col-md-6 col-sm-6"><p>Número de vezes que os usuários marcaram objetos educacionais como spam.</p></div> + <div class="col-md-6 col-sm-6"> + <p class="ls-float-right ls-float-none-xs">PerÃodo selecionado: <strong>últimos 30 dias</strong></p></div> +</div> + +<div class="ls-clearfix"></div> + +<div class="ls-board-box"> + + <div id="sending-stats" class="row ls-box-group"> + <div class="col-sm-12 col-lg-5"> + <div class="ls-box"> + <div class="ls-box-head"> + <h6 class="ls-title-4">Total de denúncias</h6> + </div> + <div class="ls-box-body"> + <strong>80</strong> + <small>spam</small> + </div> + </div> + </div> + + <div class="col-sm-12 col-lg-7"> + <div class="ls-box"> + <div class="ls-box-head"> + <h6 class="ls-title-4">Percentual comparado ao último mês</h6> + </div> + <div class="ls-box-body"> + <div class="col-lg-offset-3 col-lg-3 col-xs-6"> + <strong class="ls-color-theme" data-prefix="%">-3,60</strong> + <small>usuário falso</small> + </div> + <div class="col-lg-3 col-xs-6"> + <strong class="ls-color-danger" data-prefix="%">+0,90</strong> + <small>direitos autorais</small> + </div> + <div class="col-lg-3 col-xs-6"> + <strong class="ls-color-danger" data-prefix="%">+32</strong> + <small>conteúdo ofensivo</small> + </div> + </div> + </div> </div> + </div> + + + + <div class="ls-tabs-container" id="awesome-tab-content"> + <div id="infoAll" class="ls-tab-content" role="tabpanel" style="display: block;"> + <% @complaints.each do |complaint| %> + + <div class="ls-list"> + <header class="ls-list-header"> + <div class="ls-list-title col-md-9"> + <strong><%= complaint.object.name %></strong> + <small><%= complaint.message %></small> - <div id="suspend", class="ls-btn ls-float-right"> - Suspender conteúdo + <% if !complaint.description.blank? %> + <p><%= complaint.description %></p> + <% end %> + + </div> + <div class="col-md-3 ls-txt-right"> + <div data-ls-module="dropdown" class="ls-dropdown ls-pos-right"> + <a href="#" class="ls-btn-primary" aria-expanded="false" role="combobox">Administrar</a> + <ul class="ls-dropdown-nav" aria-hidden="true"> + <li><a href="#" role="option" title="Funcionalidade em desenvolvimento!">Suspender conteúdo</a></li> + <li> + <%= link_to 'Ignorar denúncia', destroy_mana %> + <a href="#" role="option">Ignorar denúncia</a> + </li> + </ul> + </div> + </div> + </header> + <div class="ls-list-content "> + <div class="col-xs-12 col-md-6"> + <span class="ls-list-label">Denunciado por</span> + <strong><%= complaint.user.name %></strong> + </div> + <div class="col-xs-12 col-md-6"> + <span class="ls-list-label">Data</span> + <strong><%= complaint.created_at %></strong> + </div> + </div> + </div> + + <% end %> + </div> </div> + </div> -<%end%> + +</div> \ No newline at end of file diff --git a/app/views/shared/application/_header.html.erb b/app/views/shared/application/_header.html.erb index e7cbff419fcc4a7cfcebeeb2c2bde87598d15d18..8c29a321875f9c57ab92ef918de8675eed992fc5 100644 --- a/app/views/shared/application/_header.html.erb +++ b/app/views/shared/application/_header.html.erb @@ -17,7 +17,7 @@ <div class="container"> <div class="row"> <div class="col-md-3 logo-container"> - <div class="logo" data-no-turbolink> + <div class="logo"> <%= link_to root_path do %> <%= image_tag image_path("logo.png"), class: "logo-image" %><br/> diff --git a/app/views/shared/management/_nav_menu.html.erb b/app/views/shared/management/_nav_menu.html.erb index abdab651f9847ef7ffccaf280de3d3fa6d9f3c05..91e1b4206b675da9cbeeb7ca00451b64926105bd 100644 --- a/app/views/shared/management/_nav_menu.html.erb +++ b/app/views/shared/management/_nav_menu.html.erb @@ -25,4 +25,8 @@ <li><%= link_to "Denúncias", management_complaints_path, class: 'ls-ico-bullhorn' %> <li> </ul> + + <li> <%= link_to "Voltar ao Portal", root_path %> </li> + + </nav> diff --git a/autocomplete/src/main.cpp b/autocomplete/src/main.cpp index f4c7323c3481f6d37d36cd027d90aab4372dc1ac..0fc5a90771dacf248f915cb868d17c4190f9366f 100644 --- a/autocomplete/src/main.cpp +++ b/autocomplete/src/main.cpp @@ -44,12 +44,15 @@ using namespace std; int main(int argc, char ** argv) { - if ( argc != 3 ){ - cerr << "Usage: " << argv[0] << " <dicionary:file_url> <port:int>\n"; + if ( argc < 2 ){ + cerr << "Usage: " << argv[0] << " <string dicionary=../brazilian.txt> <int port=4242>\n"; return 1; } - int port = atoi(argv[2]); + int port = 4242; + if ( argc > 2 ){ + port = atoi(argv[2]); + } EmbeddedServer server(argv[1], port); while(1) sleep(100); diff --git a/config/routes.rb b/config/routes.rb index 44d23cbf108917c170fbfb9c69607449ede56f05..3394943267b68f8cb81e40d083f987f462a4a2d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,7 @@ Rails.application.routes.draw do namespace :management do root 'welcome#index' - resource :complaints, except: ['create'] + resources :complaints, only: [:index, :destroy] resources :institutions do member do post '/user/:user_id', as: :add_user, action: :add_user @@ -48,7 +48,6 @@ Rails.application.routes.draw do root 'welcome#index' resources :subjects, only: [:index, :show] - resource :complaints, only: ['create'] resources :institutions do @@ -70,18 +69,12 @@ Rails.application.routes.draw do # collection list get :list - # add a learning object for some collection - post '/learning_object/:learning_object_id', as: :add_learning_object, action: :add_learning_object - - # remove a learning object for some collection - delete '/learning_object/:learning_object_id', as: :destroy_learning_object, action: :remove_learning_object - # change privacy post :change_privacy - # copy / move learning_objects - get '/copy', as: :copy_learning_objects, action: :copy_learning_objects - get '/move', as: :move_learning_objects, action: :move_learning_objects + # add/remove a learning object for some collection + post '/learning_objects/:learning_objects_ids', as: :add_learning_object, action: :add_learning_object + delete '/learning_objects/:learning_objects_ids', as: :remove_learning_object, action: :remove_learning_object end end diff --git a/lib/orient_db/methods/edge_methods.rb b/lib/orient_db/methods/edge_methods.rb index a28a861e7480b4c6cefeaf3bd21a7f192a0515d5..f738560e6ea7e62bd3a6706c8e3b569d01f0d6ed 100644 --- a/lib/orient_db/methods/edge_methods.rb +++ b/lib/orient_db/methods/edge_methods.rb @@ -28,7 +28,7 @@ module OrientDb end def create_edge(edge_class, from_id, to_id) - qry = "CREATE EDGE #{edge_class} FROM #{from_id} TO #{to_id}" + qry = "CREATE EDGE #{edge_class.to_s} FROM #{from_id} TO #{to_id}" logger.create qry connection.command qry end diff --git a/lib/orient_db/methods/sanitizable_methods.rb b/lib/orient_db/methods/sanitizable_methods.rb index ea8444ca4a5452865fcb25ee31b5b1cbb314e216..b7d58ec44e38730eb8b111f54ecc7920057b1194 100644 --- a/lib/orient_db/methods/sanitizable_methods.rb +++ b/lib/orient_db/methods/sanitizable_methods.rb @@ -7,7 +7,8 @@ module OrientDb end def sanitize_orientdb_values(val) - if val.respond_to? "strftime" + #date checks + if val.respond_to? :strftime val = val.strftime("%Y-%m-%d %H:%M:%S") end val diff --git a/lib/orient_db/migrations/create_collection.rb b/lib/orient_db/migrations/create_collection.rb index e421abef16ff42263b597ac01404a3fc66e288ea..545fca8708ae4c72299d88b09f5cedd5b87d2291 100644 --- a/lib/orient_db/migrations/create_collection.rb +++ b/lib/orient_db/migrations/create_collection.rb @@ -6,6 +6,8 @@ class OrientDb::Migrations::CreateCollection < OrientDb::Migration c.property 'description', :string c.link 'learning_objects', :linkset, 'LearningObject' end + metadata = {:analyzer => "org.apache.lucene.analysis.br.BrazilianAnalyzer"} + add_index 'Collection', ['name', 'description'], "FULLTEXT", "collection_search", "LUCENE", metadata.to_json end def down diff --git a/lib/orient_db/migrations/create_learning_object.rb b/lib/orient_db/migrations/create_learning_object.rb index ee70dddab45e558f53f5a049a142bc79ae967880..69fc736890ca84499c35f8c7f4a96757ab5398a8 100644 --- a/lib/orient_db/migrations/create_learning_object.rb +++ b/lib/orient_db/migrations/create_learning_object.rb @@ -2,7 +2,8 @@ class OrientDb::Migrations::CreateLearningObject < OrientDb::Migration def up create_class 'LearningObject', 'Object' do |c| - c.property 'id_dspace', :integer, :mandatory => true, :notnull => true + c.property 'id_dspace', :long, :mandatory => true, :notnull => true + c.property 'main_bitstream_id', :long c.property 'description', :string c.property 'thumbnail', :string c.property 'type', :string @@ -15,7 +16,7 @@ class OrientDb::Migrations::CreateLearningObject < OrientDb::Migration end add_index 'LearningObject', ['id_dspace'], "UNIQUE_HASH_INDEX" metadata = {:analyzer => "org.apache.lucene.analysis.br.BrazilianAnalyzer"} - add_index 'LearningObject', ['name', 'description'], "FULLTEXT", "learningobject_search", "LUCENE", metadata.to_json + add_index 'LearningObject', ['name', 'description', 'author'], "FULLTEXT", "learningobject_search", "LUCENE", metadata.to_json end def down diff --git a/test/models/collection_test.rb b/test/models/collection_test.rb index 3a4da2742e6cf63e8df3a152b204e80d3ed41e3a..eac7a38bfd207529fac40053bc58f206de882290 100644 --- a/test/models/collection_test.rb +++ b/test/models/collection_test.rb @@ -1,12 +1,6 @@ require 'test_helper' class CollectionTest < ActiveSupport::TestCase - ## Errors messages are missing, and they are required to shoulda matachers pass - - #should validate_presence_of :name - #should validate_presence_of :created_at - #should validate_presence_of :owner - #should validate_presence_of :learning_objects test 'collection is invalid when name attribute is empty' do collection = Collection.new @@ -27,14 +21,35 @@ class CollectionTest < ActiveSupport::TestCase end test 'remove learning object from collection' do - lo1 = LearningObject.new + lo1 = LearningObject.new(id: '#45:2') collection = Collection.new(name: 'Minha coleção de teste') collection.add lo1 - collection.add LearningObject.new + collection.add LearningObject.new(id: '#43:34') assert_count 2, collection.learning_objects collection.remove lo1 assert_count 1, collection.learning_objects end + test 'serialize collection for orientdb' do + collection = Collection.new(name: 'Minha coleção de teste') + assert_equal(build_collection_hash(collection), collection.to_orientdb_hash) + #collection.add LearningObject.new(id: '#43:34') + #collection.add LearningObject.new(id: '#43:53') + #assert_equal({"@class" => "Collection", "created_at" => "2015-11-18 16:10:52", "last_modified" => "2015-11-18 16:10:52", "learning_objects" => ['#43:34', '#43:53'], "privacy" => "private", "name" => "Minha coleção de teste"}, collection.to_orientdb_hash) + end + + private + + def build_collection_hash(collection) + { + "@class" => "Collection", + "created_at" => collection.created_at, + "last_modified" => collection.last_modified, + "learning_objects" => [], + "privacy" => collection.privacy, + "name" => collection.name + } + end + end \ No newline at end of file diff --git a/test/models/complaint_test.rb b/test/models/complaint_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..02a3bb18a66da317ecefcd4b2db5dd8cc9278388 --- /dev/null +++ b/test/models/complaint_test.rb @@ -0,0 +1,42 @@ +require 'test_helper' + +class ComplaintTest < ActiveSupport::TestCase + should validate_presence_of :user + should validate_presence_of :object + should validate_presence_of :message + + test 'serialize for orientdb' do + complaint = Complaint.new( + user: User.new(rid: '#14:15'), + object: LearningObject.new(id: '#16:43'), + message: Complaint.copyrights, + description: 'teste', + created_at: DateTime.now.strftime("%Y-%m-%d %H:%M:%S") + ) + + expected_hash = {"created_at" => complaint.created_at.to_s, "description" => complaint.description, "message" => complaint.message.to_s} + assert_equal(expected_hash, complaint.to_orientdb_hash) + end + + test 'should returns copyright message' do + assert_complaint_message Complaint.copyrights + end + + test 'should returns ofensive content message' do + assert_complaint_message Complaint.ofensive_content + end + + test 'should returns ofensive user message' do + assert_complaint_message Complaint.ofensive_user + end + + test 'should returns fake user message' do + assert_complaint_message Complaint.fake_user + end + + private + + def assert_complaint_message(complaint_message) + assert_instance_of ComplaintMessage, complaint_message + end +end diff --git a/test/models/learning_object_test.rb b/test/models/learning_object_test.rb index 3c3932c319c6291c1023d103d84bf24a0ba765e7..3a7c972ea22a714e93b038298a11c7c1db55d486 100644 --- a/test/models/learning_object_test.rb +++ b/test/models/learning_object_test.rb @@ -4,11 +4,22 @@ class LearningObjectTest < ActiveSupport::TestCase should validate_presence_of(:name) should validate_presence_of(:created_at) should validate_presence_of(:type) - should validate_presence_of(:likes) - should validate_presence_of(:views) - should validate_presence_of(:downloads) - should validate_numericality_of(:likes).is_greater_than_or_equal_to(0) - should validate_numericality_of(:views).is_greater_than_or_equal_to(0) - should validate_numericality_of(:downloads).is_greater_than_or_equal_to(0) + test 'serialize for orientdb' do + learning_object = LearningObject.new( + id: '#15:23', + name: 'Teste', + description: 'teste de serialização', + thumbnail: '/asdasdasd.jpg', + id_dspace: '123213', + type: 'image', + attachment: LearningObject::Attachment.new('[{"id":2203,"name":"Pontociencia_Efe_chamas_na_horizontal.flv","type":"bitstream","link":"/rest/bitstreams/2203","bundleName":"ORIGINAL","description":null,"format":"Unknown","mimeType":"application/octet-stream","sizeBytes":4108209,"parentObject":null,"retrieveLink":"/bitstreams/2203/retrieve","checkSum":{"value":"43bd43bea944dcb8708d6ec708fb510d","checkSumAlgorithm":"MD5"},"sequenceId":-1,"policies":null,"expand":["parent","policies","all"]}]'), + last_modified: '2015-03-10 15:33:45', + metadata: [] + ) + + expected_hash = {"@class" => "LearningObject", "score" => 0, "name" => "Teste", "description" => "teste de serialização", "thumbnail" => "/asdasdasd.jpg", "id_dspace" => "123213", "type" => "image", "last_modified" => "2015-03-10 15:33:45", "metadata" => [], "bitstreams" => "[{\"id\":2203,\"name\":\"Pontociencia_Efe_chamas_na_horizontal.flv\",\"type\":\"bitstream\",\"link\":\"/rest/bitstreams/2203\",\"bundleName\":\"ORIGINAL\",\"description\":null,\"format\":\"Unknown\",\"mimeType\":\"application/octet-stream\",\"sizeBytes\":4108209,\"parentObject\":null,\"retrieveLink\":\"/bitstreams/2203/retrieve\",\"checkSum\":{\"value\":\"43bd43bea944dcb8708d6ec708fb510d\",\"checkSumAlgorithm\":\"MD5\"},\"sequenceId\":-1,\"policies\":null,\"expand\":[\"parent\",\"policies\",\"all\"]}]"} + assert_equal(expected_hash, learning_object.to_orientdb_hash) + end + end diff --git a/test/repositories/orient_db/collection_repository_test.rb b/test/repositories/orient_db/collection_repository_test.rb index 5e3745c5d92e31da1bd5ebcb68c630fa09e89eb6..97f59265d7c127a075ac9a4a192b40ab42880549 100644 --- a/test/repositories/orient_db/collection_repository_test.rb +++ b/test/repositories/orient_db/collection_repository_test.rb @@ -12,13 +12,15 @@ class OrientDb::CollectionRepositoryTest < ActiveSupport::TestCase end test 'save learning objects to persisted collection' do - lo = LearningObject.new(id: '#14:14') - collection = Collection.new(id: '#12:12', learning_objects: [lo]) + lo = ::LearningObject.new(id: '#14:14') + collection = ::Collection.new(id: '#12:12', learning_objects: [lo]) # setup orient4r mock - expected_mock_arg = sprintf("update %s add learning_objects = %s", collection.id, lo.id) + expected_remove_mock_arg = sprintf('update %s REMOVE learning_objects', collection.id) + expected_add_mock_arg = sprintf("update %s ADD learning_objects = [%s] SET last_modified='%s'", collection.id, collection.learning_objects.map(&:id).join(','), Time.now()) odb_client = mock - odb_client.expect :command, nil, [expected_mock_arg] + odb_client.expect :command, nil, [expected_remove_mock_arg] + odb_client.expect :command, nil, [expected_add_mock_arg] collection_repository = OrientDb::CollectionRepository.new odb_client collection_repository.save_learning_objects collection