8286: convert star method into action controller action and refresh the star icon...
authorradhika <radhika@curoverse.com>
Mon, 15 Feb 2016 20:26:05 +0000 (15:26 -0500)
committerradhika <radhika@curoverse.com>
Mon, 15 Feb 2016 20:26:05 +0000 (15:26 -0500)
apps/workbench/app/controllers/actions_controller.rb
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/views/application/_show_star.html.erb [new file with mode: 0644]
apps/workbench/app/views/application/star.js.erb [new file with mode: 0644]
apps/workbench/app/views/projects/show.html.erb
apps/workbench/config/routes.rb

index 58b8cdc54f018e6dae20ba7b9c182bfbaef909c0..28680df33f3cf4f5902d5abdc278c305011018f2 100644 (file)
@@ -238,6 +238,35 @@ You can try recreating the collection to get a copy with full provenance data."
     end
   end
 
+  # star / unstar the current project
+  def star
+    links = Link.where(tail_uuid: current_user.uuid,
+                       head_uuid: @object.uuid,
+                       link_class: 'star')
+
+    if params['status'] == 'create'
+      # create 'star' link if one does not already exist
+      if !links.andand.any?
+        dst = Link.new(owner_uuid: current_user.uuid,
+                       tail_uuid: current_user.uuid,
+                       head_uuid: @object.uuid,
+                       link_class: 'star',
+                       name: @object.uuid)
+        dst.save!
+      end
+    else # delete any existing 'star' links
+      if links.andand.any?
+        links.each do |link|
+          link.destroy
+        end
+      end
+    end
+
+    respond_to do |format|
+      format.js
+    end
+  end
+
   protected
 
   def derive_unique_filename filename, manifest_files
index 5094556d64e69b924c4016444d17a7ce434fedee..1fc15807c9568e05876a349cc38ed152887dc943 100644 (file)
@@ -446,32 +446,6 @@ class ApplicationController < ActionController::Base
     end
   end
 
-  def star
-    links = Link.where(tail_uuid: current_user.uuid,
-                       head_uuid: @object.uuid,
-                       link_class: 'star')
-
-    if params['status'] == 'create'
-      # create 'star' link if one does not already exist
-      if !links.andand.any?
-        dst = Link.new(owner_uuid: current_user.uuid,
-                       tail_uuid: current_user.uuid,
-                       head_uuid: @object.uuid,
-                       link_class: 'star',
-                       name: @object.uuid)
-        dst.save!
-      end
-    else # delete any existing 'star' links
-      if links.andand.any?
-        links.each do |link|
-          link.destroy
-        end
-      end
-    end
-
-    show
-  end
-
   helper_method :is_starred
   def is_starred
     links = Link.where(tail_uuid: current_user.uuid,
diff --git a/apps/workbench/app/views/application/_show_star.html.erb b/apps/workbench/app/views/application/_show_star.html.erb
new file mode 100644 (file)
index 0000000..50775f1
--- /dev/null
@@ -0,0 +1,9 @@
+<% if is_starred %>
+  <%= link_to(star_path(status: 'delete', id:@object.uuid, action_method: 'get'), class: "btn btn-xs star-unstar", title: "Remove from list of favorites", remote: true) do  %>
+            <i class="fa fa-fw fa-star"></i>
+          <% end %>
+<% else %>
+  <%= link_to(star_path(status: 'create', id:@object.uuid, action_method: 'get'), class: "btn btn-xs star-unstar", title: "Add to list of favorites", remote: true) do %>
+            <i class="fa fa-fw fa-star-o"></i>
+          <% end %>
+<% end %>
diff --git a/apps/workbench/app/views/application/star.js.erb b/apps/workbench/app/views/application/star.js.erb
new file mode 100644 (file)
index 0000000..e472ab0
--- /dev/null
@@ -0,0 +1 @@
+$(".star-unstar").html("<%= escape_javascript(render partial: 'show_star') %>");
index 0f9df7693f11c57e9ab87804a440dca1db7a8070..6033a3491051d657bfb470eb351f2df710edb90c 100644 (file)
@@ -3,17 +3,7 @@
     <% if @object.uuid == current_user.andand.uuid %>
       Home
     <% else %>
-      <% starred = false %>
-      <% starred = true if is_starred %>
-      <% if starred %>
-        <%= link_to(url_for({action: 'star', status: 'delete', id: @object.uuid, controller: 'projects'}), method: :post, class: "btn btn-xs", title: "Remove from list of favorites") do %>
-            <i class="fa fa-fw fa-star"></i>
-          <% end %>
-      <% else %>
-        <%= link_to(url_for({action: 'star', status: 'create', id: @object.uuid, controller: 'projects'}), method: :post, class: "btn btn-xs", title: "Add to list of favorites") do %>
-            <i class="fa fa-fw fa-star-o"></i>
-          <% end %>
-      <% end %>
+      <%= render partial: "show_star" %>
       <%= render_editable_attribute @object, 'name', nil, { 'data-emptytext' => "New project" } %>
     <% end %>
   </h2>
index b1119e72c1b4a3a34bc9859b8633fe284237260b..fc72ea2222508db8b19d540b089deaf03f128df5 100644 (file)
@@ -12,6 +12,7 @@ ArvadosWorkbench::Application.routes.draw do
   get "users/setup" => 'users#setup', :as => :setup_user
   get "report_issue_popup" => 'actions#report_issue_popup', :as => :report_issue_popup
   post "report_issue" => 'actions#report_issue', :as => :report_issue
+  get "star" => 'actions#star', :as => :star
   resources :nodes
   resources :humans
   resources :traits
@@ -89,7 +90,6 @@ ArvadosWorkbench::Application.routes.draw do
     post 'share_with', on: :member
     get 'tab_counts', on: :member
     get 'public', on: :collection
-    post 'star', on: :member
   end
 
   resources :search do