From edd81a79c5c2a61e565664cfa787185c4e19729b Mon Sep 17 00:00:00 2001 From: randx Date: Tue, 12 Jun 2012 23:13:42 +0300 Subject: [PATCH] Dashboard refactoring: * dashboard should be in dashboard controller not project index * projects index removed --- app/assets/stylesheets/common.scss | 6 ++- app/controllers/dashboard_controller.rb | 17 ++++---- app/helpers/application_helper.rb | 3 +- .../index.atom.builder | 0 .../{projects => dashboard}/index.html.haml | 7 ++++ app/views/dashboard/index.js.haml | 2 + app/views/layouts/_app_menu.html.haml | 2 +- app/views/projects/index.js.haml | 2 - app/views/projects/show.html.haml | 4 -- config/routes.rb | 12 +++++- spec/requests/dashboard_spec.rb | 39 +++++++++++++++++++ spec/requests/last_push_widget_spec.rb | 2 +- spec/requests/projects_security_spec.rb | 16 ++++---- spec/requests/projects_spec.rb | 36 +---------------- spec/requests/top_panel_spec.rb | 37 ------------------ 15 files changed, 84 insertions(+), 101 deletions(-) rename app/views/{projects => dashboard}/index.atom.builder (100%) rename app/views/{projects => dashboard}/index.html.haml (87%) create mode 100644 app/views/dashboard/index.js.haml delete mode 100644 app/views/projects/index.js.haml create mode 100644 spec/requests/dashboard_spec.rb delete mode 100644 spec/requests/top_panel_spec.rb diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 18023c55..32667ec6 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -659,6 +659,10 @@ li.note { width:24px; vertical-align:top; } + + strong { + line-height:24px; + } } .automerge_widget { @@ -741,7 +745,7 @@ li.note { */ .event_lp { @extend .alert-info; - margin-bottom:15px; + margin-bottom:20px; padding:8px; border-style: solid; border-width: 1px; diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index c28f1716..a0549407 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -2,18 +2,17 @@ class DashboardController < ApplicationController respond_to :html def index - @projects = current_user.projects.all + @projects = current_user.projects.includes(:events).order("events.created_at DESC") + @projects = @projects.page(params[:page]).per(40) - @active_projects = @projects.select(&:last_activity_date).sort_by(&:last_activity_date).reverse + @events = Event.where(:project_id => current_user.projects.map(&:id)).recent.limit(20) - @merge_requests = MergeRequest.where("author_id = :id or assignee_id = :id", :id => current_user.id).opened.order("created_at DESC").limit(5) + @last_push = current_user.recent_push - @user = current_user - @issues = current_user.assigned_issues.opened.order("created_at DESC").limit(5) - @issues = @issues.includes(:author, :project) - - @events = Event.where(:project_id => @projects.map(&:id)).recent.limit(20) - @last_push = Event.where(:project_id => @projects.map(&:id)).recent.code_push.limit(1).first + respond_to do |format| + format.html + format.atom { render :layout => false } + end end # Get authored or assigned open merge requests diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6b9e457c..be0e0c9e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -60,8 +60,9 @@ module ApplicationHelper def search_autocomplete_source projects = current_user.projects.map{ |p| { :label => p.name, :url => project_path(p) } } default_nav = [ + { :label => "Profile", :url => profile_path }, { :label => "Keys", :url => keys_path }, - { :label => "Projects", :url => projects_path }, + { :label => "Dashboard", :url => root_path }, { :label => "Admin", :url => admin_root_path } ] diff --git a/app/views/projects/index.atom.builder b/app/views/dashboard/index.atom.builder similarity index 100% rename from app/views/projects/index.atom.builder rename to app/views/dashboard/index.atom.builder diff --git a/app/views/projects/index.html.haml b/app/views/dashboard/index.html.haml similarity index 87% rename from app/views/projects/index.html.haml rename to app/views/dashboard/index.html.haml index 3a77e39d..b3854450 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -34,6 +34,13 @@ → .bottom= paginate @projects, :theme => "gitlab" + %hr + %div + %span.rss-icon + = link_to dashboard_path(:atom, { :private_token => current_user.private_token }) do + = image_tag "rss_ui.png", :title => "feed" + %strong News Feed + - else %h3.nothing_here_message There are no projects you have access to. %br diff --git a/app/views/dashboard/index.js.haml b/app/views/dashboard/index.js.haml new file mode 100644 index 00000000..aa038e75 --- /dev/null +++ b/app/views/dashboard/index.js.haml @@ -0,0 +1,2 @@ +:plain + $(".projects .activities").append("#{escape_javascript(render(@events))}"); diff --git a/app/views/layouts/_app_menu.html.haml b/app/views/layouts/_app_menu.html.haml index c0e3e8a3..7b5f2cf9 100644 --- a/app/views/layouts/_app_menu.html.haml +++ b/app/views/layouts/_app_menu.html.haml @@ -1,5 +1,5 @@ %nav.main_menu - = link_to "Home", root_path, :class => "home #{"current" if current_page?(projects_path) || current_page?(root_path)}", :title => "Home" + = link_to "Home", root_path, :class => "home #{"current" if current_page?(dashboard_path) || current_page?(root_path)}", :title => "Home" = link_to dashboard_issues_path, :class => "#{"current" if current_page?(dashboard_issues_path)}", :id => "issues_slide" do Issues %span.count= current_user.assigned_issues.opened.count diff --git a/app/views/projects/index.js.haml b/app/views/projects/index.js.haml deleted file mode 100644 index 15bbd973..00000000 --- a/app/views/projects/index.js.haml +++ /dev/null @@ -1,2 +0,0 @@ -:plain - Pager.append(#{@projects.count}, "#{escape_javascript(render(:partial => 'projects/tile'))}"); diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 9ecbce38..48b54154 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -2,10 +2,6 @@ .entry .row - -#.span2 - .back_link - = link_to projects_path do - ← To projects list .span7 .form-horizontal .input-prepend diff --git a/config/routes.rb b/config/routes.rb index e835f58f..c3754bc6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,10 @@ Gitlab::Application.routes.draw do end get "errors/githost" + + # + # Profile Area + # get "profile/password", :to => "profile#password" put "profile/password", :to => "profile#password_update" get "profile/token", :to => "profile#token" @@ -41,10 +45,14 @@ Gitlab::Application.routes.draw do get "profile/design", :to => "profile#design" put "profile/update", :to => "profile#update" + # + # Dashboard Area + # + get "dashboard", :to => "dashboard#index" get "dashboard/issues", :to => "dashboard#issues" get "dashboard/merge_requests", :to => "dashboard#merge_requests" - resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create, :index] + resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create] resources :keys devise_for :users, :controllers => { :omniauth_callbacks => :omniauth_callbacks } @@ -145,5 +153,5 @@ Gitlab::Application.routes.draw do end resources :notes, :only => [:index, :create, :destroy] end - root :to => "projects#index" + root :to => "dashboard#index" end diff --git a/spec/requests/dashboard_spec.rb b/spec/requests/dashboard_spec.rb new file mode 100644 index 00000000..16ededd0 --- /dev/null +++ b/spec/requests/dashboard_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe "User Dashboard" do + before { login_as :user } + + describe "GET /" do + before do + @project = Factory :project, :owner => @user + @project.add_access(@user, :read) + visit dashboard_path + end + + it "should be on projects page" do + current_path.should == dashboard_path + end + + it "should have link to new project" do + page.should have_content("New Project") + end + + it "should have project" do + page.should have_content(@project.name) + end + + it "should render projects atom feed via private token" do + logout + + visit dashboard_path(:atom, :private_token => @user.private_token) + page.body.should have_selector("feed title") + end + + it "should not render projects page via private token" do + logout + + visit dashboard_path(:private_token => @user.private_token) + current_path.should == new_user_session_path + end + end +end diff --git a/spec/requests/last_push_widget_spec.rb b/spec/requests/last_push_widget_spec.rb index f3d06e86..831359a7 100644 --- a/spec/requests/last_push_widget_spec.rb +++ b/spec/requests/last_push_widget_spec.rb @@ -7,7 +7,7 @@ describe "Last Push widget" do @project = Factory :project, :owner => @user @project.add_access(@user, :read) create_push_event - visit projects_path + visit dashboard_path end it "should display last push widget with link to merge request page" do diff --git a/spec/requests/projects_security_spec.rb b/spec/requests/projects_security_spec.rb index cf97716c..df4d1122 100644 --- a/spec/requests/projects_security_spec.rb +++ b/spec/requests/projects_security_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' -describe "Projects" do - describe "GET /projects" do - it { projects_path.should be_allowed_for :admin } - it { projects_path.should be_allowed_for :user } - it { projects_path.should be_denied_for :visitor } +describe "Projects Security" do + describe "GET /" do + it { root_path.should be_allowed_for :admin } + it { root_path.should be_allowed_for :user } + it { root_path.should be_denied_for :visitor } end describe "GET /projects/new" do - it { projects_path.should be_allowed_for :admin } - it { projects_path.should be_allowed_for :user } - it { projects_path.should be_denied_for :visitor } + it { new_project_path.should be_allowed_for :admin } + it { new_project_path.should be_allowed_for :user } + it { new_project_path.should be_denied_for :visitor } end describe "Project" do diff --git a/spec/requests/projects_spec.rb b/spec/requests/projects_spec.rb index 79c94955..b55a4db5 100644 --- a/spec/requests/projects_spec.rb +++ b/spec/requests/projects_spec.rb @@ -3,43 +3,9 @@ require 'spec_helper' describe "Projects" do before { login_as :user } - describe "GET /projects" do - before do - @project = Factory :project, :owner => @user - @project.add_access(@user, :read) - visit projects_path - end - - it "should be on projects page" do - current_path.should == projects_path - end - - it "should have link to new project" do - page.should have_content("New Project") - end - - it "should have project" do - page.should have_content(@project.name) - end - - it "should render projects atom feed via private token" do - logout - - visit projects_path(:atom, :private_token => @user.private_token) - page.body.should have_selector("feed title") - end - - it "should not render projects page via private token" do - logout - - visit projects_path(:private_token => @user.private_token) - current_path.should == new_user_session_path - end - end - describe "GET /projects/new" do before do - visit projects_path + visit root_path click_link "New Project" end diff --git a/spec/requests/top_panel_spec.rb b/spec/requests/top_panel_spec.rb deleted file mode 100644 index 1be0789b..00000000 --- a/spec/requests/top_panel_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -__END__ -require 'spec_helper' - -describe "Top Panel", :js => true do - before { login_as :user } - - describe "Search autocomplete" do - before do - visit projects_path - fill_in "search", :with => "Ke" - within ".ui-autocomplete" do - find(:xpath, "//a[.=\"Keys\"]").click - end - end - - it "should be on projects page" do - current_path.should == keys_path - end - end - - describe "with project" do - before do - @project = Factory :project - @project.add_access(@user, :read) - visit project_path(@project) - - fill_in "search", :with => "Commi" - within ".ui-autocomplete" do - find(:xpath, "//a[.=\"#{@project.code} / Commits\"]").click - end - end - - it "should be on projects page" do - current_path.should == project_commits_path(@project) - end - end -end