From 1b6a3dfec9bdadb8c607bf57e4b6699c4ab3a80b Mon Sep 17 00:00:00 2001 From: randx Date: Tue, 2 Oct 2012 20:42:15 +0300 Subject: [PATCH] Move all stuff to groups controller --- app/assets/stylesheets/sections/projects.scss | 2 + app/controllers/dashboard_controller.rb | 15 +--- app/controllers/groups_controller.rb | 69 +++++++++++++++++ app/views/dashboard/_groups.html.haml | 2 +- app/views/dashboard/index.html.haml | 2 +- app/views/groups/_projects.html.haml | 20 +++++ app/views/groups/issues.atom.builder | 24 ++++++ app/views/groups/issues.html.haml | 19 +++++ app/views/groups/merge_requests.html.haml | 18 +++++ app/views/groups/people.html.haml | 12 +++ app/views/groups/search.html.haml | 75 +++++++++++++++++++ app/views/groups/show.atom.builder | 29 +++++++ app/views/groups/show.html.haml | 42 +++++++++++ app/views/groups/show.js.haml | 2 + app/views/layouts/group.html.haml | 22 +++--- config/routes.rb | 13 ++++ 16 files changed, 339 insertions(+), 27 deletions(-) create mode 100644 app/controllers/groups_controller.rb create mode 100644 app/views/groups/_projects.html.haml create mode 100644 app/views/groups/issues.atom.builder create mode 100644 app/views/groups/issues.html.haml create mode 100644 app/views/groups/merge_requests.html.haml create mode 100644 app/views/groups/people.html.haml create mode 100644 app/views/groups/search.html.haml create mode 100644 app/views/groups/show.atom.builder create mode 100644 app/views/groups/show.html.haml create mode 100644 app/views/groups/show.js.haml diff --git a/app/assets/stylesheets/sections/projects.scss b/app/assets/stylesheets/sections/projects.scss index a29504ec..53a7c2bc 100644 --- a/app/assets/stylesheets/sections/projects.scss +++ b/app/assets/stylesheets/sections/projects.scss @@ -13,6 +13,8 @@ font-size:16px; text-shadow: 0 1px 1px #fff; padding: 2px 10px; + line-height:32px; + font-size:14px; } ul { li { diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 75cf726d..1f142dae 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -3,21 +3,14 @@ class DashboardController < ApplicationController def index @groups = Group.where(id: current_user.projects.pluck(:group_id)) - @projects = current_user.projects_with_events - - if params[:group].present? - @group = Group.find_by_code(params[:group]) - @projects = @projects.where(group_id: @group.id) - end - @projects = @projects.page(params[:page]).per(40) @events = Event.recent_for_user(current_user).limit(20).offset(params[:offset] || 0) @last_push = current_user.recent_push respond_to do |format| - format.html { render 'index', layout: determine_layout } + format.html format.js format.atom { render layout: false } end @@ -41,10 +34,4 @@ class DashboardController < ApplicationController format.atom { render layout: false } end end - - protected - - def determine_layout - @group ? 'group' : 'application' - end end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb new file mode 100644 index 00000000..486b0bee --- /dev/null +++ b/app/controllers/groups_controller.rb @@ -0,0 +1,69 @@ +class GroupsController < ApplicationController + respond_to :html + layout 'group' + + before_filter :group + before_filter :projects + + def show + @events = Event.where(project_id: project_ids). + order('id DESC'). + limit(20).offset(params[:offset] || 0) + + @last_push = current_user.recent_push + + respond_to do |format| + format.html + format.js + format.atom { render layout: false } + end + end + + # Get authored or assigned open merge requests + def merge_requests + @merge_requests = current_user.cared_merge_requests.order("created_at DESC").page(params[:page]).per(20) + end + + # Get only assigned issues + def issues + @user = current_user + @issues = current_user.assigned_issues.opened.order("created_at DESC").page(params[:page]).per(20) + @issues = @issues.includes(:author, :project) + + respond_to do |format| + format.html + format.atom { render layout: false } + end + end + + def search + query = params[:search] + + @merge_requests = [] + @issues = [] + + if query.present? + @projects = @projects.search(query).limit(10) + @merge_requests = MergeRequest.where(project_id: project_ids).search(query).limit(10) + @issues = Issue.where(project_id: project_ids).search(query).limit(10) + end + end + + def people + @users = group.projects.map(&:users).flatten.uniq + end + + protected + + def group + @group ||= Group.find_by_code(params[:id]) + end + + def projects + @projects ||= current_user.projects_with_events.where(group_id: @group.id) + end + + def project_ids + projects.map(&:id) + end +end diff --git a/app/views/dashboard/_groups.html.haml b/app/views/dashboard/_groups.html.haml index b46f675f..5180bfa0 100644 --- a/app/views/dashboard/_groups.html.haml +++ b/app/views/dashboard/_groups.html.haml @@ -6,7 +6,7 @@ %ul.unstyled - groups.each do |group| %li.wll - = link_to dashboard_path(group: group), class: dom_class(group) do + = link_to group_path(id: group.code), class: dom_class(group) do %strong.group_name= truncate(group.name, length: 25) %span.arrow → diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index aa53ebfd..dc520a22 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -9,7 +9,7 @@ .loading.hide .side = render "events/event_last_push", event: @last_push - - unless @group + - if @groups.present? = render "groups", groups: @groups = render "projects", projects: @projects %div diff --git a/app/views/groups/_projects.html.haml b/app/views/groups/_projects.html.haml new file mode 100644 index 00000000..35433057 --- /dev/null +++ b/app/views/groups/_projects.html.haml @@ -0,0 +1,20 @@ +.projects_box + %h5 + Projects + %small + (#{projects.count}) + - if current_user.can_create_project? + %span.right + = link_to new_project_path, class: "btn very_small info" do + %i.icon-plus + New Project + %ul.unstyled + - projects.each do |project| + %li.wll + = link_to project_path(project), class: dom_class(project) do + %strong.project_name= truncate(project.name, length: 25) + %span.arrow + → + %span.last_activity + %strong Last activity: + %span= project_last_activity(project) diff --git a/app/views/groups/issues.atom.builder b/app/views/groups/issues.atom.builder new file mode 100644 index 00000000..5bd07bcd --- /dev/null +++ b/app/views/groups/issues.atom.builder @@ -0,0 +1,24 @@ +xml.instruct! +xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do + xml.title "#{@user.name} issues" + xml.link :href => dashboard_issues_url(:atom, :private_token => @user.private_token), :rel => "self", :type => "application/atom+xml" + xml.link :href => dashboard_issues_url(:private_token => @user.private_token), :rel => "alternate", :type => "text/html" + xml.id dashboard_issues_url(:private_token => @user.private_token) + xml.updated @issues.first.created_at.strftime("%Y-%m-%dT%H:%M:%SZ") if @issues.any? + + @issues.each do |issue| + xml.entry do + xml.id project_issue_url(issue.project, issue) + xml.link :href => project_issue_url(issue.project, issue) + xml.title truncate(issue.title, :length => 80) + xml.updated issue.created_at.strftime("%Y-%m-%dT%H:%M:%SZ") + xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(issue.author_email) + xml.author do |author| + xml.name issue.author_name + xml.email issue.author_email + end + xml.summary issue.title + end + end +end + diff --git a/app/views/groups/issues.html.haml b/app/views/groups/issues.html.haml new file mode 100644 index 00000000..cc488d57 --- /dev/null +++ b/app/views/groups/issues.html.haml @@ -0,0 +1,19 @@ +%h3.page_title + Issues + %small (assigned to you) + %small.right #{@issues.total_count} issues + +%br +.clearfix +- if @issues.any? + - @issues.group_by(&:project).each do |group| + %div.ui-box + - @project = group[0] + %h5= @project.name + %ul.unstyled.issues_table + - group[1].each do |issue| + = render(partial: 'issues/show', locals: {issue: issue}) + %hr + = paginate @issues, theme: "gitlab" +- else + %h3.nothing_here_message Nothing to show here diff --git a/app/views/groups/merge_requests.html.haml b/app/views/groups/merge_requests.html.haml new file mode 100644 index 00000000..23a7e722 --- /dev/null +++ b/app/views/groups/merge_requests.html.haml @@ -0,0 +1,18 @@ +%h3.page_title + Merge Requests + %small (authored by or assigned to you) + %small.right #{@merge_requests.total_count} merge requests + +%br +- if @merge_requests.any? + - @merge_requests.group_by(&:project).each do |group| + %ul.unstyled.ui-box + - @project = group[0] + %h5= @project.name + - group[1].each do |merge_request| + = render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request}) + %hr + = paginate @merge_requests, theme: "gitlab" + +- else + %h3.nothing_here_message Nothing to show here diff --git a/app/views/groups/people.html.haml b/app/views/groups/people.html.haml new file mode 100644 index 00000000..4c1865a2 --- /dev/null +++ b/app/views/groups/people.html.haml @@ -0,0 +1,12 @@ +.ui-box + %h5 + People + %small + (#{@users.count}) + %ul.unstyled + - @users.each do |user| + %li.wll + = image_tag gravatar_icon(user.email, 16), class: "avatar s16" + %strong= user.name + %span.cgray= user.email + diff --git a/app/views/groups/search.html.haml b/app/views/groups/search.html.haml new file mode 100644 index 00000000..6ca5630f --- /dev/null +++ b/app/views/groups/search.html.haml @@ -0,0 +1,75 @@ += form_tag search_group_path(@group), method: :get, class: 'form-inline' do |f| + .padded + = label_tag :search do + %strong Looking for + .input + = search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search" + = submit_tag 'Search', class: "btn primary wide" +- if params[:search].present? + %br + %h3 + Search results + %small (#{@projects.count + @merge_requests.count + @issues.count}) + %hr + .search_results + .row + .span6 + %table + %thead + %tr + %th Projects + %tbody + - @projects.each do |project| + %tr + %td + = link_to project do + %strong.term= project.name + %small.cgray + last activity at + = project.last_activity_date.stamp("Aug 25, 2011") + - if @projects.blank? + %tr + %td + %h4.nothing_here_message No Projects + %br + %table + %thead + %tr + %th Merge Requests + %tbody + - @merge_requests.each do |merge_request| + %tr + %td + = link_to [merge_request.project, merge_request] do + %span.badge.badge-info ##{merge_request.id} + – + %strong.term= truncate merge_request.title, length: 50 + %strong.right + %span.label= merge_request.project.name + - if @merge_requests.blank? + %tr + %td + %h4.nothing_here_message No Merge Requests + .span6 + %table + %thead + %tr + %th Issues + %tbody + - @issues.each do |issue| + %tr + %td + = link_to [issue.project, issue] do + %span.badge.badge-info ##{issue.id} + – + %strong.term= truncate issue.title, length: 40 + %strong.right + %span.label= issue.project.name + - if @issues.blank? + %tr + %td + %h4.nothing_here_message No Issues + :javascript + $(function() { + $(".search_results .term").highlight("#{params[:search]}"); + }) diff --git a/app/views/groups/show.atom.builder b/app/views/groups/show.atom.builder new file mode 100644 index 00000000..fa3bfade --- /dev/null +++ b/app/views/groups/show.atom.builder @@ -0,0 +1,29 @@ +xml.instruct! +xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://search.yahoo.com/mrss/" do + xml.title "Dashboard feed#{" - #{current_user.name}" if current_user.name.present?}" + xml.link :href => projects_url(:atom), :rel => "self", :type => "application/atom+xml" + xml.link :href => projects_url, :rel => "alternate", :type => "text/html" + xml.id projects_url + xml.updated @events.maximum(:updated_at).strftime("%Y-%m-%dT%H:%M:%SZ") if @events.any? + + @events.each do |event| + if event.allowed? + event = EventDecorator.decorate(event) + xml.entry do + event_link = event.feed_url + event_title = event.feed_title + + xml.id "tag:#{request.host},#{event.created_at.strftime("%Y-%m-%d")}:#{event.id}" + xml.link :href => event_link + xml.title truncate(event_title, :length => 80) + xml.updated event.created_at.strftime("%Y-%m-%dT%H:%M:%SZ") + xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(event.author_email) + xml.author do |author| + xml.name event.author_name + xml.email event.author_email + end + xml.summary event_title + end + end + end +end diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml new file mode 100644 index 00000000..7552128e --- /dev/null +++ b/app/views/groups/show.html.haml @@ -0,0 +1,42 @@ +- if @projects.any? + .projects + .activities.span8 + = render 'shared/no_ssh' + - if @events.any? + .content_list= render @events + - else + %h4.nothing_here_message Projects activity will be displayed here + .loading.hide + .side + = render "events/event_last_push", event: @last_push + = render "projects", projects: @projects + %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 + + %hr + .gitlab-promo + = link_to "Homepage", "http://gitlabhq.com" + = link_to "Blog", "http://blog.gitlabhq.com" + = link_to "@gitlabhq", "https://twitter.com/gitlabhq" + + +- else + %h3.nothing_here_message There are no projects you have access to. + %br + %h4.nothing_here_message + - if current_user.can_create_project? + You can create up to + = current_user.projects_limit + projects. Click on button below to add a new one + .link_holder + = link_to new_project_path, class: "btn primary" do + New Project ยป + - else + If you will be added to project - it will be displayed here + + +:javascript + $(function(){ Pager.init(20); }); diff --git a/app/views/groups/show.js.haml b/app/views/groups/show.js.haml new file mode 100644 index 00000000..7e5a148e --- /dev/null +++ b/app/views/groups/show.js.haml @@ -0,0 +1,2 @@ +:plain + Pager.append(#{@events.count}, "#{escape_javascript(render(@events))}"); diff --git a/app/views/layouts/group.html.haml b/app/views/layouts/group.html.haml index 810c296e..e4277eff 100644 --- a/app/views/layouts/group.html.haml +++ b/app/views/layouts/group.html.haml @@ -3,22 +3,22 @@ = render "layouts/head" %body{class: "#{app_theme} application"} = render "layouts/flash" - = render "layouts/head_panel", title: "#{@group.name}:Dashboard" + = render "layouts/head_panel", title: "#{@group.name}" .container %ul.main_menu - = nav_link(path: 'dashboard#index', html_options: {class: 'home'}) do - = link_to "Home", root_path, title: "Home" - = nav_link(path: 'dashboard#issues') do - = link_to dashboard_issues_path(group: @group) do + = nav_link(path: 'groups#show', html_options: {class: 'home'}) do + = link_to "Home", group_path(@group), title: "Home" + = nav_link(path: 'groups#issues') do + = link_to issues_group_path(@group) do Issues %span.count= current_user.assigned_issues.opened.count - = nav_link(path: 'dashboard#merge_requests') do - = link_to dashboard_merge_requests_path(group: @group) do + = nav_link(path: 'groups#merge_requests') do + = link_to merge_requests_group_path(@group) do Merge Requests %span.count= current_user.cared_merge_requests.count - = nav_link(path: 'search#show') do - = link_to "People", "#" - = nav_link(path: 'help#index') do - = link_to "Help", help_path + = nav_link(path: 'groups#search') do + = link_to "Search", search_group_path(@group) + = nav_link(path: 'groups#people') do + = link_to "People", people_group_path(@group) .content= yield diff --git a/config/routes.rb b/config/routes.rb index 2b923379..f6bebc6b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,6 +86,19 @@ Gitlab::Application.routes.draw do get "dashboard/issues" => "dashboard#issues" get "dashboard/merge_requests" => "dashboard#merge_requests" + + # + # Groups Area + # + resources :groups, constraints: { id: /[^\/]+/ }, only: [:show] do + member do + get :issues + get :merge_requests + get :search + get :people + end + end + resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create] devise_for :users, controllers: { omniauth_callbacks: :omniauth_callbacks }