Commit f6f414ce authored by Andrey Kumanyaev's avatar Andrey Kumanyaev Committed by Dmitriy Zaporozhets

refactoring project team members controller (corresponding mental model)

parent ccf8fa4f
...@@ -7,12 +7,12 @@ class TeamMembersController < ProjectResourceController ...@@ -7,12 +7,12 @@ class TeamMembersController < ProjectResourceController
end end
def show def show
@team_member = project.users_projects.find(params[:id]) @user_project_relation = project.users_projects.find_by_user_id(member)
@events = @team_member.user.recent_events.where(:project_id => @project.id).limit(7) @events = member.recent_events.in_projects(project).limit(7)
end end
def new def new
@team_member = project.users_projects.new @user_project_relation = project.users_projects.new
end end
def create def create
...@@ -28,18 +28,18 @@ class TeamMembersController < ProjectResourceController ...@@ -28,18 +28,18 @@ class TeamMembersController < ProjectResourceController
end end
def update def update
@team_member = project.users_projects.find(params[:id]) @user_project_relation = project.users_projects.find_by_user_id(member)
@team_member.update_attributes(params[:team_member]) @user_project_relation.update_attributes(params[:team_member])
unless @team_member.valid? unless @user_project_relation.valid?
flash[:alert] = "User should have at least one role" flash[:alert] = "User should have at least one role"
end end
redirect_to project_team_index_path(@project) redirect_to project_team_index_path(@project)
end end
def destroy def destroy
@team_member = project.users_projects.find(params[:id]) @user_project_relation = project.users_projects.find_by_user_id(params[:id])
@team_member.destroy @user_project_relation.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to project_team_index_path(@project) } format.html { redirect_to project_team_index_path(@project) }
...@@ -54,4 +54,10 @@ class TeamMembersController < ProjectResourceController ...@@ -54,4 +54,10 @@ class TeamMembersController < ProjectResourceController
redirect_to project_team_members_path(project), notice: notice redirect_to project_team_members_path(project), notice: notice
end end
protected
def member
@member ||= User.find(params[:id])
end
end end
...@@ -3,8 +3,8 @@ module ProjectsHelper ...@@ -3,8 +3,8 @@ module ProjectsHelper
@project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access) @project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access)
end end
def remove_from_team_message(project, member) def remove_from_project_team_message(project, user)
"You are going to remove #{member.user_name} from #{project.name}. Are you sure?" "You are going to remove #{user.name} from #{project.name} project team. Are you sure?"
end end
def link_to_project project def link_to_project project
......
%h3.page_title %h3.page_title
= "New Team member(s)" = "New Team member(s)"
%hr %hr
= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f| = form_for @user_project_relation, as: :team_member, url: project_team_members_path(@project) do |f|
-if @team_member.errors.any? -if @user_project_relation.errors.any?
.alert-message.block-message.error .alert-message.block-message.error
%ul %ul
- @team_member.errors.full_messages.each do |msg| - @user_project_relation.errors.full_messages.each do |msg|
%li= msg %li= msg
%h6 1. Choose people you want in the team %h6 1. Choose people you want in the team
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
%h6 2. Set access level for them %h6 2. Set access level for them
.clearfix .clearfix
= f.label :project_access, "Project Access" = f.label :project_access, "Project Access"
.input= select_tag :project_access, options_for_select(Project.access_options, @team_member.project_access), class: "project-access-select chosen" .input= select_tag :project_access, options_for_select(Project.access_options, @user_project_relation.project_access), class: "project-access-select chosen"
.actions .actions
= f.submit 'Save', class: "btn save-btn" = f.submit 'Save', class: "btn save-btn"
......
- user = member.user - user = member.user
- allow_admin = can? current_user, :admin_project, @project - allow_admin = can? current_user, :admin_project, @project
%li{id: dom_id(member), class: "team_member_row user_#{user.id}"} %li{id: dom_id(user), class: "team_member_row user_#{user.id}"}
.row .row
.span6 .span6
= link_to project_team_member_path(@project, member), title: user.name, class: "dark" do = link_to project_team_member_path(@project, user), title: user.name, class: "dark" do
= image_tag gravatar_icon(user.email, 40), class: "avatar s32" = image_tag gravatar_icon(user.email, 40), class: "avatar s32"
= link_to project_team_member_path(@project, member), title: user.name, class: "dark" do = link_to project_team_member_path(@project, user), title: user.name, class: "dark" do
%strong= truncate(user.name, lenght: 40) %strong= truncate(user.name, lenght: 40)
%br %br
%small.cgray= user.email %small.cgray= user.email
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
.span5.right .span5.right
- if allow_admin - if allow_admin
.left .left
= form_for(member, as: :team_member, url: project_team_member_path(@project, member)) do |f| = form_for(member, as: :team_member, url: project_team_member_path(@project, member.user)) do |f|
= f.select :project_access, options_for_select(UsersProject.access_roles, member.project_access), {}, class: "medium project-access-select span2" = f.select :project_access, options_for_select(UsersProject.access_roles, member.project_access), {}, class: "medium project-access-select span2"
.right .right
- if current_user == user - if current_user == user
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
- elsif user.blocked - elsif user.blocked
%span.btn.disabled.blocked Blocked %span.btn.disabled.blocked Blocked
- elsif allow_admin - elsif allow_admin
= link_to project_team_member_path(project_id: @project, id: member.id), confirm: remove_from_team_message(@project, member), method: :delete, class: "very_small btn danger" do = link_to project_team_member_path(@project, user), confirm: remove_from_project_team_message(@project, user), method: :delete, class: "very_small btn danger" do
%i.icon-minus.icon-white %i.icon-minus.icon-white
- if @team_member.valid? - if @user_project_relation.valid?
:plain :plain
$("#new_team_member").hide("slide", { direction: "right" }, 150, function(){ $("#new_team_member").hide("slide", { direction: "right" }, 150, function(){
$("#team-table").show("slide", { direction: "left" }, 150, function() { $("#team-table").show("slide", { direction: "left" }, 150, function() {
......
= render "projects/project_head" = render "projects/project_head"
%h3.page_title %h3.page_title
Team Members Team Members
(#{@project.users_projects.count}) (#{@project.users.count})
%small %small
Read more about project permissions Read more about project permissions
%strong= link_to "here", help_permissions_path, class: "vlink" %strong= link_to "here", help_permissions_path, class: "vlink"
......
- allow_admin = can? current_user, :admin_project, @project - allow_admin = can? current_user, :admin_project, @project
- user = @team_member.user
.team_member_show .team_member_show
- if can? current_user, :admin_project, @project - if can? current_user, :admin_project, @project
= link_to 'Remove from team', project_team_member_path(project_id: @project, id: @team_member.id), confirm: 'Are you sure?', method: :delete, class: "right btn danger" = link_to 'Remove from team', project_team_member_path(@project, @member), confirm: 'Are you sure?', method: :delete, class: "right btn danger"
.profile_avatar_holder .profile_avatar_holder
= image_tag gravatar_icon(user.email, 60), class: "borders" = image_tag gravatar_icon(@member.email, 60), class: "borders"
%h3.page_title %h3.page_title
= user.name = @member.name
%small (@#{user.username}) %small (@#{@member.username})
%hr %hr
.back_link .back_link
...@@ -21,34 +20,34 @@ ...@@ -21,34 +20,34 @@
%table.lite %table.lite
%tr %tr
%td Email %td Email
%td= mail_to user.email %td= mail_to @member.email
%tr %tr
%td Skype %td Skype
%td= user.skype %td= @member.skype
- unless user.linkedin.blank? - unless @member.linkedin.blank?
%tr %tr
%td LinkedIn %td LinkedIn
%td= user.linkedin %td= @member.linkedin
- unless user.twitter.blank? - unless @member.twitter.blank?
%tr %tr
%td Twitter %td Twitter
%td= user.twitter %td= @member.twitter
- unless user.bio.blank? - unless @member.bio.blank?
%tr %tr
%td Bio %td Bio
%td= user.bio %td= @member.bio
.span6 .span6
%table.lite %table.lite
%tr %tr
%td Member since %td Member since
%td= @team_member.created_at.stamp("Aug 21, 2011") %td= @user_project_relation.created_at.stamp("Aug 21, 2011")
%tr %tr
%td %td
Project Access: Project Access:
%small (#{link_to "read more", help_permissions_path, class: "vlink"}) %small (#{link_to "read more", help_permissions_path, class: "vlink"})
%td %td
= form_for(@team_member, as: :team_member, url: project_team_member_path(@project, @team_member)) do |f| = form_for(@user_project_relation, as: :team_member, url: project_team_member_path(@project, @member)) do |f|
= f.select :project_access, options_for_select(Project.access_options, @team_member.project_access), {}, class: "project-access-select", disabled: !allow_admin = f.select :project_access, options_for_select(Project.access_options, @user_project_relation.project_access), {}, class: "project-access-select", disabled: !allow_admin
%hr %hr
= render @events = render @events
:javascript :javascript
......
- if @team_member.valid? - if @user_project_relation.valid?
:plain :plain
$("##{dom_id(@team_member)}").effect("highlight", {color: "#529214"}, 1000);; $("##{dom_id(@user_project_relation)}").effect("highlight", {color: "#529214"}, 1000);;
- else - else
:plain :plain
$("##{dom_id(@team_member)}").effect("highlight", {color: "#D12F19"}, 1000);; $("##{dom_id(@user_project_relation)}").effect("highlight", {color: "#D12F19"}, 1000);;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment