Commit edd81a79c5c2a61e565664cfa787185c4e19729b

Authored by randx
1 parent 9ef9c58f

Dashboard refactoring:

* dashboard should be in dashboard controller not project index
* projects index removed
app/assets/stylesheets/common.scss
... ... @@ -659,6 +659,10 @@ li.note {
659 659 width:24px;
660 660 vertical-align:top;
661 661 }
  662 +
  663 + strong {
  664 + line-height:24px;
  665 + }
662 666 }
663 667  
664 668 .automerge_widget {
... ... @@ -741,7 +745,7 @@ li.note {
741 745 */
742 746 .event_lp {
743 747 @extend .alert-info;
744   - margin-bottom:15px;
  748 + margin-bottom:20px;
745 749 padding:8px;
746 750 border-style: solid;
747 751 border-width: 1px;
... ...
app/controllers/dashboard_controller.rb
... ... @@ -2,18 +2,17 @@ class DashboardController < ApplicationController
2 2 respond_to :html
3 3  
4 4 def index
5   - @projects = current_user.projects.all
6   -
7   - @active_projects = @projects.select(&:last_activity_date).sort_by(&:last_activity_date).reverse
  5 + @projects = current_user.projects.includes(:events).order("events.created_at DESC")
  6 + @projects = @projects.page(params[:page]).per(40)
8 7  
9   - @merge_requests = MergeRequest.where("author_id = :id or assignee_id = :id", :id => current_user.id).opened.order("created_at DESC").limit(5)
  8 + @events = Event.where(:project_id => current_user.projects.map(&:id)).recent.limit(20)
10 9  
11   - @user = current_user
12   - @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(5)
13   - @issues = @issues.includes(:author, :project)
  10 + @last_push = current_user.recent_push
14 11  
15   - @events = Event.where(:project_id => @projects.map(&:id)).recent.limit(20)
16   - @last_push = Event.where(:project_id => @projects.map(&:id)).recent.code_push.limit(1).first
  12 + respond_to do |format|
  13 + format.html
  14 + format.atom { render :layout => false }
  15 + end
17 16 end
18 17  
19 18 # Get authored or assigned open merge requests
... ...
app/helpers/application_helper.rb
... ... @@ -60,8 +60,9 @@ module ApplicationHelper
60 60 def search_autocomplete_source
61 61 projects = current_user.projects.map{ |p| { :label => p.name, :url => project_path(p) } }
62 62 default_nav = [
  63 + { :label => "Profile", :url => profile_path },
63 64 { :label => "Keys", :url => keys_path },
64   - { :label => "Projects", :url => projects_path },
  65 + { :label => "Dashboard", :url => root_path },
65 66 { :label => "Admin", :url => admin_root_path }
66 67 ]
67 68  
... ...
app/views/dashboard/index.atom.builder 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +xml.instruct!
  2 +xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do
  3 + xml.title "Dashboard feed#{" - #{current_user.name}" if current_user.name.present?}"
  4 + xml.link :href => projects_url(:atom), :rel => "self", :type => "application/atom+xml"
  5 + xml.link :href => projects_url, :rel => "alternate", :type => "text/html"
  6 + xml.id projects_url
  7 + xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any?
  8 +
  9 + @events.each do |event|
  10 + if event.allowed?
  11 + xml.entry do
  12 + if event.issue?
  13 + event_link = project_issue_url(event.project, event.issue)
  14 + event_title = event.issue_title
  15 + elsif event.merge_request?
  16 + event_link = project_merge_request_url(event.project, event.merge_request)
  17 + event_title = event.merge_request_title
  18 + elsif event.push?
  19 + event_link = project_commits_url(event.project, :ref => event.ref_name)
  20 + event_title = event.ref_name
  21 + end
  22 +
  23 + xml.id "tag:#{request.host},#{event.created_at.strftime("%Y-%m-%d")}:#{event.id}"
  24 + xml.link :href => event_link
  25 + xml.title truncate(event_title, :length => 80)
  26 + xml.updated event.created_at.strftime("%Y-%m-%dT%H:%M:%SZ")
  27 + xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(event.author_email)
  28 + xml.author do |author|
  29 + xml.name event.author_name
  30 + xml.email event.author_email
  31 + end
  32 + xml.summary event_title
  33 + end
  34 + end
  35 + end
  36 +end
... ...
app/views/dashboard/index.html.haml 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +- if @projects.any?
  2 + .projects
  3 + .activities.span8
  4 + - if current_user.require_ssh_key?
  5 + .alert.alert-error.padded
  6 + %span
  7 + You wont be able to pull/push project code unless you
  8 + %strong
  9 + = link_to new_key_path, :class => "vlink" do
  10 + add new key
  11 + to your profile
  12 + - if @events.any?
  13 + = render @events
  14 + - else
  15 + %h4.nothing_here_message Projects activity will be displayed here
  16 + .side
  17 + = render "events/event_last_push", :event => @last_push
  18 + .projects_box
  19 + %h5
  20 + Projects
  21 + %small
  22 + (#{@projects.total_count})
  23 + - if current_user.can_create_project?
  24 + %span.right
  25 + = link_to new_project_path, :class => "btn very_small info" do
  26 + %i.icon-plus
  27 + New Project
  28 + - @projects.each do |project|
  29 + = link_to project_path(project), :class => dom_class(project) do
  30 + %h4
  31 + %span.ico.project
  32 + = truncate(project.name, :length => 25)
  33 + %span.right
  34 + →
  35 + .bottom= paginate @projects, :theme => "gitlab"
  36 +
  37 + %hr
  38 + %div
  39 + %span.rss-icon
  40 + = link_to dashboard_path(:atom, { :private_token => current_user.private_token }) do
  41 + = image_tag "rss_ui.png", :title => "feed"
  42 + %strong News Feed
  43 +
  44 +- else
  45 + %h3.nothing_here_message There are no projects you have access to.
  46 + %br
  47 + %h4.nothing_here_message
  48 + - if current_user.can_create_project?
  49 + You can create up to
  50 + = current_user.projects_limit
  51 + projects. Click on button below to add a new one
  52 + .link_holder
  53 + = link_to new_project_path, :class => "btn primary" do
  54 + New Project »
  55 + - else
  56 + If you will be added to project - it will be displayed here
... ...
app/views/dashboard/index.js.haml 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +:plain
  2 + $(".projects .activities").append("#{escape_javascript(render(@events))}");
... ...
app/views/layouts/_app_menu.html.haml
1 1 %nav.main_menu
2   - = link_to "Home", root_path, :class => "home #{"current" if current_page?(projects_path) || current_page?(root_path)}", :title => "Home"
  2 + = link_to "Home", root_path, :class => "home #{"current" if current_page?(dashboard_path) || current_page?(root_path)}", :title => "Home"
3 3 = link_to dashboard_issues_path, :class => "#{"current" if current_page?(dashboard_issues_path)}", :id => "issues_slide" do
4 4 Issues
5 5 %span.count= current_user.assigned_issues.opened.count
... ...
app/views/projects/index.atom.builder
... ... @@ -1,36 +0,0 @@
1   -xml.instruct!
2   -xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do
3   - xml.title "Dashboard feed#{" - #{current_user.name}" if current_user.name.present?}"
4   - xml.link :href => projects_url(:atom), :rel => "self", :type => "application/atom+xml"
5   - xml.link :href => projects_url, :rel => "alternate", :type => "text/html"
6   - xml.id projects_url
7   - xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any?
8   -
9   - @events.each do |event|
10   - if event.allowed?
11   - xml.entry do
12   - if event.issue?
13   - event_link = project_issue_url(event.project, event.issue)
14   - event_title = event.issue_title
15   - elsif event.merge_request?
16   - event_link = project_merge_request_url(event.project, event.merge_request)
17   - event_title = event.merge_request_title
18   - elsif event.push?
19   - event_link = project_commits_url(event.project, :ref => event.ref_name)
20   - event_title = event.ref_name
21   - end
22   -
23   - xml.id "tag:#{request.host},#{event.created_at.strftime("%Y-%m-%d")}:#{event.id}"
24   - xml.link :href => event_link
25   - xml.title truncate(event_title, :length => 80)
26   - xml.updated event.created_at.strftime("%Y-%m-%dT%H:%M:%SZ")
27   - xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(event.author_email)
28   - xml.author do |author|
29   - xml.name event.author_name
30   - xml.email event.author_email
31   - end
32   - xml.summary event_title
33   - end
34   - end
35   - end
36   -end
app/views/projects/index.html.haml
... ... @@ -1,49 +0,0 @@
1   -- if @projects.any?
2   - .projects
3   - .activities.span8
4   - - if current_user.require_ssh_key?
5   - .alert.alert-error.padded
6   - %span
7   - You wont be able to pull/push project code unless you
8   - %strong
9   - = link_to new_key_path, :class => "vlink" do
10   - add new key
11   - to your profile
12   - - if @events.any?
13   - = render @events
14   - - else
15   - %h4.nothing_here_message Projects activity will be displayed here
16   - .side
17   - = render "events/event_last_push", :event => @last_push
18   - .projects_box
19   - %h5
20   - Projects
21   - %small
22   - (#{@projects.total_count})
23   - - if current_user.can_create_project?
24   - %span.right
25   - = link_to new_project_path, :class => "btn very_small info" do
26   - %i.icon-plus
27   - New Project
28   - - @projects.each do |project|
29   - = link_to project_path(project), :class => dom_class(project) do
30   - %h4
31   - %span.ico.project
32   - = truncate(project.name, :length => 25)
33   - %span.right
34   - →
35   - .bottom= paginate @projects, :theme => "gitlab"
36   -
37   -- else
38   - %h3.nothing_here_message There are no projects you have access to.
39   - %br
40   - %h4.nothing_here_message
41   - - if current_user.can_create_project?
42   - You can create up to
43   - = current_user.projects_limit
44   - projects. Click on button below to add a new one
45   - .link_holder
46   - = link_to new_project_path, :class => "btn primary" do
47   - New Project »
48   - - else
49   - If you will be added to project - it will be displayed here
app/views/projects/index.js.haml
... ... @@ -1,2 +0,0 @@
1   -:plain
2   - Pager.append(#{@projects.count}, "#{escape_javascript(render(:partial => 'projects/tile'))}");
app/views/projects/show.html.haml
... ... @@ -2,10 +2,6 @@
2 2  
3 3 .entry
4 4 .row
5   - -#.span2
6   - .back_link
7   - = link_to projects_path do
8   - ← To projects list
9 5 .span7
10 6 .form-horizontal
11 7 .input-prepend
... ...
config/routes.rb
... ... @@ -33,6 +33,10 @@ Gitlab::Application.routes.draw do
33 33 end
34 34  
35 35 get "errors/githost"
  36 +
  37 + #
  38 + # Profile Area
  39 + #
36 40 get "profile/password", :to => "profile#password"
37 41 put "profile/password", :to => "profile#password_update"
38 42 get "profile/token", :to => "profile#token"
... ... @@ -41,10 +45,14 @@ Gitlab::Application.routes.draw do
41 45 get "profile/design", :to => "profile#design"
42 46 put "profile/update", :to => "profile#update"
43 47  
  48 + #
  49 + # Dashboard Area
  50 + #
  51 + get "dashboard", :to => "dashboard#index"
44 52 get "dashboard/issues", :to => "dashboard#issues"
45 53 get "dashboard/merge_requests", :to => "dashboard#merge_requests"
46 54  
47   - resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create, :index]
  55 + resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create]
48 56 resources :keys
49 57  
50 58 devise_for :users, :controllers => { :omniauth_callbacks => :omniauth_callbacks }
... ... @@ -145,5 +153,5 @@ Gitlab::Application.routes.draw do
145 153 end
146 154 resources :notes, :only => [:index, :create, :destroy]
147 155 end
148   - root :to => "projects#index"
  156 + root :to => "dashboard#index"
149 157 end
... ...
spec/requests/dashboard_spec.rb 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +require 'spec_helper'
  2 +
  3 +describe "User Dashboard" do
  4 + before { login_as :user }
  5 +
  6 + describe "GET /" do
  7 + before do
  8 + @project = Factory :project, :owner => @user
  9 + @project.add_access(@user, :read)
  10 + visit dashboard_path
  11 + end
  12 +
  13 + it "should be on projects page" do
  14 + current_path.should == dashboard_path
  15 + end
  16 +
  17 + it "should have link to new project" do
  18 + page.should have_content("New Project")
  19 + end
  20 +
  21 + it "should have project" do
  22 + page.should have_content(@project.name)
  23 + end
  24 +
  25 + it "should render projects atom feed via private token" do
  26 + logout
  27 +
  28 + visit dashboard_path(:atom, :private_token => @user.private_token)
  29 + page.body.should have_selector("feed title")
  30 + end
  31 +
  32 + it "should not render projects page via private token" do
  33 + logout
  34 +
  35 + visit dashboard_path(:private_token => @user.private_token)
  36 + current_path.should == new_user_session_path
  37 + end
  38 + end
  39 +end
... ...
spec/requests/last_push_widget_spec.rb
... ... @@ -7,7 +7,7 @@ describe "Last Push widget" do
7 7 @project = Factory :project, :owner => @user
8 8 @project.add_access(@user, :read)
9 9 create_push_event
10   - visit projects_path
  10 + visit dashboard_path
11 11 end
12 12  
13 13 it "should display last push widget with link to merge request page" do
... ...
spec/requests/projects_security_spec.rb
1 1 require 'spec_helper'
2 2  
3   -describe "Projects" do
4   - describe "GET /projects" do
5   - it { projects_path.should be_allowed_for :admin }
6   - it { projects_path.should be_allowed_for :user }
7   - it { projects_path.should be_denied_for :visitor }
  3 +describe "Projects Security" do
  4 + describe "GET /" do
  5 + it { root_path.should be_allowed_for :admin }
  6 + it { root_path.should be_allowed_for :user }
  7 + it { root_path.should be_denied_for :visitor }
8 8 end
9 9  
10 10 describe "GET /projects/new" do
11   - it { projects_path.should be_allowed_for :admin }
12   - it { projects_path.should be_allowed_for :user }
13   - it { projects_path.should be_denied_for :visitor }
  11 + it { new_project_path.should be_allowed_for :admin }
  12 + it { new_project_path.should be_allowed_for :user }
  13 + it { new_project_path.should be_denied_for :visitor }
14 14 end
15 15  
16 16 describe "Project" do
... ...
spec/requests/projects_spec.rb
... ... @@ -3,43 +3,9 @@ require 'spec_helper'
3 3 describe "Projects" do
4 4 before { login_as :user }
5 5  
6   - describe "GET /projects" do
7   - before do
8   - @project = Factory :project, :owner => @user
9   - @project.add_access(@user, :read)
10   - visit projects_path
11   - end
12   -
13   - it "should be on projects page" do
14   - current_path.should == projects_path
15   - end
16   -
17   - it "should have link to new project" do
18   - page.should have_content("New Project")
19   - end
20   -
21   - it "should have project" do
22   - page.should have_content(@project.name)
23   - end
24   -
25   - it "should render projects atom feed via private token" do
26   - logout
27   -
28   - visit projects_path(:atom, :private_token => @user.private_token)
29   - page.body.should have_selector("feed title")
30   - end
31   -
32   - it "should not render projects page via private token" do
33   - logout
34   -
35   - visit projects_path(:private_token => @user.private_token)
36   - current_path.should == new_user_session_path
37   - end
38   - end
39   -
40 6 describe "GET /projects/new" do
41 7 before do
42   - visit projects_path
  8 + visit root_path
43 9 click_link "New Project"
44 10 end
45 11  
... ...
spec/requests/top_panel_spec.rb
... ... @@ -1,37 +0,0 @@
1   -__END__
2   -require 'spec_helper'
3   -
4   -describe "Top Panel", :js => true do
5   - before { login_as :user }
6   -
7   - describe "Search autocomplete" do
8   - before do
9   - visit projects_path
10   - fill_in "search", :with => "Ke"
11   - within ".ui-autocomplete" do
12   - find(:xpath, "//a[.=\"Keys\"]").click
13   - end
14   - end
15   -
16   - it "should be on projects page" do
17   - current_path.should == keys_path
18   - end
19   - end
20   -
21   - describe "with project" do
22   - before do
23   - @project = Factory :project
24   - @project.add_access(@user, :read)
25   - visit project_path(@project)
26   -
27   - fill_in "search", :with => "Commi"
28   - within ".ui-autocomplete" do
29   - find(:xpath, "//a[.=\"#{@project.code} / Commits\"]").click
30   - end
31   - end
32   -
33   - it "should be on projects page" do
34   - current_path.should == project_commits_path(@project)
35   - end
36   - end
37   -end