BigW Consortium Gitlab

Commit f6f414ce by Andrey Kumanyaev Committed by Dmitriy Zaporozhets

refactoring project team members controller (corresponding mental model)

parent ccf8fa4f
......@@ -7,12 +7,12 @@ class TeamMembersController < ProjectResourceController
end
def show
@team_member = project.users_projects.find(params[:id])
@events = @team_member.user.recent_events.where(:project_id => @project.id).limit(7)
@user_project_relation = project.users_projects.find_by_user_id(member)
@events = member.recent_events.in_projects(project).limit(7)
end
def new
@team_member = project.users_projects.new
@user_project_relation = project.users_projects.new
end
def create
......@@ -28,18 +28,18 @@ class TeamMembersController < ProjectResourceController
end
def update
@team_member = project.users_projects.find(params[:id])
@team_member.update_attributes(params[:team_member])
@user_project_relation = project.users_projects.find_by_user_id(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"
end
redirect_to project_team_index_path(@project)
end
def destroy
@team_member = project.users_projects.find(params[:id])
@team_member.destroy
@user_project_relation = project.users_projects.find_by_user_id(params[:id])
@user_project_relation.destroy
respond_to do |format|
format.html { redirect_to project_team_index_path(@project) }
......@@ -54,4 +54,10 @@ class TeamMembersController < ProjectResourceController
redirect_to project_team_members_path(project), notice: notice
end
protected
def member
@member ||= User.find(params[:id])
end
end
......@@ -3,8 +3,8 @@ module ProjectsHelper
@project.users_projects.sort_by(&:project_access).reverse.group_by(&:project_access)
end
def remove_from_team_message(project, member)
"You are going to remove #{member.user_name} from #{project.name}. Are you sure?"
def remove_from_project_team_message(project, user)
"You are going to remove #{user.name} from #{project.name} project team. Are you sure?"
end
def link_to_project project
......
%h3.page_title
= "New Team member(s)"
%hr
= form_for @team_member, as: :team_member, url: project_team_members_path(@project, @team_member) do |f|
-if @team_member.errors.any?
= form_for @user_project_relation, as: :team_member, url: project_team_members_path(@project) do |f|
-if @user_project_relation.errors.any?
.alert-message.block-message.error
%ul
- @team_member.errors.full_messages.each do |msg|
- @user_project_relation.errors.full_messages.each do |msg|
%li= msg
%h6 1. Choose people you want in the team
......@@ -16,7 +16,7 @@
%h6 2. Set access level for them
.clearfix
= 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
= f.submit 'Save', class: "btn save-btn"
......
- user = member.user
- 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
.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"
= 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)
%br
%small.cgray= user.email
......@@ -13,7 +13,7 @@
.span5.right
- if allow_admin
.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"
.right
- if current_user == user
......@@ -23,6 +23,6 @@
- elsif user.blocked
%span.btn.disabled.blocked Blocked
- 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
- if @team_member.valid?
- if @user_project_relation.valid?
:plain
$("#new_team_member").hide("slide", { direction: "right" }, 150, function(){
$("#team-table").show("slide", { direction: "left" }, 150, function() {
......
= render "projects/project_head"
%h3.page_title
Team Members
(#{@project.users_projects.count})
(#{@project.users.count})
%small
Read more about project permissions
%strong= link_to "here", help_permissions_path, class: "vlink"
......
- allow_admin = can? current_user, :admin_project, @project
- user = @team_member.user
.team_member_show
- 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
= image_tag gravatar_icon(user.email, 60), class: "borders"
= image_tag gravatar_icon(@member.email, 60), class: "borders"
%h3.page_title
= user.name
%small (@#{user.username})
= @member.name
%small (@#{@member.username})
%hr
.back_link
......@@ -21,34 +20,34 @@
%table.lite
%tr
%td Email
%td= mail_to user.email
%td= mail_to @member.email
%tr
%td Skype
%td= user.skype
- unless user.linkedin.blank?
%td= @member.skype
- unless @member.linkedin.blank?
%tr
%td LinkedIn
%td= user.linkedin
- unless user.twitter.blank?
%td= @member.linkedin
- unless @member.twitter.blank?
%tr
%td Twitter
%td= user.twitter
- unless user.bio.blank?
%td= @member.twitter
- unless @member.bio.blank?
%tr
%td Bio
%td= user.bio
%td= @member.bio
.span6
%table.lite
%tr
%td Member since
%td= @team_member.created_at.stamp("Aug 21, 2011")
%td= @user_project_relation.created_at.stamp("Aug 21, 2011")
%tr
%td
Project Access:
%small (#{link_to "read more", help_permissions_path, class: "vlink"})
%td
= form_for(@team_member, as: :team_member, url: project_team_member_path(@project, @team_member)) do |f|
= f.select :project_access, options_for_select(Project.access_options, @team_member.project_access), {}, class: "project-access-select", disabled: !allow_admin
= 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, @user_project_relation.project_access), {}, class: "project-access-select", disabled: !allow_admin
%hr
= render @events
:javascript
......
- if @team_member.valid?
- if @user_project_relation.valid?
:plain
$("##{dom_id(@team_member)}").effect("highlight", {color: "#529214"}, 1000);;
$("##{dom_id(@user_project_relation)}").effect("highlight", {color: "#529214"}, 1000);;
- else
: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