From 14bd3defc174444838dffa4b258b28714b0c4057 Mon Sep 17 00:00:00 2001
From: Matheus Agio Nerone <man13@inf.ufpr.br>
Date: Fri, 13 Nov 2015 10:33:38 -0200
Subject: [PATCH] ideia of how to do the upload

Signed-off-by: Matheus Agio Nerone <man13@inf.ufpr.br>
---
 .../learning_objects_controller.rb            |  46 ++++++-
 app/models/learning_object.rb                 |   3 +-
 app/views/learning_objects/_form.html.erb     | 122 ++++++------------
 3 files changed, 85 insertions(+), 86 deletions(-)

diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb
index 909b6f62..03481bf7 100644
--- a/app/controllers/learning_objects_controller.rb
+++ b/app/controllers/learning_objects_controller.rb
@@ -3,6 +3,7 @@ class LearningObjectsController < ApplicationController
   after_action :increment_learning_object_views, only: [:show]
   before_action :authenticate_user!, except: [:index, :show, :like]
   before_action :set_complaint_messages, only: :show
+  before_action :login_on_dspace, only: :create
 
   # GET /learning_objects
   # GET /learning_objects.json
@@ -29,6 +30,21 @@ class LearningObjectsController < ApplicationController
   # POST /learning_objects
   # POST /learning_objects.json
   def create
+    # # TODO: the code is doing an extra requisition that is not necessary, need to fix it
+    # repo = Dspace::Client.instance.repository.collection_repository
+    # collection = repo.get_collection_by_id('4')
+    #
+    # # trata o form da aula
+    # lo = DSpaceRest::Item.new(learning_object_params)
+    # dspace_keys = get_dspace_metadata_names("invert")
+    # learning_object_params.each do |k,v|
+    #   unless dspace_keys[k].nil?
+    #     lo.add_metadata(dspace_keys[k], v, "pt-BR")
+    #   end
+    # end
+    #
+    # collection_repository.create_item_for(collection, lo)
+
     subjects = []
     learning_object_params[:subjects].each do |subject|
       subjects << subject_repository.find_by_name(subject)
@@ -37,11 +53,8 @@ class LearningObjectsController < ApplicationController
     @learning_object.subjects = subjects
     @learning_object.created_at = Time.now
     @learning_object.last_modified = Time.now
-    @learning_object.type = 'undefined'
-    @learning_object.author = current_user
     @learning_object.publisher = current_user
     @learning_object.metadata = nil
-
     respond_to do |format|
       if learning_object_repository.create @learning_object
         learning_object_repository.create_relations(@learning_object)
@@ -109,6 +122,33 @@ class LearningObjectsController < ApplicationController
 
   private
 
+  def get_dspace_metadata_names(invert=nil)
+    h = {
+        "dc.title" => "name",
+        "dc.contributor.author" => "author",
+        "dc.description" => "description",
+        "dc.language" => "language",
+        "dc.source" => "source",
+        "dc.type" => "type",
+        "dc.date.issued" => "date",
+        "dc.rights" => "license",
+        "dc.rights.holder" => "copyright",
+        "dc.location.country" => "country",
+        "dc.date.accessioned" => "date_created",
+        "dc.date.available" => "date_available"
+        # TODO: subjects dc.subject.category
+
+    }
+    if (invert != nil)
+      return h.invert
+    end
+    h
+  end
+
+  def login_on_dspace
+    Dspace::Client.instance.login 'admin@mecdb3.c3sl.ufpr.br', 'admin'
+  end
+
   # Use callbacks to share common setup or constraints between actions.
   def set_learning_object
     @learning_object = learning_object_repository.find params[:id]
diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb
index 76e10d79..c0ef0f7b 100644
--- a/app/models/learning_object.rb
+++ b/app/models/learning_object.rb
@@ -6,7 +6,8 @@ class LearningObject
                 :published_at, :thumbnail, :created_at, :last_modified,
                 :type, :grade_level, :bitstreams, :metadata, :likes, :views,
                 :downloads, :subjects, :attributes, :score, :publisher,
-                :school_level
+                :school_level, :language, :source, :license, :copyright,
+                :country, :keywords
 
   validates_presence_of :name, :created_at, :type, :likes, :views, :downloads
   validates_numericality_of :likes, greater_than_or_equal_to: 0
diff --git a/app/views/learning_objects/_form.html.erb b/app/views/learning_objects/_form.html.erb
index 0faff231..5a2cee7b 100644
--- a/app/views/learning_objects/_form.html.erb
+++ b/app/views/learning_objects/_form.html.erb
@@ -11,91 +11,49 @@
     </div>
   <% end %>
 
+<div class="row">
+  <div class="col-md-12">
+    Upload de arquivos
+  </div>
 
