Commit 74e329064abc1306132dd73dcb2e25221379f568

Authored by Dmitriy Zaporozhets
1 parent 1c88fbb3

teams refactoring and cleanup pt.1

app/controllers/teams_controller.rb
... ... @@ -64,16 +64,6 @@ class TeamsController < ApplicationController
64 64 @issues = @issues.includes(:author, :project)
65 65 end
66 66  
67   - def search
68   - result = SearchContext.new(user_team.project_ids, params).execute
69   -
70   - @projects = result[:projects]
71   - @merge_requests = result[:merge_requests]
72   - @issues = result[:issues]
73   - @wiki_pages = result[:wiki_pages]
74   - @teams = result[:teams]
75   - end
76   -
77 67 protected
78 68  
79 69 def projects
... ...
app/models/project.rb
... ... @@ -80,7 +80,7 @@ class Project < ActiveRecord::Base
80 80 # Scopes
81 81 scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }
82 82 scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }
83   - scope :without_team, ->(team) { where("id NOT IN (:ids)", ids: team.projects.map(&:id)) }
  83 + scope :without_team, ->(team) { team.projects.present? ? where("id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped }
84 84 scope :in_team, ->(team) { where("id IN (:ids)", ids: team.projects.map(&:id)) }
85 85 scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) }
86 86 scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") }
... ...
app/views/layouts/user_team.html.haml
... ... @@ -19,18 +19,16 @@
19 19 Merge Requests
20 20 %span.count= MergeRequest.opened.of_user_team(@team).count
21 21  
22   - = nav_link(path: 'teams#search') do
23   - = link_to "Search", search_team_path(@team)
24   -
25 22 = nav_link(controller: [:members]) do
26 23 = link_to team_members_path(@team), class: "team-tab tab" do
27 24 Members
  25 + %span.count= @team.members.count
28 26  
29 27 - if can? current_user, :admin_user_team, @team
30 28 = nav_link(controller: [:projects]) do
31 29 = link_to team_projects_path(@team), class: "team-tab tab" do
32   - %i.icon-briefcase
33 30 Projects
  31 + %span.count= @team.projects.count
34 32  
35 33 = nav_link(path: 'teams#edit') do
36 34 = link_to edit_team_path(@team), class: "stat-tab tab " do
... ...
app/views/profiles/show.html.haml
... ... @@ -31,6 +31,20 @@
31 31 .controls
32 32 = f.text_field :email, class: "input-xlarge", required: true
33 33 %span.help-block We also use email for avatar detection.
  34 + .control-group
  35 + = f.label :skype, class: "control-label"
  36 + .controls= f.text_field :skype, class: "input-xlarge"
  37 + .control-group
  38 + = f.label :linkedin, class: "control-label"
  39 + .controls= f.text_field :linkedin, class: "input-xlarge"
  40 + .control-group
  41 + = f.label :twitter, class: "control-label"
  42 + .controls= f.text_field :twitter, class: "input-xlarge"
  43 + .control-group
  44 + = f.label :bio, class: "control-label"
  45 + .controls
  46 + = f.text_area :bio, rows: 6, class: "input-xlarge", maxlength: 250
  47 + %span.help-block Tell us about yourself in fewer than 250 characters.
34 48  
35 49 .span5.right
36 50 %fieldset.tips
... ... @@ -59,24 +73,6 @@
59 73 Want to share a team between projects?
60 74 = link_to new_team_path, class: "btn very_small" do
61 75 Create a team
62   -
63   - .row
64   - .span7
65   - .control-group
66   - = f.label :skype, class: "control-label"
67   - .controls= f.text_field :skype, class: "input-xlarge"
68   - .control-group
69   - = f.label :linkedin, class: "control-label"
70   - .controls= f.text_field :linkedin, class: "input-xlarge"
71   - .control-group
72   - = f.label :twitter, class: "control-label"
73   - .controls= f.text_field :twitter, class: "input-xlarge"
74   - .control-group
75   - = f.label :bio, class: "control-label"
76   - .controls
77   - = f.text_area :bio, rows: 6, class: "input-xlarge", maxlength: 250
78   - %span.help-block Tell us about yourself in fewer than 250 characters.
79   - .span5.right
80 76 %fieldset
81 77 %legend
82 78 Personal projects:
... ...
app/views/teams/_team_head.html.haml
app/views/teams/edit.html.haml
1   -= render "team_head"
2   -
3 1 %h3.page_title= "Edit Team #{@team.name}"
4 2 %hr
5 3 = form_for @team, url: teams_path do |f|
... ...
app/views/teams/index.html.haml
... ... @@ -1,38 +0,0 @@
1   -%h3.page_title
2   - Teams
3   - %small
4   - list of all teams
5   -
6   - = link_to 'New Team', new_team_path, class: "btn success small right"
7   - %br
8   -
9   -= form_tag search_teams_path, method: :get, class: 'form-inline' do
10   - = text_field_tag :name, params[:name], class: "xlarge"
11   - = submit_tag "Search", class: "btn submit primary"
12   -
13   -%table.teams_list
14   - %thead
15   - %tr
16   - %th
17   - Name
18   - %i.icon-sort-down
19   - %th Path
20   - %th Projects
21   - %th Members
22   - %th Owner
23   - %th.cred Danger Zone!
24   -
25   - - @teams.each do |team|
26   - %tr
27   - %td
28   - %strong= link_to team.name, team_path(team)
29   - %td= team.path
30   - %td= link_to team.projects.count, team_projects_path(team)
31   - %td= link_to team.members.count, team_members_path(team)
32   - %td= link_to team.owner.name, team_member_path(team, team.owner)
33   - %td.bgred
34   - - if current_user.can?(:manage_user_team, team)
35   - = link_to "Edit", edit_team_path(team), class: "btn small"
36   - - if current_user.can?(:admin_user_team, team)
37   - = link_to "Destroy", team_path(team), method: :delete, confirm: "You are shure?", class: "danger btn small"
38   -  
app/views/teams/issues.html.haml
1   -= render "team_head"
2   -
3 1 %h3.page_title
4 2 Issues
5 3 %small (in Team projects assigned to Team members)
... ...
app/views/teams/members/edit.html.haml
1   -= render "teams/team_head"
2   -
3   -%h3
  1 +%h3.page_title
