diff --git a/Gemfile b/Gemfile index 19723fa4d4c33b19fe8700d96f89edd348558499..188a4e5607a179f6e1fe761be3da83605802f670 100644 --- a/Gemfile +++ b/Gemfile @@ -169,3 +169,5 @@ gem 'mimemagic' # html screenshot gem 'screencap' + +gem 'wicked' diff --git a/app/controllers/learning_objects/build_controller.rb b/app/controllers/learning_objects/build_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..ea5e1ee947db117e93deb310e739b0109c04d1be --- /dev/null +++ b/app/controllers/learning_objects/build_controller.rb @@ -0,0 +1,32 @@ +class LearningObjects::BuildController < ::ApplicationController + include Wicked::Wizard + before_action :set_learning_object, only: [:show, :update] + steps :upload_attachments, :select_default_attachment, :define_highlight_picture + + def show + render_wizard + end + + def update + @learning_object.update_attributes(params[:learning_object]) + publish_learning_object if step == steps.last + render_wizard @learning_object + end + + + def create + @learning_object = LearningObject.create + redirect_to wizard_path(steps.first, learning_object_id: @learning_object.id) + end + + private + + def set_learning_object + @learning_object = LearningObject.unscoped.find(params[:learning_object_id]) + end + + def publish_learning_object + @learning_object.publish + @learning_object.save + end +end \ No newline at end of file diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb index 923ea7fb1bf39f08b33be7d05a5551bccc2a0c56..2b7d043189cfb205f9ce8ce81c748fa08f2d1590 100644 --- a/app/controllers/learning_objects_controller.rb +++ b/app/controllers/learning_objects_controller.rb @@ -45,9 +45,6 @@ class LearningObjectsController < ApplicationController end end - def upload - end - # PATCH/PUT /learning_objects/1 # PATCH/PUT /learning_objects/1.json def update @@ -74,7 +71,7 @@ class LearningObjectsController < ApplicationController def like if @learning_object.liked? current_user @learning_object.dislike current_user - elseg + else @learning_object.like current_user end @@ -121,11 +118,7 @@ class LearningObjectsController < ApplicationController end def success_redirect(learning_object) - id = learning_object.id - if 'Website externo' == learning_object.object_type.name - redirect_to learning_object_path(id: id), notice: 'Seu objeto foi criado e publicado com sucesso!' - else - redirect_to upload_learning_object_path(id: id), notice: 'Seu objeto foi criado! Para que ele seja publicado é necessário enviar o arquivo.' - end + #if 'Website externo' == learning_object.object_type.name + redirect_to learning_object_build_path(learning_object, :upload_attachments), notice: 'Seu objeto foi criado com sucesso!' end end diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index 3c0587f57e65bcf6a81a657cf609d4b0c3849050..8757123f6729e8019043499c22df22b498336d7d 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -8,7 +8,7 @@ class LearningObject < ActiveRecord::Base has_many :collection_items, as: :collectionable has_many :collections, through: :collection_items - has_many :complaints + has_many :complaints, as: :complaintable has_many :attachments, class_name: 'LearningObject::Attachment', autosave: true # autosave to allow import belongs_to :publisher, polymorphic: true @@ -18,7 +18,7 @@ class LearningObject < ActiveRecord::Base has_attached_file :thumbnail, styles: { medium: '530x300', small: '250x140' } validates_attachment_content_type :thumbnail, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif'] - validates_presence_of :name, :id_dspace + validates_presence_of :name, :id_dspace, :publisher, :object_type validates_uniqueness_of :id_dspace searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author, :object_type] diff --git a/app/models/learning_object/attachment.rb b/app/models/learning_object/attachment.rb index 7b93f32b805630d528aba18fee9f16308b8f5393..10fba61f1b98643e252c6fa206aa22153959cb34 100644 --- a/app/models/learning_object/attachment.rb +++ b/app/models/learning_object/attachment.rb @@ -1,3 +1,6 @@ class LearningObject::Attachment < ActiveRecord::Base belongs_to :learning_object + + has_attached_file :thumbnail, styles: {medium: "530x300", small: "250x140"} + validates_attachment_content_type :thumbnail, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"] end diff --git a/app/models/learning_object/type.rb b/app/models/learning_object/type.rb deleted file mode 100644 index 5c7496f1c8a180fab03a32f80cd6813f361c95f8..0000000000000000000000000000000000000000 --- a/app/models/learning_object/type.rb +++ /dev/null @@ -1,5 +0,0 @@ -class LearningObject::Type - URL_REFERENCE = 'url_reference' - VIDEO = 'video' - IMAGE = 'imagem' -end diff --git a/app/services/dspace/learning_object_importer.rb b/app/services/dspace/learning_object_importer.rb index a5d20a8cadc9e6449c53fec3ab8562b0342e1d33..6e250dcbb78fa4d1e13e9513f59de6353e194307 100644 --- a/app/services/dspace/learning_object_importer.rb +++ b/app/services/dspace/learning_object_importer.rb @@ -9,20 +9,14 @@ class Dspace::LearningObjectImporter @items.each do |item| next if item_exists? item - learning_object = LearningObjectBuilder.build_from_dspace(item) - next if learning_object.blank? - create_attachments(learning_object, item.bit_streams) - items << learning_object - yield(learning_object) if block_given? end LearningObject.import items, recursive: true - end private diff --git a/app/services/learning_object_publisher.rb b/app/services/learning_object_publisher.rb index e72c822f0871cd69bf59194dffd25c5c1d1a1e58..775020bd95572afe24e3ba320f7257649fb8281e 100644 --- a/app/services/learning_object_publisher.rb +++ b/app/services/learning_object_publisher.rb @@ -22,7 +22,6 @@ class LearningObjectPublisher #post *media_path* to *learning_object* on dspace def post(learning_object, media_path) DspaceUploadWorker.perform_async learning_object.id, learning_object.id_dspace, media_path, learning_object.description - ThumbnailGenerateWorker.perform_async media_path, learning_object.id end ##publish *learning_object* @@ -42,7 +41,7 @@ class LearningObjectPublisher item = @dspace.collections.create_item(build_dspace_item(draft), id: DspaceService::TEST_COLLECTION) # update dspace metadata - metadata = [::Dspace::Metadata.new({'key' => 'dc.title', 'value' => draft.name, 'language' => draft.language.name})] + metadata = ::Dspace::Metadata.new({'key' => 'dc.title', 'value' => draft.name, 'language' => draft.language.name}) @dspace.items.add_metadata(metadata, id: item.id) item diff --git a/app/views/learning_objects/_form.html.erb b/app/views/learning_objects/_form.html.erb index c800e53ce0dcb1cfae3aa9b5e3a35d70872e682d..ef6cdf8214fbf7a0c593912c9f0d16da9fee34aa 100644 --- a/app/views/learning_objects/_form.html.erb +++ b/app/views/learning_objects/_form.html.erb @@ -35,7 +35,7 @@ <%= f.label :object_type_id, "Tipo do objeto" %> <div class="radio"> - <%= f.collection_radio_buttons :object_type, @types, :id, :name do |b| + <%= f.collection_radio_buttons :object_type_id, @types, :id, :name do |b| b.label { b.radio_button + b.text } + '<br />'.html_safe end %> </div> diff --git a/app/views/learning_objects/_file_upload_form.html.erb b/app/views/learning_objects/build/_file_upload_form.html.erb similarity index 100% rename from app/views/learning_objects/_file_upload_form.html.erb rename to app/views/learning_objects/build/_file_upload_form.html.erb diff --git a/app/views/learning_objects/build/define_highlight_picture.html.erb b/app/views/learning_objects/build/define_highlight_picture.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/views/learning_objects/build/select_default_attachment.html.erb b/app/views/learning_objects/build/select_default_attachment.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/views/learning_objects/build/upload_attachments.html.erb b/app/views/learning_objects/build/upload_attachments.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c3f4353999d606437cb070cf053bd6e45cf7f8cc --- /dev/null +++ b/app/views/learning_objects/build/upload_attachments.html.erb @@ -0,0 +1,3 @@ +<%= form_for @learning_object , url: wizard_path do |f| %> + <%= render 'file_upload_form' %> +<% end %> \ No newline at end of file diff --git a/app/workers/dspace_upload_worker.rb b/app/workers/dspace_upload_worker.rb index dcdd84b076aee2efa6529a35e009c3374e719e3b..94fbbf51063445af10a9753f923e507e7a80d481 100644 --- a/app/workers/dspace_upload_worker.rb +++ b/app/workers/dspace_upload_worker.rb @@ -12,8 +12,10 @@ class DspaceUploadWorker #find learning object learning_object = LearningObject.find learning_object_id - learning_object.attachments.create map_bitstream2attachment(bitstream) + attachment = learning_object.attachments.create map_bitstream2attachment(bitstream) publisher.publish! learning_object + + ThumbnailGenerateWorker.perform_async media_path, attachment.id end private diff --git a/app/workers/thumbnail_generate_worker.rb b/app/workers/thumbnail_generate_worker.rb index 98e7715c4a3be8090f751c32892d2e6c8af63b54..6ff453857100971fe2bc203cfadff5a448ac013c 100644 --- a/app/workers/thumbnail_generate_worker.rb +++ b/app/workers/thumbnail_generate_worker.rb @@ -4,15 +4,17 @@ require 'screencap' class ThumbnailGenerateWorker include Sidekiq::Worker - def perform(media_path, object_id) + def perform(media_path, attachment_id) media = create_media media_path - thumbnail_service.update_object(thumbnail_service.create_thumbnail(media), object_id) + attachment = ::LearningObject::Attachment.find(attachment_id) + attachment.thumbnail = thumbnail_service.create_thumbnail media + attachment.save! end private def create_media(path) - return ::Screencap::Fetcher.new(path) if url =~ URI::regexp + return ::Screencap::Fetcher.new(path) if path =~ URI::regexp File.open path end diff --git a/db/migrate/20160301103501_add_paperclip_to_attachments.rb b/db/migrate/20160301103501_add_paperclip_to_attachments.rb new file mode 100644 index 0000000000000000000000000000000000000000..6873a858d86953cdbee35e3923ba7c439deb67b8 --- /dev/null +++ b/db/migrate/20160301103501_add_paperclip_to_attachments.rb @@ -0,0 +1,9 @@ +class AddPaperclipToAttachments < ActiveRecord::Migration + def up + add_attachment :learning_objects, :thumbnail + end + + def down + remove_attachment :learning_objects, :thumbnail + end +end diff --git a/lib/tasks/portalmec.rake b/lib/tasks/portalmec.rake index 8eb7b2b3247733a223f29662ff24043fafeb7aaf..609fa6b392c9c44ebea6e2365ea2fcfc8ea03ca7 100644 --- a/lib/tasks/portalmec.rake +++ b/lib/tasks/portalmec.rake @@ -2,12 +2,15 @@ namespace :portalmec do desc 'setup initial environment' task :setup do + + # runs db:drop db:create db:migrate Rake::Task['db:migrate:reset'].invoke Rake::Task['db:seed'].invoke - Rake::Task['import:learning_objects'].invoke + Rake::Task['import:topics'].invoke Rake::Task['topics:define_defaults'].invoke Rake::Task['import:institutions'].invoke + Rake::Task['import:learning_objects'].invoke end end diff --git a/test/models/learning_object_test.rb b/test/models/learning_object_test.rb index c37c3d8078e4090bc576e56276b62549e38caa4e..d79a9d8e4597d11f0910aec2235caa6f2c1e7172 100644 --- a/test/models/learning_object_test.rb +++ b/test/models/learning_object_test.rb @@ -1,7 +1,14 @@ require 'test_helper' class LearningObjectTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + should have_and_belong_to_many :topics + + should have_many :collection_items + should have_many(:collections).through(:collection_items) + should have_many :complaints + should have_many(:attachments).class_name('LearningObject::Attachment') + + should belong_to :publisher + should belong_to :language + should belong_to :object_type end diff --git a/test/services/score_calculator_service_test.rb b/test/services/score_calculator_service_test.rb index 875c69a7a392a5053e8e372687e85ed8d49e7185..a7e8f64539a53ae7bd0f0134656db5918eea48eb 100644 --- a/test/services/score_calculator_service_test.rb +++ b/test/services/score_calculator_service_test.rb @@ -2,10 +2,6 @@ require 'test_helper' class ScoreCalculatorServiceTest < ActiveSupport::TestCase - # def setup - # - # end - test 'reputation calculation' do hash_stub = { 'submitted_objects': 60,