-
-
-  <div class="container">
-    <div class="row">
-      <div class="col-md-12">
-          <div class="container-fluid" style="margin-left:10px;">
-            <%= image_tag image_path('icons/upload.png'), class: "logo",style:"width:50px;" %>
-            <span class="pull-left"><h3 style="position:absolute; margin-left:60px;">Adicionando x arquivos</h3>
-        </div>
-      </div><br/>
-        <div class="grey-panel">
-          <div class="container-fluid">
-              <div class="row">
-              <div class="white-input">
-
-                <div class="col-md-3">
-                  <%= image_tag image_path('icons/square.png'), style:"width:250px; height:150px;" %><br/>
-                  <%= link_to 'editar foto', search_path,style:'color: #1676bc;' %>
-                </div>
-                <div class="col-md-9">
-
-                  <table style="margin-left:0px;">
-                    <tr>
-                    <td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;
-                      <%= f.text_field :name, size: '70', style: "height:30px;font-size:14pt; margin-bottom: 10px;", placeholder: "Título do arquivo" %>
-                    </td>
-                    </tr>
-                    <tr>
-                    <td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;
-                      <%= f.text_field :description, size: '70', style: "height:65px;font-size:14pt; margin-bottom: 10px;", placeholder: "Descrição" %>
-                      <br/>
-                    </td>
-                    </tr>
-                    <tr>
-                    <td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;
-                      <select id='subjectSelect' name="learning_object[subjects][]" multiple>
-                        <%= @subjects.each do |subject| %>
-                          <option value='<%= subject %>'><%= subject %></option>
-                        <% end %>
-                      </select>
-                    </td>
-                    </tr>
-                    <tr>
-                    <td>
-                      <select style="width: 345px; margin-left:8px" name="learning_object[school_level]">
-                         <option value="">Nível</option>
-                         <%= @school_levels.each do |school_level|%>
-                         <option value="<%= school_level %>"><%= school_level %></option>
-                         <% end %>
-                      </select>
-
-                    </td>
-                    <td>
-                      <select style="width: 345px;">
-                         <option value="">Adicionar à coleção</option>
-                       <option value="">..</option>
-                      </select>
-                    </td>
-                    </tr>
-                    <tr>
-                    <td colspan="2">
-                      <!-- <div class=" pull-right">  <%= button_to "Remover", new_user_registration_path,class: "btn btn-danger", style: 'margin-top: 15px; width: 130px; background-color: #FF2134;'%></div> -->
-                    </td>
-                    </tr>
-                  </table>
-
-                </div>
-              </div>
-            </div>
-          </div>
-        </div>
-        <div class="col-md-12">
-            <div class="container-fluid" >
-              <div class="pull-right">
-                <input type="checkbox" >&nbsp;Li e concordo com os <%= link_to 'termos e condições', search_path, style:'color: #1676bc;' %> de upload e copyright<br/><br/>
-                  <div class="pull-left"><div style= 'margin-left:130px;'><%= link_to 'Cancelar', search_path %></div></div>
-                  <div class="pull-right"><%= f.submit "Salvar", class: 'btn pull-right', style: 'margin-top: -10px; width: 230px; color:white; background-color: #1676bc;' %></div>
-                  <!-- <%= f.submit "Salvar", class: 'btn pull-right', style: 'margin-top: -10px; width: 230px; color:white; background-color: #1676bc;' %> -->
-              </div>
-            </div>
-        </div>
-      </div>
+  <div class="row">
+    <div class="col-md-12">
+      <%= f.label :author, "Autor" %>
+      <%= f.text_field :author %><br>
+      <%= f.label :name, "Título" %>
+      <%= f.text_field :name %> <br>
+      <%= f.label :description, "Descrição" %>
+      <%= f.text_field :description %><br>
+      <%= f.label :language, "Linguagem" %>
+      <%= f.text_field :language %><br>
+      <%= f.label :source, "Fonte" %>
+      <%= f.text_field :source %><br>
+      <%= f.label :type, "Tipo de objeto" %>
+      <%= f.text_field :type %><br>
+      <%= f.label :license, "Licença"%>
+      <%= f.text_field :license %><br>
+      <%= f.label :copyright, "Detentor dos direitos autorais" %>
+      <%= f.text_field :copyright %><br>
+      <%= f.label :country, "Pais" %>
+      <%= f.text_field :country %> <br>
+      <select id='subjectSelect' name="learning_object[subjects][]" multiple>
+        <%= @subjects.each do |subject| %>
+          <option value='<%= subject %>'><%= subject %></option>
+        <% end %>
+      </select>
+      <%= f.label :keywords, "Palavras-chave" %>
+      <%= f.text_field :keywords %> <br>
+      <select name="learning_object[school_level]">
+         <%= @school_levels.each do |school_level|%>
+         <option value="<%= school_level %>"><%= school_level %></option>
+         <% end %>
+      </select>
+      <br>
+      <br>
+      <%= f.submit %>
     </div>
   </div>
+</div>
 
 <% end %>
 <script>
-- 
GitLab