4 2 Edit access #{@member.name} in #{@team.name} team
5 3  
6 4 %hr
... ...
app/views/teams/members/index.html.haml
1   -= render "teams/team_head"
2   -
3 1 %h3.page_title
4 2 Team Members
5 3 (#{@members.count})
... ...
app/views/teams/members/new.html.haml
1   -= render "teams/team_head"
2   -
3 1 %h3.page_title
4 2 Team: #{@team.name}
5 3  
... ...
app/views/teams/members/show.html.haml
1   -= render "teams/team_head"
2   -
3 1 - allow_admin = can? current_user, :admin_project, @project
4 2 - user = @team_member.user
5 3  
... ...
app/views/teams/merge_requests.html.haml
1   -= render "team_head"
2   -
3 1 %h3.page_title
4 2 Merge Requests
5 3 %small (authored by or assigned to Team members)
... ...
app/views/teams/projects/edit.html.haml
1   -= render "teams/team_head"
2   -
3 1 %h3
4 2 Edit max access in #{@project.name} for #{@team.name} team
5 3  
... ...
app/views/teams/projects/index.html.haml
1   -= render "teams/team_head"
2   -
3 1 %h3.page_title
4 2 Assigned projects (#{@team.projects.count})
5 3 %small
... ... @@ -13,22 +11,26 @@
13 11  
14 12 %hr
15 13  
16   -%table.projects-table
17   - %thead
18   - %tr
19   - %th Project name
20   - %th Max access
21   - - if current_user.can?(:admin_user_team, @team)
22   - %th.span3
  14 +- if @team.projects.present?
  15 + %table.projects-table
  16 + %thead
  17 + %tr
  18 + %th Project name
  19 + %th Max access
  20 + - if current_user.can?(:admin_user_team, @team)
  21 + %th.span3
  22 +
  23 + - @team.projects.each do |project|
  24 + %tr.project
  25 + %td
  26 + = link_to project.name_with_namespace, project_path(project)
  27 + %td
  28 + %span= @team.human_max_project_access(project)
23 29  
24   - - @team.projects.each do |project|
25   - %tr.project
26   - %td
27   - = link_to project.name_with_namespace, project_path(project)
28   - %td
29   - %span= @team.human_max_project_access(project)
  30 + - if current_user.can?(:admin_user_team, @team)
  31 + %td.bgred
  32 + = link_to 'Edit max access', edit_team_project_path(@team, project), class: "btn small"
  33 + = link_to 'Relegate', team_project_path(@team, project), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small"
30 34  
31   - - if current_user.can?(:admin_user_team, @team)
32   - %td.bgred
33   - = link_to 'Edit max access', edit_team_project_path(@team, project), class: "btn small"
34   - = link_to 'Relegate', team_project_path(@team, project), confirm: 'Remove project from team and move to global namespace. Are you sure?', method: :delete, class: "btn danger small"
  35 +- else
  36 + %p.nothing_here_message This team has no projects yet
... ...
app/views/teams/projects/new.html.haml
1   -= render "teams/team_head"
2   -
3 1 %h3.page_title
4 2 Team: #{@team.name}
5 3  
... ...
app/views/teams/search.html.haml
... ... @@ -1,11 +0,0 @@
1   -= render "team_head"
2   -
3   -= form_tag search_team_path(@team), method: :get, class: 'form-inline' do |f|
4   - .padded
5   - = label_tag :search do
6   - %strong Looking for
7   - .input
8   - = search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search"
9   - = submit_tag 'Search', class: "btn primary wide"
10   -- if params[:search].present?
11   - = render 'search/result'
app/views/teams/show.html.haml
1   -= render "team_head"
2   -
3 1 .projects
4 2 .activities.span8
5 3 = link_to dashboard_path, class: 'btn very_small' do
... ...
config/routes.rb
... ... @@ -142,15 +142,11 @@ Gitlab::Application.routes.draw do
142 142 member do
143 143 get :issues
144 144 get :merge_requests
145   - get :search
146 145 end
147 146 scope module: :teams do
148 147 resources :members, only: [:index, :new, :create, :edit, :update, :destroy]
149 148 resources :projects, only: [:index, :new, :create, :edit, :update, :destroy], constraints: { id: /[a-zA-Z.0-9_\-\/]+/ }
150 149 end
151   - collection do
152   - get :search
153   - end
154 150 end
155 151  
156 152 resources :projects, constraints: { id: /[^\/]+/ }, only: [:new, :create]
... ...