[ARVADOS] created: a6310e8b0eedce1323f02d285c0709516558f937

git at public.curoverse.com git at public.curoverse.com
Tue Feb 2 18:24:36 EST 2016


        at  a6310e8b0eedce1323f02d285c0709516558f937 (commit)


commit a6310e8b0eedce1323f02d285c0709516558f937
Author: radhika <radhika at curoverse.com>
Date:   Tue Feb 2 18:22:18 2016 -0500

    8286: add "star" route for projects. Update projects dropdown in breadcrumbs to display only starred projects instead of all my_projects.

diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index db3d430..5d8f1d8 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -94,6 +94,7 @@ class ApplicationController < ActionController::Base
         # Fall back to the default-setting code later.
       end
     end
+    @starred_projects ||= []
     @my_project_tree ||= []
     @shared_project_tree ||= []
     render_error(err_opts)
@@ -444,6 +445,41 @@ 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: @object.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,
+               head_uuid: @object.uuid,
+               link_class: 'star')
+
+    return links.andand.any?
+  end
+
   protected
 
   helper_method :strip_token_from_path
@@ -833,6 +869,17 @@ class ApplicationController < ActionController::Base
     {collections: c, owners: own}
   end
 
+  helper_method :my_starred_projects
+  def my_starred_projects
+    return if @starred_projects
+    links = Link.filter([['tail_uuid', '=', current_user.uuid],
+                         ['link_class', '=', 'star'],
+                         ['head_uuid', 'is_a', 'arvados#group']]).select(%w(head_uuid))
+    uuids =links.collect { |x| x.head_uuid }
+    starred_projects = Group.filter([['uuid', 'in', uuids]]).order('name')
+    @starred_projects = starred_projects.results
+  end
+
   helper_method :my_project_tree
   def my_project_tree
     build_project_trees
diff --git a/apps/workbench/app/views/application/_projects_tree_menu.html.erb b/apps/workbench/app/views/application/_projects_tree_menu.html.erb
index 77b9d45..7eefc66 100644
--- a/apps/workbench/app/views/application/_projects_tree_menu.html.erb
+++ b/apps/workbench/app/views/application/_projects_tree_menu.html.erb
@@ -6,11 +6,10 @@
     <span style="padding-left: 0">Home</span>
   <% end %>
 </li>
-<% my_project_tree.each do |pnode| %>
-  <% next if pnode[:object].class != Group %>
+<% my_starred_projects.each do |pnode| %>
   <li>
-    <%= project_link_to.call pnode do %>
-      <span style="padding-left: <%= pnode[:depth] %>em"></span><%= pnode[:object].name %>
+    <%= project_link_to.call({object: pnode, depth: 0}) do%>
+      <span style="padding-left: 0em"></span><%= pnode[:name] %>
     <% end %>
   </li>
 <% end %>
diff --git a/apps/workbench/app/views/projects/show.html.erb b/apps/workbench/app/views/projects/show.html.erb
index 2a85da8..2b0a574 100644
--- a/apps/workbench/app/views/projects/show.html.erb
+++ b/apps/workbench/app/views/projects/show.html.erb
@@ -3,6 +3,17 @@
     <% 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: "Undo favorite") 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: "Mark favorite") do %>
+            <i class="fa fa-fw fa-star-o"></i>
+          <% end %>
+      <% end %>
       <%= render_editable_attribute @object, 'name', nil, { 'data-emptytext' => "New project" } %>
     <% end %>
   </h2>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 1042609..b1119e7 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -89,6 +89,7 @@ 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

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list