From a4887323fb7bfd9584997c0bb2da16682bc145ad Mon Sep 17 00:00:00 2001
From: Lucas Ernesto Kindinger <lek@dinf.ufpr.br>
Date: Thu, 17 Dec 2015 10:31:22 -0200
Subject: [PATCH] Added a function to create download edge

Signed-off-by: Lucas Ernesto Kindinger <lek@dinf.ufpr.br>
---
 app/controllers/learning_objects_controller.rb |  3 ++-
 app/models/learning_object.rb                  |  4 ++++
 app/views/learning_objects/show.html.erb       | 17 +++++++++++++++--
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/app/controllers/learning_objects_controller.rb b/app/controllers/learning_objects_controller.rb
index 63da0568..9bb8b7fe 100644
--- a/app/controllers/learning_objects_controller.rb
+++ b/app/controllers/learning_objects_controller.rb
@@ -132,7 +132,8 @@ class LearningObjectsController < ApplicationController
   end  
 
   def download
-    @learning_object.download current_user    
+    @learning_object.download current_user
+    redirect_to @learning_object.get_retrievelink
   end
 
   # POST /learning_objects/1/bookmarks
diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb
index 98c24eec..5c1d6234 100644
--- a/app/models/learning_object.rb
+++ b/app/models/learning_object.rb
@@ -56,6 +56,10 @@ class LearningObject
     learning_object_repository.dislike user, self
   end
 
+  def download(user)
+    learning_object_repository.download user, self
+  end
+
   ## end social actions
 
   ## metadata methods
diff --git a/app/views/learning_objects/show.html.erb b/app/views/learning_objects/show.html.erb
index 6570547e..65e5d4f4 100644
--- a/app/views/learning_objects/show.html.erb
+++ b/app/views/learning_objects/show.html.erb
@@ -59,10 +59,11 @@
               <% end %>
             </div>
             <div class="col-sm-3 action">
-              <a href="<%= @learning_object.get_retrievelink %>">
+              <%= link_to download_learning_object_path do %>
+              <%#= @learning_object.get_retrievelink %>
                 <%= image_tag "icons/download.png", alt: "Download do objeto" %>
                 <h6>salvar no computador</h6>
-              </a>
+              <%end%>
             </div>
             <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 %>">
@@ -133,4 +134,16 @@
       this.removeAttribute("controls")
     }
   });
+
+  // $("#button-download").click(
+  //   function()
+  //   {
+  //     $.ajax({
+  //       url: <%= download_learning_object_path %>
+  //       type: 'GET'
+  //     }).done(
+  //     function{
+  //       alert("ololo");
+  //     });
+  //   });
 </script>
-- 
GitLab