Highlight "Dashboard" instead "Users" in left nav when on
[arvados.git] / apps / workbench / app / controllers / users_controller.rb
1 class UsersController < ApplicationController
2   skip_before_filter :find_object_by_uuid, :only => :welcome
3   skip_around_filter :thread_with_api_token, :only => :welcome
4   around_filter :thread_with_optional_api_token, :only => :welcome
5
6   def welcome
7     if current_user
8       params[:action] = 'home'
9       home
10     end
11   end
12
13   def home
14     @showallalerts = false
15     @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid)
16     # @my_vm_perms = Link.where(tail_uuid: current_user.uuid, head_kind: 'arvados#virtual_machine', link_class: 'permission', name: 'can_login')
17     # @my_repo_perms = Link.where(tail_uuid: current_user.uuid, head_kind: 'arvados#repository', link_class: 'permission', name: 'can_write')
18
19     @my_tag_links = {}
20
21     @my_jobs = Job.
22       limit(10).
23       order('created_at desc').
24       where(created_by: current_user.uuid)
25
26     @my_collections = Collection.
27       limit(10).
28       order('created_at desc').
29       where(created_by: current_user.uuid)
30
31     Link.limit(1000).where(head_uuid: @my_collections.collect(&:uuid),
32                            link_class: 'tag').each do |link|
33       (@my_tag_links[link.head_uuid] ||= []) << link
34     end
35
36     @my_pipelines = PipelineInstance.
37       limit(10).
38       order('created_at desc').
39       where(created_by: current_user.uuid)
40
41
42     # A Tutorial is a Link which has link_class "resources" and name
43     # "wants", and is owned by the Tutorials Group (i.e., named
44     # "Arvados Tutorials" and owned by the system user).
45     @tutorial_group = Group.where(owner_uuid: User.system.uuid,
46                                   name: 'Arvados Tutorials').first
47     if @tutorial_group
48       @tutorial_links = Link.where(tail_uuid: @tutorial_group.uuid,
49                                    link_class: 'resources',
50                                    name: 'wants')
51     else
52       @tutorial_links = []
53     end
54     @tutorial_complete = {
55       'Run a job' => @my_last_job
56     }
57     respond_to do |f|
58       f.js { render template: 'users/home.js' }
59       f.html { render template: 'users/home' }
60     end
61   end
62 end